From 034a14caed1e064ef0557614e64026c683c7c140 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Wed, 19 Jul 2023 23:03:48 +0800 Subject: [PATCH] Add new mount api syscall for linux --- src/backend/libc/fs/syscalls.rs | 13 --- src/backend/linux_raw/fs/syscalls.rs | 13 --- src/fs/mount.rs | 124 ++++++++++++++++++++++++++- 3 files changed, 123 insertions(+), 27 deletions(-) diff --git a/src/backend/libc/fs/syscalls.rs b/src/backend/libc/fs/syscalls.rs index c38b4b6bf..817d89c19 100644 --- a/src/backend/libc/fs/syscalls.rs +++ b/src/backend/libc/fs/syscalls.rs @@ -2087,7 +2087,6 @@ pub(crate) fn unmount(target: &CStr, flags: super::types::UnmountFlags) -> io::R unsafe { ret(c::umount2(target.as_ptr(), bitflags_bits!(flags))) } } -#[allow(dead_code)] #[cfg(linux_kernel)] pub(crate) fn fsopen(fs_name: &CStr, flags: super::types::FsOpenFlags) -> io::Result { syscall! { @@ -2099,7 +2098,6 @@ pub(crate) fn fsopen(fs_name: &CStr, flags: super::types::FsOpenFlags) -> io::Re unsafe { ret_owned_fd(fsopen(c_str(fs_name), flags.bits())) } } -#[allow(dead_code)] #[cfg(linux_kernel)] pub(crate) fn fsmount( fs_fd: BorrowedFd<'_>, @@ -2116,7 +2114,6 @@ pub(crate) fn fsmount( unsafe { ret(fsmount(borrowed_fd(fs_fd), flags.bits(), attr_flags.bits())) } } -#[allow(dead_code)] #[cfg(linux_kernel)] pub(crate) fn move_mount( from_dfd: BorrowedFd<'_>, @@ -2145,7 +2142,6 @@ pub(crate) fn move_mount( } } -#[allow(dead_code)] #[cfg(linux_kernel)] pub(crate) fn open_tree( dfd: BorrowedFd<'_>, @@ -2163,7 +2159,6 @@ pub(crate) fn open_tree( unsafe { ret_owned_fd(open_tree(borrowed_fd(dfd), c_str(filename), flags.bits())) } } -#[allow(dead_code)] #[cfg(linux_kernel)] pub(crate) fn fspick( dfd: BorrowedFd<'_>, @@ -2192,7 +2187,6 @@ syscall! { ) via SYS_fsconfig -> c::c_int } -#[allow(dead_code)] #[cfg(linux_kernel)] pub(crate) fn fsconfig_set_flag(fs_fd: BorrowedFd<'_>, key: &CStr) -> io::Result<()> { unsafe { @@ -2206,7 +2200,6 @@ pub(crate) fn fsconfig_set_flag(fs_fd: BorrowedFd<'_>, key: &CStr) -> io::Result } } -#[allow(dead_code)] #[cfg(linux_kernel)] pub(crate) fn fsconfig_set_string( fs_fd: BorrowedFd<'_>, @@ -2224,7 +2217,6 @@ pub(crate) fn fsconfig_set_string( } } -#[allow(dead_code)] #[cfg(linux_kernel)] pub(crate) fn fsconfig_set_binary( fs_fd: BorrowedFd<'_>, @@ -2242,7 +2234,6 @@ pub(crate) fn fsconfig_set_binary( } } -#[allow(dead_code)] #[cfg(linux_kernel)] pub(crate) fn fsconfig_set_fd( fs_fd: BorrowedFd<'_>, @@ -2260,7 +2251,6 @@ pub(crate) fn fsconfig_set_fd( } } -#[allow(dead_code)] #[cfg(linux_kernel)] pub(crate) fn fsconfig_set_path( fs_fd: BorrowedFd<'_>, @@ -2279,7 +2269,6 @@ pub(crate) fn fsconfig_set_path( } } -#[allow(dead_code)] #[cfg(linux_kernel)] pub(crate) fn fsconfig_set_path_empty( fs_fd: BorrowedFd<'_>, @@ -2297,7 +2286,6 @@ pub(crate) fn fsconfig_set_path_empty( } } -#[allow(dead_code)] #[cfg(linux_kernel)] pub(crate) fn fsconfig_create(fs_fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { @@ -2311,7 +2299,6 @@ pub(crate) fn fsconfig_create(fs_fd: BorrowedFd<'_>) -> io::Result<()> { } } -#[allow(dead_code)] #[cfg(linux_kernel)] pub(crate) fn fsconfig_reconfigure(fs_fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { diff --git a/src/backend/linux_raw/fs/syscalls.rs b/src/backend/linux_raw/fs/syscalls.rs index 8d8b76c7a..425c0efc2 100644 --- a/src/backend/linux_raw/fs/syscalls.rs +++ b/src/backend/linux_raw/fs/syscalls.rs @@ -1436,13 +1436,11 @@ pub(crate) fn mount( } } -#[allow(dead_code)] #[inline] pub(crate) fn fsopen(fs_name: &CStr, flags: super::types::FsOpenFlags) -> io::Result { unsafe { ret_owned_fd(syscall_readonly!(__NR_fsopen, fs_name, flags)) } } -#[allow(dead_code)] #[inline] pub(crate) fn fsmount( fs_fd: BorrowedFd<'_>, @@ -1452,7 +1450,6 @@ pub(crate) fn fsmount( unsafe { ret(syscall_readonly!(__NR_fsmount, fs_fd, flags, attr_flags)) } } -#[allow(dead_code)] #[inline] pub(crate) fn move_mount( from_dfd: BorrowedFd<'_>, @@ -1473,7 +1470,6 @@ pub(crate) fn move_mount( } } -#[allow(dead_code)] #[inline] pub(crate) fn open_tree( dfd: BorrowedFd<'_>, @@ -1483,7 +1479,6 @@ pub(crate) fn open_tree( unsafe { ret_owned_fd(syscall_readonly!(__NR_open_tree, dfd, filename, flags)) } } -#[allow(dead_code)] #[inline] pub(crate) fn fspick( dfd: BorrowedFd<'_>, @@ -1493,7 +1488,6 @@ pub(crate) fn fspick( unsafe { ret_owned_fd(syscall_readonly!(__NR_fspick, dfd, path, flags)) } } -#[allow(dead_code)] #[inline] pub(crate) fn fsconfig_set_flag(fs_fd: BorrowedFd<'_>, key: &CStr) -> io::Result<()> { unsafe { @@ -1508,7 +1502,6 @@ pub(crate) fn fsconfig_set_flag(fs_fd: BorrowedFd<'_>, key: &CStr) -> io::Result } } -#[allow(dead_code)] #[inline] pub(crate) fn fsconfig_set_string( fs_fd: BorrowedFd<'_>, @@ -1527,7 +1520,6 @@ pub(crate) fn fsconfig_set_string( } } -#[allow(dead_code)] #[inline] pub(crate) fn fsconfig_set_binary( fs_fd: BorrowedFd<'_>, @@ -1547,7 +1539,6 @@ pub(crate) fn fsconfig_set_binary( } } -#[allow(dead_code)] #[inline] pub(crate) fn fsconfig_set_fd( fs_fd: BorrowedFd<'_>, @@ -1566,7 +1557,6 @@ pub(crate) fn fsconfig_set_fd( } } -#[allow(dead_code)] #[inline] pub(crate) fn fsconfig_set_path( fs_fd: BorrowedFd<'_>, @@ -1586,7 +1576,6 @@ pub(crate) fn fsconfig_set_path( } } -#[allow(dead_code)] #[inline] pub(crate) fn fsconfig_set_path_empty( fs_fd: BorrowedFd<'_>, @@ -1605,7 +1594,6 @@ pub(crate) fn fsconfig_set_path_empty( } } -#[allow(dead_code)] #[inline] pub(crate) fn fsconfig_create(fs_fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { @@ -1620,7 +1608,6 @@ pub(crate) fn fsconfig_create(fs_fd: BorrowedFd<'_>) -> io::Result<()> { } } -#[allow(dead_code)] #[inline] pub(crate) fn fsconfig_reconfigure(fs_fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { diff --git a/src/fs/mount.rs b/src/fs/mount.rs index 1439b1f32..0f1850b63 100644 --- a/src/fs/mount.rs +++ b/src/fs/mount.rs @@ -1,8 +1,10 @@ //! Linux `mount`. use crate::backend::fs::types::{ - InternalMountFlags, MountFlags, MountFlagsArg, MountPropagationFlags, UnmountFlags, + FsMountFlags, FsOpenFlags, FsPickFlags, InternalMountFlags, MountAttrFlags, MountFlags, + MountFlagsArg, MountPropagationFlags, MoveMountFlags, OpenTreeFlags, UnmountFlags, }; +use crate::fd::{BorrowedFd, OwnedFd}; use crate::{backend, io, path}; /// `mount(source, target, filesystemtype, mountflags, data)` @@ -164,3 +166,123 @@ pub fn move_mount( pub fn unmount(target: Target, flags: UnmountFlags) -> io::Result<()> { target.into_with_c_str(|target| backend::fs::syscalls::unmount(target, flags)) } + +/// `fsopen(fs_name, flags)` +pub fn fsopen(fs_name: Fs, flags: FsOpenFlags) -> io::Result { + fs_name.into_with_c_str(|fs_name| backend::fs::syscalls::fsopen(fs_name, flags)) +} + +/// `fsmount(fs_fd, flags, attr_flags)` +pub fn fsmount( + fs_fd: BorrowedFd<'_>, + flags: FsMountFlags, + attr_flags: MountAttrFlags, +) -> io::Result<()> { + backend::fs::syscalls::fsmount(fs_fd, flags, attr_flags) +} + +/// `move_mount(from_dfd, from_pathname, to_dfd, to_pathname, flags)` +pub fn move_mount_( + from_dfd: BorrowedFd<'_>, + from_pathname: From, + to_dfd: BorrowedFd<'_>, + to_pathname: To, + flags: MoveMountFlags, +) -> io::Result<()> { + from_pathname.into_with_c_str(|from_pathname| { + to_pathname.into_with_c_str(|to_pathname| { + backend::fs::syscalls::move_mount(from_dfd, from_pathname, to_dfd, to_pathname, flags) + }) + }) +} + +/// `open_tree(dfd, filename, flags)` +pub fn open_tree( + dfd: BorrowedFd<'_>, + filename: Path, + flags: OpenTreeFlags, +) -> io::Result { + filename.into_with_c_str(|filename| backend::fs::syscalls::open_tree(dfd, filename, flags)) +} + +/// `fspick(dfd, path, flags)` +pub fn fspick( + dfd: BorrowedFd<'_>, + path: Path, + flags: FsPickFlags, +) -> io::Result { + path.into_with_c_str(|path| backend::fs::syscalls::fspick(dfd, path, flags)) +} + +/// `fsconfig(fs_fd, FSCONFIG_SET_FLAG, key, NULL, 0)` +#[doc(alias = "fsconfig")] +pub fn fsconfig_set_flag(fs_fd: BorrowedFd<'_>, key: Key) -> io::Result<()> { + key.into_with_c_str(|key| backend::fs::syscalls::fsconfig_set_flag(fs_fd, key)) +} + +/// `fsconfig(fs_fd, FSCONFIG_SET_STRING, key, value, 0)` +#[doc(alias = "fsconfig")] +pub fn fsconfig_set_string( + fs_fd: BorrowedFd<'_>, + key: Key, + value: Value, +) -> io::Result<()> { + key.into_with_c_str(|key| { + value.into_with_c_str(|value| backend::fs::syscalls::fsconfig_set_string(fs_fd, key, value)) + }) +} + +/// `fsconfig(fs_fd, FSCONFIG_SET_BINARY, key, value, value.len())` +#[doc(alias = "fsconfig")] +pub fn fsconfig_set_binary( + fs_fd: BorrowedFd<'_>, + key: Key, + value: &[u8], +) -> io::Result<()> { + key.into_with_c_str(|key| backend::fs::syscalls::fsconfig_set_binary(fs_fd, key, value)) +} + +/// `fsconfig(fs_fd, FSCONFIG_SET_PATH, key, path, fd)` +#[doc(alias = "fsconfig")] +pub fn fsconfig_set_path( + fs_fd: BorrowedFd<'_>, + key: Key, + path: Path, + fd: BorrowedFd<'_>, +) -> io::Result<()> { + key.into_with_c_str(|key| { + path.into_with_c_str(|path| backend::fs::syscalls::fsconfig_set_path(fs_fd, key, path, fd)) + }) +} + +/// `fsconfig(fs_fd, FSCONFIG_SET_PATH_EMPTY, key, "", fd)` +#[doc(alias = "fsconfig")] +pub fn fsconfig_set_path_empty( + fs_fd: BorrowedFd<'_>, + key: Key, + fd: BorrowedFd<'_>, +) -> io::Result<()> { + key.into_with_c_str(|key| backend::fs::syscalls::fsconfig_set_path_empty(fs_fd, key, fd)) +} + +/// `fsconfig(fs_fd, FSCONFIG_SET_FD, key, NULL, fd)` +#[doc(alias = "fsconfig")] +pub fn fsconfig_set_fd( + fs_fd: BorrowedFd<'_>, + key: Key, + fd: BorrowedFd<'_>, +) -> io::Result<()> { + key.into_with_c_str(|key| backend::fs::syscalls::fsconfig_set_fd(fs_fd, key, fd)) +} + +/// `fsconfig(fs_fd, FSCONFIG_CMD_CREATE, key, NULL, 0)` +#[doc(alias = "fsconfig")] +pub fn fsconfig_create(fs_fd: BorrowedFd<'_>) -> io::Result<()> { + backend::fs::syscalls::fsconfig_create(fs_fd) +} + +/// `fsconfig(fs_fd, FSCONFIG_CMD_RECONFIGURE, key, NULL, 0)` +#[doc(alias = "fsconfig")] +pub fn fsconfig_reconfigure(fs_fd: BorrowedFd<'_>) -> io::Result<()> { + backend::fs::syscalls::fsconfig_reconfigure(fs_fd) +}