starnix_uapi/
mount_flags.rs

1// Copyright 2023 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use crate::uapi;
6use bitflags::bitflags;
7
8bitflags! {
9    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
10    pub struct MountFlags: u32 {
11        // per-mountpoint flags
12        const RDONLY = uapi::MS_RDONLY;
13        const NOEXEC = uapi::MS_NOEXEC;
14        const NOSUID = uapi::MS_NOSUID;
15        const NODEV = uapi::MS_NODEV;
16        const NOATIME = uapi::MS_NOATIME;
17        const NODIRATIME = uapi::MS_NODIRATIME;
18        const RELATIME = uapi::MS_RELATIME;
19        const STRICTATIME = uapi::MS_STRICTATIME;
20
21        // per-superblock flags
22        const SILENT = uapi::MS_SILENT;
23        const LAZYTIME = uapi::MS_LAZYTIME;
24        const SYNCHRONOUS = uapi::MS_SYNCHRONOUS;
25        const DIRSYNC = uapi::MS_DIRSYNC;
26        const MANDLOCK = uapi::MS_MANDLOCK;
27
28        // mount() control flags
29        const REMOUNT = uapi::MS_REMOUNT;
30        const BIND = uapi::MS_BIND;
31        const REC = uapi::MS_REC;
32        const DOWNSTREAM = uapi::MS_SLAVE;
33        const SHARED = uapi::MS_SHARED;
34        const PRIVATE = uapi::MS_PRIVATE;
35
36        /// Flags stored in Mount state.
37        const STORED_ON_MOUNT = Self::RDONLY.bits() | Self::NOEXEC.bits() | Self::NOSUID.bits() |
38            Self::NODEV.bits() | Self::NOATIME.bits() | Self::NODIRATIME.bits() | Self::RELATIME.bits();
39
40        /// Flags stored in FileSystem options.
41        const STORED_ON_FILESYSTEM = Self::RDONLY.bits() | Self::DIRSYNC.bits() | Self::LAZYTIME.bits() |
42            Self::MANDLOCK.bits() | Self::SILENT.bits() | Self::SYNCHRONOUS.bits();
43
44        /// Flags that change be changed with REMOUNT.
45        ///
46        /// MS_DIRSYNC and MS_SILENT cannot be changed with REMOUNT.
47        const CHANGEABLE_WITH_REMOUNT = Self::STORED_ON_MOUNT.bits() | Self::STRICTATIME.bits() |
48            Self::MANDLOCK.bits() | Self::LAZYTIME.bits() | Self::SYNCHRONOUS.bits();
49    }
50}
51
52impl std::fmt::Display for MountFlags {
53    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54        write!(f, "{}", if self.contains(Self::RDONLY) { "ro" } else { "rw" })?;
55        if self.contains(Self::NOEXEC) {
56            write!(f, ",noexec")?;
57        }
58        if self.contains(Self::NOSUID) {
59            write!(f, ",nosuid")?;
60        }
61        if self.contains(Self::NODEV) {
62            write!(f, ",nodev")?
63        }
64        if self.contains(Self::NOATIME) {
65            write!(f, ",noatime")?;
66        }
67        if self.contains(Self::NOEXEC) {
68            write!(f, ",noexec")?;
69        }
70        if self.contains(Self::SILENT) {
71            write!(f, ",silent")?;
72        }
73        if self.contains(Self::BIND) {
74            write!(f, ",bind")?;
75        }
76        if self.contains(Self::LAZYTIME) {
77            write!(f, ",lazytime")?;
78        }
79        Ok(())
80    }
81}