summaryrefslogtreecommitdiff
path: root/mkfs.aya
diff options
context:
space:
mode:
Diffstat (limited to 'mkfs.aya')
-rw-r--r--mkfs.aya/Cargo.toml5
-rw-r--r--mkfs.aya/src/block_device.rs5
-rw-r--r--mkfs.aya/src/ioctl.rs6
-rw-r--r--mkfs.aya/src/main.rs43
4 files changed, 44 insertions, 15 deletions
diff --git a/mkfs.aya/Cargo.toml b/mkfs.aya/Cargo.toml
index c75e3cb..930feb7 100644
--- a/mkfs.aya/Cargo.toml
+++ b/mkfs.aya/Cargo.toml
@@ -4,5 +4,8 @@ version = "0.1.0"
edition = "2021"
[dependencies]
+ayafs-core = { path = "../ayafs-core" }
users = "0.11.0"
-clap = { version = "4.4.10", features = ["derive"] } \ No newline at end of file
+clap = { version = "4.4.10", features = ["derive"] }
+nix = { version = "0.27.1", features = ["ioctl"] }
+libc = "0.2.150" \ No newline at end of file
diff --git a/mkfs.aya/src/block_device.rs b/mkfs.aya/src/block_device.rs
deleted file mode 100644
index 295b357..0000000
--- a/mkfs.aya/src/block_device.rs
+++ /dev/null
@@ -1,5 +0,0 @@
-pub(crate) const BLOCK_SIZE: usize = 4096;
-pub(crate) trait BlockDevice {
- fn read(&self, block_id: usize, buffer: &mut [u8]);
- fn write(&self, block_id: usize, buffer: &[u8]);
-} \ No newline at end of file
diff --git a/mkfs.aya/src/ioctl.rs b/mkfs.aya/src/ioctl.rs
new file mode 100644
index 0000000..7327f4b
--- /dev/null
+++ b/mkfs.aya/src/ioctl.rs
@@ -0,0 +1,6 @@
+use nix::ioctl_read;
+
+const BLKGETSIZE64_CODE: u8 = 0x12;
+const BLKGETSIZE64_SEQ: u8 = 114;
+
+ioctl_read!(ioctl_blkgetsize64, BLKGETSIZE64_CODE, BLKGETSIZE64_SEQ, u64); \ No newline at end of file
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);
+}