Skip to content

Commit 48bc8c2

Browse files
committed
Add new mount api syscall for libc of linux
1 parent 135da1b commit 48bc8c2

File tree

2 files changed

+431
-0
lines changed

2 files changed

+431
-0
lines changed

src/backend/libc/fs/syscalls.rs

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

0 commit comments

Comments
 (0)