Crate sys_mount

Source
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§

Mount
Handle for managing a mounted file system.
MountBuilder
Builder API for mounting devices
MountFlags
Flags which may be specified when mounting a file system.
Mounts
An abstraction that will ensure that temporary mounts are dropped in reverse.
SupportedFilesystems
Data structure for validating if a filesystem argument is valid, and used within automatic file system mounting.
UnmountDrop
Unmounts the underlying mounted device upon drop.
UnmountFlags
Flags which may be specified when unmounting a file system.

Enums§

FilesystemType
Defines how the file system type should be derived for a mount – auto or manual
ScopedMountError

Traits§

Unmount
Unmount trait which enables any type that implements it to be upgraded into an UnmountDrop.

Functions§

scoped_mount
Mount a partition temporarily for the duration of the scoped block within.
swapoff
Unmounts a swap partition using libc::swapoff
unmount
Unmounts the device at path using the provided UnmountFlags.