Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

abi: Disable unsupported flags and functionality on MacOS #162

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 2 additions & 75 deletions src/abi/fuse_abi.rs → src/abi/fuse_abi_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,16 @@ use std::mem;
use bitflags::bitflags;
use vm_memory::ByteValued;

#[cfg(target_os = "linux")]
pub use libc::{
blksize_t, dev_t, ino64_t, mode_t, nlink_t, off64_t, pread64, preadv64, pwrite64, pwritev64,
stat64, statvfs64,
};

#[cfg(target_os = "macos")]
pub use libc::{
blksize_t, dev_t, ino_t as ino64_t, mode_t, nlink_t, off_t as off64_t, pread as pread64,
preadv as preadv64, pwrite as pwrite64, pwritev as pwritev64, stat as stat64,
statvfs as statvfs64,
};

/// Version number of this interface.
pub const KERNEL_VERSION: u32 = 7;

/// Minor version number of this interface.
#[cfg(target_os = "linux")]
pub const KERNEL_MINOR_VERSION: u32 = 33;
#[cfg(target_os = "macos")]
pub const KERNEL_MINOR_VERSION: u32 = 19;

/// Init reply size is FUSE_COMPAT_INIT_OUT_SIZE
pub const KERNEL_MINOR_VERSION_INIT_OUT_SIZE: u32 = 5;
Expand Down Expand Up @@ -571,25 +560,16 @@ pub struct Attr {
pub atime: u64,
pub mtime: u64,
pub ctime: u64,
#[cfg(target_os = "macos")]
pub crtime: u64,
pub atimensec: u32,
pub mtimensec: u32,
pub ctimensec: u32,
#[cfg(target_os = "macos")]
pub crtimensec: u32,
pub mode: u32,
pub nlink: u32,
pub uid: u32,
pub gid: u32,
pub rdev: u32,
#[cfg(target_os = "macos")]
pub flags: u32,
pub blksize: u32,
#[cfg(target_os = "linux")]
pub flags: u32,
#[cfg(target_os = "macos")]
pub padding: u32,
}
unsafe impl ByteValued for Attr {}

Expand All @@ -611,39 +591,19 @@ impl Attr {
atimensec: st.st_atime_nsec as u32,
mtimensec: st.st_mtime_nsec as u32,
ctimensec: st.st_ctime_nsec as u32,
#[cfg(target_os = "linux")]
mode: st.st_mode,
#[cfg(target_os = "macos")]
mode: st.st_mode as u32,
// In Linux st.st_nlink is u64 on x86_64 and powerpc64, and u32 on other architectures
// In macos, st_nlink is always u16
// ref:
// linux: https://github.com/rust-lang/rust/blob/1.69.0/library/std/src/os/linux/raw.rs#L333
// macos: https://github.com/rust-lang/rust/blob/1.69.0/library/std/src/os/macos/raw.rs#L44
#[cfg(any(
target_os = "macos",
all(
target_os = "linux",
any(target_arch = "x86_64", target_arch = "powerpc64")
)
))]
#[cfg(any(target_arch = "x86_64", target_arch = "powerpc64"))]
nlink: st.st_nlink as u32,
#[cfg(all(
target_os = "linux",
not(any(target_arch = "x86_64", target_arch = "powerpc64"))
))]
#[cfg(not(any(target_arch = "x86_64", target_arch = "powerpc64")))]
nlink: st.st_nlink,
uid: st.st_uid,
gid: st.st_gid,
rdev: st.st_rdev as u32,
blksize: st.st_blksize as u32,
flags,
#[cfg(target_os = "macos")]
crtime: 0,
#[cfg(target_os = "macos")]
crtimensec: 0,
#[cfg(target_os = "macos")]
padding: 0,
}
}
}
Expand Down Expand Up @@ -689,7 +649,6 @@ pub struct Kstatfs {
unsafe impl ByteValued for Kstatfs {}

impl From<statvfs64> for Kstatfs {
#[cfg(target_os = "linux")]
fn from(st: statvfs64) -> Self {
Kstatfs {
blocks: st.f_blocks,
Expand All @@ -703,21 +662,6 @@ impl From<statvfs64> for Kstatfs {
..Default::default()
}
}

#[cfg(target_os = "macos")]
fn from(st: statvfs64) -> Self {
Kstatfs {
blocks: st.f_blocks as u64,
bfree: st.f_bfree as u64,
bavail: st.f_bavail as u64,
files: st.f_files as u64,
ffree: st.f_ffree as u64,
bsize: st.f_bsize as u32,
namelen: st.f_namemax as u32,
frsize: st.f_frsize as u32,
..Default::default()
}
}
}

#[repr(C)]
Expand Down Expand Up @@ -885,10 +829,6 @@ unsafe impl ByteValued for MkdirIn {}
#[derive(Debug, Default, Copy, Clone)]
pub struct RenameIn {
pub newdir: u64,
#[cfg(target_os = "macos")]
pub flags: u32,
#[cfg(target_os = "macos")]
pub padding: u32,
}
unsafe impl ByteValued for RenameIn {}

Expand Down Expand Up @@ -1059,10 +999,6 @@ unsafe impl ByteValued for SetxattrIn {}
pub struct GetxattrIn {
pub size: u32,
pub padding: u32,
#[cfg(target_os = "macos")]
pub position: u32,
#[cfg(target_os = "macos")]
pub padding2: u32,
}
unsafe impl ByteValued for GetxattrIn {}

Expand Down Expand Up @@ -1377,24 +1313,15 @@ mod tests {

#[test]
fn test_struct_size() {
#[cfg(target_os = "linux")]
assert_eq!(std::mem::size_of::<Attr>(), 88);
#[cfg(target_os = "macos")]
assert_eq!(std::mem::size_of::<Attr>(), 104);
assert_eq!(std::mem::size_of::<Kstatfs>(), 80);
assert_eq!(std::mem::size_of::<FileLock>(), 24);
#[cfg(target_os = "linux")]
assert_eq!(std::mem::size_of::<EntryOut>(), 128);
#[cfg(target_os = "macos")]
assert_eq!(std::mem::size_of::<EntryOut>(), 144);
assert_eq!(std::mem::size_of::<ForgetIn>(), 8);
assert_eq!(std::mem::size_of::<ForgetOne>(), 16);
assert_eq!(std::mem::size_of::<BatchForgetIn>(), 8);
assert_eq!(std::mem::size_of::<GetattrIn>(), 16);
#[cfg(target_os = "linux")]
assert_eq!(std::mem::size_of::<AttrOut>(), 104);
#[cfg(target_os = "macos")]
assert_eq!(std::mem::size_of::<AttrOut>(), 120);
assert_eq!(std::mem::size_of::<MknodIn>(), 16);
assert_eq!(std::mem::size_of::<MkdirIn>(), 8);
assert_eq!(std::mem::size_of::<InHeader>(), 40);
Expand Down
Loading
Loading