Skip to content

Commit

Permalink
feat(dokan/examples/memfs): unmount from another thread
Browse files Browse the repository at this point in the history
  • Loading branch information
KoltesDigital committed Oct 4, 2022
1 parent b3aaf54 commit bab8283
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dokan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 24 additions & 4 deletions dokan/examples/memfs/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1332,7 +1332,27 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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();

Expand Down

0 comments on commit bab8283

Please sign in to comment.