Skip to content

Commit 3f39d7d

Browse files
committed
Add new mount api syscall for linux
1 parent 27338be commit 3f39d7d

File tree

3 files changed

+128
-28
lines changed

3 files changed

+128
-28
lines changed

src/backend/libc/fs/syscalls.rs

-13
Original file line numberDiff line numberDiff line change
@@ -2087,7 +2087,6 @@ pub(crate) fn unmount(target: &CStr, flags: super::types::UnmountFlags) -> io::R
20872087
unsafe { ret(c::umount2(target.as_ptr(), bitflags_bits!(flags))) }
20882088
}
20892089

2090-
#[allow(dead_code)]
20912090
#[cfg(linux_kernel)]
20922091
pub(crate) fn fsopen(fs_name: &CStr, flags: super::types::FsOpenFlags) -> io::Result<OwnedFd> {
20932092
syscall! {
@@ -2099,7 +2098,6 @@ pub(crate) fn fsopen(fs_name: &CStr, flags: super::types::FsOpenFlags) -> io::Re
20992098
unsafe { ret_owned_fd(fsopen(c_str(fs_name), flags.bits())) }
21002099
}
21012100

2102-
#[allow(dead_code)]
21032101
#[cfg(linux_kernel)]
21042102
pub(crate) fn fsmount(
21052103
fs_fd: BorrowedFd<'_>,
@@ -2116,7 +2114,6 @@ pub(crate) fn fsmount(
21162114
unsafe { ret(fsmount(borrowed_fd(fs_fd), flags.bits(), attr_flags.bits())) }
21172115
}
21182116

2119-
#[allow(dead_code)]
21202117
#[cfg(linux_kernel)]
21212118
pub(crate) fn move_mount(
21222119
from_dfd: BorrowedFd<'_>,
@@ -2145,7 +2142,6 @@ pub(crate) fn move_mount(
21452142
}
21462143
}
21472144

2148-
#[allow(dead_code)]
21492145
#[cfg(linux_kernel)]
21502146
pub(crate) fn open_tree(
21512147
dfd: BorrowedFd<'_>,
@@ -2163,7 +2159,6 @@ pub(crate) fn open_tree(
21632159
unsafe { ret_owned_fd(open_tree(borrowed_fd(dfd), c_str(filename), flags.bits())) }
21642160
}
21652161

2166-
#[allow(dead_code)]
21672162
#[cfg(linux_kernel)]
21682163
pub(crate) fn fspick(
21692164
dfd: BorrowedFd<'_>,
@@ -2192,7 +2187,6 @@ syscall! {
21922187
) via SYS_fsconfig -> c::c_int
21932188
}
21942189

2195-
#[allow(dead_code)]
21962190
#[cfg(linux_kernel)]
21972191
pub(crate) fn fsconfig_set_flag(fs_fd: BorrowedFd<'_>, key: &CStr) -> io::Result<()> {
21982192
unsafe {
@@ -2206,7 +2200,6 @@ pub(crate) fn fsconfig_set_flag(fs_fd: BorrowedFd<'_>, key: &CStr) -> io::Result
22062200
}
22072201
}
22082202

2209-
#[allow(dead_code)]
22102203
#[cfg(linux_kernel)]
22112204
pub(crate) fn fsconfig_set_string(
22122205
fs_fd: BorrowedFd<'_>,
@@ -2224,7 +2217,6 @@ pub(crate) fn fsconfig_set_string(
22242217
}
22252218
}
22262219

2227-
#[allow(dead_code)]
22282220
#[cfg(linux_kernel)]
22292221
pub(crate) fn fsconfig_set_binary(
22302222
fs_fd: BorrowedFd<'_>,
@@ -2242,7 +2234,6 @@ pub(crate) fn fsconfig_set_binary(
22422234
}
22432235
}
22442236

2245-
#[allow(dead_code)]
22462237
#[cfg(linux_kernel)]
22472238
pub(crate) fn fsconfig_set_fd(
22482239
fs_fd: BorrowedFd<'_>,
@@ -2260,7 +2251,6 @@ pub(crate) fn fsconfig_set_fd(
22602251
}
22612252
}
22622253

2263-
#[allow(dead_code)]
22642254
#[cfg(linux_kernel)]
22652255
pub(crate) fn fsconfig_set_path(
22662256
fs_fd: BorrowedFd<'_>,
@@ -2279,7 +2269,6 @@ pub(crate) fn fsconfig_set_path(
22792269
}
22802270
}
22812271

2282-
#[allow(dead_code)]
22832272
#[cfg(linux_kernel)]
22842273
pub(crate) fn fsconfig_set_path_empty(
22852274
fs_fd: BorrowedFd<'_>,
@@ -2297,7 +2286,6 @@ pub(crate) fn fsconfig_set_path_empty(
22972286
}
22982287
}
22992288

2300-
#[allow(dead_code)]
23012289
#[cfg(linux_kernel)]
23022290
pub(crate) fn fsconfig_create(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
23032291
unsafe {
@@ -2311,7 +2299,6 @@ pub(crate) fn fsconfig_create(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
23112299
}
23122300
}
23132301

2314-
#[allow(dead_code)]
23152302
#[cfg(linux_kernel)]
23162303
pub(crate) fn fsconfig_reconfigure(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
23172304
unsafe {

src/backend/linux_raw/fs/syscalls.rs

-13
Original file line numberDiff line numberDiff line change
@@ -1436,13 +1436,11 @@ pub(crate) fn mount(
14361436
}
14371437
}
14381438

1439-
#[allow(dead_code)]
14401439
#[inline]
14411440
pub(crate) fn fsopen(fs_name: &CStr, flags: super::types::FsOpenFlags) -> io::Result<OwnedFd> {
14421441
unsafe { ret_owned_fd(syscall_readonly!(__NR_fsopen, fs_name, flags)) }
14431442
}
14441443

1445-
#[allow(dead_code)]
14461444
#[inline]
14471445
pub(crate) fn fsmount(
14481446
fs_fd: BorrowedFd<'_>,
@@ -1452,7 +1450,6 @@ pub(crate) fn fsmount(
14521450
unsafe { ret(syscall_readonly!(__NR_fsmount, fs_fd, flags, attr_flags)) }
14531451
}
14541452

1455-
#[allow(dead_code)]
14561453
#[inline]
14571454
pub(crate) fn move_mount(
14581455
from_dfd: BorrowedFd<'_>,
@@ -1473,7 +1470,6 @@ pub(crate) fn move_mount(
14731470
}
14741471
}
14751472

1476-
#[allow(dead_code)]
14771473
#[inline]
14781474
pub(crate) fn open_tree(
14791475
dfd: BorrowedFd<'_>,
@@ -1483,7 +1479,6 @@ pub(crate) fn open_tree(
14831479
unsafe { ret_owned_fd(syscall_readonly!(__NR_open_tree, dfd, filename, flags)) }
14841480
}
14851481

1486-
#[allow(dead_code)]
14871482
#[inline]
14881483
pub(crate) fn fspick(
14891484
dfd: BorrowedFd<'_>,
@@ -1493,7 +1488,6 @@ pub(crate) fn fspick(
14931488
unsafe { ret_owned_fd(syscall_readonly!(__NR_fspick, dfd, path, flags)) }
14941489
}
14951490

1496-
#[allow(dead_code)]
14971491
#[inline]
14981492
pub(crate) fn fsconfig_set_flag(fs_fd: BorrowedFd<'_>, key: &CStr) -> io::Result<()> {
14991493
unsafe {
@@ -1508,7 +1502,6 @@ pub(crate) fn fsconfig_set_flag(fs_fd: BorrowedFd<'_>, key: &CStr) -> io::Result
15081502
}
15091503
}
15101504

1511-
#[allow(dead_code)]
15121505
#[inline]
15131506
pub(crate) fn fsconfig_set_string(
15141507
fs_fd: BorrowedFd<'_>,
@@ -1527,7 +1520,6 @@ pub(crate) fn fsconfig_set_string(
15271520
}
15281521
}
15291522

1530-
#[allow(dead_code)]
15311523
#[inline]
15321524
pub(crate) fn fsconfig_set_binary(
15331525
fs_fd: BorrowedFd<'_>,
@@ -1547,7 +1539,6 @@ pub(crate) fn fsconfig_set_binary(
15471539
}
15481540
}
15491541

1550-
#[allow(dead_code)]
15511542
#[inline]
15521543
pub(crate) fn fsconfig_set_fd(
15531544
fs_fd: BorrowedFd<'_>,
@@ -1566,7 +1557,6 @@ pub(crate) fn fsconfig_set_fd(
15661557
}
15671558
}
15681559

1569-
#[allow(dead_code)]
15701560
#[inline]
15711561
pub(crate) fn fsconfig_set_path(
15721562
fs_fd: BorrowedFd<'_>,
@@ -1586,7 +1576,6 @@ pub(crate) fn fsconfig_set_path(
15861576
}
15871577
}
15881578

1589-
#[allow(dead_code)]
15901579
#[inline]
15911580
pub(crate) fn fsconfig_set_path_empty(
15921581
fs_fd: BorrowedFd<'_>,
@@ -1605,7 +1594,6 @@ pub(crate) fn fsconfig_set_path_empty(
16051594
}
16061595
}
16071596

1608-
#[allow(dead_code)]
16091597
#[inline]
16101598
pub(crate) fn fsconfig_create(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
16111599
unsafe {
@@ -1620,7 +1608,6 @@ pub(crate) fn fsconfig_create(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
16201608
}
16211609
}
16221610

1623-
#[allow(dead_code)]
16241611
#[inline]
16251612
pub(crate) fn fsconfig_reconfigure(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
16261613
unsafe {

src/fs/mount.rs

+128-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
//! Linux `mount`.
22
33
use crate::backend::fs::types::{
4-
InternalMountFlags, MountFlags, MountFlagsArg, MountPropagationFlags, UnmountFlags,
4+
FsMountFlags, FsOpenFlags, FsPickFlags, InternalMountFlags, MountAttrFlags, MountFlags,
5+
MountFlagsArg, MountPropagationFlags, MoveMountFlags, OpenTreeFlags, UnmountFlags,
56
};
7+
use crate::fd::{BorrowedFd, OwnedFd};
68
use crate::{backend, io, path};
79

810
/// `mount(source, target, filesystemtype, mountflags, data)`
@@ -130,7 +132,11 @@ pub fn change_mount<Target: path::Arg>(
130132
}
131133

132134
/// `mount(source, target, NULL, MS_MOVE, NULL)`
133-
///
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+
///
134140
/// # References
135141
/// - [Linux]
136142
///
@@ -164,3 +170,123 @@ pub fn move_mount<Source: path::Arg, Target: path::Arg>(
164170
pub fn unmount<Target: path::Arg>(target: Target, flags: UnmountFlags) -> io::Result<()> {
165171
target.into_with_c_str(|target| backend::fs::syscalls::unmount(target, flags))
166172
}
173+
174+
/// `fsopen(fs_name, flags)`
175+
pub fn fsopen<Fs: path::Arg>(fs_name: Fs, flags: FsOpenFlags) -> io::Result<OwnedFd> {
176+
fs_name.into_with_c_str(|fs_name| backend::fs::syscalls::fsopen(fs_name, flags))
177+
}
178+
179+
/// `fsmount(fs_fd, flags, attr_flags)`
180+
pub fn fsmount(
181+
fs_fd: BorrowedFd<'_>,
182+
flags: FsMountFlags,
183+
attr_flags: MountAttrFlags,
184+
) -> io::Result<()> {
185+
backend::fs::syscalls::fsmount(fs_fd, flags, attr_flags)
186+
}
187+
188+
/// `move_mount(from_dfd, from_pathname, to_dfd, to_pathname, flags)`
189+
pub fn move_mount_syscall<From: path::Arg, To: path::Arg>(
190+
from_dfd: BorrowedFd<'_>,
191+
from_pathname: From,
192+
to_dfd: BorrowedFd<'_>,
193+
to_pathname: To,
194+
flags: MoveMountFlags,
195+
) -> io::Result<()> {
196+
from_pathname.into_with_c_str(|from_pathname| {
197+
to_pathname.into_with_c_str(|to_pathname| {
198+
backend::fs::syscalls::move_mount(from_dfd, from_pathname, to_dfd, to_pathname, flags)
199+
})
200+
})
201+
}
202+
203+
/// `open_tree(dfd, filename, flags)`
204+
pub fn open_tree<Path: path::Arg>(
205+
dfd: BorrowedFd<'_>,
206+
filename: Path,
207+
flags: OpenTreeFlags,
208+
) -> io::Result<OwnedFd> {
209+
filename.into_with_c_str(|filename| backend::fs::syscalls::open_tree(dfd, filename, flags))
210+
}
211+
212+
/// `fspick(dfd, path, flags)`
213+
pub fn fspick<Path: path::Arg>(
214+
dfd: BorrowedFd<'_>,
215+
path: Path,
216+
flags: FsPickFlags,
217+
) -> io::Result<OwnedFd> {
218+
path.into_with_c_str(|path| backend::fs::syscalls::fspick(dfd, path, flags))
219+
}
220+
221+
/// `fsconfig(fs_fd, FSCONFIG_SET_FLAG, key, NULL, 0)`
222+
#[doc(alias = "fsconfig")]
223+
pub fn fsconfig_set_flag<Key: path::Arg>(fs_fd: BorrowedFd<'_>, key: Key) -> io::Result<()> {
224+
key.into_with_c_str(|key| backend::fs::syscalls::fsconfig_set_flag(fs_fd, key))
225+
}
226+
227+
/// `fsconfig(fs_fd, FSCONFIG_SET_STRING, key, value, 0)`
228+
#[doc(alias = "fsconfig")]
229+
pub fn fsconfig_set_string<Key: path::Arg, Value: path::Arg>(
230+
fs_fd: BorrowedFd<'_>,
231+
key: Key,
232+
value: Value,
233+
) -> io::Result<()> {
234+
key.into_with_c_str(|key| {
235+
value.into_with_c_str(|value| backend::fs::syscalls::fsconfig_set_string(fs_fd, key, value))
236+
})
237+
}
238+
239+
/// `fsconfig(fs_fd, FSCONFIG_SET_BINARY, key, value, value.len())`
240+
#[doc(alias = "fsconfig")]
241+
pub fn fsconfig_set_binary<Key: path::Arg>(
242+
fs_fd: BorrowedFd<'_>,
243+
key: Key,
244+
value: &[u8],
245+
) -> io::Result<()> {
246+
key.into_with_c_str(|key| backend::fs::syscalls::fsconfig_set_binary(fs_fd, key, value))
247+
}
248+
249+
/// `fsconfig(fs_fd, FSCONFIG_SET_PATH, key, path, fd)`
250+
#[doc(alias = "fsconfig")]
251+
pub fn fsconfig_set_path<Key: path::Arg, Path: path::Arg>(
252+
fs_fd: BorrowedFd<'_>,
253+
key: Key,
254+
path: Path,
255+
fd: BorrowedFd<'_>,
256+
) -> io::Result<()> {
257+
key.into_with_c_str(|key| {
258+
path.into_with_c_str(|path| backend::fs::syscalls::fsconfig_set_path(fs_fd, key, path, fd))
259+
})
260+
}
261+
262+
/// `fsconfig(fs_fd, FSCONFIG_SET_PATH_EMPTY, key, "", fd)`
263+
#[doc(alias = "fsconfig")]
264+
pub fn fsconfig_set_path_empty<Key: path::Arg>(
265+
fs_fd: BorrowedFd<'_>,
266+
key: Key,
267+
fd: BorrowedFd<'_>,
268+
) -> io::Result<()> {
269+
key.into_with_c_str(|key| backend::fs::syscalls::fsconfig_set_path_empty(fs_fd, key, fd))
270+
}
271+
272+
/// `fsconfig(fs_fd, FSCONFIG_SET_FD, key, NULL, fd)`
273+
#[doc(alias = "fsconfig")]
274+
pub fn fsconfig_set_fd<Key: path::Arg>(
275+
fs_fd: BorrowedFd<'_>,
276+
key: Key,
277+
fd: BorrowedFd<'_>,
278+
) -> io::Result<()> {
279+
key.into_with_c_str(|key| backend::fs::syscalls::fsconfig_set_fd(fs_fd, key, fd))
280+
}
281+
282+
/// `fsconfig(fs_fd, FSCONFIG_CMD_CREATE, key, NULL, 0)`
283+
#[doc(alias = "fsconfig")]
284+
pub fn fsconfig_create(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
285+
backend::fs::syscalls::fsconfig_create(fs_fd)
286+
}
287+
288+
/// `fsconfig(fs_fd, FSCONFIG_CMD_RECONFIGURE, key, NULL, 0)`
289+
#[doc(alias = "fsconfig")]
290+
pub fn fsconfig_reconfigure(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
291+
backend::fs::syscalls::fsconfig_reconfigure(fs_fd)
292+
}

0 commit comments

Comments
 (0)