Skip to content

Commit 91de7e6

Browse files
committed
Document the mount.linux module
Also, deprecate a few flags that should not be used by userland.
1 parent c5d6732 commit 91de7e6

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

src/mount/linux.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#![allow(missing_docs)]
21
use crate::errno::Errno;
32
use crate::{NixPath, Result};
43
use libc::{self, c_int, c_ulong};
54

65
libc_bitflags!(
6+
/// Used with [`mount`].
77
pub struct MsFlags: c_ulong {
88
/// Mount read-only
99
MS_RDONLY;
@@ -27,36 +27,80 @@ libc_bitflags!(
2727
MS_NODIRATIME;
2828
/// Linux 2.4.0 - Bind directory at different place
2929
MS_BIND;
30+
/// Move an existing mount to a new location
3031
MS_MOVE;
32+
/// Used to create a recursive bind mount.
3133
MS_REC;
34+
/// Suppress the display of certain kernel warning messages.
3235
MS_SILENT;
36+
/// VFS does not apply the umask
3337
MS_POSIXACL;
38+
/// The resulting mount cannot subsequently be bind mounted.
3439
MS_UNBINDABLE;
40+
/// Make this mount point private.
3541
MS_PRIVATE;
42+
/// If this is a shared mount point that is a member of a peer group
43+
/// that contains other members, convert it to a slave mount.
3644
MS_SLAVE;
45+
/// Make this mount point shared.
3746
MS_SHARED;
47+
/// When a file on this filesystem is accessed, update the file's
48+
/// last access time (atime) only if the current value of atime is
49+
/// less than or equal to the file's last modification time (mtime) or
50+
/// last status change time (ctime).
3851
MS_RELATIME;
52+
/// Mount request came from within the kernel
53+
#[deprecated(since = "0.27.0", note = "Should only be used in-kernel")]
3954
MS_KERNMOUNT;
55+
/// Update inode I_version field
4056
MS_I_VERSION;
57+
/// Always update the last access time (atime) when files on this
58+
/// filesystem are accessed.
4159
MS_STRICTATIME;
60+
/// Reduce on-disk updates of inode timestamps (atime, mtime, ctime) by
61+
/// maintaining these changes only in memory.
4262
MS_LAZYTIME;
63+
#[deprecated(since = "0.27.0", note = "Should only be used in-kernel")]
64+
#[allow(missing_docs)] // Not documented in Linux
4365
MS_ACTIVE;
66+
#[deprecated(since = "0.27.0", note = "Should only be used in-kernel")]
67+
#[allow(missing_docs)] // Not documented in Linux
4468
MS_NOUSER;
69+
#[allow(missing_docs)] // Not documented in Linux; possibly kernel-only
4570
MS_RMT_MASK;
71+
#[allow(missing_docs)] // Not documented in Linux; possibly kernel-only
4672
MS_MGC_VAL;
73+
#[allow(missing_docs)] // Not documented in Linux; possibly kernel-only
4774
MS_MGC_MSK;
4875
}
4976
);
5077

5178
libc_bitflags!(
79+
/// Used with [`umount2].
5280
pub struct MntFlags: c_int {
81+
/// Attempt to unmount even if still in use, aborting pending requests.
5382
MNT_FORCE;
83+
/// Lazy unmount. Disconnect the file system immediately, but don't
84+
/// actually unmount it until it ceases to be busy.
5485
MNT_DETACH;
86+
/// Mark the mount point as expired.
5587
MNT_EXPIRE;
88+
/// Don't dereference `target` if it is a symlink.
5689
UMOUNT_NOFOLLOW;
5790
}
5891
);
5992

93+
/// Mount a file system.
94+
///
95+
/// # Arguments
96+
/// - `source` - Specifies the file system. e.g. `/dev/sd0`.
97+
/// - `target` - Specifies the destination. e.g. `/mnt`.
98+
/// - `fstype` - The file system type, e.g. `ext4`.
99+
/// - `flags` - Optional flags controlling the mount.
100+
/// - `data` - Optional file system specific data.
101+
///
102+
/// # See Also
103+
/// [`mount`](https://man7.org/linux/man-pages/man2/mount.2.html)
60104
pub fn mount<
61105
P1: ?Sized + NixPath,
62106
P2: ?Sized + NixPath,
@@ -99,13 +143,17 @@ pub fn mount<
99143
Errno::result(res).map(drop)
100144
}
101145

146+
/// Unmount the file system mounted at `target`.
102147
pub fn umount<P: ?Sized + NixPath>(target: &P) -> Result<()> {
103148
let res =
104149
target.with_nix_path(|cstr| unsafe { libc::umount(cstr.as_ptr()) })?;
105150

106151
Errno::result(res).map(drop)
107152
}
108153

154+
/// Unmount the file system mounted at `target`.
155+
///
156+
/// See also [`umount`](https://man7.org/linux/man-pages/man2/umount.2.html)
109157
pub fn umount2<P: ?Sized + NixPath>(target: &P, flags: MntFlags) -> Result<()> {
110158
let res = target.with_nix_path(|cstr| unsafe {
111159
libc::umount2(cstr.as_ptr(), flags.bits)

0 commit comments

Comments
 (0)