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§

source§

impl<'a> MountBuilder<'a>

source

pub fn data(self, data: &'a str) -> Self

Options to apply for the file system on mount.

source

pub fn fstype(self, fs: impl Into<FilesystemType<'a>>) -> Self

The file system that is to be mounted.

source

pub fn flags(self, flags: MountFlags) -> Self

Mount flags for the mount syscall.

source

pub fn loopback_offset(self, offset: u64) -> Self

Offset for the loopback device

source

pub fn explicit_loopback(self) -> Self

Use loopback even if not an iso or squashfs is being mounted

source

pub fn mount( self, source: impl AsRef<Path>, target: impl AsRef<Path> ) -> Result<Mount>

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()
    .fstype(&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
source

pub fn mount_autodrop( self, source: impl AsRef<Path>, target: impl AsRef<Path>, unmount_flags: UnmountFlags ) -> Result<UnmountDrop<Mount>>

Perform a mount which auto-unmounts on drop.

§Errors

On failure to mount

Trait Implementations§

source§

impl<'a> Clone for MountBuilder<'a>

source§

fn clone(&self) -> MountBuilder<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Default for MountBuilder<'a>

source§

fn default() -> Self

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

source§

impl<'a> Copy for MountBuilder<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for MountBuilder<'a>

§

impl<'a> Send for MountBuilder<'a>

§

impl<'a> Sync for MountBuilder<'a>

§

impl<'a> Unpin for MountBuilder<'a>

§

impl<'a> UnwindSafe for MountBuilder<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more