summaryrefslogtreecommitdiff
path: root/mkfs.aya/src/main.rs
blob: 3a96d0c43a06b40a1ab4dc6ab9822fce28ebee55 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
mod ioctl;

use clap::Parser;
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>,
}

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();
    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);
}