Struct sys_mount::MountBuilder

source ·
pub struct MountBuilder<'a> { /* private fields */ }
Expand description

Builder API for mounting devices

use sys_mount::*;

fn main() -> std::io::Result<()> {
    let _mount = Mount::builder()
        .fstype("btrfs")
        .data("subvol=@home")
        .mount("/dev/sda1", "/home")?;
    Ok(())
}

Implementations

Options to apply for the file system on mount.

The file system that is to be mounted.

Mount flags for the mount syscall.

Offset for the loopback device

Mounts a file system at source to a target path in the system.

use sys_mount::{
    Mount,
    MountFlags,
    SupportedFilesystems
};

// 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()
    .fs_type(&supported)
    .mount("/imaginary/block/device", "/tmp/location");
Notes

The provided source device and target destinations must exist within the file system.

If the source is a file with an extension, a loopback device will be created, and the file will be associated with the loopback device. If the extension is iso or squashfs, the filesystem type will be set accordingly, and the MountFlags will also be modified to ensure that the MountFlags::RDONLY flag is set before mounting.

The fstype parameter accepts either a &str or &SupportedFilesystem as input. If the input is a &str, then a particular file system will be used to mount the source with. If the input is a &SupportedFilesystems, then the file system will be selected automatically from the list.

The automatic variant of fstype works by attempting to mount the source with all supported device-based file systems until it succeeds, or fails after trying all possible options.

Errors
  • If a fstype is not defined and supported filesystems cannot be detected
  • If a loopback device cannot be created
  • If the source or target are not valid C strings
  • If mounting fails

Perform a mount which auto-unmounts on drop.

Errors

On failure to mount

Trait Implementations

Return MountBuilder { flags: MountFlags :: empty(), fstype: Default::default(), loopback_offset: Default::default(), data: Default::default() }

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more