sys_mount/flags.rs
1// Copyright 2018-2022 System76 <info@system76.com>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4use libc::{
5 c_int, c_ulong, MNT_DETACH, MNT_EXPIRE, MNT_FORCE, MS_BIND, MS_DIRSYNC, MS_MANDLOCK, MS_MOVE,
6 MS_NOATIME, MS_NODEV, MS_NODIRATIME, MS_NOEXEC, MS_NOSUID, MS_PRIVATE, MS_RDONLY, MS_REC,
7 MS_RELATIME, MS_REMOUNT, MS_SHARED, MS_SILENT, MS_SLAVE, MS_STRICTATIME, MS_SYNCHRONOUS,
8 MS_UNBINDABLE, O_NOFOLLOW,
9};
10
11bitflags! {
12 /// Flags which may be specified when mounting a file system.
13 #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
14 pub struct MountFlags: c_ulong {
15 /// Perform a bind mount, making a file or a directory subtree visible at another
16 /// point within a file system. Bind mounts may cross file system boundaries and
17 /// span chroot(2) jails. The filesystemtype and data arguments are ignored. Up
18 /// until Linux 2.6.26, mountflags was also ignored (the bind mount has the same
19 /// mount options as the underlying mount point).
20 const BIND = MS_BIND;
21
22 /// Make directory changes on this file system synchronous.(This property can be
23 /// obtained for individual directories or subtrees using chattr(1).)
24 const DIRSYNC = MS_DIRSYNC;
25
26 /// Permit mandatory locking on files in this file system. (Mandatory locking must
27 /// still be enabled on a per-file basis, as described in fcntl(2).)
28 const MANDLOCK = MS_MANDLOCK;
29
30 /// Move a subtree. source specifies an existing mount point and target specifies
31 /// the new location. The move is atomic: at no point is the subtree unmounted.
32 /// The filesystemtype, mountflags, and data arguments are ignored.
33 const MOVE = MS_MOVE;
34
35 /// Do not update access times for (all types of) files on this file system.
36 const NOATIME = MS_NOATIME;
37
38 /// Do not allow access to devices (special files) on this file system.
39 const NODEV = MS_NODEV;
40
41 /// Do not update access times for directories on this file system. This flag provides
42 /// a subset of the functionality provided by MS_NOATIME; that is, MS_NOATIME implies
43 /// MS_NODIRATIME.
44 const NODIRATIME = MS_NODIRATIME;
45
46 /// Do not allow programs to be executed from this file system.
47 const NOEXEC = MS_NOEXEC;
48
49 /// Do not honor set-user-ID and set-group-ID bits when executing programs from this
50 /// file system.
51 const NOSUID = MS_NOSUID;
52
53 /// Mount file system read-only.
54 const RDONLY = MS_RDONLY;
55
56 /// Used in conjunction with MS_BIND to create a recursive bind mount, and in
57 /// conjunction with the propagation type flags to recursively change the propagation
58 /// type of all of the mounts in a subtree.
59 const REC = MS_REC;
60
61 /// When a file on this file system is accessed, only update the file's last access
62 /// time (atime) if the current value of atime is less than or equal to the file's
63 /// last modification time (mtime) or last status change time (ctime). This option is
64 /// useful for programs, such as mutt(1), that need to know when a file has been read
65 /// since it was last modified. Since Linux 2.6.30, the kernel defaults to the behavior
66 /// provided by this flag (unless MS_NOATIME was specified), and the MS_STRICTATIME
67 /// flag is required to obtain traditional semantics. In addition, since Linux 2.6.30,
68 /// the file's last access time is always updated if it is more than 1 day old.
69 const RELATIME = MS_RELATIME;
70
71 /// Remount an existing mount. This allows you to change the mountflags and data of an
72 /// existing mount without having to unmount and remount the file system. target should
73 /// be the same value specified in the initial mount() call; source and filesystemtype
74 /// are ignored.
75 ///
76 /// The following mountflags can be changed: MS_RDONLY, MS_SYNCHRONOUS, MS_MANDLOCK;
77 /// before kernel 2.6.16, the following could also be changed: MS_NOATIME and
78 /// MS_NODIRATIME; and, additionally, before kernel 2.4.10, the following could also
79 /// be changed: MS_NOSUID, MS_NODEV, MS_NOEXEC.
80 const REMOUNT = MS_REMOUNT;
81
82 /// Suppress the display of certain (printk()) warning messages in the kernel log.
83 /// This flag supersedes the misnamed and obsolete MS_VERBOSE flag (available
84 /// since Linux 2.4.12), which has the same meaning.
85 const SILENT = MS_SILENT;
86
87 /// Always update the last access time (atime) when files on this file system are
88 /// accessed. (This was the default behavior before Linux 2.6.30.) Specifying this
89 /// flag overrides the effect of setting the MS_NOATIME and MS_RELATIME flags.
90 const STRICTATIME = MS_STRICTATIME;
91
92 /// Make writes on this file system synchronous (as though the O_SYNC flag to
93 /// open(2) was specified for all file opens to this file system).
94 const SYNCHRONOUS = MS_SYNCHRONOUS;
95 }
96}
97
98bitflags! {
99 /// Propagation type flags which may be specified after mounting a file system to specify how mount
100 /// events are propagated.
101 #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
102 pub struct PropagationType: c_ulong {
103 /// The mount is in a peer group, it can be replicated to as many mountpoints, and all replicas are identical
104 /// (events are propagated to other peer mounts).
105 const SHARED = MS_SHARED;
106
107 /// The mount can receive propagated mount events from its parent (peer group), but cannot propagate mount
108 /// events to the peer group.
109 const SLAVE = MS_SLAVE;
110
111 /// The mount is private, it neither receives or sends any mount events
112 const PRIVATE = MS_PRIVATE;
113
114 /// The mount is private and cannot be used as a bind mount source.
115 const UNBINDABLE = MS_UNBINDABLE;
116 }
117}
118
119bitflags! {
120 /// Flags which may be specified when unmounting a file system.
121 #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
122 pub struct UnmountFlags: c_int {
123 /// Force unmount even if busy. This can cause data loss. (Only for NFS mounts.)
124 const FORCE = MNT_FORCE;
125
126 /// Perform a lazy unmount: make the mount point unavailable for new accesses,
127 /// and actually perform the unmount when the mount point ceases to be busy.
128 const DETACH = MNT_DETACH;
129
130 /// Mark the mount point as expired. If a mount point is not currently in use,
131 /// then an initial call to umount2() with this flag fails with the error EAGAIN,
132 /// but marks the mount point as expired. The mount point remains expired as
133 /// long as it isn't accessed by any process. A second umount2() call specifying
134 /// MNT_EXPIRE unmounts an expired mount point. This flag cannot be specified with
135 /// either MNT_FORCE or MNT_DETACH.
136 const EXPIRE = MNT_EXPIRE;
137
138 /// Don't dereference target if it is a symbolic link. This flag allows security
139 /// problems to be avoided in set-user-ID-root programs that allow unprivileged
140 /// users to unmount file systems.
141 const NOFOLLOW = O_NOFOLLOW;
142 }
143}