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! --- mkfs.aya/Cargo.toml | 2 ++ mkfs.aya/src/main.rs | 40 +++++++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 13 deletions(-) (limited to 'mkfs.aya') diff --git a/mkfs.aya/Cargo.toml b/mkfs.aya/Cargo.toml index 930feb7..36745ef 100644 --- a/mkfs.aya/Cargo.toml +++ b/mkfs.aya/Cargo.toml @@ -5,6 +5,8 @@ edition = "2021" [dependencies] ayafs-core = { path = "../ayafs-core" } +log = "0.4.20" +env_logger = "0.10.1" users = "0.11.0" clap = { version = "4.4.10", features = ["derive"] } nix = { version = "0.27.1", features = ["ioctl"] } diff --git a/mkfs.aya/src/main.rs b/mkfs.aya/src/main.rs index 3a96d0c..00bef5b 100644 --- a/mkfs.aya/src/main.rs +++ b/mkfs.aya/src/main.rs @@ -5,8 +5,10 @@ use std::fs::File; use std::os::fd::AsRawFd; use std::path::{Path, PathBuf}; use std::sync::Arc; +use log::LevelFilter; +use users::{get_current_gid, get_current_uid}; use aya::AyaFS; -use aya::block_device::{BLOCK_SIZE, BlockDevice}; +use aya::block_device::BLOCK_SIZE; use aya::block_device::disk::Disk; use crate::ioctl::ioctl_blkgetsize64; @@ -14,33 +16,45 @@ use crate::ioctl::ioctl_blkgetsize64; #[command(author, version, about)] struct Args { block_device: Option, + #[arg(short, action = clap::ArgAction::Count)] + verbosity: u8, } fn get_device_size>(path: T) -> u64 { let device = File::options() .write(true) .open(path.as_ref()) - .unwrap(); + .expect("Failed to open device."); let device_raw_fd = device.as_raw_fd(); let mut device_size = 0u64; let device_size_ptr = &mut device_size as *mut u64; unsafe { - ioctl_blkgetsize64(device_raw_fd, device_size_ptr).unwrap(); + ioctl_blkgetsize64(device_raw_fd, device_size_ptr) + .expect("ioctl exceptions occur."); } device_size } - - fn main() { let args = Args::parse(); - let device_path = args.block_device.unwrap(); + let device_path = args.block_device + .expect("Not device path specified."); + 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 device_size = get_device_size(device_path.as_path()); - let device = File::options() - .read(true) - .write(true) - .open(device_path.as_path()) - .unwrap(); - let disk =Arc::new( Disk::new(device_path)); - let fs = AyaFS::new(disk, device_size as usize / BLOCK_SIZE); + let disk = Arc::new(Disk::new(device_path)); + let mut fs = AyaFS::new( + disk, + device_size as usize / BLOCK_SIZE, + get_current_uid(), + get_current_gid(), + ); + fs.write_back(); } -- cgit v1.2.3-70-g09d2