Skip to content

Commit

Permalink
Add new mount api syscall for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
yujincheng08 committed Jul 19, 2023
1 parent 2d0d366 commit 034a14c
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 27 deletions.
13 changes: 0 additions & 13 deletions src/backend/libc/fs/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<OwnedFd> {
syscall! {
Expand All @@ -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<'_>,
Expand All @@ -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<'_>,
Expand Down Expand Up @@ -2145,7 +2142,6 @@ pub(crate) fn move_mount(
}
}

#[allow(dead_code)]
#[cfg(linux_kernel)]
pub(crate) fn open_tree(
dfd: BorrowedFd<'_>,
Expand All @@ -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<'_>,
Expand Down Expand Up @@ -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 {
Expand All @@ -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<'_>,
Expand All @@ -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<'_>,
Expand All @@ -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<'_>,
Expand All @@ -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<'_>,
Expand All @@ -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<'_>,
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
13 changes: 0 additions & 13 deletions src/backend/linux_raw/fs/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<OwnedFd> {
unsafe { ret_owned_fd(syscall_readonly!(__NR_fsopen, fs_name, flags)) }
}

#[allow(dead_code)]
#[inline]
pub(crate) fn fsmount(
fs_fd: BorrowedFd<'_>,
Expand All @@ -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<'_>,
Expand All @@ -1473,7 +1470,6 @@ pub(crate) fn move_mount(
}
}

#[allow(dead_code)]
#[inline]
pub(crate) fn open_tree(
dfd: BorrowedFd<'_>,
Expand All @@ -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<'_>,
Expand All @@ -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 {
Expand All @@ -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<'_>,
Expand All @@ -1527,7 +1520,6 @@ pub(crate) fn fsconfig_set_string(
}
}

#[allow(dead_code)]
#[inline]
pub(crate) fn fsconfig_set_binary(
fs_fd: BorrowedFd<'_>,
Expand All @@ -1547,7 +1539,6 @@ pub(crate) fn fsconfig_set_binary(
}
}

#[allow(dead_code)]
#[inline]
pub(crate) fn fsconfig_set_fd(
fs_fd: BorrowedFd<'_>,
Expand All @@ -1566,7 +1557,6 @@ pub(crate) fn fsconfig_set_fd(
}
}

#[allow(dead_code)]
#[inline]
pub(crate) fn fsconfig_set_path(
fs_fd: BorrowedFd<'_>,
Expand All @@ -1586,7 +1576,6 @@ pub(crate) fn fsconfig_set_path(
}
}

#[allow(dead_code)]
#[inline]
pub(crate) fn fsconfig_set_path_empty(
fs_fd: BorrowedFd<'_>,
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
124 changes: 123 additions & 1 deletion src/fs/mount.rs
Original file line number Diff line number Diff line change
@@ -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)`
Expand Down Expand Up @@ -164,3 +166,123 @@ pub fn move_mount<Source: path::Arg, Target: path::Arg>(
pub fn unmount<Target: path::Arg>(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: path::Arg>(fs_name: Fs, flags: FsOpenFlags) -> io::Result<OwnedFd> {
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: path::Arg, To: path::Arg>(
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<Path: path::Arg>(
dfd: BorrowedFd<'_>,
filename: Path,
flags: OpenTreeFlags,
) -> io::Result<OwnedFd> {
filename.into_with_c_str(|filename| backend::fs::syscalls::open_tree(dfd, filename, flags))
}

/// `fspick(dfd, path, flags)`
pub fn fspick<Path: path::Arg>(
dfd: BorrowedFd<'_>,
path: Path,
flags: FsPickFlags,
) -> io::Result<OwnedFd> {
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<Key: path::Arg>(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<Key: path::Arg, Value: path::Arg>(
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<Key: path::Arg>(
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<Key: path::Arg, Path: path::Arg>(
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<Key: path::Arg>(
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<Key: path::Arg>(
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)
}

0 comments on commit 034a14c

Please sign in to comment.