diff options
author | Chuyan Zhang <me@zcy.moe> | 2023-11-30 12:01:11 -0800 |
---|---|---|
committer | Chuyan Zhang <me@zcy.moe> | 2023-11-30 12:01:11 -0800 |
commit | fd125947c9db0b33761414e65e919f73d9bf1815 (patch) | |
tree | c4c66d95ba85601427928aa7f23659590055d464 /mkfs.aya/src/main.rs | |
parent | 1eac97eea4ec0bcef0be061a2cba93a584355283 (diff) | |
download | myfs-fd125947c9db0b33761414e65e919f73d9bf1815.tar.gz myfs-fd125947c9db0b33761414e65e919f73d9bf1815.zip |
Refactor workspace
Diffstat (limited to 'mkfs.aya/src/main.rs')
-rw-r--r-- | mkfs.aya/src/main.rs | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/mkfs.aya/src/main.rs b/mkfs.aya/src/main.rs index 57ca3fc..3a96d0c 100644 --- a/mkfs.aya/src/main.rs +++ b/mkfs.aya/src/main.rs @@ -1,21 +1,46 @@ -mod block_device; +mod ioctl; -use std::fs::File; -use std::path::PathBuf; use clap::Parser; -use users::{get_current_gid, get_current_uid}; +use std::fs::File; +use std::os::fd::AsRawFd; +use std::path::{Path, PathBuf}; +use std::sync::Arc; +use aya::AyaFS; +use aya::block_device::{BLOCK_SIZE, BlockDevice}; +use aya::block_device::disk::Disk; +use crate::ioctl::ioctl_blkgetsize64; #[derive(Parser, Debug)] #[command(author, version, about)] struct Args { block_device: Option<PathBuf>, - start_point: Option<usize>, - length: Option<usize>, } +fn get_device_size<T: AsRef<Path>>(path: T) -> u64 { + let device = File::options() + .write(true) + .open(path.as_ref()) + .unwrap(); + 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(); + } + device_size +} + + + fn main() { let args = Args::parse(); let device_path = args.block_device.unwrap(); - println!("{:?}", device_path.as_path()); - let mut device = File::open(device_path.as_path()).unwrap(); -}
\ No newline at end of file + 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); +} |