summaryrefslogtreecommitdiff
path: root/mkfs.aya/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'mkfs.aya/src/main.rs')
-rw-r--r--mkfs.aya/src/main.rs43
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);
+}