88use std:: ffi:: { CStr , CString } ;
99use std:: fs:: File ;
1010use std:: io;
11- use std:: mem:: { self , size_of, ManuallyDrop , MaybeUninit } ;
11+ #[ cfg( target_os = "linux" ) ]
12+ use std:: mem:: size_of;
13+ use std:: mem:: { self , ManuallyDrop , MaybeUninit } ;
1214use std:: os:: unix:: io:: { AsRawFd , FromRawFd , RawFd } ;
1315use std:: sync:: atomic:: Ordering ;
1416use std:: sync:: Arc ;
@@ -19,9 +21,9 @@ use super::os_compat::LinuxDirent64;
1921#[ cfg( target_os = "linux" ) ]
2022use super :: util:: stat_fd;
2123use super :: * ;
24+ use crate :: abi:: fuse_abi:: { CreateIn , Opcode } ;
2225#[ cfg( target_os = "linux" ) ]
23- use crate :: abi:: fuse_abi:: WRITE_KILL_PRIV ;
24- use crate :: abi:: fuse_abi:: { CreateIn , Opcode , FOPEN_IN_KILL_SUIDGID } ;
26+ use crate :: abi:: fuse_abi:: { FOPEN_IN_KILL_SUIDGID , WRITE_KILL_PRIV } ;
2527#[ cfg( any( feature = "vhost-user-fs" , feature = "virtiofs" ) ) ]
2628use crate :: abi:: virtio_fs;
2729use crate :: api:: filesystem:: {
@@ -224,7 +226,10 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
224226 add_entry (
225227 DirEntry {
226228 ino : dirent. d_ino ,
229+ #[ cfg( target_os = "linux" ) ]
227230 offset : dirent. d_seekoff as u64 ,
231+ #[ cfg( target_os = "macos" ) ]
232+ offset : dirent. d_seekoff ,
228233 type_ : dirent. d_type as u32 ,
229234 name,
230235 } ,
@@ -252,7 +257,8 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
252257 & self ,
253258 inode : Inode ,
254259 flags : u32 ,
255- fuse_flags : u32 ,
260+ #[ cfg( target_os = "linux" ) ] fuse_flags : u32 ,
261+ #[ cfg( target_os = "macos" ) ] _fuse_flags : u32 ,
256262 ) -> io:: Result < ( Option < Handle > , OpenOptions , Option < u32 > ) > {
257263 #[ cfg( target_os = "linux" ) ]
258264 let killpriv = if self . killpriv_v2 . load ( Ordering :: Relaxed )
@@ -392,52 +398,58 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
392398 type Inode = Inode ;
393399 type Handle = Handle ;
394400
401+ #[ cfg( target_os = "linux" ) ]
395402 fn init ( & self , capable : FsOptions ) -> io:: Result < FsOptions > {
396403 if self . cfg . do_import {
397404 self . import ( ) ?;
398405 }
399406
400- #[ cfg( target_os = "linux" ) ]
401407 let mut opts = FsOptions :: DO_READDIRPLUS | FsOptions :: READDIRPLUS_AUTO ;
402408 // !cfg.do_import means we are under vfs, in which case capable is already
403409 // negotiated and must be honored.
404- #[ cfg( target_os = "linux" ) ]
410+
411+ if ( !self . cfg . do_import || self . cfg . writeback )
412+ && capable. contains ( FsOptions :: WRITEBACK_CACHE )
405413 {
406- if ( !self . cfg . do_import || self . cfg . writeback )
407- && capable. contains ( FsOptions :: WRITEBACK_CACHE )
408- {
409- opts |= FsOptions :: WRITEBACK_CACHE ;
410- self . writeback . store ( true , Ordering :: Relaxed ) ;
411- }
412- if ( !self . cfg . do_import || self . cfg . no_open )
413- && capable. contains ( FsOptions :: ZERO_MESSAGE_OPEN )
414- {
415- opts |= FsOptions :: ZERO_MESSAGE_OPEN ;
416- // We can't support FUSE_ATOMIC_O_TRUNC with no_open
417- opts. remove ( FsOptions :: ATOMIC_O_TRUNC ) ;
418- self . no_open . store ( true , Ordering :: Relaxed ) ;
419- }
420- if ( !self . cfg . do_import || self . cfg . no_opendir )
421- && capable. contains ( FsOptions :: ZERO_MESSAGE_OPENDIR )
422- {
423- opts |= FsOptions :: ZERO_MESSAGE_OPENDIR ;
424- self . no_opendir . store ( true , Ordering :: Relaxed ) ;
425- }
426- if ( !self . cfg . do_import || self . cfg . killpriv_v2 )
427- && capable. contains ( FsOptions :: HANDLE_KILLPRIV_V2 )
428- {
429- opts |= FsOptions :: HANDLE_KILLPRIV_V2 ;
430- self . killpriv_v2 . store ( true , Ordering :: Relaxed ) ;
431- }
414+ opts |= FsOptions :: WRITEBACK_CACHE ;
415+ self . writeback . store ( true , Ordering :: Relaxed ) ;
416+ }
417+ if ( !self . cfg . do_import || self . cfg . no_open )
418+ && capable. contains ( FsOptions :: ZERO_MESSAGE_OPEN )
419+ {
420+ opts |= FsOptions :: ZERO_MESSAGE_OPEN ;
421+ // We can't support FUSE_ATOMIC_O_TRUNC with no_open
422+ opts. remove ( FsOptions :: ATOMIC_O_TRUNC ) ;
423+ self . no_open . store ( true , Ordering :: Relaxed ) ;
424+ }
425+ if ( !self . cfg . do_import || self . cfg . no_opendir )
426+ && capable. contains ( FsOptions :: ZERO_MESSAGE_OPENDIR )
427+ {
428+ opts |= FsOptions :: ZERO_MESSAGE_OPENDIR ;
429+ self . no_opendir . store ( true , Ordering :: Relaxed ) ;
430+ }
431+ if ( !self . cfg . do_import || self . cfg . killpriv_v2 )
432+ && capable. contains ( FsOptions :: HANDLE_KILLPRIV_V2 )
433+ {
434+ opts |= FsOptions :: HANDLE_KILLPRIV_V2 ;
435+ self . killpriv_v2 . store ( true , Ordering :: Relaxed ) ;
436+ }
432437
433- if capable. contains ( FsOptions :: PERFILE_DAX ) {
434- opts |= FsOptions :: PERFILE_DAX ;
435- self . perfile_dax . store ( true , Ordering :: Relaxed ) ;
436- }
438+ if capable. contains ( FsOptions :: PERFILE_DAX ) {
439+ opts |= FsOptions :: PERFILE_DAX ;
440+ self . perfile_dax . store ( true , Ordering :: Relaxed ) ;
437441 }
438442
439- #[ cfg( target_os = "macos" ) ]
440- let mut opts = FsOptions :: FILE_OPS ;
443+ Ok ( opts)
444+ }
445+
446+ #[ cfg( target_os = "macos" ) ]
447+ fn init ( & self , _capable : FsOptions ) -> io:: Result < FsOptions > {
448+ if self . cfg . do_import {
449+ self . import ( ) ?;
450+ }
451+
452+ let opts = FsOptions :: FILE_OPS ;
441453
442454 Ok ( opts)
443455 }
@@ -803,7 +815,8 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
803815 _lock_owner : Option < u64 > ,
804816 _delayed_write : bool ,
805817 flags : u32 ,
806- fuse_flags : u32 ,
818+ #[ cfg( target_os = "linux" ) ] fuse_flags : u32 ,
819+ #[ cfg( target_os = "macos" ) ] _fuse_flags : u32 ,
807820 ) -> io:: Result < usize > {
808821 let data = self . get_data ( handle, inode, libc:: O_RDWR ) ?;
809822
@@ -1051,7 +1064,8 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
10511064 oldname : & CStr ,
10521065 newdir : Inode ,
10531066 newname : & CStr ,
1054- flags : u32 ,
1067+ #[ cfg( target_os = "linux" ) ] flags : u32 ,
1068+ #[ cfg( target_os = "macos" ) ] _flags : u32 ,
10551069 ) -> io:: Result < ( ) > {
10561070 self . validate_path_component ( oldname) ?;
10571071 self . validate_path_component ( newname) ?;
@@ -1104,7 +1118,9 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
11041118 self . validate_path_component ( name) ?;
11051119
11061120 let data = self . inode_map . get ( parent) ?;
1121+ #[ cfg( target_os = "linux" ) ]
11071122 let file = data. get_file ( ) ?;
1123+ #[ cfg( target_os = "macos" ) ]
11081124 let pathname = data. get_path ( ) ?;
11091125
11101126 let res = {
@@ -1266,7 +1282,8 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
12661282 & self ,
12671283 _ctx : & Context ,
12681284 inode : Inode ,
1269- datasync : bool ,
1285+ #[ cfg( target_os = "linux" ) ] datasync : bool ,
1286+ #[ cfg( target_os = "macos" ) ] _datasync : bool ,
12701287 handle : Handle ,
12711288 ) -> io:: Result < ( ) > {
12721289 let data = self . get_data ( handle, inode, libc:: O_RDONLY ) ?;
@@ -1358,6 +1375,7 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
13581375 }
13591376
13601377 let data = self . inode_map . get ( inode) ?;
1378+ #[ cfg( target_os = "linux" ) ]
13611379 let file = data. get_file ( ) ?;
13621380 #[ cfg( target_os = "linux" ) ]
13631381 let pathname = CString :: new ( format ! ( "/proc/self/fd/{}" , file. as_raw_fd( ) ) )
@@ -1409,6 +1427,7 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
14091427 }
14101428
14111429 let data = self . inode_map . get ( inode) ?;
1430+ #[ cfg( target_os = "linux" ) ]
14121431 let file = data. get_file ( ) ?;
14131432 let mut buf = Vec :: < u8 > :: with_capacity ( size as usize ) ;
14141433 #[ cfg( target_os = "linux" ) ]
@@ -1460,6 +1479,7 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
14601479 }
14611480
14621481 let data = self . inode_map . get ( inode) ?;
1482+ #[ cfg( target_os = "linux" ) ]
14631483 let file = data. get_file ( ) ?;
14641484 let mut buf = Vec :: < u8 > :: with_capacity ( size as usize ) ;
14651485 #[ cfg( target_os = "linux" ) ]
@@ -1508,6 +1528,7 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
15081528 }
15091529
15101530 let data = self . inode_map . get ( inode) ?;
1531+ #[ cfg( target_os = "linux" ) ]
15111532 let file = data. get_file ( ) ?;
15121533 #[ cfg( target_os = "linux" ) ]
15131534 let pathname = CString :: new ( format ! ( "/proc/self/fd/{}" , file. as_raw_fd( ) ) )
0 commit comments