8
8
//! sequentially. A FUSE session is a connection from a FUSE mountpoint to a FUSE server daemon.
9
9
//! A FUSE session can have multiple FUSE channels so that FUSE requests are handled in parallel.
10
10
11
- use core_foundation_sys:: base:: { CFIndex , CFRelease } ;
11
+ use core_foundation_sys:: base:: { CFAllocatorRef , CFIndex , CFRelease } ;
12
12
use core_foundation_sys:: string:: { kCFStringEncodingUTF8, CFStringCreateWithBytes } ;
13
- use core_foundation_sys:: url:: { kCFURLPOSIXPathStyle, CFURLCreateWithFileSystemPath } ;
14
- use diskarbitration_sys:: base:: { kDADiskUnmountOptionForce, DADiskUnmount } ;
15
- use diskarbitration_sys:: disk:: { DADiskCreateFromVolumePath , DADiskRef } ;
16
- use diskarbitration_sys:: session:: { DASessionCreate , DASessionRef } ;
13
+ use core_foundation_sys:: url:: { kCFURLPOSIXPathStyle, CFURLCreateWithFileSystemPath , CFURLRef } ;
17
14
use std:: ffi:: CString ;
18
15
use std:: fs:: File ;
16
+ use std:: io:: IoSliceMut ;
19
17
use std:: os:: unix:: ffi:: OsStrExt ;
20
18
use std:: os:: unix:: io:: { AsRawFd , FromRawFd , RawFd } ;
21
19
use std:: path:: { Path , PathBuf } ;
@@ -27,9 +25,9 @@ use nix::errno::Errno;
27
25
use nix:: fcntl:: { fcntl, FdFlag , F_SETFD } ;
28
26
use nix:: sys:: signal:: { signal, SigHandler , Signal } ;
29
27
use nix:: sys:: socket:: {
30
- recvmsg, socketpair, AddressFamily , ControlMessageOwned , MsgFlags , SockFlag , SockType ,
28
+ recvmsg, socketpair, AddressFamily , ControlMessageOwned , MsgFlags , RecvMsg , SockFlag , SockType ,
29
+ UnixAddr ,
31
30
} ;
32
- use nix:: sys:: uio:: IoVec ;
33
31
use nix:: unistd:: { close, execv, fork, getpid, read, ForkResult } ;
34
32
use nix:: { cmsg_space, NixPath } ;
35
33
@@ -42,6 +40,37 @@ const FUSE_HEADER_SIZE: usize = 0x1000;
42
40
43
41
const OSXFUSE_MOUNT_PROG : & str = "/Library/Filesystems/macfuse.fs/Contents/Resources/mount_macfuse" ;
44
42
43
+ static K_DADISK_UNMOUNT_OPTION_FORCE : u64 = 524288 ;
44
+
45
+ #[ repr( C ) ]
46
+ struct __DADisk ( c_void ) ;
47
+ type DADiskRef = * const __DADisk ;
48
+ #[ repr( C ) ]
49
+ struct __DADissenter ( c_void ) ;
50
+ type DADissenterRef = * const __DADissenter ;
51
+ #[ repr( C ) ]
52
+ struct __DASession ( c_void ) ;
53
+ type DASessionRef = * const __DASession ;
54
+
55
+ type DADiskUnmountCallback = :: std:: option:: Option <
56
+ unsafe extern "C" fn ( disk : DADiskRef , dissenter : DADissenterRef , context : * mut c_void ) ,
57
+ > ;
58
+
59
+ extern "C" {
60
+ fn DADiskUnmount (
61
+ disk : DADiskRef ,
62
+ options : u64 ,
63
+ callback : DADiskUnmountCallback ,
64
+ context : * mut c_void ,
65
+ ) ;
66
+ fn DADiskCreateFromVolumePath (
67
+ allocator : CFAllocatorRef ,
68
+ session : DASessionRef ,
69
+ path : CFURLRef ,
70
+ ) -> DADiskRef ;
71
+ fn DASessionCreate ( allocator : CFAllocatorRef ) -> DASessionRef ;
72
+ }
73
+
45
74
mod ioctl {
46
75
use nix:: ioctl_write_ptr;
47
76
@@ -247,8 +276,9 @@ impl FuseChannel {
247
276
fn receive_fd ( sock_fd : RawFd ) -> Result < RawFd > {
248
277
let mut buffer = vec ! [ 0u8 ; 4 ] ;
249
278
let mut cmsgspace = cmsg_space ! ( RawFd ) ;
250
- let iov = [ IoVec :: from_mut_slice ( & mut buffer) ] ;
251
- let r = recvmsg ( sock_fd, & iov, Some ( & mut cmsgspace) , MsgFlags :: empty ( ) ) . unwrap ( ) ;
279
+ let mut iov = [ IoSliceMut :: new ( & mut buffer) ] ;
280
+ let r: RecvMsg < UnixAddr > =
281
+ recvmsg ( sock_fd, & mut iov, Some ( & mut cmsgspace) , MsgFlags :: empty ( ) ) . unwrap ( ) ;
252
282
if let Some ( msg) = r. cmsgs ( ) . next ( ) {
253
283
match msg {
254
284
ControlMessageOwned :: ScmRights ( fds) => {
@@ -362,7 +392,6 @@ fn create_disk(mountpoint: &Path, dasession: DASessionRef) -> DADiskRef {
362
392
path_len as CFIndex ,
363
393
kCFStringEncodingUTF8,
364
394
1u8 ,
365
- std:: ptr:: null ( ) ,
366
395
) ;
367
396
let url =
368
397
CFURLCreateWithFileSystemPath ( std:: ptr:: null ( ) , url_str, kCFURLPOSIXPathStyle, 1u8 ) ;
@@ -385,7 +414,12 @@ fn fuse_kern_umount(file: File, disk: Option<DADiskRef>) -> Result<()> {
385
414
386
415
if let Some ( disk) = disk {
387
416
unsafe {
388
- DADiskUnmount ( disk, kDADiskUnmountOptionForce, None , std:: ptr:: null_mut ( ) ) ;
417
+ DADiskUnmount (
418
+ disk,
419
+ K_DADISK_UNMOUNT_OPTION_FORCE ,
420
+ None ,
421
+ std:: ptr:: null_mut ( ) ,
422
+ ) ;
389
423
CFRelease ( std:: mem:: transmute ( disk) ) ;
390
424
}
391
425
}
0 commit comments