diff --git a/Cargo.lock b/Cargo.lock index b60f235..a9c6e8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -168,6 +168,16 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "ctrlc" +version = "3.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46f93780a459b7d656ef7f071fe699c4d3d2cb201c4b24d085b6ddc505276e73" +dependencies = [ + "nix 0.30.1", + "windows-sys", +] + [[package]] name = "enum_dispatch" version = "0.3.13" @@ -243,6 +253,7 @@ name = "fat-mount" version = "0.1.0" dependencies = [ "anyhow", + "ctrlc", "env_logger", "fat-fuse", "fuser", @@ -257,7 +268,7 @@ dependencies = [ "libc", "log", "memchr", - "nix", + "nix 0.29.0", "page_size", "pkg-config", "smallvec", @@ -376,6 +387,18 @@ dependencies = [ "libc", ] +[[package]] +name = "nix" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6" +dependencies = [ + "bitflags", + "cfg-if", + "cfg_aliases", + "libc", +] + [[package]] name = "num-traits" version = "0.2.19" diff --git a/fat-mount/Cargo.toml b/fat-mount/Cargo.toml index e9f82da..ba48f80 100644 --- a/fat-mount/Cargo.toml +++ b/fat-mount/Cargo.toml @@ -5,6 +5,7 @@ edition = "2024" [dependencies] anyhow = "1.0.98" +ctrlc = "3.4.7" env_logger = "0.11.8" fat-fuse = { version = "0.1.0", path = "../fat-fuse" } fuser = "0.15.1" diff --git a/fat-mount/src/main.rs b/fat-mount/src/main.rs index d1e5bef..31a5a8f 100644 --- a/fat-mount/src/main.rs +++ b/fat-mount/src/main.rs @@ -1,6 +1,5 @@ -use std::cell::RefCell; use std::fs::File; -use std::rc::Rc; +use std::sync::mpsc::channel; use fat_fuse::FatFuse; use fuser::MountOption; @@ -10,6 +9,7 @@ fn main() -> anyhow::Result<()> { let mut args = std::env::args(); + let _prog_name = args.next().unwrap(); let path = args.next().ok_or(anyhow::anyhow!("missing fs path"))?; let mountpoint = args.next().ok_or(anyhow::anyhow!("missing mount point"))?; @@ -23,7 +23,18 @@ fn main() -> anyhow::Result<()> { MountOption::AutoUnmount, ]; - fuser::mount2(fat_fuse, mountpoint, &options).unwrap(); + let (tx, rx) = channel(); + + ctrlc::set_handler(move || { + tx.send(()).unwrap(); + }) + .unwrap(); + + let handle = fuser::spawn_mount2(fat_fuse, mountpoint, &options)?; + + rx.recv().unwrap(); + + println!("done"); Ok(()) }