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