Skip to content

Commit

Permalink
feat: memory fs in cli tool
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Oct 22, 2024
1 parent 70c5880 commit f51a415
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ All the features are enabled by default; so if you want to build it with only ce
### Usage

```sh
remotefs-fuse-cli --to /mnt/to <aws-s3|ftp|kube|smb|scp|sftp|webdav> [protocol-options...]
remotefs-fuse-cli --to /mnt/to --volume <volume-name> <aws-s3|ftp|kube|smb|scp|sftp|webdav> [protocol-options...]
```

where protocol options are
Expand All @@ -112,6 +112,7 @@ where protocol options are
- kube
- `--namespace <namespace>` (default: `default`)
- `--cluster-url <url>`
- memory: runs a virtual file system in memory
- smb
- `--address <address>`
- `--port <port>` (default: `139`; Linux/Mac only)
Expand Down
4 changes: 4 additions & 0 deletions remotefs-fuse-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ remotefs-aws-s3 = { version = "0.3", optional = true }
remotefs-ftp = { version = "0.2", features = ["rustls"], optional = true }
remotefs-fuse = { path = "../remotefs-fuse", version = "0.1" }
remotefs-kube = { version = "0.4", optional = true }
remotefs-memory = "0.1"
remotefs-smb = { version = "0.3", optional = true }
remotefs-ssh = { version = "0.4", optional = true }
remotefs-webdav = { version = "0.2", optional = true }
thiserror = "^1"
tokio = { version = "1", features = ["rt"] }

[target.'cfg(target_family = "unix")'.dependencies]
nix = { version = "0.29", features = ["user"] }

[features]
default = ["aws-s3", "ftp", "kube", "smb", "ssh", "webdav"]
aws-s3 = ["dep:remotefs-aws-s3"]
Expand Down
7 changes: 7 additions & 0 deletions remotefs-fuse-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod aws_s3;
mod ftp;
#[cfg(feature = "kube")]
mod kube;
mod memory;
#[cfg(feature = "smb")]
mod smb;
#[cfg(feature = "ssh")]
Expand All @@ -22,6 +23,7 @@ use self::aws_s3::AwsS3Args;
use self::ftp::FtpArgs;
#[cfg(feature = "kube")]
use self::kube::KubeArgs;
use self::memory::MemoryArgs;
#[cfg(feature = "smb")]
use self::smb::SmbArgs;
#[cfg(feature = "ssh")]
Expand All @@ -37,6 +39,9 @@ pub struct CliArgs {
/// path where the remote filesystem will be mounted to
#[argh(option)]
pub to: PathBuf,
/// name of mounted filesystem volume
#[argh(option)]
pub volume: String,
#[argh(subcommand)]
remote: RemoteArgs,
}
Expand All @@ -50,6 +55,7 @@ pub enum RemoteArgs {
Ftp(FtpArgs),
#[cfg(feature = "kube")]
Kube(KubeArgs),
Memory(MemoryArgs),
#[cfg(feature = "ssh")]
Scp(ScpArgs),
#[cfg(feature = "ssh")]
Expand All @@ -70,6 +76,7 @@ impl CliArgs {
RemoteArgs::Ftp(args) => Box::new(remotefs_ftp::FtpFs::from(args)),
#[cfg(feature = "kube")]
RemoteArgs::Kube(args) => Box::new(remotefs_kube::KubeMultiPodFs::from(args)),
RemoteArgs::Memory(args) => Box::new(remotefs_memory::MemoryFs::from(args)),
#[cfg(feature = "ssh")]
RemoteArgs::Scp(args) => Box::new(remotefs_ssh::ScpFs::from(args)),
#[cfg(feature = "ssh")]
Expand Down
2 changes: 1 addition & 1 deletion remotefs-fuse-cli/src/cli/kube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use argh::FromArgs;
use remotefs_kube::{Config, KubeMultiPodFs};

#[derive(FromArgs, Debug)]
#[argh(subcommand, name = "ftp")]
#[argh(subcommand, name = "kube")]
/// Mount a Kube multipod filesystem
pub struct KubeArgs {
/// namespace
Expand Down
51 changes: 51 additions & 0 deletions remotefs-fuse-cli/src/cli/memory.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use std::path::PathBuf;

use argh::FromArgs;
use remotefs::fs::UnixPex;
use remotefs_memory::{node, Inode, MemoryFs, Node, Tree};

#[derive(FromArgs, Debug)]
#[argh(subcommand, name = "memory")]
/// Mount a Virtual Memory filesystem
pub struct MemoryArgs {}

impl From<MemoryArgs> for MemoryFs {
fn from(_: MemoryArgs) -> Self {
#[cfg(unix)]
let uid = nix::unistd::getuid().as_raw();
#[cfg(windows)]
let uid = 0;

#[cfg(unix)]
let gid = nix::unistd::getgid().as_raw();
#[cfg(windows)]
let gid = 0;

let tree = Tree::new(node!(
PathBuf::from("/"),
Inode::dir(uid, gid, UnixPex::from(0o755)),
));

MemoryFs::new(tree)
.with_get_gid(|| {
#[cfg(unix)]
{
nix::unistd::getgid().as_raw()
}
#[cfg(windows)]
{
0
}
})
.with_get_uid(|| {
#[cfg(unix)]
{
nix::unistd::getuid().as_raw()
}
#[cfg(windows)]
{
0
}
})
}
}
2 changes: 2 additions & 0 deletions remotefs-fuse-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ fn main() -> anyhow::Result<()> {
env_logger::init();

let args = argh::from_env::<cli::CliArgs>();
let volume = args.volume.clone();
let mount_path = args.to.clone();
let remote = args.remote();

Expand All @@ -30,6 +31,7 @@ fn main() -> anyhow::Result<()> {
MountOption::Exec,
MountOption::Atime,
MountOption::Sync,
MountOption::FSName(volume),
],
)?;

Expand Down
1 change: 1 addition & 0 deletions remotefs-fuse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ seahash = "4"
[dev-dependencies]
env_logger = "^0.11"
pretty_assertions = "^1"
remotefs-memory = "0.1"

[features]
default = []
Expand Down
4 changes: 2 additions & 2 deletions remotefs-fuse/src/driver/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn convert_file(value: &File) -> FileAttr {
mtime: value.metadata().modified.unwrap_or(UNIX_EPOCH),
ctime: value.metadata().created.unwrap_or(UNIX_EPOCH),
crtime: UNIX_EPOCH,
kind: convert_remote_filetype(value.metadata().file_type.clone()),
kind: convert_remote_filetype(value.metadata().file_type),
perm: value
.metadata()
.mode
Expand Down Expand Up @@ -1117,7 +1117,7 @@ impl Filesystem for Driver {
let buffer_full = reply.add(
inode,
offset + index as i64 + 1,
convert_remote_filetype(entry.metadata().file_type.clone()),
convert_remote_filetype(entry.metadata().file_type),
name,
);

Expand Down

0 comments on commit f51a415

Please sign in to comment.