Expand description
High level abstraction over the mount
and umount2
system calls.
If the loop
feature is enabled (default), additionally supports creating loopback devices
automatically when mounting an iso or squashfs file.
Example
extern crate sys_mount;
use std::process::exit;
use sys_mount::{
Mount,
MountFlags,
SupportedFilesystems,
Unmount,
UnmountFlags
};
fn main() {
// Fetch a list of supported file systems.
// When mounting, a file system will be selected from this.
let supported = SupportedFilesystems::new().unwrap();
// Attempt to mount the src device to the dest directory.
let mount_result = Mount::builder()
.fstype("btrfs")
.data("subvol=@home")
.mount("/dev/sda1", "/home");
match mount_result {
Ok(mount) => {
// Make the mount temporary, so that it will be unmounted on drop.
let mount = mount.into_unmount_drop(UnmountFlags::DETACH);
// Do thing with the mounted device.
}
Err(why) => {
eprintln!("failed to mount device: {}", why);
exit(1);
}
}
}
Structs
Handle for managing a mounted file system.
Builder API for mounting devices
Flags which may be specified when mounting a file system.
An abstraction that will ensure that temporary mounts are dropped in reverse.
Data structure for validating if a filesystem argument is valid, and used within
automatic file system mounting.
Unmounts the underlying mounted device upon drop.
Flags which may be specified when unmounting a file system.
Enums
Defines how the file system type should be derived for a mount – auto or manual
Traits
Unmount trait which enables any type that implements it to be upgraded into an
UnmountDrop
.Functions
Mount a partition temporarily for the duration of the scoped block within.
Unmounts a swap partition using
libc::swapoff
Unmounts the device at
path
using the provided UnmountFlags
.