Skip to content

Commit d8cb8bb

Browse files
authored
Add new mount api syscall for linux (#752)
* Add new mount api syscall for linux_raw * Add new mount api syscall for libc of linux * Add new mount api syscall for linux
1 parent 714cbf8 commit d8cb8bb

File tree

6 files changed

+983
-1
lines changed

6 files changed

+983
-1
lines changed

src/backend/libc/fs/syscalls.rs

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,6 +2103,231 @@ pub(crate) fn unmount(target: &CStr, flags: super::types::UnmountFlags) -> io::R
21032103
unsafe { ret(c::umount2(target.as_ptr(), bitflags_bits!(flags))) }
21042104
}
21052105

2106+
#[cfg(linux_kernel)]
2107+
pub(crate) fn fsopen(fs_name: &CStr, flags: super::types::FsOpenFlags) -> io::Result<OwnedFd> {
2108+
syscall! {
2109+
fn fsopen(
2110+
fs_name: *const c::c_char,
2111+
flags: c::c_uint
2112+
) via SYS_fsopen -> c::c_int
2113+
}
2114+
unsafe { ret_owned_fd(fsopen(c_str(fs_name), flags.bits())) }
2115+
}
2116+
2117+
#[cfg(linux_kernel)]
2118+
pub(crate) fn fsmount(
2119+
fs_fd: BorrowedFd<'_>,
2120+
flags: super::types::FsMountFlags,
2121+
attr_flags: super::types::MountAttrFlags,
2122+
) -> io::Result<()> {
2123+
syscall! {
2124+
fn fsmount(
2125+
fs_fd: c::c_int,
2126+
flags: c::c_uint,
2127+
attr_flags: c::c_uint
2128+
) via SYS_fsmount -> c::c_int
2129+
}
2130+
unsafe { ret(fsmount(borrowed_fd(fs_fd), flags.bits(), attr_flags.bits())) }
2131+
}
2132+
2133+
#[cfg(linux_kernel)]
2134+
pub(crate) fn move_mount(
2135+
from_dfd: BorrowedFd<'_>,
2136+
from_pathname: &CStr,
2137+
to_dfd: BorrowedFd<'_>,
2138+
to_pathname: &CStr,
2139+
flags: super::types::MoveMountFlags,
2140+
) -> io::Result<()> {
2141+
syscall! {
2142+
fn move_mount(
2143+
from_dfd: c::c_int,
2144+
from_pathname: *const c::c_char,
2145+
to_dfd: c::c_int,
2146+
to_pathname: *const c::c_char,
2147+
flags: c::c_uint
2148+
) via SYS_move_mount -> c::c_int
2149+
}
2150+
unsafe {
2151+
ret(move_mount(
2152+
borrowed_fd(from_dfd),
2153+
c_str(from_pathname),
2154+
borrowed_fd(to_dfd),
2155+
c_str(to_pathname),
2156+
flags.bits(),
2157+
))
2158+
}
2159+
}
2160+
2161+
#[cfg(linux_kernel)]
2162+
pub(crate) fn open_tree(
2163+
dfd: BorrowedFd<'_>,
2164+
filename: &CStr,
2165+
flags: super::types::OpenTreeFlags,
2166+
) -> io::Result<OwnedFd> {
2167+
syscall! {
2168+
fn open_tree(
2169+
dfd: c::c_int,
2170+
filename: *const c::c_char,
2171+
flags: c::c_uint
2172+
) via SYS_open_tree -> c::c_int
2173+
}
2174+
2175+
unsafe { ret_owned_fd(open_tree(borrowed_fd(dfd), c_str(filename), flags.bits())) }
2176+
}
2177+
2178+
#[cfg(linux_kernel)]
2179+
pub(crate) fn fspick(
2180+
dfd: BorrowedFd<'_>,
2181+
path: &CStr,
2182+
flags: super::types::FsPickFlags,
2183+
) -> io::Result<OwnedFd> {
2184+
syscall! {
2185+
fn fspick(
2186+
dfd: c::c_int,
2187+
path: *const c::c_char,
2188+
flags: c::c_uint
2189+
) via SYS_fspick -> c::c_int
2190+
}
2191+
2192+
unsafe { ret_owned_fd(fspick(borrowed_fd(dfd), c_str(path), flags.bits())) }
2193+
}
2194+
2195+
#[cfg(linux_kernel)]
2196+
syscall! {
2197+
fn fsconfig(
2198+
fs_fd: c::c_int,
2199+
cmd: c::c_uint,
2200+
key: *const c::c_char,
2201+
val: *const c::c_char,
2202+
aux: c::c_int
2203+
) via SYS_fsconfig -> c::c_int
2204+
}
2205+
2206+
#[cfg(linux_kernel)]
2207+
pub(crate) fn fsconfig_set_flag(fs_fd: BorrowedFd<'_>, key: &CStr) -> io::Result<()> {
2208+
unsafe {
2209+
ret(fsconfig(
2210+
borrowed_fd(fs_fd),
2211+
super::types::FsConfigCmd::SetFlag as _,
2212+
c_str(key),
2213+
null(),
2214+
0,
2215+
))
2216+
}
2217+
}
2218+
2219+
#[cfg(linux_kernel)]
2220+
pub(crate) fn fsconfig_set_string(
2221+
fs_fd: BorrowedFd<'_>,
2222+
key: &CStr,
2223+
value: &CStr,
2224+
) -> io::Result<()> {
2225+
unsafe {
2226+
ret(fsconfig(
2227+
borrowed_fd(fs_fd),
2228+
super::types::FsConfigCmd::SetString as _,
2229+
c_str(key),
2230+
c_str(value),
2231+
0,
2232+
))
2233+
}
2234+
}
2235+
2236+
#[cfg(linux_kernel)]
2237+
pub(crate) fn fsconfig_set_binary(
2238+
fs_fd: BorrowedFd<'_>,
2239+
key: &CStr,
2240+
value: &[u8],
2241+
) -> io::Result<()> {
2242+
unsafe {
2243+
ret(fsconfig(
2244+
borrowed_fd(fs_fd),
2245+
super::types::FsConfigCmd::SetBinary as _,
2246+
c_str(key),
2247+
value.as_ptr().cast(),
2248+
value.len().try_into().map_err(|_| io::Errno::OVERFLOW)?,
2249+
))
2250+
}
2251+
}
2252+
2253+
#[cfg(linux_kernel)]
2254+
pub(crate) fn fsconfig_set_fd(
2255+
fs_fd: BorrowedFd<'_>,
2256+
key: &CStr,
2257+
fd: BorrowedFd<'_>,
2258+
) -> io::Result<()> {
2259+
unsafe {
2260+
ret(fsconfig(
2261+
borrowed_fd(fs_fd),
2262+
super::types::FsConfigCmd::SetFd as _,
2263+
c_str(key),
2264+
null(),
2265+
borrowed_fd(fd),
2266+
))
2267+
}
2268+
}
2269+
2270+
#[cfg(linux_kernel)]
2271+
pub(crate) fn fsconfig_set_path(
2272+
fs_fd: BorrowedFd<'_>,
2273+
key: &CStr,
2274+
path: &CStr,
2275+
fd: BorrowedFd<'_>,
2276+
) -> io::Result<()> {
2277+
unsafe {
2278+
ret(fsconfig(
2279+
borrowed_fd(fs_fd),
2280+
super::types::FsConfigCmd::SetPath as _,
2281+
c_str(key),
2282+
c_str(path),
2283+
borrowed_fd(fd),
2284+
))
2285+
}
2286+
}
2287+
2288+
#[cfg(linux_kernel)]
2289+
pub(crate) fn fsconfig_set_path_empty(
2290+
fs_fd: BorrowedFd<'_>,
2291+
key: &CStr,
2292+
fd: BorrowedFd<'_>,
2293+
) -> io::Result<()> {
2294+
unsafe {
2295+
ret(fsconfig(
2296+
borrowed_fd(fs_fd),
2297+
super::types::FsConfigCmd::SetPathEmpty as _,
2298+
c_str(key),
2299+
c_str(cstr!("")),
2300+
borrowed_fd(fd),
2301+
))
2302+
}
2303+
}
2304+
2305+
#[cfg(linux_kernel)]
2306+
pub(crate) fn fsconfig_create(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
2307+
unsafe {
2308+
ret(fsconfig(
2309+
borrowed_fd(fs_fd),
2310+
super::types::FsConfigCmd::Create as _,
2311+
null(),
2312+
null(),
2313+
0,
2314+
))
2315+
}
2316+
}
2317+
2318+
#[cfg(linux_kernel)]
2319+
pub(crate) fn fsconfig_reconfigure(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
2320+
unsafe {
2321+
ret(fsconfig(
2322+
borrowed_fd(fs_fd),
2323+
super::types::FsConfigCmd::Reconfigure as _,
2324+
null(),
2325+
null(),
2326+
0,
2327+
))
2328+
}
2329+
}
2330+
21062331
#[cfg(any(apple, linux_kernel))]
21072332
pub(crate) fn getxattr(path: &CStr, name: &CStr, value: &mut [u8]) -> io::Result<usize> {
21082333
let value_ptr = value.as_mut_ptr();

0 commit comments

Comments
 (0)