fat-rs/fat-mount/src/main.rs

38 lines
838 B
Rust
Raw Normal View History

2025-07-30 21:53:18 +02:00
use std::fs::File;
2025-07-31 01:07:48 +02:00
use std::sync::mpsc::channel;
2025-07-30 21:53:18 +02:00
use fat_fuse::FatFuse;
use fuser::MountOption;
fn main() -> anyhow::Result<()> {
env_logger::init();
let mut args = std::env::args();
2025-07-31 01:07:48 +02:00
let _prog_name = args.next().unwrap();
2025-07-30 21:53:18 +02:00
let path = args.next().ok_or(anyhow::anyhow!("missing fs path"))?;
let mountpoint = args.next().ok_or(anyhow::anyhow!("missing mount point"))?;
let file = File::open(path)?;
let fat_fuse = FatFuse::new(file)?;
2025-07-30 21:53:18 +02:00
let options = vec![
MountOption::RO,
MountOption::FSName("fat-fuse".to_owned()),
MountOption::AutoUnmount,
];
2025-07-31 01:07:48 +02:00
let (tx, rx) = channel();
ctrlc::set_handler(move || {
tx.send(()).unwrap();
})
.unwrap();
2025-07-31 01:14:28 +02:00
let _handle = fuser::spawn_mount2(fat_fuse, mountpoint, &options)?;
2025-07-31 01:07:48 +02:00
rx.recv().unwrap();
2025-07-30 21:53:18 +02:00
Ok(())
}