@@ -9,7 +9,8 @@ use libc::{EAGAIN, EINTR, ENODEV, ENOENT};
9
9
use log:: { info, warn} ;
10
10
use nix:: unistd:: geteuid;
11
11
use std:: fmt;
12
- use std:: path:: { Path , PathBuf } ;
12
+ use std:: os:: fd:: { AsFd , BorrowedFd , OwnedFd } ;
13
+ use std:: path:: Path ;
13
14
use std:: sync:: { Arc , Mutex } ;
14
15
use std:: thread:: { self , JoinHandle } ;
15
16
use std:: { io, ops:: DerefMut } ;
@@ -31,10 +32,15 @@ pub const MAX_WRITE_SIZE: usize = 16 * 1024 * 1024;
31
32
/// up to MAX_WRITE_SIZE bytes in a write request, we use that value plus some extra space.
32
33
const BUFFER_SIZE : usize = MAX_WRITE_SIZE + 4096 ;
33
34
34
- #[ derive( Debug , Eq , PartialEq ) ]
35
- pub ( crate ) enum SessionACL {
35
+ #[ derive( Default , Debug , Eq , PartialEq ) ]
36
+ /// How requests should be filtered based on the calling UID.
37
+ pub enum SessionACL {
38
+ /// Allow requests from any user. Corresponds to the `allow_other` mount option.
36
39
All ,
40
+ /// Allow requests from root. Corresponds to the `allow_root` mount option.
37
41
RootAndOwner ,
42
+ /// Allow requests from the owning UID. This is FUSE's default mode of operation.
43
+ #[ default]
38
44
Owner ,
39
45
}
40
46
@@ -47,8 +53,6 @@ pub struct Session<FS: Filesystem> {
47
53
ch : Channel ,
48
54
/// Handle to the mount. Dropping this unmounts.
49
55
mount : Arc < Mutex < Option < Mount > > > ,
50
- /// Mount point
51
- mountpoint : PathBuf ,
52
56
/// Whether to restrict access to owner, root + owner, or unrestricted
53
57
/// Used to implement allow_root and auto_unmount
54
58
pub ( crate ) allowed : SessionACL ,
@@ -64,6 +68,12 @@ pub struct Session<FS: Filesystem> {
64
68
pub ( crate ) destroyed : bool ,
65
69
}
66
70
71
+ impl < FS : Filesystem > AsFd for Session < FS > {
72
+ fn as_fd ( & self ) -> BorrowedFd < ' _ > {
73
+ self . ch . as_fd ( )
74
+ }
75
+ }
76
+
67
77
impl < FS : Filesystem > Session < FS > {
68
78
/// Create a new session by mounting the given filesystem to the given mountpoint
69
79
pub fn new < P : AsRef < Path > > (
@@ -101,7 +111,6 @@ impl<FS: Filesystem> Session<FS> {
101
111
filesystem,
102
112
ch,
103
113
mount : Arc :: new ( Mutex :: new ( Some ( mount) ) ) ,
104
- mountpoint : mountpoint. to_owned ( ) ,
105
114
allowed,
106
115
session_owner : geteuid ( ) . as_raw ( ) ,
107
116
proto_major : 0 ,
@@ -111,9 +120,21 @@ impl<FS: Filesystem> Session<FS> {
111
120
} )
112
121
}
113
122
114
- /// Return path of the mounted filesystem
115
- pub fn mountpoint ( & self ) -> & Path {
116
- & self . mountpoint
123
+ /// Wrap an existing /dev/fuse file descriptor. This doesn't mount the
124
+ /// filesystem anywhere; that must be done separately.
125
+ pub fn from_fd ( filesystem : FS , fd : OwnedFd , acl : SessionACL ) -> Self {
126
+ let ch = Channel :: new ( Arc :: new ( fd. into ( ) ) ) ;
127
+ Session {
128
+ filesystem,
129
+ ch,
130
+ mount : Arc :: new ( Mutex :: new ( None ) ) ,
131
+ allowed : acl,
132
+ session_owner : geteuid ( ) . as_raw ( ) ,
133
+ proto_major : 0 ,
134
+ proto_minor : 0 ,
135
+ initialized : false ,
136
+ destroyed : false ,
137
+ }
117
138
}
118
139
119
140
/// Run the session loop that receives kernel requests and dispatches them to method
@@ -210,14 +231,11 @@ impl<FS: Filesystem> Drop for Session<FS> {
210
231
self . filesystem . destroy ( ) ;
211
232
self . destroyed = true ;
212
233
}
213
- info ! ( "Unmounted {}" , self . mountpoint( ) . display( ) ) ;
214
234
}
215
235
}
216
236
217
237
/// The background session data structure
218
238
pub struct BackgroundSession {
219
- /// Path of the mounted filesystem
220
- pub mountpoint : PathBuf ,
221
239
/// Thread guard of the background session
222
240
pub guard : JoinHandle < io:: Result < ( ) > > ,
223
241
/// Object for creating Notifiers for client use
@@ -232,7 +250,6 @@ impl BackgroundSession {
232
250
/// session loop in a background thread. If the returned handle is dropped,
233
251
/// the filesystem is unmounted and the given session ends.
234
252
pub fn new < FS : Filesystem + Send + ' static > ( se : Session < FS > ) -> io:: Result < BackgroundSession > {
235
- let mountpoint = se. mountpoint ( ) . to_path_buf ( ) ;
236
253
#[ cfg( feature = "abi-7-11" ) ]
237
254
let sender = se. ch . sender ( ) ;
238
255
// Take the fuse_session, so that we can unmount it
@@ -243,7 +260,6 @@ impl BackgroundSession {
243
260
se. run ( )
244
261
} ) ;
245
262
Ok ( BackgroundSession {
246
- mountpoint,
247
263
guard,
248
264
#[ cfg( feature = "abi-7-11" ) ]
249
265
sender,
@@ -253,7 +269,6 @@ impl BackgroundSession {
253
269
/// Unmount the filesystem and join the background thread.
254
270
pub fn join ( self ) {
255
271
let Self {
256
- mountpoint : _,
257
272
guard,
258
273
#[ cfg( feature = "abi-7-11" ) ]
259
274
sender: _,
@@ -274,10 +289,6 @@ impl BackgroundSession {
274
289
// thread_scoped::JoinGuard
275
290
impl fmt:: Debug for BackgroundSession {
276
291
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> Result < ( ) , fmt:: Error > {
277
- write ! (
278
- f,
279
- "BackgroundSession {{ mountpoint: {:?}, guard: JoinGuard<()> }}" ,
280
- self . mountpoint
281
- )
292
+ write ! ( f, "BackgroundSession {{ guard: JoinGuard<()> }}" , )
282
293
}
283
294
}
0 commit comments