Skip to content

Commit

Permalink
fix: set mount option on mount
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Oct 25, 2024
1 parent 453dc0d commit c7fb70f
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 51 deletions.
5 changes: 1 addition & 4 deletions remotefs-fuse-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ fn main() -> anyhow::Result<()> {
options.push(MountOption::DefaultMode(default_mode));
}

let driver = Driver::new(args.remote(), options);

log::info!("Mounting remote fs at {}", mount_path.display());

// create the mount point if it does not exist
Expand All @@ -46,8 +44,7 @@ fn main() -> anyhow::Result<()> {
}

// Mount the remote file system
let mut mount = Mount::mount(driver, &mount_path)?;

let mut mount = Mount::mount(Driver::new(args.remote()), &mount_path, &options)?;
let mut umount = mount.unmounter();

// setup signal handler
Expand Down
4 changes: 2 additions & 2 deletions remotefs-fuse/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ impl Driver {
///
/// * `remote` - The instance which implements the [`RemoteFs`] trait.
/// * `options` - The mount options.
pub fn new(remote: Box<dyn RemoteFs>, options: Vec<MountOption>) -> Self {
pub fn new(remote: Box<dyn RemoteFs>) -> Self {
Self {
#[cfg(unix)]
database: unix::InodeDb::load(),
#[cfg(unix)]
file_handlers: unix::FileHandlersDb::default(),
options,
options: Vec::new(),
remote,
}
}
Expand Down
59 changes: 29 additions & 30 deletions remotefs-fuse/src/driver/unix/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ fn setup_driver() -> Driver {

let fs = Box::new(fs) as Box<dyn RemoteFs>;

Driver::new(
fs,
vec![
MountOption::AllowRoot,
MountOption::RW,
MountOption::Exec,
MountOption::Sync,
],
)
let mut driver = Driver::new(fs);
driver.options = vec![
MountOption::AllowRoot,
MountOption::RW,
MountOption::Exec,
MountOption::Sync,
];
driver
}

fn setup_driver_with_mode(mode: u32) -> Driver {
Expand All @@ -56,16 +55,16 @@ fn setup_driver_with_mode(mode: u32) -> Driver {

let fs = Box::new(fs) as Box<dyn RemoteFs>;

Driver::new(
fs,
vec![
MountOption::AllowRoot,
MountOption::RW,
MountOption::Exec,
MountOption::Sync,
MountOption::DefaultMode(mode),
],
)
let mut driver = Driver::new(fs);
driver.options = vec![
MountOption::AllowRoot,
MountOption::RW,
MountOption::Exec,
MountOption::Sync,
MountOption::DefaultMode(mode),
];

driver
}

fn setup_driver_with_uid(uid: u32, gid: u32) -> Driver {
Expand All @@ -83,17 +82,17 @@ fn setup_driver_with_uid(uid: u32, gid: u32) -> Driver {

let fs = Box::new(fs) as Box<dyn RemoteFs>;

Driver::new(
fs,
vec![
MountOption::AllowRoot,
MountOption::RW,
MountOption::Exec,
MountOption::Sync,
MountOption::Uid(uid),
MountOption::Gid(gid),
],
)
let mut driver = Driver::new(fs);
driver.options = vec![
MountOption::AllowRoot,
MountOption::RW,
MountOption::Exec,
MountOption::Sync,
MountOption::Uid(uid),
MountOption::Gid(gid),
];

driver
}

/// Make file on the remote fs at `path` with `content`
Expand Down
20 changes: 18 additions & 2 deletions remotefs-fuse/src/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ impl Mount {
/// You can specify the mount options using the `options` parameter.
#[allow(clippy::self_named_constructors)]
#[cfg(unix)]
pub fn mount(driver: Driver, mountpoint: &Path) -> Result<Self, std::io::Error> {
pub fn mount(
mut driver: Driver,
mountpoint: &Path,
options: &[MountOption],
) -> Result<Self, std::io::Error> {
driver.options = options.to_vec();

let options = driver
.options
.iter()
Expand All @@ -32,8 +38,18 @@ impl Mount {
})
}

/// Mount the filesystem implemented by [`Driver`] to the provided mountpoint.
///
/// You can specify the mount options using the `options` parameter.
#[cfg(windows)]
pub fn mount(driver: Driver, mountpoint: &Path) -> Result<Self, std::io::Error> {
#[allow(clippy::self_named_constructors)]
pub fn mount(
mut driver: Driver,
mountpoint: &Path,
options: &[MountOption],
) -> Result<Self, std::io::Error> {
driver.options = options.to_vec();

todo!()
}

Expand Down
12 changes: 2 additions & 10 deletions remotefs-fuse/tests/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::{Path, PathBuf};

use remotefs::fs::{Metadata, UnixPex};
use remotefs::{RemoteError, RemoteErrorType, RemoteFs};
use remotefs_fuse::{Driver, MountOption};
use remotefs_fuse::Driver;
use remotefs_memory::{node, Inode, MemoryFs, Node, Tree};

pub fn mounted_file_path() -> &'static Path {
Expand All @@ -27,15 +27,7 @@ pub fn setup_driver() -> Driver {

make_file_at(&mut fs, mounted_file_path(), b"Hello, world!");

Driver::new(
fs,
vec![
MountOption::AllowRoot,
MountOption::RW,
MountOption::Exec,
MountOption::Sync,
],
)
Driver::new(fs)
}

/// Make file on the remote fs at `path` with `content`
Expand Down
15 changes: 12 additions & 3 deletions remotefs-fuse/tests/fuse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::{Arc, Mutex};
use std::thread::JoinHandle;
use std::time::Duration;

use remotefs_fuse::{Mount, Umount};
use remotefs_fuse::{Mount, MountOption, Umount};
use tempfile::TempDir;

use crate::driver::mounted_file_path;
Expand All @@ -24,8 +24,17 @@ fn mount(p: &Path) -> (UmountLock, JoinHandle<()>) {
let umount_t = umount.clone();

let join = std::thread::spawn(move || {
let mut mount =
Mount::mount(crate::driver::setup_driver(), &mountpoint).expect("failed to mount");
let mut mount = Mount::mount(
crate::driver::setup_driver(),
&mountpoint,
&[
MountOption::AllowRoot,
MountOption::RW,
MountOption::Exec,
MountOption::Sync,
],
)
.expect("failed to mount");

let umount = mount.unmounter();
*umount_t.lock().unwrap() = Some(umount);
Expand Down

0 comments on commit c7fb70f

Please sign in to comment.