1
- #![ allow( missing_docs) ]
2
1
use crate :: errno:: Errno ;
3
2
use crate :: { NixPath , Result } ;
4
3
use libc:: { self , c_int, c_ulong} ;
5
4
6
5
libc_bitflags ! (
6
+ /// Used with [`mount`].
7
7
pub struct MsFlags : c_ulong {
8
8
/// Mount read-only
9
9
MS_RDONLY ;
@@ -27,36 +27,80 @@ libc_bitflags!(
27
27
MS_NODIRATIME ;
28
28
/// Linux 2.4.0 - Bind directory at different place
29
29
MS_BIND ;
30
+ /// Move an existing mount to a new location
30
31
MS_MOVE ;
32
+ /// Used to create a recursive bind mount.
31
33
MS_REC ;
34
+ /// Suppress the display of certain kernel warning messages.
32
35
MS_SILENT ;
36
+ /// VFS does not apply the umask
33
37
MS_POSIXACL ;
38
+ /// The resulting mount cannot subsequently be bind mounted.
34
39
MS_UNBINDABLE ;
40
+ /// Make this mount point private.
35
41
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.
36
44
MS_SLAVE ;
45
+ /// Make this mount point shared.
37
46
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).
38
51
MS_RELATIME ;
52
+ /// Mount request came from within the kernel
53
+ #[ deprecated( since = "0.27.0" , note = "Should only be used in-kernel" ) ]
39
54
MS_KERNMOUNT ;
55
+ /// Update inode I_version field
40
56
MS_I_VERSION ;
57
+ /// Always update the last access time (atime) when files on this
58
+ /// filesystem are accessed.
41
59
MS_STRICTATIME ;
60
+ /// Reduce on-disk updates of inode timestamps (atime, mtime, ctime) by
61
+ /// maintaining these changes only in memory.
42
62
MS_LAZYTIME ;
63
+ #[ deprecated( since = "0.27.0" , note = "Should only be used in-kernel" ) ]
64
+ #[ allow( missing_docs) ] // Not documented in Linux
43
65
MS_ACTIVE ;
66
+ #[ deprecated( since = "0.27.0" , note = "Should only be used in-kernel" ) ]
67
+ #[ allow( missing_docs) ] // Not documented in Linux
44
68
MS_NOUSER ;
69
+ #[ allow( missing_docs) ] // Not documented in Linux; possibly kernel-only
45
70
MS_RMT_MASK ;
71
+ #[ allow( missing_docs) ] // Not documented in Linux; possibly kernel-only
46
72
MS_MGC_VAL ;
73
+ #[ allow( missing_docs) ] // Not documented in Linux; possibly kernel-only
47
74
MS_MGC_MSK ;
48
75
}
49
76
) ;
50
77
51
78
libc_bitflags ! (
79
+ /// Used with [`umount2].
52
80
pub struct MntFlags : c_int {
81
+ /// Attempt to unmount even if still in use, aborting pending requests.
53
82
MNT_FORCE ;
83
+ /// Lazy unmount. Disconnect the file system immediately, but don't
84
+ /// actually unmount it until it ceases to be busy.
54
85
MNT_DETACH ;
86
+ /// Mark the mount point as expired.
55
87
MNT_EXPIRE ;
88
+ /// Don't dereference `target` if it is a symlink.
56
89
UMOUNT_NOFOLLOW ;
57
90
}
58
91
) ;
59
92
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)
60
104
pub fn mount <
61
105
P1 : ?Sized + NixPath ,
62
106
P2 : ?Sized + NixPath ,
@@ -99,13 +143,17 @@ pub fn mount<
99
143
Errno :: result ( res) . map ( drop)
100
144
}
101
145
146
+ /// Unmount the file system mounted at `target`.
102
147
pub fn umount < P : ?Sized + NixPath > ( target : & P ) -> Result < ( ) > {
103
148
let res =
104
149
target. with_nix_path ( |cstr| unsafe { libc:: umount ( cstr. as_ptr ( ) ) } ) ?;
105
150
106
151
Errno :: result ( res) . map ( drop)
107
152
}
108
153
154
+ /// Unmount the file system mounted at `target`.
155
+ ///
156
+ /// See also [`umount`](https://man7.org/linux/man-pages/man2/umount.2.html)
109
157
pub fn umount2 < P : ?Sized + NixPath > ( target : & P , flags : MntFlags ) -> Result < ( ) > {
110
158
let res = target. with_nix_path ( |cstr| unsafe {
111
159
libc:: umount2 ( cstr. as_ptr ( ) , flags. bits )
0 commit comments