Debian Codegraph @

debian/rust-vendor/rustix/src/mount/mount_unmount.rs

raw
1 //! Linux `mount`.
2
3 use crate::backend::mount::types::{
4 InternalMountFlags, MountFlags, MountFlagsArg, MountPropagationFlags, UnmountFlags,
5 };
6 use crate::ffi::CStr;
7 use crate::path::{self, option_into_with_c_str};
8 use crate::{backend, io};
9
10 /// `mount(source, target, filesystemtype, mountflags, data)`
11 ///
12 /// # References
13 /// - [Linux]
14 ///
15 /// [Linux]: https://man7.org/linux/man-pages/man2/mount.2.html
16 #[inline]
17 pub fn mount<
18 'a,
19 Source: path::Arg,
20 Target: path::Arg,
21 Fs: path::Arg,
22 Data: Into<Option<&'a CStr>>,
23 >(
24 source: Source,
25 target: Target,
26 file_system_type: Fs,
27 flags: MountFlags,
28 data: Data,
29 ) -> io::Result<()> {
30 source.into_with_c_str(|source| {
31 target.into_with_c_str(|target| {
32 file_system_type.into_with_c_str(|file_system_type| {
33 option_into_with_c_str(data.into(), |data| {
34 backend::mount::syscalls::mount(
35 Some(source),
36 target,
37 Some(file_system_type),
38 MountFlagsArg(flags.bits()),
39 data,
40 )
41 })
42 })
43 })
44 })
45 }
46
47 /// `mount(NULL, target, NULL, MS_REMOUNT | mountflags, data)`
48 ///
49 /// # References
50 /// - [Linux]
51 ///
52 /// [Linux]: https://man7.org/linux/man-pages/man2/mount.2.html
53 #[inline]
54 #[doc(alias = "mount")]
55 #[doc(alias = "MS_REMOUNT")]
56 pub fn mount_remount<Target: path::Arg, Data: path::Arg>(
57 target: Target,
58 flags: MountFlags,
59 data: Data,
60 ) -> io::Result<()> {
61 target.into_with_c_str(|target| {
62 data.into_with_c_str(|data| {
63 backend::mount::syscalls::mount(
64 None,
65 target,
66 None,
67 MountFlagsArg(InternalMountFlags::REMOUNT.bits() | flags.bits()),
68 Some(data),
69 )
70 })
71 })
72 }
73
74 /// `mount(source, target, NULL, MS_BIND, NULL)`
75 ///
76 /// # References
77 /// - [Linux]
78 ///
79 /// [Linux]: https://man7.org/linux/man-pages/man2/mount.2.html
80 #[inline]
81 #[doc(alias = "mount")]
82 #[doc(alias = "MS_BIND")]
83 pub fn mount_bind<Source: path::Arg, Target: path::Arg>(
84 source: Source,
85 target: Target,
86 ) -> io::Result<()> {
87 source.into_with_c_str(|source| {
88 target.into_with_c_str(|target| {
89 backend::mount::syscalls::mount(
90 Some(source),
91 target,
92 None,
93 MountFlagsArg(MountFlags::BIND.bits()),
94 None,
95 )
96 })
97 })
98 }
99
100 /// `mount(source, target, NULL, MS_BIND | MS_REC, NULL)`
101 ///
102 /// # References
103 /// - [Linux]
104 ///
105 /// [Linux]: https://man7.org/linux/man-pages/man2/mount.2.html
106 #[inline]
107 #[doc(alias = "mount")]
108 #[doc(alias = "MS_REC")]
109 pub fn mount_bind_recursive<Source: path::Arg, Target: path::Arg>(
110 source: Source,
111 target: Target,
112 ) -> io::Result<()> {
113 source.into_with_c_str(|source| {
114 target.into_with_c_str(|target| {
115 backend::mount::syscalls::mount(
116 Some(source),
117 target,
118 None,
119 MountFlagsArg(MountFlags::BIND.bits() | MountPropagationFlags::REC.bits()),
120 None,
121 )
122 })
123 })
124 }
125
126 /// `mount(NULL, target, NULL, mountflags, NULL)`
127 ///
128 /// # References
129 /// - [Linux]
130 ///
131 /// [Linux]: https://man7.org/linux/man-pages/man2/mount.2.html
132 #[inline]
133 #[doc(alias = "mount")]
134 pub fn mount_change<Target: path::Arg>(
135 target: Target,
136 flags: MountPropagationFlags,
137 ) -> io::Result<()> {
138 target.into_with_c_str(|target| {
139 backend::mount::syscalls::mount(None, target, None, MountFlagsArg(flags.bits()), None)
140 })
141 }
142
143 /// `mount(source, target, NULL, MS_MOVE, NULL)`
144 ///
145 /// This is not the same as the `move_mount` syscall. If you want to use that,
146 /// use [`move_mount`] instead.
147 ///
148 /// # References
149 /// - [Linux]
150 ///
151 /// [`move_mount`]: crate::mount::move_mount
152 /// [Linux]: https://man7.org/linux/man-pages/man2/mount.2.html
153 #[inline]
154 #[doc(alias = "mount")]
155 #[doc(alias = "MS_MOVE")]
156 pub fn mount_move<Source: path::Arg, Target: path::Arg>(
157 source: Source,
158 target: Target,
159 ) -> io::Result<()> {
160 source.into_with_c_str(|source| {
161 target.into_with_c_str(|target| {
162 backend::mount::syscalls::mount(
163 Some(source),
164 target,
165 None,
166 MountFlagsArg(InternalMountFlags::MOVE.bits()),
167 None,
168 )
169 })
170 })
171 }
172
173 /// `umount2(target, flags)`
174 ///
175 /// # References
176 /// - [Linux]
177 ///
178 /// [Linux]: https://man7.org/linux/man-pages/man2/umount.2.html
179 #[inline]
180 #[doc(alias = "umount", alias = "umount2")]
181 pub fn unmount<Target: path::Arg>(target: Target, flags: UnmountFlags) -> io::Result<()> {
182 target.into_with_c_str(|target| backend::mount::syscalls::unmount(target, flags))
183 }