diff --git a/examples/hello.rs b/examples/hello.rs index 03207a0..3c8ee16 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -92,9 +92,6 @@ impl Filesystem for HelloFS { fn main() { env_logger::init(); let mountpoint = env::args_os().nth(1).unwrap(); - let options = ["-o", "ro", "-o", "fsname=hello"] - .iter() - .map(|o| o.as_ref()) - .collect::>(); + let options = OsStr::new("-o ro -o fsname=hello"); fuse::mount(HelloFS, mountpoint, &options).unwrap(); } diff --git a/examples/null.rs b/examples/null.rs index 05bd46c..9daa1d8 100644 --- a/examples/null.rs +++ b/examples/null.rs @@ -8,5 +8,6 @@ impl Filesystem for NullFS {} fn main() { env_logger::init(); let mountpoint = env::args_os().nth(1).unwrap(); - fuse::mount(NullFS, mountpoint, &[]).unwrap(); + + fuse::mount(NullFS, mountpoint, &"").unwrap(); } diff --git a/src/channel.rs b/src/channel.rs index 429475a..53887c6 100644 --- a/src/channel.rs +++ b/src/channel.rs @@ -14,9 +14,11 @@ use crate::reply::ReplySender; /// Helper function to provide options as a fuse_args struct /// (which contains an argc count and an argv pointer) -fn with_fuse_args T>(options: &[&OsStr], f: F) -> T { - let mut args = vec![CString::new("rust-fuse").unwrap()]; - args.extend(options.iter().map(|s| CString::new(s.as_bytes()).unwrap())); +fn with_fuse_args T>(options: &OsStr, f: F) -> T { + let args = vec![ + CString::new("rust-fuse").unwrap(), + CString::new(options.to_str().unwrap()).unwrap() + ]; let argptrs: Vec<_> = args.iter().map(|s| s.as_ptr()).collect(); f(&fuse_args { argc: argptrs.len() as i32, argv: argptrs.as_ptr(), allocated: 0 }) } @@ -33,7 +35,7 @@ impl Channel { /// given path. The kernel driver will delegate filesystem operations of /// the given path to the channel. If the channel is dropped, the path is /// unmounted. - pub fn new(mountpoint: &Path, options: &[&OsStr]) -> io::Result { + pub fn new(mountpoint: &Path, options: &OsStr) -> io::Result { let mountpoint = mountpoint.canonicalize()?; with_fuse_args(options, |args| { let mnt = CString::new(mountpoint.as_os_str().as_bytes())?; @@ -164,11 +166,10 @@ mod test { #[test] fn fuse_args() { - with_fuse_args(&[OsStr::new("foo"), OsStr::new("bar")], |args| { - assert_eq!(args.argc, 3); + with_fuse_args(&OsStr::new("foo bar"), |args| { + assert_eq!(args.argc, 2); assert_eq!(unsafe { CStr::from_ptr(*args.argv.offset(0)).to_bytes() }, b"rust-fuse"); - assert_eq!(unsafe { CStr::from_ptr(*args.argv.offset(1)).to_bytes() }, b"foo"); - assert_eq!(unsafe { CStr::from_ptr(*args.argv.offset(2)).to_bytes() }, b"bar"); + assert_eq!(unsafe { CStr::from_ptr(*args.argv.offset(1)).to_bytes() }, b"foo bar"); }); } } diff --git a/src/lib.rs b/src/lib.rs index 064039d..a7ffb6e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -367,8 +367,8 @@ pub trait Filesystem { /// /// Note that you need to lead each option with a separate `"-o"` string. See /// `examples/hello.rs`. -pub fn mount>(filesystem: FS, mountpoint: P, options: &[&OsStr]) -> io::Result<()>{ - Session::new(filesystem, mountpoint.as_ref(), options).and_then(|mut se| se.run()) +pub fn mount, O: AsRef>(filesystem: FS, mountpoint: P, options: O) -> io::Result<()> { + Session::new(filesystem, mountpoint.as_ref(), options.as_ref()).and_then(|mut se| se.run()) } /// Mount the given filesystem to the given mountpoint. This function spawns @@ -376,6 +376,6 @@ pub fn mount>(filesystem: FS, mountpoint: P, opti /// and therefore returns immediately. The returned handle should be stored /// to reference the mounted filesystem. If it's dropped, the filesystem will /// be unmounted. -pub unsafe fn spawn_mount<'a, FS: Filesystem+Send+'a, P: AsRef>(filesystem: FS, mountpoint: P, options: &[&OsStr]) -> io::Result> { - Session::new(filesystem, mountpoint.as_ref(), options).and_then(|se| se.spawn()) +pub unsafe fn spawn_mount<'a, FS: Filesystem+Send+'a, P: AsRef, O: AsRef>(filesystem: FS, mountpoint: P, options: O) -> io::Result> { + Session::new(filesystem, mountpoint.as_ref(), options.as_ref()).and_then(|se| se.spawn()) } diff --git a/src/session.rs b/src/session.rs index b687efc..e204d90 100644 --- a/src/session.rs +++ b/src/session.rs @@ -45,7 +45,7 @@ pub struct Session { impl Session { /// Create a new session by mounting the given filesystem to the given mountpoint - pub fn new(filesystem: FS, mountpoint: &Path, options: &[&OsStr]) -> io::Result> { + pub fn new(filesystem: FS, mountpoint: &Path, options: &OsStr) -> io::Result> { info!("Mounting {}", mountpoint.display()); Channel::new(mountpoint, options).map(|ch| { Session {