From 8e2c9e5b64f42405e414bfb236dabd3b4e007d14 Mon Sep 17 00:00:00 2001 From: Jiang Liu Date: Wed, 25 Oct 2023 22:34:29 +0800 Subject: [PATCH] macos: clean up code related to macos Clean up code related to macos. Follow up of https://github.com/cloud-hypervisor/fuse-backend-rs/pull/162 Signed-off-by: Jiang Liu --- src/api/server/sync_io.rs | 6 ++--- src/api/vfs/mod.rs | 47 ++++++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/api/server/sync_io.rs b/src/api/server/sync_io.rs index 990df423c..8904b2d07 100644 --- a/src/api/server/sync_io.rs +++ b/src/api/server/sync_io.rs @@ -696,10 +696,8 @@ impl Server { return ctx.reply_ok(Some(out), None); } - #[cfg(not(target_os = "macos"))] - let mut flags_u64 = flags as u64; - #[cfg(target_os = "macos")] - let flags_u64 = flags as u64; + let mut flags_u64; + flags_u64 = flags as u64; #[cfg(not(target_os = "macos"))] if flags_u64 & FsOptions::INIT_EXT.bits() != 0 { let InitIn2 { flags2, unused: _ } = ctx.r.read_obj().map_err(Error::DecodeMessage)?; diff --git a/src/api/vfs/mod.rs b/src/api/vfs/mod.rs index 7aee1c34b..8210e7458 100644 --- a/src/api/vfs/mod.rs +++ b/src/api/vfs/mod.rs @@ -220,6 +220,20 @@ struct MountPointData { #[derive(Debug, Copy, Clone)] /// vfs init options pub struct VfsOptions { + /// Make readdir/readdirplus request return zero dirent even if dir has children. + pub no_readdir: bool, + /// Reject requests which will change the file size, or allocate file + /// blocks exceed file size. + pub seal_size: bool, + /// File system options passed in from client + pub in_opts: FsOptions, + /// File system options returned to client + pub out_opts: FsOptions, + /// Declaration of ID mapping, in the format (internal ID, external ID, range). + /// For example, (0, 1, 65536) represents mapping the external UID/GID range of `1~65536` + /// to the range of `0~65535` within the filesystem. + pub id_mapping: (u32, u32, u32), + /// Disable fuse open request handling. When enabled, fuse open /// requests are always replied with ENOSYS. #[cfg(not(target_os = "macos"))] @@ -232,24 +246,11 @@ pub struct VfsOptions { /// buffer writes. #[cfg(not(target_os = "macos"))] pub no_writeback: bool, - /// Make readdir/readdirplus request return zero dirent even if dir has children. - pub no_readdir: bool, /// Enable fuse killpriv_v2 support. When enabled, fuse file system makes sure /// to remove security.capability xattr and setuid/setgid bits. See details in /// comments for HANDLE_KILLPRIV_V2 #[cfg(not(target_os = "macos"))] pub killpriv_v2: bool, - /// Reject requests which will change the file size, or allocate file - /// blocks exceed file size. - pub seal_size: bool, - /// File system options passed in from client - pub in_opts: FsOptions, - /// File system options returned to client - pub out_opts: FsOptions, - /// Declaration of ID mapping, in the format (internal ID, external ID, range). - /// For example, (0, 1, 65536) represents mapping the external UID/GID range of `1~65536` - /// to the range of `0~65535` within the filesystem. - pub id_mapping: (u32, u32, u32), } impl VfsOptions { @@ -259,8 +260,8 @@ impl VfsOptions { } impl Default for VfsOptions { + #[cfg(not(target_os = "macos"))] fn default() -> Self { - #[cfg(not(target_os = "macos"))] let out_opts = FsOptions::ASYNC_READ | FsOptions::PARALLEL_DIROPS | FsOptions::BIG_WRITES @@ -278,24 +279,30 @@ impl Default for VfsOptions { | FsOptions::ZERO_MESSAGE_OPENDIR | FsOptions::HANDLE_KILLPRIV_V2 | FsOptions::PERFILE_DAX; - #[cfg(target_os = "macos")] - let out_opts = FsOptions::ASYNC_READ | FsOptions::BIG_WRITES | FsOptions::ATOMIC_O_TRUNC; VfsOptions { - #[cfg(not(target_os = "macos"))] no_open: true, - #[cfg(not(target_os = "macos"))] no_opendir: true, - #[cfg(not(target_os = "macos"))] no_writeback: false, no_readdir: false, seal_size: false, - #[cfg(not(target_os = "macos"))] killpriv_v2: false, in_opts: FsOptions::empty(), out_opts, id_mapping: (0, 0, 0), } } + + #[cfg(target_os = "macos")] + fn default() -> Self { + let out_opts = FsOptions::ASYNC_READ | FsOptions::BIG_WRITES | FsOptions::ATOMIC_O_TRUNC; + VfsOptions { + no_readdir: false, + seal_size: false, + in_opts: FsOptions::empty(), + out_opts, + id_mapping: (0, 0, 0), + } + } } /// A union fs that combines multiple backend file systems.