Root dir of zipfuse gets permission 500
In preparation for enabling `-o default_permissions` the root directory
of a zipfuse filesystem gets the permission mode of 500 so that it is
readable and searchable by the owner.
Bug: 264668376
Test: `ls -al /mnt` inside the VM gives the following:
```
total 4
drwxr-xr-x 9 root system 180 2023-01-09 08:43 .
drwxr-xr-x 14 root root 4096 2021-01-25 10:14 ..
drwxr-xr-x 2 root root 40 2023-01-09 08:43 androidwritable
dr-x------ 6 root root 0 1970-01-01 00:00 apk
...
```
Previously, the mode for `apk` was `d---------`.
Change-Id: I2a2513adfd708a93b66dcb70630aeda5036689cc
diff --git a/zipfuse/src/inode.rs b/zipfuse/src/inode.rs
index 6a61924..3edbc49 100644
--- a/zipfuse/src/inode.rs
+++ b/zipfuse/src/inode.rs
@@ -31,6 +31,11 @@
const INVALID: Inode = 0;
const ROOT: Inode = 1;
+const DEFAULT_DIR_MODE: u32 = libc::S_IRUSR | libc::S_IXUSR;
+// b/264668376 some files in APK don't have unix permissions specified. Default to 400
+// otherwise those files won't be readable even by the owner.
+const DEFAULT_FILE_MODE: u32 = libc::S_IRUSR;
+
/// `InodeData` represents an inode which has metadata about a file or a directory
#[derive(Debug)]
pub struct InodeData {
@@ -95,9 +100,6 @@
}
fn new_file(zip_index: ZipIndex, zip_file: &zip::read::ZipFile) -> InodeData {
- // b/264668376 some files in APK don't have unix permissions specified. Default to 400
- // otherwise those files won't be readable even by the owner.
- const DEFAULT_FILE_MODE: u32 = libc::S_IRUSR;
InodeData {
mode: zip_file.unix_mode().unwrap_or(DEFAULT_FILE_MODE),
size: zip_file.size(),
@@ -172,7 +174,7 @@
// Add the inodes for the invalid and the root directory
assert_eq!(INVALID, table.put(InodeData::new_dir(0)));
- assert_eq!(ROOT, table.put(InodeData::new_dir(0)));
+ assert_eq!(ROOT, table.put(InodeData::new_dir(DEFAULT_DIR_MODE)));
// For each zip file in the archive, create an inode and add it to the table. If the file's
// parent directories don't have corresponding inodes in the table, handle them too.
@@ -203,13 +205,11 @@
// Update the mode if this is a directory leaf.
if !is_file && is_leaf {
let mut inode = table.get_mut(parent).unwrap();
- inode.mode = file.unix_mode().unwrap_or(0);
+ inode.mode = file.unix_mode().unwrap_or(DEFAULT_DIR_MODE);
}
continue;
}
- const DEFAULT_DIR_MODE: u32 = libc::S_IRUSR | libc::S_IXUSR;
-
// No inode found. Create a new inode and add it to the inode table.
let inode = if is_file {
InodeData::new_file(i, &file)