Skip to content

Commit a8d8cd9

Browse files
griffjiangliu
authored andcommitted
abi: Disable unsupported flags and functionality on MacOS
MacFUSE is a fork of FUSE version 19 with its own custom flags that sometimes clash with later versions of FUSE. E.g. INIT_EXT flags clashes with MacFUSE flag VOL_RENAME. So to avoid confussion this change splits fuse_abi into fuse_abi_linux and fuse_abi_macos and hopefully disables all functionality not supported on MacOS. This applies both to MacFUSE and FUSE-T because FUSE-T is built to be compatible with MacFUSE and not upstream FUSE. Signed-off-by: Brian Olsen <[email protected]>
1 parent 890e5b1 commit a8d8cd9

File tree

8 files changed

+1221
-146
lines changed

8 files changed

+1221
-146
lines changed

src/abi/fuse_abi.rs renamed to src/abi/fuse_abi_linux.rs

+2-75
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,16 @@ use std::mem;
1212
use bitflags::bitflags;
1313
use vm_memory::ByteValued;
1414

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

21-
#[cfg(target_os = "macos")]
22-
pub use libc::{
23-
blksize_t, dev_t, ino_t as ino64_t, mode_t, nlink_t, off_t as off64_t, pread as pread64,
24-
preadv as preadv64, pwrite as pwrite64, pwritev as pwritev64, stat as stat64,
25-
statvfs as statvfs64,
26-
};
27-
2820
/// Version number of this interface.
2921
pub const KERNEL_VERSION: u32 = 7;
3022

3123
/// Minor version number of this interface.
32-
#[cfg(target_os = "linux")]
3324
pub const KERNEL_MINOR_VERSION: u32 = 33;
34-
#[cfg(target_os = "macos")]
35-
pub const KERNEL_MINOR_VERSION: u32 = 19;
3625

3726
/// Init reply size is FUSE_COMPAT_INIT_OUT_SIZE
3827
pub const KERNEL_MINOR_VERSION_INIT_OUT_SIZE: u32 = 5;
@@ -571,25 +560,16 @@ pub struct Attr {
571560
pub atime: u64,
572561
pub mtime: u64,
573562
pub ctime: u64,
574-
#[cfg(target_os = "macos")]
575-
pub crtime: u64,
576563
pub atimensec: u32,
577564
pub mtimensec: u32,
578565
pub ctimensec: u32,
579-
#[cfg(target_os = "macos")]
580-
pub crtimensec: u32,
581566
pub mode: u32,
582567
pub nlink: u32,
583568
pub uid: u32,
584569
pub gid: u32,
585570
pub rdev: u32,
586-
#[cfg(target_os = "macos")]
587-
pub flags: u32,
588571
pub blksize: u32,
589-
#[cfg(target_os = "linux")]
590572
pub flags: u32,
591-
#[cfg(target_os = "macos")]
592-
pub padding: u32,
593573
}
594574
unsafe impl ByteValued for Attr {}
595575

@@ -611,39 +591,19 @@ impl Attr {
611591
atimensec: st.st_atime_nsec as u32,
612592
mtimensec: st.st_mtime_nsec as u32,
613593
ctimensec: st.st_ctime_nsec as u32,
614-
#[cfg(target_os = "linux")]
615594
mode: st.st_mode,
616-
#[cfg(target_os = "macos")]
617-
mode: st.st_mode as u32,
618595
// In Linux st.st_nlink is u64 on x86_64 and powerpc64, and u32 on other architectures
619-
// In macos, st_nlink is always u16
620596
// ref:
621597
// linux: https://github.com/rust-lang/rust/blob/1.69.0/library/std/src/os/linux/raw.rs#L333
622-
// macos: https://github.com/rust-lang/rust/blob/1.69.0/library/std/src/os/macos/raw.rs#L44
623-
#[cfg(any(
624-
target_os = "macos",
625-
all(
626-
target_os = "linux",
627-
any(target_arch = "x86_64", target_arch = "powerpc64")
628-
)
629-
))]
598+
#[cfg(any(target_arch = "x86_64", target_arch = "powerpc64"))]
630599
nlink: st.st_nlink as u32,
631-
#[cfg(all(
632-
target_os = "linux",
633-
not(any(target_arch = "x86_64", target_arch = "powerpc64"))
634-
))]
600+
#[cfg(not(any(target_arch = "x86_64", target_arch = "powerpc64")))]
635601
nlink: st.st_nlink,
636602
uid: st.st_uid,
637603
gid: st.st_gid,
638604
rdev: st.st_rdev as u32,
639605
blksize: st.st_blksize as u32,
640606
flags,
641-
#[cfg(target_os = "macos")]
642-
crtime: 0,
643-
#[cfg(target_os = "macos")]
644-
crtimensec: 0,
645-
#[cfg(target_os = "macos")]
646-
padding: 0,
647607
}
648608
}
649609
}
@@ -689,7 +649,6 @@ pub struct Kstatfs {
689649
unsafe impl ByteValued for Kstatfs {}
690650

691651
impl From<statvfs64> for Kstatfs {
692-
#[cfg(target_os = "linux")]
693652
fn from(st: statvfs64) -> Self {
694653
Kstatfs {
695654
blocks: st.f_blocks,
@@ -703,21 +662,6 @@ impl From<statvfs64> for Kstatfs {
703662
..Default::default()
704663
}
705664
}
706-
707-
#[cfg(target_os = "macos")]
708-
fn from(st: statvfs64) -> Self {
709-
Kstatfs {
710-
blocks: st.f_blocks as u64,
711-
bfree: st.f_bfree as u64,
712-
bavail: st.f_bavail as u64,
713-
files: st.f_files as u64,
714-
ffree: st.f_ffree as u64,
715-
bsize: st.f_bsize as u32,
716-
namelen: st.f_namemax as u32,
717-
frsize: st.f_frsize as u32,
718-
..Default::default()
719-
}
720-
}
721665
}
722666

723667
#[repr(C)]
@@ -885,10 +829,6 @@ unsafe impl ByteValued for MkdirIn {}
885829
#[derive(Debug, Default, Copy, Clone)]
886830
pub struct RenameIn {
887831
pub newdir: u64,
888-
#[cfg(target_os = "macos")]
889-
pub flags: u32,
890-
#[cfg(target_os = "macos")]
891-
pub padding: u32,
892832
}
893833
unsafe impl ByteValued for RenameIn {}
894834

@@ -1059,10 +999,6 @@ unsafe impl ByteValued for SetxattrIn {}
1059999
pub struct GetxattrIn {
10601000
pub size: u32,
10611001
pub padding: u32,
1062-
#[cfg(target_os = "macos")]
1063-
pub position: u32,
1064-
#[cfg(target_os = "macos")]
1065-
pub padding2: u32,
10661002
}
10671003
unsafe impl ByteValued for GetxattrIn {}
10681004

@@ -1377,24 +1313,15 @@ mod tests {
13771313

13781314
#[test]
13791315
fn test_struct_size() {
1380-
#[cfg(target_os = "linux")]
13811316
assert_eq!(std::mem::size_of::<Attr>(), 88);
1382-
#[cfg(target_os = "macos")]
1383-
assert_eq!(std::mem::size_of::<Attr>(), 104);
13841317
assert_eq!(std::mem::size_of::<Kstatfs>(), 80);
13851318
assert_eq!(std::mem::size_of::<FileLock>(), 24);
1386-
#[cfg(target_os = "linux")]
13871319
assert_eq!(std::mem::size_of::<EntryOut>(), 128);
1388-
#[cfg(target_os = "macos")]
1389-
assert_eq!(std::mem::size_of::<EntryOut>(), 144);
13901320
assert_eq!(std::mem::size_of::<ForgetIn>(), 8);
13911321
assert_eq!(std::mem::size_of::<ForgetOne>(), 16);
13921322
assert_eq!(std::mem::size_of::<BatchForgetIn>(), 8);
13931323
assert_eq!(std::mem::size_of::<GetattrIn>(), 16);
1394-
#[cfg(target_os = "linux")]
13951324
assert_eq!(std::mem::size_of::<AttrOut>(), 104);
1396-
#[cfg(target_os = "macos")]
1397-
assert_eq!(std::mem::size_of::<AttrOut>(), 120);
13981325
assert_eq!(std::mem::size_of::<MknodIn>(), 16);
13991326
assert_eq!(std::mem::size_of::<MkdirIn>(), 8);
14001327
assert_eq!(std::mem::size_of::<InHeader>(), 40);

0 commit comments

Comments
 (0)