-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
105 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use std::path::Path; | ||
|
||
use fuser::{MountOption, Session, SessionUnmounter}; | ||
|
||
use crate::Driver; | ||
|
||
/// A struct to mount the filesystem. | ||
pub struct Mount { | ||
#[cfg(unix)] | ||
session: Session<Driver>, | ||
} | ||
|
||
impl Mount { | ||
/// Mount the filesystem implemented by [`Driver`] to the provided mountpoint. | ||
/// | ||
/// You can specify the mount options using the `options` parameter. | ||
pub fn mount( | ||
driver: Driver, | ||
mountpoint: &Path, | ||
options: &[MountOption], | ||
) -> Result<Self, std::io::Error> { | ||
let session = Session::new(driver, mountpoint, options)?; | ||
|
||
Ok(Self { | ||
#[cfg(unix)] | ||
session, | ||
}) | ||
} | ||
|
||
/// Run the filesystem event loop. | ||
/// | ||
/// This function will block the current thread. | ||
pub fn run(&mut self) -> Result<(), std::io::Error> { | ||
#[cfg(unix)] | ||
self.session.run() | ||
} | ||
|
||
/// Get a handle to unmount the filesystem. | ||
/// | ||
/// To umount see [`Umount::umount`]. | ||
pub fn unmounter(&mut self) -> Umount { | ||
#[cfg(unix)] | ||
Umount { | ||
umount: self.session.unmount_callable(), | ||
} | ||
} | ||
} | ||
|
||
/// A thread-safe handle to unmount the filesystem. | ||
pub struct Umount { | ||
#[cfg(unix)] | ||
umount: SessionUnmounter, | ||
} | ||
|
||
impl Umount { | ||
/// Unmount the filesystem. | ||
pub fn umount(&mut self) -> Result<(), std::io::Error> { | ||
#[cfg(unix)] | ||
self.umount.unmount() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters