@@ -46,7 +46,7 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
46
46
fn ensure_file_flags < ' a > (
47
47
& self ,
48
48
data : & ' a Arc < HandleData > ,
49
- file : & File ,
49
+ fd : & impl AsRawFd ,
50
50
mut flags : u32 ,
51
51
) -> io:: Result < FileFlagGuard < ' a , u32 > > {
52
52
let guard = data. open_flags . read ( ) . unwrap ( ) ;
@@ -63,7 +63,7 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
63
63
} else {
64
64
flags = * guard & !libc:: O_DIRECT as u32 ;
65
65
}
66
- let ret = unsafe { libc:: fcntl ( file . as_raw_fd ( ) , libc:: F_SETFL , flags) } ;
66
+ let ret = unsafe { libc:: fcntl ( fd . as_raw_fd ( ) , libc:: F_SETFL , flags) } ;
67
67
if ret != 0 {
68
68
return Err ( io:: Error :: last_os_error ( ) ) ;
69
69
}
@@ -134,8 +134,7 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
134
134
135
135
let ( front, back) = rem. split_at ( size_of :: < LinuxDirent64 > ( ) ) ;
136
136
137
- let dirent64 = LinuxDirent64 :: from_slice ( front)
138
- . expect ( "fuse: unable to get LinuxDirent64 from slice" ) ;
137
+ let dirent64 = LinuxDirent64 :: from_slice ( front) . ok_or_else ( einval) ?;
139
138
140
139
let namelen = dirent64. d_reclen as usize - size_of :: < LinuxDirent64 > ( ) ;
141
140
debug_assert ! (
@@ -677,16 +676,14 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
677
676
flags : u32 ,
678
677
) -> io:: Result < usize > {
679
678
let data = self . get_data ( handle, inode, libc:: O_RDONLY ) ?;
679
+ let fd = data. borrow_fd ( ) ;
680
+
681
+ self . ensure_file_flags ( & data, & fd, flags) ?;
680
682
681
683
// Manually implement File::try_clone() by borrowing fd of data.file instead of dup().
682
684
// It's safe because the `data` variable's lifetime spans the whole function,
683
685
// so data.file won't be closed.
684
- let f = unsafe { File :: from_raw_fd ( data. borrow_fd ( ) . as_raw_fd ( ) ) } ;
685
-
686
- self . ensure_file_flags ( & data, & f, flags) ?;
687
-
688
- let mut f = ManuallyDrop :: new ( f) ;
689
-
686
+ let mut f = unsafe { ManuallyDrop :: new ( File :: from_raw_fd ( fd. as_raw_fd ( ) ) ) } ;
690
687
w. write_from ( & mut * f, size as usize , offset)
691
688
}
692
689
@@ -704,21 +701,14 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
704
701
fuse_flags : u32 ,
705
702
) -> io:: Result < usize > {
706
703
let data = self . get_data ( handle, inode, libc:: O_RDWR ) ?;
704
+ let fd = data. borrow_fd ( ) ;
707
705
708
- // Manually implement File::try_clone() by borrowing fd of data.file instead of dup().
709
- // It's safe because the `data` variable's lifetime spans the whole function,
710
- // so data.file won't be closed.
711
- let f = unsafe { File :: from_raw_fd ( data. borrow_fd ( ) . as_raw_fd ( ) ) } ;
712
-
713
- self . ensure_file_flags ( & data, & f, flags) ?;
714
-
706
+ self . ensure_file_flags ( & data, & fd, flags) ?;
715
707
if self . seal_size . load ( Ordering :: Relaxed ) {
716
- let st = stat_fd ( & f , None ) ?;
708
+ let st = stat_fd ( & fd , None ) ?;
717
709
self . seal_size_check ( Opcode :: Write , st. st_size as u64 , offset, size as u64 , 0 ) ?;
718
710
}
719
711
720
- let mut f = ManuallyDrop :: new ( f) ;
721
-
722
712
// Cap restored when _killpriv is dropped
723
713
let _killpriv =
724
714
if self . killpriv_v2 . load ( Ordering :: Relaxed ) && ( fuse_flags & WRITE_KILL_PRIV != 0 ) {
@@ -727,6 +717,10 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
727
717
None
728
718
} ;
729
719
720
+ // Manually implement File::try_clone() by borrowing fd of data.file instead of dup().
721
+ // It's safe because the `data` variable's lifetime spans the whole function,
722
+ // so data.file won't be closed.
723
+ let mut f = unsafe { ManuallyDrop :: new ( File :: from_raw_fd ( fd. as_raw_fd ( ) ) ) } ;
730
724
r. read_to ( & mut * f, size as usize , offset)
731
725
}
732
726
0 commit comments