Implement root directory as a ReadonlyDirectory
This makes the handling in `lookup` consistent without having to deal
with inode 1 as a special case.
AuthFs is now initialized outside of fusefs module, in order to allow
the caller to add named entries to the filesystem's root directory more
directly.
The `ReadonlyDirectory` can also be used later to support remote
readonly directory.
Bug: 203251769
Test: atest AuthFsHostTest
Change-Id: Ia27f7f3c2f39d48559c329f6a086408745fbc3d9
diff --git a/authfs/src/file.rs b/authfs/src/file.rs
index bbe5e6c..6353209 100644
--- a/authfs/src/file.rs
+++ b/authfs/src/file.rs
@@ -1,12 +1,13 @@
-mod remote_dir;
+mod dir;
mod remote_file;
-pub use remote_dir::RemoteDirEditor;
+pub use dir::{InMemoryDir, RemoteDirEditor};
pub use remote_file::{RemoteFileEditor, RemoteFileReader, RemoteMerkleTreeReader};
use binder::unstable_api::{new_spibinder, AIBinder};
use binder::FromIBinder;
use std::io;
+use std::path::{Path, MAIN_SEPARATOR};
use crate::common::CHUNK_SIZE;
use authfs_aidl_interface::aidl::com::android::virt::fs::IVirtFdService::IVirtFdService;
@@ -71,3 +72,12 @@
/// Resizes the file to the new size.
fn resize(&self, size: u64) -> io::Result<()>;
}
+
+/// Checks whether the path is a simple file name without any directory separator.
+pub fn validate_basename(path: &Path) -> io::Result<()> {
+ if matches!(path.to_str(), Some(path_str) if !path_str.contains(MAIN_SEPARATOR)) {
+ Ok(())
+ } else {
+ Err(io::Error::from_raw_os_error(libc::EINVAL))
+ }
+}