Skip to main content

Mount

Struct Mount 

Source
pub struct Mount { /* private fields */ }
Expand description

A mount.

Implementations§

Source§

impl Mount

Source

pub fn new<S: AsRef<OsStr>>(target: S) -> Self

Creates a new mount at the path target.

Source

pub fn bind<S: AsRef<OsStr>, D: AsRef<OsStr>>(source: S, destination: D) -> Self

Creates a bind mount. This effectively creates hardlink of a directory, making the contents accessible at both places.

By default, none of the mounts in the source directory are visible in destination. To make all mounts recursively visible, combine this with Mount::recursive. Can also be used with Mount::readonly to make the contents of destination read-only.

Source

pub fn rename<S: AsRef<OsStr>, D: AsRef<OsStr>>( source: S, destination: D, ) -> Self

Move/rename a mount.

Source

pub fn devpts<S: AsRef<OsStr>>(target: S) -> Self

Mount a fresh devpts file system. The target is usually /dev/pts.

In order for this devpts to be private and independent of other devpts (i.e., for containers), use:

Mount::devpts("/dev/pts").data("newinstance,ptmxmode=0666")

And either make /dev/ptmx a symlink pointing to /dev/pts/ptmx or bind-mount it.

See also: https://www.kernel.org/doc/Documentation/filesystems/devpts.txt

Source

pub fn proc() -> Self

Mount a fresh proc file system at /proc.

Source

pub fn overlay( lowerdir: &Path, upperdir: &Path, workdir: &Path, merged: &Path, ) -> Self

Mount an overlay file system.

NOTE: This only works in Linux 5.11 or newer when mounted from a user namespace. Otherwise, you need real root privileges to mount an overlayfs.

An overlay filesystem combines two filesystems - an upper filesystem and a lower filesystem. When a name exists in both filesystems, the object in the upper filesystem is visible while the object in the lower filesystem is either hidden or, in the case of directories, merged with the upper object.

In other words, the lowerdir and upperdir are combined into a directory merged using workdir as a temporary work area.

The lower filesystem can be any filesystem supported by Linux and does not need to be writable. The lower filesystem can even be another overlayfs. The upper filesystem should be writable.

See https://www.kernel.org/doc/html/latest/filesystems/overlayfs.html for more information.

§Arguments
  • lowerdir - The lower directory of the overlay. Can be any filesystem and does not need to be writable. This directory is never modified by writes to merged.
  • upperdir - The upper directory of the overlay. This is where all changes to merged are collected. Does not need to be empty, but should be when starting a new overlay from scratch.
  • workdir - The work directory. This should always be empty.
  • merged - The combination of lowerdir and upperdir.
Source

pub fn tmpfs<S: AsRef<OsStr>>(target: S) -> Self

Creates a temporary file system at the location specified.

Source

pub fn sysfs<S: AsRef<OsStr>>(target: S) -> Self

Creates a sys file system at the location specified. The target directory is usually /sys. This is useful when creating a network namespace.

Source

pub fn target<S: AsRef<OsStr>>(self, target: S) -> Self

Sets the mount point target.

Source

pub fn get_target(&self) -> &Path

Returns the mount point target path.

Source

pub fn source<S: AsRef<OsStr>>(self, path: S) -> Self

Sets the source of the mount.

Source

pub fn get_source(&self) -> Option<&Path>

Returns the mount point source path (if any).

Source

pub fn touch_target(self) -> Self

Indicates that the target of a bind mount should be created automatically.

Source

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

Adds mount flags.

Source

pub fn readonly(self) -> Self

Make the file system read-only.

Source

pub fn allow_readonly_fallback(self) -> Self

Allows a new writable proc mount that fails with EPERM to retry read-only.

This explicitly permits the resulting mount to be less capable than requested. It has no effect on non-proc or already-read-only mounts, remounts, bind mounts, moves, or propagation changes.

Source

pub fn recursive(self) -> Self

Makes a bind mount recursive.

Source

pub fn private(self) -> Self

Makes this mount point private. Mount and unmount events do not propagate into or out of this mount point.

Source

pub fn shared(self) -> Self

Make this mount point shared. Mount and unmount events immediately under this mount point will propagate to the other mount points that are members of this mount’s peer group. Propagation here means that the same mount or unmount will automatically occur under all of the other mount points in the peer group. Conversely, mount and unmount events that take place under peer mount points will propagate to this mount point.

Source

pub fn rprivate(self) -> Self

Same as specifying both Mount::recursive and Mount::private.

Source

pub fn rshared(self) -> Self

Same as specifying both Mount::recursive and Mount::shared.

Source

pub fn fstype<S: AsRef<OsStr>>(self, fstype: S) -> Self

Sets the filesystem type.

Source

pub fn data<S: AsRef<OsStr>>(self, data: S) -> Self

Sets any additional data required by the mount.

Trait Implementations§

Source§

impl Clone for Mount

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Mount

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Mount

Source§

impl From<Bind> for Mount

Source§

fn from(b: Bind) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Mount

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a Mount. This accepts the same syntax as Docker mounts where each mount consists of a comma-separated key-value list.

See https://docs.docker.com/storage/bind-mounts/ for more information.

Source§

type Err = MountParseError

The associated error which can be returned from parsing.
Source§

impl PartialEq for Mount

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Mount

Auto Trait Implementations§

§

impl Freeze for Mount

§

impl RefUnwindSafe for Mount

§

impl Send for Mount

§

impl Sync for Mount

§

impl Unpin for Mount

§

impl UnsafeUnpin for Mount

§

impl UnwindSafe for Mount

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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,

Source§

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>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.