Assign inode values properly in AuthFS
Previously, inode_table provides inode -> entry mapping, and the inode
value is derived from the entry name, which is supposed to be the remote
FD value. That is, remote FD was equal to the filesystem entry name as
string and the actual inode value inside the filesystem.
This change makes inode an internal notion in the filesystem, which is
really the correct way. When a client provides the path -> entry mapping
(root_entries), AuthFS now breaks it into two mappings (see below) and
assigns the inode for its own internal purpose.
To look up an entry in to root directory, we use the path -> inode
table (root_entries) to find the inode, then look for the actual entry
with the inode -> entry table (inode_table).
This gives us the freedom to add more inodes without risking breaking
existing entries. It also makes it possible to create inodes not
backing by a remote FD. For example, later we could open file by path
like "framework/framework.jar" relative to a path FD of /system on the
host side. That is, we wouldn't necessarily need to open
"/system/framework" and create an inode, then use that inode to open
"framework.jar".
Bug: 203251769
Test: atest AuthFsHostTest
Change-Id: I49b222b91002da12a25fbf03b0c6285f0223f16b
diff --git a/authfs/src/main.rs b/authfs/src/main.rs
index 432cfab..f6a2a56 100644
--- a/authfs/src/main.rs
+++ b/authfs/src/main.rs
@@ -29,7 +29,7 @@
use anyhow::{bail, Context, Result};
use log::error;
-use std::collections::BTreeMap;
+use std::collections::HashMap;
use std::convert::TryInto;
use std::path::PathBuf;
use structopt::StructOpt;
@@ -44,7 +44,7 @@
use auth::FakeAuthenticator;
use file::{RemoteDirEditor, RemoteFileEditor, RemoteFileReader, RemoteMerkleTreeReader};
use fsverity::{VerifiedFileEditor, VerifiedFileReader};
-use fusefs::{AuthFsEntry, Inode};
+use fusefs::AuthFsEntry;
#[derive(StructOpt)]
struct Args {
@@ -160,14 +160,14 @@
Ok(AuthFsEntry::VerifiedNewDirectory { dir })
}
-fn prepare_root_dir_entries(args: &Args) -> Result<BTreeMap<Inode, AuthFsEntry>> {
- let mut root_entries = BTreeMap::new();
+fn prepare_root_dir_entries(args: &Args) -> Result<HashMap<PathBuf, AuthFsEntry>> {
+ let mut root_entries = HashMap::new();
let service = file::get_rpc_binder_service(args.cid)?;
for config in &args.remote_ro_file {
root_entries.insert(
- config.remote_fd.try_into()?,
+ remote_fd_to_path_buf(config.remote_fd),
new_remote_verified_file_entry(
service.clone(),
config.remote_fd,
@@ -179,7 +179,7 @@
for remote_fd in &args.remote_ro_file_unverified {
let remote_fd = *remote_fd;
root_entries.insert(
- remote_fd.try_into()?,
+ remote_fd_to_path_buf(remote_fd),
new_remote_unverified_file_entry(
service.clone(),
remote_fd,
@@ -191,7 +191,7 @@
for remote_fd in &args.remote_new_rw_file {
let remote_fd = *remote_fd;
root_entries.insert(
- remote_fd.try_into()?,
+ remote_fd_to_path_buf(remote_fd),
new_remote_new_verified_file_entry(service.clone(), remote_fd)?,
);
}
@@ -199,7 +199,7 @@
for remote_fd in &args.remote_new_rw_dir {
let remote_fd = *remote_fd;
root_entries.insert(
- remote_fd.try_into()?,
+ remote_fd_to_path_buf(remote_fd),
new_remote_new_verified_dir_entry(service.clone(), remote_fd)?,
);
}
@@ -207,6 +207,10 @@
Ok(root_entries)
}
+fn remote_fd_to_path_buf(fd: i32) -> PathBuf {
+ PathBuf::from(fd.to_string())
+}
+
fn try_main() -> Result<()> {
let args = Args::from_args();