Skip to content

Commit c7c4362

Browse files
committed
Factor out a new top-level mount module.
Create `rustix::mount`, and move the mount-related and fsopen-related functions into it, adding deprecated aliases in `rustix::fs` for compatibility. This also renames several functions which are all specialized forms of the `mount` system call, so I renamed them to have `mount` at the beginning. It also fixes the collision with the real `move_mount` system call. - `remount` to `mount_remount` - `bind_mount` to `mount_bind` - `recursive_bind_mount` to `mount_recursive_bind` - `change_mount` to `mount_change` - `move_mount` to `mount_move` And, it adds documentation links to a [new repository] I set up to host formatted versions of the draft manual pages that were posted. [new repository]: https://github.com/sunfishcode/linux-mount-api-documentation
1 parent d8cb8bb commit c7c4362

File tree

8 files changed

+448
-307
lines changed

8 files changed

+448
-307
lines changed

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ fs = []
146146
# Enable `rustix::io_uring::*` (on platforms that support it).
147147
io_uring = ["fs", "net", "linux-raw-sys/io_uring"]
148148

149+
# Enable `rustix::mount::*`.
150+
mount = []
151+
149152
# Enable `rustix::net::*`.
150153
net = ["linux-raw-sys/net", "linux-raw-sys/netlink", "linux-raw-sys/if_ether"]
151154

@@ -195,6 +198,7 @@ all-apis = [
195198
"fs",
196199
"io_uring",
197200
"mm",
201+
"mount",
198202
"net",
199203
"param",
200204
"pipe",

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ by default. The rest of the API is conditional with cargo feature flags:
6161
| `fs` | [`rustix::fs`] and [`rustix::path`]—Filesystem operations.
6262
| `io_uring` | [`rustix::io_uring`]—Linux io_uring.
6363
| `mm` | [`rustix::mm`]—Memory map operations.
64+
| `mount` | [`rustix::mount`]—Linux mount API.
6465
| `net` | [`rustix::net`] and [`rustix::path`]—Network-related operations.
6566
| `param` | [`rustix::param`]—Process parameters.
6667
| `pipe` | [`rustix::pipe`]—Pipe operations.
@@ -80,6 +81,7 @@ by default. The rest of the API is conditional with cargo feature flags:
8081
[`rustix::fs`]: https://docs.rs/rustix/*/rustix/fs/index.html
8182
[`rustix::io_uring`]: https://docs.rs/rustix/*/rustix/io_uring/index.html
8283
[`rustix::mm`]: https://docs.rs/rustix/*/rustix/mm/index.html
84+
[`rustix::mount`]: https://docs.rs/rustix/*/rustix/mount/index.html
8385
[`rustix::net`]: https://docs.rs/rustix/*/rustix/net/index.html
8486
[`rustix::param`]: https://docs.rs/rustix/*/rustix/param/index.html
8587
[`rustix::pipe`]: https://docs.rs/rustix/*/rustix/pipe/index.html

src/fs/mount.rs

+28-307
Original file line numberDiff line numberDiff line change
@@ -1,309 +1,30 @@
11
//! Linux `mount`.
22
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;

src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ pub mod io_uring;
214214
#[cfg(feature = "mm")]
215215
#[cfg_attr(doc_cfg, doc(cfg(feature = "mm")))]
216216
pub mod mm;
217+
#[cfg(linux_kernel)]
218+
#[cfg(feature = "mount")]
219+
#[cfg_attr(doc_cfg, doc(cfg(feature = "mount")))]
220+
pub mod mount;
217221
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
218222
#[cfg(feature = "net")]
219223
#[cfg_attr(doc_cfg, doc(cfg(feature = "net")))]
@@ -290,6 +294,12 @@ pub mod time;
290294
#[cfg_attr(doc_cfg, doc(cfg(feature = "runtime")))]
291295
pub mod runtime;
292296

297+
// Temporarily provide some mount functions for use in the fs module for
298+
// backwards compatibility.
299+
#[cfg(linux_kernel)]
300+
#[cfg(all(feature = "fs", not(feature = "mount")))]
301+
pub(crate) mod mount;
302+
293303
// Private modules used by multiple public modules.
294304
#[cfg(not(any(windows, target_os = "espidf")))]
295305
#[cfg(any(feature = "thread", feature = "time", target_arch = "x86"))]

0 commit comments

Comments
 (0)