Skip to content

Commit

Permalink
Add new mount api syscall for linux (#752)
Browse files Browse the repository at this point in the history
* Add new mount api syscall for linux_raw

* Add new mount api syscall for libc of linux

* Add new mount api syscall for linux
  • Loading branch information
yujincheng08 authored Jul 31, 2023
1 parent 714cbf8 commit d8cb8bb
Show file tree
Hide file tree
Showing 6 changed files with 983 additions and 1 deletion.
225 changes: 225 additions & 0 deletions src/backend/libc/fs/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,231 @@ pub(crate) fn unmount(target: &CStr, flags: super::types::UnmountFlags) -> io::R
unsafe { ret(c::umount2(target.as_ptr(), bitflags_bits!(flags))) }
}

#[cfg(linux_kernel)]
pub(crate) fn fsopen(fs_name: &CStr, flags: super::types::FsOpenFlags) -> io::Result<OwnedFd> {
syscall! {
fn fsopen(
fs_name: *const c::c_char,
flags: c::c_uint
) via SYS_fsopen -> c::c_int
}
unsafe { ret_owned_fd(fsopen(c_str(fs_name), flags.bits())) }
}

#[cfg(linux_kernel)]
pub(crate) fn fsmount(
fs_fd: BorrowedFd<'_>,
flags: super::types::FsMountFlags,
attr_flags: super::types::MountAttrFlags,
) -> io::Result<()> {
syscall! {
fn fsmount(
fs_fd: c::c_int,
flags: c::c_uint,
attr_flags: c::c_uint
) via SYS_fsmount -> c::c_int
}
unsafe { ret(fsmount(borrowed_fd(fs_fd), flags.bits(), attr_flags.bits())) }
}

#[cfg(linux_kernel)]
pub(crate) fn move_mount(
from_dfd: BorrowedFd<'_>,
from_pathname: &CStr,
to_dfd: BorrowedFd<'_>,
to_pathname: &CStr,
flags: super::types::MoveMountFlags,
) -> io::Result<()> {
syscall! {
fn move_mount(
from_dfd: c::c_int,
from_pathname: *const c::c_char,
to_dfd: c::c_int,
to_pathname: *const c::c_char,
flags: c::c_uint
) via SYS_move_mount -> c::c_int
}
unsafe {
ret(move_mount(
borrowed_fd(from_dfd),
c_str(from_pathname),
borrowed_fd(to_dfd),
c_str(to_pathname),
flags.bits(),
))
}
}

#[cfg(linux_kernel)]
pub(crate) fn open_tree(
dfd: BorrowedFd<'_>,
filename: &CStr,
flags: super::types::OpenTreeFlags,
) -> io::Result<OwnedFd> {
syscall! {
fn open_tree(
dfd: c::c_int,
filename: *const c::c_char,
flags: c::c_uint
) via SYS_open_tree -> c::c_int
}

unsafe { ret_owned_fd(open_tree(borrowed_fd(dfd), c_str(filename), flags.bits())) }
}

#[cfg(linux_kernel)]
pub(crate) fn fspick(
dfd: BorrowedFd<'_>,
path: &CStr,
flags: super::types::FsPickFlags,
) -> io::Result<OwnedFd> {
syscall! {
fn fspick(
dfd: c::c_int,
path: *const c::c_char,
flags: c::c_uint
) via SYS_fspick -> c::c_int
}

unsafe { ret_owned_fd(fspick(borrowed_fd(dfd), c_str(path), flags.bits())) }
}

#[cfg(linux_kernel)]
syscall! {
fn fsconfig(
fs_fd: c::c_int,
cmd: c::c_uint,
key: *const c::c_char,
val: *const c::c_char,
aux: c::c_int
) via SYS_fsconfig -> c::c_int
}

#[cfg(linux_kernel)]
pub(crate) fn fsconfig_set_flag(fs_fd: BorrowedFd<'_>, key: &CStr) -> io::Result<()> {
unsafe {
ret(fsconfig(
borrowed_fd(fs_fd),
super::types::FsConfigCmd::SetFlag as _,
c_str(key),
null(),
0,
))
}
}

#[cfg(linux_kernel)]
pub(crate) fn fsconfig_set_string(
fs_fd: BorrowedFd<'_>,
key: &CStr,
value: &CStr,
) -> io::Result<()> {
unsafe {
ret(fsconfig(
borrowed_fd(fs_fd),
super::types::FsConfigCmd::SetString as _,
c_str(key),
c_str(value),
0,
))
}
}

#[cfg(linux_kernel)]
pub(crate) fn fsconfig_set_binary(
fs_fd: BorrowedFd<'_>,
key: &CStr,
value: &[u8],
) -> io::Result<()> {
unsafe {
ret(fsconfig(
borrowed_fd(fs_fd),
super::types::FsConfigCmd::SetBinary as _,
c_str(key),
value.as_ptr().cast(),
value.len().try_into().map_err(|_| io::Errno::OVERFLOW)?,
))
}
}

#[cfg(linux_kernel)]
pub(crate) fn fsconfig_set_fd(
fs_fd: BorrowedFd<'_>,
key: &CStr,
fd: BorrowedFd<'_>,
) -> io::Result<()> {
unsafe {
ret(fsconfig(
borrowed_fd(fs_fd),
super::types::FsConfigCmd::SetFd as _,
c_str(key),
null(),
borrowed_fd(fd),
))
}
}

#[cfg(linux_kernel)]
pub(crate) fn fsconfig_set_path(
fs_fd: BorrowedFd<'_>,
key: &CStr,
path: &CStr,
fd: BorrowedFd<'_>,
) -> io::Result<()> {
unsafe {
ret(fsconfig(
borrowed_fd(fs_fd),
super::types::FsConfigCmd::SetPath as _,
c_str(key),
c_str(path),
borrowed_fd(fd),
))
}
}

#[cfg(linux_kernel)]
pub(crate) fn fsconfig_set_path_empty(
fs_fd: BorrowedFd<'_>,
key: &CStr,
fd: BorrowedFd<'_>,
) -> io::Result<()> {
unsafe {
ret(fsconfig(
borrowed_fd(fs_fd),
super::types::FsConfigCmd::SetPathEmpty as _,
c_str(key),
c_str(cstr!("")),
borrowed_fd(fd),
))
}
}

#[cfg(linux_kernel)]
pub(crate) fn fsconfig_create(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
unsafe {
ret(fsconfig(
borrowed_fd(fs_fd),
super::types::FsConfigCmd::Create as _,
null(),
null(),
0,
))
}
}

#[cfg(linux_kernel)]
pub(crate) fn fsconfig_reconfigure(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
unsafe {
ret(fsconfig(
borrowed_fd(fs_fd),
super::types::FsConfigCmd::Reconfigure as _,
null(),
null(),
0,
))
}
}

#[cfg(any(apple, linux_kernel))]
pub(crate) fn getxattr(path: &CStr, name: &CStr, value: &mut [u8]) -> io::Result<usize> {
let value_ptr = value.as_mut_ptr();
Expand Down
Loading

0 comments on commit d8cb8bb

Please sign in to comment.