Remove file size from authfs flags
authfs used to take flags like `--remote-unverified-file 5:10:40960`
where the 40969 is the file size provided by the client. The intention
is that since the file is readonly, we can set up the FUSE with the
information ready, and avoid requesting the size on every stat(2)-like
syscall.
It's just that this make it harder to use for authfs' clients. This
change remove the needs for the clients to provide the size. Instead,
authfs internally just query fd_server before starting the FUSE.
Bug: 198824883
Test: atest AuthFsHostTest ComposHostTestCases
Change-Id: I9b26b6e13bfa170d766a2428cb485d97e0423e13
diff --git a/authfs/fd_server/src/main.rs b/authfs/fd_server/src/main.rs
index d63fe93..4f17c83 100644
--- a/authfs/fd_server/src/main.rs
+++ b/authfs/fd_server/src/main.rs
@@ -27,6 +27,9 @@
mod fsverity;
+use anyhow::{bail, Context, Result};
+use binder::unstable_api::AsNative;
+use log::{debug, error};
use std::cmp::min;
use std::collections::BTreeMap;
use std::convert::TryInto;
@@ -36,12 +39,9 @@
use std::os::unix::fs::FileExt;
use std::os::unix::io::{AsRawFd, FromRawFd};
-use anyhow::{bail, Context, Result};
-use binder::unstable_api::AsNative;
-use log::{debug, error};
-
use authfs_aidl_interface::aidl::com::android::virt::fs::IVirtFdService::{
- BnVirtFdService, IVirtFdService, ERROR_IO, ERROR_UNKNOWN_FD, MAX_REQUESTING_DATA,
+ BnVirtFdService, IVirtFdService, ERROR_FILE_TOO_LARGE, ERROR_IO, ERROR_UNKNOWN_FD,
+ MAX_REQUESTING_DATA,
};
use authfs_aidl_interface::binder::{
add_service, BinderFeatures, ExceptionCode, Interface, ProcessState, Result as BinderResult,
@@ -226,6 +226,30 @@
}
}
}
+
+ fn getFileSize(&self, id: i32) -> BinderResult<i64> {
+ match &self.get_file_config(id)? {
+ FdConfig::Readonly { file, .. } => {
+ let size = file
+ .metadata()
+ .map_err(|e| {
+ error!("getFileSize error: {}", e);
+ Status::from(ERROR_IO)
+ })?
+ .len();
+ Ok(size.try_into().map_err(|e| {
+ error!("getFileSize: File too large: {}", e);
+ Status::from(ERROR_FILE_TOO_LARGE)
+ })?)
+ }
+ FdConfig::ReadWrite(_file) => {
+ // Content and metadata of a writable file needs to be tracked by authfs, since
+ // fd_server isn't considered trusted. So there is no point to support getFileSize
+ // for a writable file.
+ Err(new_binder_exception(ExceptionCode::UNSUPPORTED_OPERATION, "Unsupported"))
+ }
+ }
+ }
}
fn read_into_buf(file: &File, max_size: usize, offset: u64) -> io::Result<Vec<u8>> {