Skip to content

Commit

Permalink
feat: working on windows driver
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Nov 1, 2024
1 parent 2985ad4 commit 88e8623
Show file tree
Hide file tree
Showing 6 changed files with 1,000 additions and 49 deletions.
3 changes: 2 additions & 1 deletion remotefs-fuse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ path = "src/lib.rs"
[dependencies]
log = "^0.4"
remotefs = "0.3"
tempfile = "^3"


[target.'cfg(unix)'.dependencies]
fuser = "0.14"
libc = "^0.2"
nix = { version = "0.29", features = ["fs"] }
seahash = "4"
tempfile = "^3"

[target.'cfg(windows)'.dependencies]
dashmap = "6"
dokan = "0.3.1"
dokan-sys = "0.3.1"
widestring = "0.4.3"
Expand Down
37 changes: 6 additions & 31 deletions remotefs-fuse/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ pub struct Driver<T: RemoteFs> {
#[cfg(windows)]
/// [`RemoteFs`] instance usable as `Sync` in immutable references
remote: std::sync::Arc<std::sync::Mutex<T>>,
#[cfg(windows)]
/// [`windows::DirEntry`] foor directory
file_handlers:
dashmap::DashMap<widestring::U16CString, std::sync::Arc<std::sync::RwLock<windows::Stat>>>,
}

impl<T> Driver<T>
Expand All @@ -55,37 +59,8 @@ where
remote,
#[cfg(windows)]
remote: std::sync::Arc::new(std::sync::Mutex::new(remote)),
#[cfg(windows)]
file_handlers: dashmap::DashMap::new(),
}
}

/// Get the specified uid from the mount options.
#[cfg(unix)]
fn uid(&self) -> Option<u32> {
self.options.iter().find_map(|opt| match opt {
MountOption::Uid(uid) => Some(*uid),
_ => None,
})
}

/// Get the specified gid from the mount options.
#[cfg(unix)]
fn gid(&self) -> Option<u32> {
self.options.iter().find_map(|opt| match opt {
MountOption::Gid(gid) => Some(*gid),
_ => None,
})
}

/// Get the specified default mode from the mount options.
/// If not set, the default is 0755.
#[cfg(unix)]
fn default_mode(&self) -> u32 {
self.options
.iter()
.find_map(|opt| match opt {
MountOption::DefaultMode(mode) => Some(*mode),
_ => None,
})
.unwrap_or(0o755)
}
}
29 changes: 29 additions & 0 deletions remotefs-fuse/src/driver/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use remotefs::{File, RemoteError, RemoteErrorType, RemoteFs, RemoteResult};
pub use self::file_handle::FileHandlersDb;
pub use self::inode::InodeDb;
use super::Driver;
use crate::MountOption;

const BLOCK_SIZE: usize = 512;
const FMODE_EXEC: c_int = 0x20;
Expand Down Expand Up @@ -390,6 +391,34 @@ where
.create_file(file.path(), file.metadata(), Box::new(reader))
.map(|len| len as u32)
}

/// Get the specified uid from the mount options.
fn uid(&self) -> Option<u32> {
self.options.iter().find_map(|opt| match opt {
MountOption::Uid(uid) => Some(*uid),
_ => None,
})
}

/// Get the specified gid from the mount options.
fn gid(&self) -> Option<u32> {
self.options.iter().find_map(|opt| match opt {
MountOption::Gid(gid) => Some(*gid),
_ => None,
})
}

/// Get the specified default mode from the mount options.
/// If not set, the default is 0755.
fn default_mode(&self) -> u32 {
self.options
.iter()
.find_map(|opt| match opt {
MountOption::DefaultMode(mode) => Some(*mode),
_ => None,
})
.unwrap_or(0o755)
}
}

impl<T> Filesystem for Driver<T>
Expand Down
Loading

0 comments on commit 88e8623

Please sign in to comment.