diff options
Diffstat (limited to 'vendor/rustix/src/backend/libc/fs/syscalls.rs')
-rw-r--r-- | vendor/rustix/src/backend/libc/fs/syscalls.rs | 342 |
1 files changed, 190 insertions, 152 deletions
diff --git a/vendor/rustix/src/backend/libc/fs/syscalls.rs b/vendor/rustix/src/backend/libc/fs/syscalls.rs index 1d1891f0f..77b49ee3e 100644 --- a/vendor/rustix/src/backend/libc/fs/syscalls.rs +++ b/vendor/rustix/src/backend/libc/fs/syscalls.rs @@ -9,49 +9,36 @@ use super::super::conv::{syscall_ret, syscall_ret_owned_fd, syscall_ret_ssize_t} #[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] use super::super::offset::libc_fallocate; #[cfg(not(any( + apple, + netbsdlike, + solarish, target_os = "dragonfly", target_os = "haiku", - target_os = "illumos", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "redox", - target_os = "solaris", )))] use super::super::offset::libc_posix_fadvise; #[cfg(not(any( + apple, + netbsdlike, + solarish, target_os = "aix", target_os = "android", target_os = "dragonfly", target_os = "fuchsia", - target_os = "illumos", - target_os = "ios", target_os = "linux", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "redox", - target_os = "solaris", )))] use super::super::offset::libc_posix_fallocate; use super::super::offset::{libc_fstat, libc_fstatat, libc_ftruncate, libc_lseek, libc_off_t}; #[cfg(not(any( + solarish, target_os = "haiku", - target_os = "illumos", target_os = "netbsd", target_os = "redox", - target_os = "solaris", target_os = "wasi", )))] use super::super::offset::{libc_fstatfs, libc_statfs}; -#[cfg(not(any( - target_os = "haiku", - target_os = "illumos", - target_os = "redox", - target_os = "solaris", - target_os = "wasi", -)))] +#[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))] use super::super::offset::{libc_fstatvfs, libc_statvfs}; #[cfg(all( any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), @@ -60,33 +47,28 @@ use super::super::offset::{libc_fstatvfs, libc_statvfs}; use super::super::time::types::LibcTimespec; use crate::fd::{BorrowedFd, OwnedFd}; use crate::ffi::CStr; -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple)] use crate::ffi::CString; -#[cfg(not(any(target_os = "illumos", target_os = "solaris")))] +#[cfg(not(solarish))] use crate::fs::Access; #[cfg(not(any( + apple, + netbsdlike, + solarish, target_os = "dragonfly", target_os = "haiku", - target_os = "illumos", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "redox", - target_os = "solaris", )))] use crate::fs::Advice; #[cfg(not(any( + netbsdlike, + solarish, target_os = "aix", target_os = "dragonfly", - target_os = "illumos", - target_os = "netbsd", - target_os = "openbsd", target_os = "redox", - target_os = "solaris", )))] use crate::fs::FallocateFlags; -#[cfg(not(any(target_os = "solaris", target_os = "wasi")))] +#[cfg(not(target_os = "wasi"))] use crate::fs::FlockOperation; #[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))] use crate::fs::MemfdFlags; @@ -98,31 +80,19 @@ use crate::fs::MemfdFlags; ))] use crate::fs::SealFlags; #[cfg(not(any( + solarish, target_os = "haiku", - target_os = "illumos", target_os = "netbsd", target_os = "redox", - target_os = "solaris", target_os = "wasi", )))] use crate::fs::StatFs; #[cfg(any(target_os = "android", target_os = "linux"))] use crate::fs::{cwd, RenameFlags, ResolveFlags, Statx, StatxFlags}; -#[cfg(not(any( - target_os = "ios", - target_os = "macos", - target_os = "redox", - target_os = "wasi", -)))] +#[cfg(not(any(apple, target_os = "redox", target_os = "wasi")))] use crate::fs::{Dev, FileType}; use crate::fs::{Mode, OFlags, Stat, Timestamps}; -#[cfg(not(any( - target_os = "haiku", - target_os = "illumos", - target_os = "redox", - target_os = "solaris", - target_os = "wasi", -)))] +#[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))] use crate::fs::{StatVfs, StatVfsMountFlags}; use crate::io::{self, SeekFrom}; #[cfg(not(target_os = "wasi"))] @@ -133,24 +103,14 @@ use crate::process::{Gid, Uid}; )))] use crate::utils::as_ptr; use core::convert::TryInto; -#[cfg(any( - target_os = "android", - target_os = "ios", - target_os = "linux", - target_os = "macos", -))] +#[cfg(any(apple, target_os = "android", target_os = "linux"))] use core::mem::size_of; use core::mem::MaybeUninit; #[cfg(any(target_os = "android", target_os = "linux"))] use core::ptr::null; -#[cfg(any( - target_os = "android", - target_os = "ios", - target_os = "linux", - target_os = "macos", -))] +#[cfg(any(apple, target_os = "android", target_os = "linux"))] use core::ptr::null_mut; -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple)] use { super::super::conv::nonnegative_ret, crate::fs::{copyfile_state_t, CloneFlags, CopyfileFlags}, @@ -202,7 +162,7 @@ pub(crate) fn openat( mode: Mode, ) -> io::Result<OwnedFd> { // Work around <https://sourceware.org/bugzilla/show_bug.cgi?id=17523>. - // Basically old glibc versions don't handle O_TMPFILE correctly. + // GLIBC versions before 2.25 don't handle `O_TMPFILE` correctly. #[cfg(all(unix, target_env = "gnu"))] if oflags.contains(OFlags::TMPFILE) && crate::backend::if_glibc_is_less_than_2_25() { return openat_via_syscall(dirfd, path, oflags, mode); @@ -221,11 +181,10 @@ pub(crate) fn openat( } #[cfg(not(any( + solarish, target_os = "haiku", - target_os = "illumos", target_os = "netbsd", target_os = "redox", - target_os = "solaris", target_os = "wasi", )))] #[inline] @@ -237,13 +196,7 @@ pub(crate) fn statfs(filename: &CStr) -> io::Result<StatFs> { } } -#[cfg(not(any( - target_os = "haiku", - target_os = "illumos", - target_os = "redox", - target_os = "solaris", - target_os = "wasi", -)))] +#[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))] #[inline] pub(crate) fn statvfs(filename: &CStr) -> io::Result<StatVfs> { unsafe { @@ -278,6 +231,22 @@ pub(crate) fn mkdirat(dirfd: BorrowedFd<'_>, path: &CStr, mode: Mode) -> io::Res } } +#[cfg(any(target_os = "android", target_os = "linux"))] +pub(crate) fn getdents_uninit( + fd: BorrowedFd<'_>, + buf: &mut [MaybeUninit<u8>], +) -> io::Result<usize> { + unsafe { + syscall_ret_ssize_t(c::syscall( + c::SYS_getdents64, + fd, + buf.as_mut_ptr().cast::<c::c_char>(), + buf.len(), + )) + } + .map(|nread| nread as usize) +} + #[cfg(not(target_os = "redox"))] pub(crate) fn linkat( old_dirfd: BorrowedFd<'_>, @@ -433,12 +402,7 @@ fn statat_old(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result< } } -#[cfg(not(any( - target_os = "emscripten", - target_os = "illumos", - target_os = "redox", - target_os = "solaris", -)))] +#[cfg(not(any(solarish, target_os = "emscripten", target_os = "redox")))] pub(crate) fn accessat( dirfd: BorrowedFd<'_>, path: &CStr, @@ -499,8 +463,7 @@ pub(crate) fn utimensat( // Main version: libc is y2038 safe and has `utimensat`. Or, the platform // is not y2038 safe and there's nothing practical we can do. #[cfg(not(any( - target_os = "ios", - target_os = "macos", + apple, all( any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), target_env = "gnu", @@ -519,7 +482,7 @@ pub(crate) fn utimensat( } // `utimensat` was introduced in macOS 10.13. - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple)] unsafe { // ABI details weak! { @@ -675,13 +638,41 @@ unsafe fn utimensat_old( target_os = "redox", target_os = "wasi", )))] -pub(crate) fn chmodat(dirfd: BorrowedFd<'_>, path: &CStr, mode: Mode) -> io::Result<()> { - unsafe { ret(c::fchmodat(borrowed_fd(dirfd), c_str(path), mode.bits(), 0)) } +pub(crate) fn chmodat( + dirfd: BorrowedFd<'_>, + path: &CStr, + mode: Mode, + flags: AtFlags, +) -> io::Result<()> { + unsafe { + ret(c::fchmodat( + borrowed_fd(dirfd), + c_str(path), + mode.bits() as c::mode_t, + flags.bits(), + )) + } } #[cfg(any(target_os = "android", target_os = "linux"))] -pub(crate) fn chmodat(dirfd: BorrowedFd<'_>, path: &CStr, mode: Mode) -> io::Result<()> { +pub(crate) fn chmodat( + dirfd: BorrowedFd<'_>, + path: &CStr, + mode: Mode, + flags: AtFlags, +) -> io::Result<()> { // Linux's `fchmodat` does not have a flags argument. + // + // Use `c::syscall` rather than `c::fchmodat` because some libc + // implementations, such as musl, add extra logic to `fchmod` to emulate + // support for `AT_SYMLINK_NOFOLLOW`, which uses `/proc` outside our + // control. + if flags == AtFlags::SYMLINK_NOFOLLOW { + return Err(io::Errno::OPNOTSUPP); + } + if !flags.is_empty() { + return Err(io::Errno::INVAL); + } unsafe { // Pass `mode` as a `c_uint` even if `mode_t` is narrower, since // `libc_openat` is declared as a variadic function and narrower @@ -695,7 +686,7 @@ pub(crate) fn chmodat(dirfd: BorrowedFd<'_>, path: &CStr, mode: Mode) -> io::Res } } -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple)] pub(crate) fn fclonefileat( srcfd: BorrowedFd<'_>, dst_dirfd: BorrowedFd<'_>, @@ -734,12 +725,7 @@ pub(crate) fn chownat( } } -#[cfg(not(any( - target_os = "ios", - target_os = "macos", - target_os = "redox", - target_os = "wasi", -)))] +#[cfg(not(any(apple, target_os = "redox", target_os = "wasi")))] pub(crate) fn mknodat( dirfd: BorrowedFd<'_>, path: &CStr, @@ -763,8 +749,8 @@ pub(crate) fn copy_file_range( off_in: Option<&mut u64>, fd_out: BorrowedFd<'_>, off_out: Option<&mut u64>, - len: u64, -) -> io::Result<u64> { + len: usize, +) -> io::Result<usize> { assert_eq!(size_of::<c::loff_t>(), size_of::<u64>()); let mut off_in_val: c::loff_t = 0; @@ -782,7 +768,6 @@ pub(crate) fn copy_file_range( } else { null_mut() }; - let len: usize = len.try_into().unwrap_or(usize::MAX); let copied = unsafe { syscall_ret_ssize_t(c::syscall( c::SYS_copy_file_range, @@ -800,19 +785,16 @@ pub(crate) fn copy_file_range( if let Some(off_out) = off_out { *off_out = off_out_val as u64; } - Ok(copied as u64) + Ok(copied as usize) } #[cfg(not(any( + apple, + netbsdlike, + solarish, target_os = "dragonfly", target_os = "haiku", - target_os = "illumos", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "redox", - target_os = "solaris", )))] pub(crate) fn fadvise(fd: BorrowedFd<'_>, offset: u64, len: u64, advice: Advice) -> io::Result<()> { let offset = offset as i64; @@ -875,6 +857,40 @@ pub(crate) fn fcntl_add_seals(fd: BorrowedFd<'_>, seals: SealFlags) -> io::Resul unsafe { ret(c::fcntl(borrowed_fd(fd), c::F_ADD_SEALS, seals.bits())) } } +#[cfg(not(any( + target_os = "emscripten", + target_os = "fuchsia", + target_os = "redox", + target_os = "wasi" +)))] +#[inline] +pub(crate) fn fcntl_lock(fd: BorrowedFd<'_>, operation: FlockOperation) -> io::Result<()> { + use c::{flock, F_RDLCK, F_SETLK, F_SETLKW, F_UNLCK, F_WRLCK, SEEK_SET}; + + let (cmd, l_type) = match operation { + FlockOperation::LockShared => (F_SETLKW, F_RDLCK), + FlockOperation::LockExclusive => (F_SETLKW, F_WRLCK), + FlockOperation::Unlock => (F_SETLKW, F_UNLCK), + FlockOperation::NonBlockingLockShared => (F_SETLK, F_RDLCK), + FlockOperation::NonBlockingLockExclusive => (F_SETLK, F_WRLCK), + FlockOperation::NonBlockingUnlock => (F_SETLK, F_UNLCK), + }; + + unsafe { + let mut lock: flock = core::mem::zeroed(); + lock.l_type = l_type as _; + + // When `l_len` is zero, this locks all the bytes from + // `l_whence`/`l_start` to the end of the file, even as the + // file grows dynamically. + lock.l_whence = SEEK_SET as _; + lock.l_start = 0; + lock.l_len = 0; + + ret(c::fcntl(borrowed_fd(fd), cmd, &lock)) + } +} + pub(crate) fn seek(fd: BorrowedFd<'_>, pos: SeekFrom) -> io::Result<u64> { let (whence, offset): (c::c_int, libc_off_t) = match pos { SeekFrom::Start(pos) => { @@ -884,6 +900,10 @@ pub(crate) fn seek(fd: BorrowedFd<'_>, pos: SeekFrom) -> io::Result<u64> { } SeekFrom::End(offset) => (c::SEEK_END, offset), SeekFrom::Current(offset) => (c::SEEK_CUR, offset), + #[cfg(any(freebsdlike, target_os = "linux", target_os = "solaris"))] + SeekFrom::Data(offset) => (c::SEEK_DATA, offset), + #[cfg(any(freebsdlike, target_os = "linux", target_os = "solaris"))] + SeekFrom::Hole(offset) => (c::SEEK_HOLE, offset), }; let offset = unsafe { ret_off_t(libc_lseek(borrowed_fd(fd), offset, whence))? }; Ok(offset as u64) @@ -939,6 +959,25 @@ pub(crate) fn flock(fd: BorrowedFd<'_>, operation: FlockOperation) -> io::Result unsafe { ret(c::flock(borrowed_fd(fd), operation as c::c_int)) } } +#[cfg(any(target_os = "android", target_os = "linux"))] +pub(crate) fn syncfs(fd: BorrowedFd<'_>) -> io::Result<()> { + unsafe { ret(c::syncfs(borrowed_fd(fd))) } +} + +#[cfg(not(any(solarish, target_os = "redox", target_os = "wasi")))] +pub(crate) fn sync() { + // TODO: Remove this when upstream libc adds `sync`. + #[cfg(target_os = "android")] + unsafe { + syscall_ret(c::syscall(c::SYS_sync)).ok(); + } + + #[cfg(not(target_os = "android"))] + unsafe { + c::sync() + } +} + pub(crate) fn fstat(fd: BorrowedFd<'_>) -> io::Result<Stat> { // 32-bit and mips64 Linux: `struct stat64` is not y2038 compatible; use // `statx`. @@ -980,11 +1019,10 @@ fn fstat_old(fd: BorrowedFd<'_>) -> io::Result<Stat> { } #[cfg(not(any( + solarish, target_os = "haiku", - target_os = "illumos", target_os = "netbsd", target_os = "redox", - target_os = "solaris", target_os = "wasi", )))] pub(crate) fn fstatfs(fd: BorrowedFd<'_>) -> io::Result<StatFs> { @@ -995,13 +1033,7 @@ pub(crate) fn fstatfs(fd: BorrowedFd<'_>) -> io::Result<StatFs> { } } -#[cfg(not(any( - target_os = "haiku", - target_os = "illumos", - target_os = "redox", - target_os = "solaris", - target_os = "wasi", -)))] +#[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))] pub(crate) fn fstatvfs(fd: BorrowedFd<'_>) -> io::Result<StatVfs> { let mut statvfs = MaybeUninit::<libc_statvfs>::uninit(); unsafe { @@ -1010,13 +1042,7 @@ pub(crate) fn fstatvfs(fd: BorrowedFd<'_>) -> io::Result<StatVfs> { } } -#[cfg(not(any( - target_os = "haiku", - target_os = "illumos", - target_os = "redox", - target_os = "solaris", - target_os = "wasi" -)))] +#[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))] fn libc_statvfs_to_statvfs(from: libc_statvfs) -> StatVfs { StatVfs { f_bsize: from.f_bsize as u64, @@ -1055,8 +1081,7 @@ pub(crate) fn futimens(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> // Main version: libc is y2038 safe and has `futimens`. Or, the platform // is not y2038 safe and there's nothing practical we can do. #[cfg(not(any( - target_os = "ios", - target_os = "macos", + apple, all( any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), target_env = "gnu", @@ -1070,7 +1095,7 @@ pub(crate) fn futimens(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> } // `futimens` was introduced in macOS 10.13. - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple)] unsafe { // ABI details. weak! { @@ -1135,15 +1160,12 @@ unsafe fn futimens_old(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> } #[cfg(not(any( + apple, + netbsdlike, + solarish, target_os = "aix", target_os = "dragonfly", - target_os = "illumos", - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd", target_os = "redox", - target_os = "solaris", )))] pub(crate) fn fallocate( fd: BorrowedFd<'_>, @@ -1174,7 +1196,7 @@ pub(crate) fn fallocate( } } -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple)] pub(crate) fn fallocate( fd: BorrowedFd<'_>, mode: FallocateFlags, @@ -1196,6 +1218,8 @@ pub(crate) fn fallocate( }; unsafe { if c::fcntl(borrowed_fd(fd), c::F_PREALLOCATE, &store) == -1 { + // Unable to allocate contiguous disk space; attempt to allocate + // non-contiguously. store.fst_flags = c::F_ALLOCATEALL; let _ = ret_c_int(c::fcntl(borrowed_fd(fd), c::F_PREALLOCATE, &store))?; } @@ -1208,10 +1232,9 @@ pub(crate) fn fsync(fd: BorrowedFd<'_>) -> io::Result<()> { } #[cfg(not(any( + apple, target_os = "dragonfly", target_os = "haiku", - target_os = "ios", - target_os = "macos", target_os = "redox", )))] pub(crate) fn fdatasync(fd: BorrowedFd<'_>) -> io::Result<()> { @@ -1469,18 +1492,9 @@ fn stat64_to_stat(s64: c::stat64) -> io::Result<Stat> { mod sys { use super::{c, BorrowedFd, Statx}; - #[cfg(all(target_os = "android", target_arch = "arm"))] - const SYS_statx: c::c_long = 397; - #[cfg(all(target_os = "android", target_arch = "x86"))] - const SYS_statx: c::c_long = 383; - #[cfg(all(target_os = "android", target_arch = "aarch64"))] - const SYS_statx: c::c_long = 291; - #[cfg(all(target_os = "android", target_arch = "x86_64"))] - const SYS_statx: c::c_long = 332; - weak_or_syscall! { pub(super) fn statx( - pirfd: BorrowedFd<'_>, + dirfd_: BorrowedFd<'_>, path: *const c::c_char, flags: c::c_int, mask: c::c_uint, @@ -1545,7 +1559,7 @@ pub(crate) fn is_statx_available() -> bool { } } -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple)] pub(crate) unsafe fn fcopyfile( from: BorrowedFd<'_>, to: BorrowedFd<'_>, @@ -1569,7 +1583,7 @@ pub(crate) unsafe fn fcopyfile( )) } -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple)] pub(crate) fn copyfile_state_alloc() -> io::Result<copyfile_state_t> { extern "C" { fn copyfile_state_alloc() -> copyfile_state_t; @@ -1583,7 +1597,7 @@ pub(crate) fn copyfile_state_alloc() -> io::Result<copyfile_state_t> { } } -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple)] pub(crate) unsafe fn copyfile_state_free(state: copyfile_state_t) -> io::Result<()> { extern "C" { fn copyfile_state_free(state: copyfile_state_t) -> c::c_int; @@ -1592,17 +1606,17 @@ pub(crate) unsafe fn copyfile_state_free(state: copyfile_state_t) -> io::Result< nonnegative_ret(copyfile_state_free(state)) } -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple)] const COPYFILE_STATE_COPIED: u32 = 8; -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple)] pub(crate) unsafe fn copyfile_state_get_copied(state: copyfile_state_t) -> io::Result<u64> { let mut copied = MaybeUninit::<u64>::uninit(); copyfile_state_get(state, COPYFILE_STATE_COPIED, copied.as_mut_ptr().cast())?; Ok(copied.assume_init()) } -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple)] pub(crate) unsafe fn copyfile_state_get( state: copyfile_state_t, flag: u32, @@ -1615,9 +1629,9 @@ pub(crate) unsafe fn copyfile_state_get( nonnegative_ret(copyfile_state_get(state, flag, dst)) } -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple)] pub(crate) fn getpath(fd: BorrowedFd<'_>) -> io::Result<CString> { - // The use of PATH_MAX is generally not encouraged, but it + // The use of `PATH_MAX` is generally not encouraged, but it // is inevitable in this case because macOS defines `fcntl` with // `F_GETPATH` in terms of `MAXPATHLEN`, and there are no // alternatives. If a better method is invented, it should be used @@ -1643,7 +1657,7 @@ pub(crate) fn getpath(fd: BorrowedFd<'_>) -> io::Result<CString> { Ok(CString::new(buf).unwrap()) } -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple)] pub(crate) fn fcntl_rdadvise(fd: BorrowedFd<'_>, offset: u64, len: u64) -> io::Result<()> { // From the [macOS `fcntl` man page]: // `F_RDADVISE` - Issue an advisory read async with no copy to user. @@ -1680,14 +1694,14 @@ pub(crate) fn fcntl_rdadvise(fd: BorrowedFd<'_>, offset: u64, len: u64) -> io::R } } -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple)] pub(crate) fn fcntl_fullfsync(fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { ret(c::fcntl(borrowed_fd(fd), c::F_FULLFSYNC)) } } /// Convert `times` from a `futimens`/`utimensat` argument into `setattrlist` /// arguments. -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple)] fn times_to_attrlist(times: &Timestamps) -> (c::size_t, [c::timespec; 2], Attrlist) { // ABI details. const ATTR_CMN_MODTIME: u32 = 0x0000_0400; @@ -1755,11 +1769,11 @@ fn times_to_attrlist(times: &Timestamps) -> (c::size_t, [c::timespec; 2], Attrli } /// Support type for `Attrlist`. -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple)] type Attrgroup = u32; /// Attribute list for use with `setattrlist`. -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple)] #[repr(C)] struct Attrlist { bitmapcount: u16, @@ -1770,3 +1784,27 @@ struct Attrlist { fileattr: Attrgroup, forkattr: Attrgroup, } + +#[cfg(any(target_os = "android", target_os = "linux"))] +pub(crate) fn mount( + source: Option<&CStr>, + target: &CStr, + file_system_type: Option<&CStr>, + flags: super::types::MountFlagsArg, + data: Option<&CStr>, +) -> io::Result<()> { + unsafe { + ret(c::mount( + source.map_or_else(null, CStr::as_ptr), + target.as_ptr(), + file_system_type.map_or_else(null, CStr::as_ptr), + flags.0, + data.map_or_else(null, CStr::as_ptr).cast(), + )) + } +} + +#[cfg(any(target_os = "android", target_os = "linux"))] +pub(crate) fn unmount(target: &CStr, flags: super::types::UnmountFlags) -> io::Result<()> { + unsafe { ret(c::umount2(target.as_ptr(), flags.bits())) } +} |