|
1 | 1 | //! Linux `mount`.
|
2 | 2 |
|
3 |
| -use crate::backend::fs::types::{ |
4 |
| - FsMountFlags, FsOpenFlags, FsPickFlags, InternalMountFlags, MountAttrFlags, MountFlags, |
5 |
| - MountFlagsArg, MountPropagationFlags, MoveMountFlags, OpenTreeFlags, UnmountFlags, |
6 |
| -}; |
7 |
| -use crate::fd::{BorrowedFd, OwnedFd}; |
8 |
| -use crate::{backend, io, path}; |
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<Source: path::Arg, Target: path::Arg, Fs: path::Arg, Data: path::Arg>( |
18 |
| - source: Source, |
19 |
| - target: Target, |
20 |
| - file_system_type: Fs, |
21 |
| - flags: MountFlags, |
22 |
| - data: Data, |
23 |
| -) -> io::Result<()> { |
24 |
| - source.into_with_c_str(|source| { |
25 |
| - target.into_with_c_str(|target| { |
26 |
| - file_system_type.into_with_c_str(|file_system_type| { |
27 |
| - data.into_with_c_str(|data| { |
28 |
| - backend::fs::syscalls::mount( |
29 |
| - Some(source), |
30 |
| - target, |
31 |
| - Some(file_system_type), |
32 |
| - MountFlagsArg(flags.bits()), |
33 |
| - Some(data), |
34 |
| - ) |
35 |
| - }) |
36 |
| - }) |
37 |
| - }) |
38 |
| - }) |
39 |
| -} |
40 |
| - |
41 |
| -/// `mount(NULL, target, NULL, MS_REMOUNT | mountflags, data)` |
42 |
| -/// |
43 |
| -/// # References |
44 |
| -/// - [Linux] |
45 |
| -/// |
46 |
| -/// [Linux]: https://man7.org/linux/man-pages/man2/mount.2.html |
47 |
| -#[inline] |
48 |
| -#[doc(alias = "mount")] |
49 |
| -pub fn remount<Target: path::Arg, Data: path::Arg>( |
50 |
| - target: Target, |
51 |
| - flags: MountFlags, |
52 |
| - data: Data, |
53 |
| -) -> io::Result<()> { |
54 |
| - target.into_with_c_str(|target| { |
55 |
| - data.into_with_c_str(|data| { |
56 |
| - backend::fs::syscalls::mount( |
57 |
| - None, |
58 |
| - target, |
59 |
| - None, |
60 |
| - MountFlagsArg(InternalMountFlags::REMOUNT.bits() | flags.bits()), |
61 |
| - Some(data), |
62 |
| - ) |
63 |
| - }) |
64 |
| - }) |
65 |
| -} |
66 |
| - |
67 |
| -/// `mount(source, target, NULL, MS_BIND, NULL)` |
68 |
| -/// |
69 |
| -/// # References |
70 |
| -/// - [Linux] |
71 |
| -/// |
72 |
| -/// [Linux]: https://man7.org/linux/man-pages/man2/mount.2.html |
73 |
| -#[inline] |
74 |
| -#[doc(alias = "mount")] |
75 |
| -pub fn bind_mount<Source: path::Arg, Target: path::Arg>( |
76 |
| - source: Source, |
77 |
| - target: Target, |
78 |
| -) -> io::Result<()> { |
79 |
| - source.into_with_c_str(|source| { |
80 |
| - target.into_with_c_str(|target| { |
81 |
| - backend::fs::syscalls::mount( |
82 |
| - Some(source), |
83 |
| - target, |
84 |
| - None, |
85 |
| - MountFlagsArg(MountFlags::BIND.bits()), |
86 |
| - None, |
87 |
| - ) |
88 |
| - }) |
89 |
| - }) |
90 |
| -} |
91 |
| - |
92 |
| -/// `mount(source, target, NULL, MS_BIND | MS_REC, NULL)` |
93 |
| -/// |
94 |
| -/// # References |
95 |
| -/// - [Linux] |
96 |
| -/// |
97 |
| -/// [Linux]: https://man7.org/linux/man-pages/man2/mount.2.html |
98 |
| -#[inline] |
99 |
| -#[doc(alias = "mount")] |
100 |
| -pub fn recursive_bind_mount<Source: path::Arg, Target: path::Arg>( |
101 |
| - source: Source, |
102 |
| - target: Target, |
103 |
| -) -> io::Result<()> { |
104 |
| - source.into_with_c_str(|source| { |
105 |
| - target.into_with_c_str(|target| { |
106 |
| - backend::fs::syscalls::mount( |
107 |
| - Some(source), |
108 |
| - target, |
109 |
| - None, |
110 |
| - MountFlagsArg(MountFlags::BIND.bits() | MountPropagationFlags::REC.bits()), |
111 |
| - None, |
112 |
| - ) |
113 |
| - }) |
114 |
| - }) |
115 |
| -} |
116 |
| - |
117 |
| -/// `mount(NULL, target, NULL, mountflags, NULL)` |
118 |
| -/// |
119 |
| -/// # References |
120 |
| -/// - [Linux] |
121 |
| -/// |
122 |
| -/// [Linux]: https://man7.org/linux/man-pages/man2/mount.2.html |
123 |
| -#[inline] |
124 |
| -#[doc(alias = "mount")] |
125 |
| -pub fn change_mount<Target: path::Arg>( |
126 |
| - target: Target, |
127 |
| - flags: MountPropagationFlags, |
128 |
| -) -> io::Result<()> { |
129 |
| - target.into_with_c_str(|target| { |
130 |
| - backend::fs::syscalls::mount(None, target, None, MountFlagsArg(flags.bits()), None) |
131 |
| - }) |
132 |
| -} |
133 |
| - |
134 |
| -/// `mount(source, target, NULL, MS_MOVE, NULL)` |
135 |
| -/// |
136 |
| -/// This is not the same as the `move_mount` syscall. If you want to use that, |
137 |
| -/// use [`move_mount_syscall`] instead. |
138 |
| -/// Its name will be changed in the next semver bump to avoid confusion. |
139 |
| -/// |
140 |
| -/// # References |
141 |
| -/// - [Linux] |
142 |
| -/// |
143 |
| -/// [Linux]: https://man7.org/linux/man-pages/man2/mount.2.html |
144 |
| -#[inline] |
145 |
| -#[doc(alias = "mount")] |
146 |
| -pub fn move_mount<Source: path::Arg, Target: path::Arg>( |
147 |
| - source: Source, |
148 |
| - target: Target, |
149 |
| -) -> io::Result<()> { |
150 |
| - source.into_with_c_str(|source| { |
151 |
| - target.into_with_c_str(|target| { |
152 |
| - backend::fs::syscalls::mount( |
153 |
| - Some(source), |
154 |
| - target, |
155 |
| - None, |
156 |
| - MountFlagsArg(InternalMountFlags::MOVE.bits()), |
157 |
| - None, |
158 |
| - ) |
159 |
| - }) |
160 |
| - }) |
161 |
| -} |
162 |
| - |
163 |
| -/// `umount2(target, flags)` |
164 |
| -/// |
165 |
| -/// # References |
166 |
| -/// - [Linux] |
167 |
| -/// |
168 |
| -/// [Linux]: https://man7.org/linux/man-pages/man2/umount.2.html |
169 |
| -#[inline] |
170 |
| -#[doc(alias = "umount", alias = "umount2")] |
171 |
| -pub fn unmount<Target: path::Arg>(target: Target, flags: UnmountFlags) -> io::Result<()> { |
172 |
| - target.into_with_c_str(|target| backend::fs::syscalls::unmount(target, flags)) |
173 |
| -} |
174 |
| - |
175 |
| -/// `fsopen(fs_name, flags)` |
176 |
| -#[inline] |
177 |
| -pub fn fsopen<Fs: path::Arg>(fs_name: Fs, flags: FsOpenFlags) -> io::Result<OwnedFd> { |
178 |
| - fs_name.into_with_c_str(|fs_name| backend::fs::syscalls::fsopen(fs_name, flags)) |
179 |
| -} |
180 |
| - |
181 |
| -/// `fsmount(fs_fd, flags, attr_flags)` |
182 |
| -#[inline] |
183 |
| -pub fn fsmount( |
184 |
| - fs_fd: BorrowedFd<'_>, |
185 |
| - flags: FsMountFlags, |
186 |
| - attr_flags: MountAttrFlags, |
187 |
| -) -> io::Result<()> { |
188 |
| - backend::fs::syscalls::fsmount(fs_fd, flags, attr_flags) |
189 |
| -} |
190 |
| - |
191 |
| -/// `move_mount(from_dfd, from_pathname, to_dfd, to_pathname, flags)` |
192 |
| -/// This is the `move_mount` syscall, and it will be renamed to `move_mount` |
193 |
| -/// in the next semver bump. |
194 |
| -#[inline] |
195 |
| -#[doc(alias = "move_mount")] |
196 |
| -pub fn move_mount_syscall<From: path::Arg, To: path::Arg>( |
197 |
| - from_dfd: BorrowedFd<'_>, |
198 |
| - from_pathname: From, |
199 |
| - to_dfd: BorrowedFd<'_>, |
200 |
| - to_pathname: To, |
201 |
| - flags: MoveMountFlags, |
202 |
| -) -> io::Result<()> { |
203 |
| - from_pathname.into_with_c_str(|from_pathname| { |
204 |
| - to_pathname.into_with_c_str(|to_pathname| { |
205 |
| - backend::fs::syscalls::move_mount(from_dfd, from_pathname, to_dfd, to_pathname, flags) |
206 |
| - }) |
207 |
| - }) |
208 |
| -} |
209 |
| - |
210 |
| -/// `open_tree(dfd, filename, flags)` |
211 |
| -#[inline] |
212 |
| -pub fn open_tree<Path: path::Arg>( |
213 |
| - dfd: BorrowedFd<'_>, |
214 |
| - filename: Path, |
215 |
| - flags: OpenTreeFlags, |
216 |
| -) -> io::Result<OwnedFd> { |
217 |
| - filename.into_with_c_str(|filename| backend::fs::syscalls::open_tree(dfd, filename, flags)) |
218 |
| -} |
219 |
| - |
220 |
| -/// `fspick(dfd, path, flags)` |
221 |
| -#[inline] |
222 |
| -pub fn fspick<Path: path::Arg>( |
223 |
| - dfd: BorrowedFd<'_>, |
224 |
| - path: Path, |
225 |
| - flags: FsPickFlags, |
226 |
| -) -> io::Result<OwnedFd> { |
227 |
| - path.into_with_c_str(|path| backend::fs::syscalls::fspick(dfd, path, flags)) |
228 |
| -} |
229 |
| - |
230 |
| -/// `fsconfig(fs_fd, FSCONFIG_SET_FLAG, key, NULL, 0)` |
231 |
| -#[inline] |
232 |
| -#[doc(alias = "fsconfig")] |
233 |
| -pub fn fsconfig_set_flag<Key: path::Arg>(fs_fd: BorrowedFd<'_>, key: Key) -> io::Result<()> { |
234 |
| - key.into_with_c_str(|key| backend::fs::syscalls::fsconfig_set_flag(fs_fd, key)) |
235 |
| -} |
236 |
| - |
237 |
| -/// `fsconfig(fs_fd, FSCONFIG_SET_STRING, key, value, 0)` |
238 |
| -#[inline] |
239 |
| -#[doc(alias = "fsconfig")] |
240 |
| -pub fn fsconfig_set_string<Key: path::Arg, Value: path::Arg>( |
241 |
| - fs_fd: BorrowedFd<'_>, |
242 |
| - key: Key, |
243 |
| - value: Value, |
244 |
| -) -> io::Result<()> { |
245 |
| - key.into_with_c_str(|key| { |
246 |
| - value.into_with_c_str(|value| backend::fs::syscalls::fsconfig_set_string(fs_fd, key, value)) |
247 |
| - }) |
248 |
| -} |
249 |
| - |
250 |
| -/// `fsconfig(fs_fd, FSCONFIG_SET_BINARY, key, value, value.len())` |
251 |
| -#[inline] |
252 |
| -#[doc(alias = "fsconfig")] |
253 |
| -pub fn fsconfig_set_binary<Key: path::Arg>( |
254 |
| - fs_fd: BorrowedFd<'_>, |
255 |
| - key: Key, |
256 |
| - value: &[u8], |
257 |
| -) -> io::Result<()> { |
258 |
| - key.into_with_c_str(|key| backend::fs::syscalls::fsconfig_set_binary(fs_fd, key, value)) |
259 |
| -} |
260 |
| - |
261 |
| -/// `fsconfig(fs_fd, FSCONFIG_SET_PATH, key, path, fd)` |
262 |
| -#[inline] |
263 |
| -#[doc(alias = "fsconfig")] |
264 |
| -pub fn fsconfig_set_path<Key: path::Arg, Path: path::Arg>( |
265 |
| - fs_fd: BorrowedFd<'_>, |
266 |
| - key: Key, |
267 |
| - path: Path, |
268 |
| - fd: BorrowedFd<'_>, |
269 |
| -) -> io::Result<()> { |
270 |
| - key.into_with_c_str(|key| { |
271 |
| - path.into_with_c_str(|path| backend::fs::syscalls::fsconfig_set_path(fs_fd, key, path, fd)) |
272 |
| - }) |
273 |
| -} |
274 |
| - |
275 |
| -/// `fsconfig(fs_fd, FSCONFIG_SET_PATH_EMPTY, key, "", fd)` |
276 |
| -#[inline] |
277 |
| -#[doc(alias = "fsconfig")] |
278 |
| -pub fn fsconfig_set_path_empty<Key: path::Arg>( |
279 |
| - fs_fd: BorrowedFd<'_>, |
280 |
| - key: Key, |
281 |
| - fd: BorrowedFd<'_>, |
282 |
| -) -> io::Result<()> { |
283 |
| - key.into_with_c_str(|key| backend::fs::syscalls::fsconfig_set_path_empty(fs_fd, key, fd)) |
284 |
| -} |
285 |
| - |
286 |
| -/// `fsconfig(fs_fd, FSCONFIG_SET_FD, key, NULL, fd)` |
287 |
| -#[inline] |
288 |
| -#[doc(alias = "fsconfig")] |
289 |
| -pub fn fsconfig_set_fd<Key: path::Arg>( |
290 |
| - fs_fd: BorrowedFd<'_>, |
291 |
| - key: Key, |
292 |
| - fd: BorrowedFd<'_>, |
293 |
| -) -> io::Result<()> { |
294 |
| - key.into_with_c_str(|key| backend::fs::syscalls::fsconfig_set_fd(fs_fd, key, fd)) |
295 |
| -} |
296 |
| - |
297 |
| -/// `fsconfig(fs_fd, FSCONFIG_CMD_CREATE, key, NULL, 0)` |
298 |
| -#[inline] |
299 |
| -#[doc(alias = "fsconfig")] |
300 |
| -pub fn fsconfig_create(fs_fd: BorrowedFd<'_>) -> io::Result<()> { |
301 |
| - backend::fs::syscalls::fsconfig_create(fs_fd) |
302 |
| -} |
303 |
| - |
304 |
| -/// `fsconfig(fs_fd, FSCONFIG_CMD_RECONFIGURE, key, NULL, 0)` |
305 |
| -#[inline] |
306 |
| -#[doc(alias = "fsconfig")] |
307 |
| -pub fn fsconfig_reconfigure(fs_fd: BorrowedFd<'_>) -> io::Result<()> { |
308 |
| - backend::fs::syscalls::fsconfig_reconfigure(fs_fd) |
309 |
| -} |
| 3 | +/// These have been moved to a new `rustix::mount` module. |
| 4 | +#[deprecated(note = "These functions have moved to `rustix::mount`.")] |
| 5 | +pub use crate::mount::{mount, unmount}; |
| 6 | + |
| 7 | +#[deprecated( |
| 8 | + note = "`rustix::fs::remount` is renamed and moved to `rustix::mount::mount_remount`." |
| 9 | +)] |
| 10 | +pub use crate::mount::mount_remount as remount; |
| 11 | + |
| 12 | +#[deprecated( |
| 13 | + note = "`rustix::fs::bind_mount` is renamed and moved to `rustix::mount::mount_bind`." |
| 14 | +)] |
| 15 | +pub use crate::mount::mount_bind as bind_mount; |
| 16 | + |
| 17 | +#[deprecated( |
| 18 | + note = "`rustix::fs::recursive_bind_mount` is renamed and moved to `rustix::mount::mount_recursive_bind`." |
| 19 | +)] |
| 20 | +pub use crate::mount::mount_recursive_bind as recursive_bind_mount; |
| 21 | + |
| 22 | +#[deprecated( |
| 23 | + note = "`rustix::fs::change_mount` is renamed and moved to `rustix::mount::mount_change`." |
| 24 | +)] |
| 25 | +pub use crate::mount::mount_change as change_mount; |
| 26 | + |
| 27 | +#[deprecated( |
| 28 | + note = "`rustix::fs::move_mount` is renamed and moved to `rustix::mount::mount_move`." |
| 29 | +)] |
| 30 | +pub use crate::mount::mount_move as move_mount; |
0 commit comments