[][src]Crate sys_mount

High level abstraction over the mount and umount2 system calls.

Additionally creates 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::new(
        "/imaginary/block/device",
        "/tmp/location",
        &supported,
        MountFlags::empty(),
        None
    );

    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.

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

Traits

Unmount

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

Functions

swapoff

Unmounts a swap partition using libc::swapoff

unmount

Unmounts the device at path using the provided UnmountFlags.