From 4c34414b26bf71e747ea3ecb2586645bab4aba52 Mon Sep 17 00:00:00 2001 From: Chuyan Zhang Date: Fri, 1 Dec 2023 19:42:13 -0800 Subject: Multiple bugfix, it works! --- ayafs-core/src/bin/main.rs | 9 +++++---- ayafs-core/src/bin/mem_run.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 ayafs-core/src/bin/mem_run.rs (limited to 'ayafs-core/src/bin') diff --git a/ayafs-core/src/bin/main.rs b/ayafs-core/src/bin/main.rs index 25504b9..a2d838c 100644 --- a/ayafs-core/src/bin/main.rs +++ b/ayafs-core/src/bin/main.rs @@ -9,6 +9,7 @@ use aya::block_device::disk::Disk; #[derive(Parser, Debug)] #[command(author, version, about)] struct Args { + device_path: Option, mount_point: Option, #[arg(short, action = clap::ArgAction::Count)] verbosity: u8, @@ -20,6 +21,7 @@ struct Args { fn main() { let args = Args::parse(); + let device_path = args.device_path.unwrap(); let mount_point = args.mount_point.unwrap(); let verbosity = args.verbosity; let log_level = match verbosity { @@ -36,9 +38,8 @@ fn main() { MountOption::AutoUnmount, MountOption::AllowRoot, ]; - let disk = Arc::new(Disk::new(PathBuf::from("/dev/nvme0n1p4"))); - // let disk = Arc::new(MemoryDisk::new(16384)); - let filesystem = AyaFS::new(disk, 7864320); - + let disk = Arc::new(Disk::new(PathBuf::from(device_path))); + let filesystem = AyaFS::load(disk); + fuser::mount2(filesystem, mount_point, &options).unwrap(); } \ No newline at end of file diff --git a/ayafs-core/src/bin/mem_run.rs b/ayafs-core/src/bin/mem_run.rs new file mode 100644 index 0000000..7ba6f4e --- /dev/null +++ b/ayafs-core/src/bin/mem_run.rs @@ -0,0 +1,43 @@ +use std::sync::Arc; +use clap::Parser; +use fuser::MountOption; +use log::LevelFilter; +use users::{get_current_gid, get_current_uid}; +use aya::AyaFS; +use aya::block_device::memory_disk::MemoryDisk; + +#[derive(Parser, Debug)] +#[command(author, version, about)] +struct Args { + mount_point: Option, + #[arg(short, action = clap::ArgAction::Count)] + verbosity: u8, + #[arg(long)] + auto_unmount: bool, + #[arg(long)] + allow_root: bool, +} + +fn main() { + let args = Args::parse(); + let mount_point = args.mount_point.unwrap(); + let verbosity = args.verbosity; + let log_level = match verbosity { + 0 => LevelFilter::Error, + 1 => LevelFilter::Warn, + 2 => LevelFilter::Info, + 3 => LevelFilter::Debug, + _ => LevelFilter::Trace, + }; + env_logger::builder().filter_level(log_level).init(); + let options = vec![ + // MountOption::RO, + MountOption::FSName("hello".to_string()), + MountOption::AutoUnmount, + MountOption::AllowRoot, + ]; + let disk = Arc::new(MemoryDisk::new(16384)); + let filesystem = AyaFS::new(disk, 16384, get_current_uid(), get_current_gid()); + + fuser::mount2(filesystem, mount_point, &options).unwrap(); +} \ No newline at end of file -- cgit v1.2.3-70-g09d2