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>
impl<'a> MountBuilder<'a>
sourcepub fn fstype(self, fs: impl Into<FilesystemType<'a>>) -> Self
pub fn fstype(self, fs: impl Into<FilesystemType<'a>>) -> Self
The file system that is to be mounted.
sourcepub fn flags(self, flags: MountFlags) -> Self
pub fn flags(self, flags: MountFlags) -> Self
Mount flags for the mount syscall.
sourcepub fn loopback_offset(self, offset: u64) -> Self
pub fn loopback_offset(self, offset: u64) -> Self
Offset for the loopback device
sourcepub fn explicit_loopback(self) -> Self
pub fn explicit_loopback(self) -> Self
Use loopback even if not an iso or squashfs is being mounted
sourcepub fn mount(
self,
source: impl AsRef<Path>,
target: impl AsRef<Path>
) -> Result<Mount>
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
sourcepub fn mount_autodrop(
self,
source: impl AsRef<Path>,
target: impl AsRef<Path>,
unmount_flags: UnmountFlags
) -> Result<UnmountDrop<Mount>>
pub fn mount_autodrop( self, source: impl AsRef<Path>, target: impl AsRef<Path>, unmount_flags: UnmountFlags ) -> Result<UnmountDrop<Mount>>
Trait Implementations§
source§impl<'a> Clone for MountBuilder<'a>
impl<'a> Clone for MountBuilder<'a>
source§fn clone(&self) -> MountBuilder<'a>
fn clone(&self) -> MountBuilder<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more