diff --git a/Cargo.lock b/Cargo.lock index 7079b6e..9915b79 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -70,12 +70,23 @@ dependencies = [ "vec_map", ] +[[package]] +name = "ctrlc" +version = "3.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d91974fbbe88ec1df0c24a4f00f99583667a7e2e6272b2b92d294d81e462173" +dependencies = [ + "nix", + "winapi", +] + [[package]] name = "dokan" version = "0.3.1+dokan206" dependencies = [ "bitflags", "clap", + "ctrlc", "dokan-sys", "lazy_static", "parking_lot", @@ -139,6 +150,18 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "nix" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e322c04a9e3440c327fca7b6c8a63e6890a32fa2ad689db972425f07e0d22abb" +dependencies = [ + "autocfg", + "bitflags", + "cfg-if", + "libc", +] + [[package]] name = "parking_lot" version = "0.11.2" diff --git a/dokan/Cargo.toml b/dokan/Cargo.toml index 5bc7d52..59400c9 100644 --- a/dokan/Cargo.toml +++ b/dokan/Cargo.toml @@ -23,6 +23,7 @@ winapi = { version = "0.3.9", features = ["std", "errhandlingapi", "handleapi", [dev-dependencies] clap = "2.33.3" +ctrlc = "3.2.3" lazy_static = "1.4.0" parking_lot = "0.11.1" regex = "1.4.3" diff --git a/dokan/examples/memfs/main.rs b/dokan/examples/memfs/main.rs index 8ea13ce..7b3b3ad 100644 --- a/dokan/examples/memfs/main.rs +++ b/dokan/examples/memfs/main.rs @@ -15,9 +15,9 @@ use std::{ use clap::{App, Arg}; use dokan::{ - init, shutdown, CreateFileInfo, DiskSpaceInfo, FileInfo, FileSystemHandler, FileSystemMounter, - FileTimeOperation, FillDataError, FillDataResult, FindData, FindStreamData, MountFlags, - MountOptions, OperationInfo, OperationResult, VolumeInfo, IO_SECURITY_CONTEXT, + init, shutdown, unmount, CreateFileInfo, DiskSpaceInfo, FileInfo, FileSystemHandler, + FileSystemMounter, FileTimeOperation, FillDataError, FillDataResult, FindData, FindStreamData, + MountFlags, MountOptions, OperationInfo, OperationResult, VolumeInfo, IO_SECURITY_CONTEXT, }; use dokan_sys::win32::{ FILE_CREATE, FILE_DELETE_ON_CLOSE, FILE_DIRECTORY_FILE, FILE_MAXIMUM_DISPOSITION, @@ -1332,7 +1332,27 @@ fn main() -> Result<(), Box> { init(); let mut mounter = FileSystemMounter::new(&handler, &mount_point, &options); - mounter.mount()?; + + println!("File system will mount..."); + + let file_system = mounter.mount()?; + + // Another thread can unmount the file system. + let mount_point = mount_point.clone(); + ctrlc::set_handler(move || { + if unmount(&mount_point) { + println!("File system will unmount...") + } else { + eprintln!("Failed to unmount file system."); + } + }) + .expect("failed to set Ctrl-C handler"); + + println!("File system is mounted, press Ctrl-C to unmount."); + + drop(file_system); + + println!("File system is unmounted."); shutdown();