summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/src/backend/libc/fs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/rustix/src/backend/libc/fs')
-rw-r--r--vendor/rustix/src/backend/libc/fs/dir.rs136
-rw-r--r--vendor/rustix/src/backend/libc/fs/inotify.rs121
-rw-r--r--vendor/rustix/src/backend/libc/fs/makedev.rs38
-rw-r--r--vendor/rustix/src/backend/libc/fs/mod.rs16
-rw-r--r--vendor/rustix/src/backend/libc/fs/syscalls.rs342
-rw-r--r--vendor/rustix/src/backend/libc/fs/types.rs326
6 files changed, 555 insertions, 424 deletions
diff --git a/vendor/rustix/src/backend/libc/fs/dir.rs b/vendor/rustix/src/backend/libc/fs/dir.rs
index 6b69c3600..d1c901323 100644
--- a/vendor/rustix/src/backend/libc/fs/dir.rs
+++ b/vendor/rustix/src/backend/libc/fs/dir.rs
@@ -1,6 +1,6 @@
use super::super::c;
use super::super::conv::owned_fd;
-#[cfg(not(any(target_os = "haiku", target_os = "illumos", target_os = "solaris")))]
+#[cfg(not(any(solarish, target_os = "haiku")))]
use super::types::FileType;
use crate::fd::{AsFd, BorrowedFd};
use crate::ffi::CStr;
@@ -8,48 +8,25 @@ use crate::ffi::CStr;
use crate::ffi::CString;
use crate::fs::{fcntl_getfl, fstat, openat, Mode, OFlags, Stat};
#[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::{fstatfs, 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 crate::fs::{fstatvfs, StatVfs};
use crate::io;
#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))]
use crate::process::fchdir;
#[cfg(target_os = "wasi")]
use alloc::borrow::ToOwned;
-#[cfg(not(any(
- target_os = "android",
- target_os = "emscripten",
- target_os = "l4re",
- target_os = "linux",
- target_os = "openbsd",
-)))]
+#[cfg(not(any(linux_like, target_os = "openbsd")))]
use c::dirent as libc_dirent;
-#[cfg(not(any(
- target_os = "android",
- target_os = "emscripten",
- target_os = "l4re",
- target_os = "linux",
-)))]
+#[cfg(not(linux_like))]
use c::readdir as libc_readdir;
-#[cfg(any(
- target_os = "android",
- target_os = "emscripten",
- target_os = "l4re",
- target_os = "linux",
-))]
+#[cfg(linux_like)]
use c::{dirent64 as libc_dirent, readdir64 as libc_readdir};
use core::fmt;
use core::mem::zeroed;
@@ -139,11 +116,10 @@ impl Dir {
/// `fstatfs(self)`
#[cfg(not(any(
+ solarish,
target_os = "haiku",
- target_os = "illumos",
target_os = "netbsd",
target_os = "redox",
- target_os = "solaris",
target_os = "wasi",
)))]
#[inline]
@@ -152,13 +128,7 @@ impl Dir {
}
/// `fstatvfs(self)`
- #[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 fn statvfs(&self) -> io::Result<StatVfs> {
fstatvfs(unsafe { BorrowedFd::borrow_raw(c::dirfd(self.0.as_ptr())) })
@@ -176,21 +146,14 @@ impl Dir {
// struct, as the name is NUL-terminated and memory may not be allocated for
// the full extent of the struct. Copy the fields one at a time.
unsafe fn read_dirent(input: &libc_dirent) -> libc_dirent {
- #[cfg(not(any(
- target_os = "aix",
- target_os = "haiku",
- target_os = "illumos",
- target_os = "solaris"
- )))]
+ #[cfg(not(any(solarish, target_os = "aix", target_os = "haiku")))]
let d_type = input.d_type;
#[cfg(not(any(
+ apple,
+ freebsdlike,
target_os = "aix",
- target_os = "dragonfly",
- target_os = "freebsd",
target_os = "haiku",
- target_os = "ios",
- target_os = "macos",
target_os = "netbsd",
target_os = "wasi",
)))]
@@ -199,36 +162,19 @@ unsafe fn read_dirent(input: &libc_dirent) -> libc_dirent {
#[cfg(target_os = "aix")]
let d_offset = input.d_offset;
- #[cfg(not(any(
- target_os = "dragonfly",
- target_os = "freebsd",
- target_os = "netbsd",
- target_os = "openbsd",
- )))]
+ #[cfg(not(any(freebsdlike, netbsdlike)))]
let d_ino = input.d_ino;
- #[cfg(any(
- target_os = "dragonfly",
- target_os = "freebsd",
- target_os = "netbsd",
- target_os = "openbsd"
- ))]
+ #[cfg(any(freebsdlike, netbsdlike))]
let d_fileno = input.d_fileno;
#[cfg(not(any(target_os = "dragonfly", target_os = "wasi")))]
let d_reclen = input.d_reclen;
- #[cfg(any(
- target_os = "dragonfly",
- target_os = "freebsd",
- target_os = "netbsd",
- target_os = "openbsd",
- target_os = "ios",
- target_os = "macos",
- ))]
+ #[cfg(any(bsd, target_os = "aix"))]
let d_namlen = input.d_namlen;
- #[cfg(any(target_os = "ios", target_os = "macos"))]
+ #[cfg(apple)]
let d_seekoff = input.d_seekoff;
#[cfg(target_os = "haiku")]
@@ -242,43 +188,30 @@ unsafe fn read_dirent(input: &libc_dirent) -> libc_dirent {
// with a field that we missed here. And we can avoid blindly copying the
// whole `d_name` field, which may not be entirely allocated.
#[cfg_attr(target_os = "wasi", allow(unused_mut))]
- #[cfg(not(any(target_os = "freebsd", target_os = "dragonfly")))]
+ #[cfg(not(freebsdlike))]
let mut dirent = libc_dirent {
- #[cfg(not(any(
- target_os = "aix",
- target_os = "haiku",
- target_os = "illumos",
- target_os = "solaris"
- )))]
+ #[cfg(not(any(solarish, target_os = "aix", target_os = "haiku")))]
d_type,
#[cfg(not(any(
+ apple,
target_os = "aix",
target_os = "freebsd", // Until FreeBSD 12
target_os = "haiku",
- target_os = "ios",
- target_os = "macos",
target_os = "netbsd",
target_os = "wasi",
)))]
d_off,
#[cfg(target_os = "aix")]
d_offset,
- #[cfg(not(any(target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")))]
+ #[cfg(not(any(netbsdlike, target_os = "freebsd")))]
d_ino,
- #[cfg(any(target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))]
+ #[cfg(any(netbsdlike, target_os = "freebsd"))]
d_fileno,
#[cfg(not(target_os = "wasi"))]
d_reclen,
- #[cfg(any(
- target_os = "aix",
- target_os = "freebsd",
- target_os = "ios",
- target_os = "macos",
- target_os = "netbsd",
- target_os = "openbsd",
- ))]
+ #[cfg(any(apple, netbsdlike, target_os = "aix", target_os = "freebsd"))]
d_namlen,
- #[cfg(any(target_os = "ios", target_os = "macos"))]
+ #[cfg(apple)]
d_seekoff,
// The `d_name` field is NUL-terminated, and we need to be careful not
// to read bytes past the NUL, even though they're within the nominal
@@ -304,11 +237,11 @@ unsafe fn read_dirent(input: &libc_dirent) -> libc_dirent {
pub d_pino: i64,
pub d_reclen: ::c_ushort,
pub d_name: [::c_char; 1024], // Max length is _POSIX_PATH_MAX
- // */
+ */
// On dragonfly and FreeBSD 12, `dirent` has some non-public padding fields
// so we can't directly initialize it.
- #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
+ #[cfg(freebsdlike)]
let mut dirent = {
let mut dirent: libc_dirent = zeroed();
dirent.d_fileno = d_fileno;
@@ -386,36 +319,21 @@ impl DirEntry {
}
/// Returns the type of this directory entry.
- #[cfg(not(any(
- target_os = "aix",
- target_os = "haiku",
- target_os = "illumos",
- target_os = "solaris"
- )))]
+ #[cfg(not(any(solarish, target_os = "aix", target_os = "haiku")))]
#[inline]
pub fn file_type(&self) -> FileType {
FileType::from_dirent_d_type(self.dirent.d_type)
}
/// Return the inode number of this directory entry.
- #[cfg(not(any(
- target_os = "dragonfly",
- target_os = "freebsd",
- target_os = "netbsd",
- target_os = "openbsd",
- )))]
+ #[cfg(not(any(freebsdlike, netbsdlike)))]
#[inline]
pub fn ino(&self) -> u64 {
self.dirent.d_ino as u64
}
/// Return the inode number of this directory entry.
- #[cfg(any(
- target_os = "dragonfly",
- target_os = "freebsd",
- target_os = "netbsd",
- target_os = "openbsd",
- ))]
+ #[cfg(any(freebsdlike, netbsdlike))]
#[inline]
pub fn ino(&self) -> u64 {
#[allow(clippy::useless_conversion)]
diff --git a/vendor/rustix/src/backend/libc/fs/inotify.rs b/vendor/rustix/src/backend/libc/fs/inotify.rs
new file mode 100644
index 000000000..8a42e0583
--- /dev/null
+++ b/vendor/rustix/src/backend/libc/fs/inotify.rs
@@ -0,0 +1,121 @@
+//! inotify support for working with inotifies
+
+use super::super::c;
+use super::super::conv::{borrowed_fd, c_str, ret, ret_c_int, ret_owned_fd};
+use crate::fd::{BorrowedFd, OwnedFd};
+use crate::io;
+use bitflags::bitflags;
+
+bitflags! {
+ /// `IN_*` for use with [`inotify_init`].
+ ///
+ /// [`inotify_init`]: crate::fs::inotify::inotify_init
+ pub struct CreateFlags: c::c_int {
+ /// `IN_CLOEXEC`
+ const CLOEXEC = c::IN_CLOEXEC;
+ /// `IN_NONBLOCK`
+ const NONBLOCK = c::IN_NONBLOCK;
+ }
+}
+
+bitflags! {
+ /// `IN*` for use with [`inotify_add_watch`].
+ ///
+ /// [`inotify_add_watch`]: crate::fs::inotify::inotify_add_watch
+ #[derive(Default)]
+ pub struct WatchFlags: u32 {
+ /// `IN_ACCESS`
+ const ACCESS = c::IN_ACCESS;
+ /// `IN_ATTRIB`
+ const ATTRIB = c::IN_ATTRIB;
+ /// `IN_CLOSE_NOWRITE`
+ const CLOSE_NOWRITE = c::IN_CLOSE_NOWRITE;
+ /// `IN_CLOSE_WRITE`
+ const CLOSE_WRITE = c::IN_CLOSE_WRITE;
+ /// `IN_CREATE `
+ const CREATE = c::IN_CREATE;
+ /// `IN_DELETE`
+ const DELETE = c::IN_DELETE;
+ /// `IN_DELETE_SELF`
+ const DELETE_SELF = c::IN_DELETE_SELF;
+ /// `IN_MODIFY`
+ const MODIFY = c::IN_MODIFY;
+ /// `IN_MOVE_SELF`
+ const MOVE_SELF = c::IN_MOVE_SELF;
+ /// `IN_MOVED_FROM`
+ const MOVED_FROM = c::IN_MOVED_FROM;
+ /// `IN_MOVED_TO`
+ const MOVED_TO = c::IN_MOVED_TO;
+ /// `IN_OPEN`
+ const OPEN = c::IN_OPEN;
+
+ /// `IN_CLOSE`
+ const CLOSE = c::IN_CLOSE;
+ /// `IN_MOVE`
+ const MOVE = c::IN_MOVE;
+ /// `IN_ALL_EVENTS`
+ const ALL_EVENTS = c::IN_ALL_EVENTS;
+
+ /// `IN_DONT_FOLLOW`
+ const DONT_FOLLOW = c::IN_DONT_FOLLOW;
+ /// `IN_EXCL_UNLINK`
+ const EXCL_UNLINK = 1;
+ /// `IN_MASK_ADD`
+ const MASK_ADD = 1;
+ /// `IN_MASK_CREATE`
+ const MASK_CREATE = 1;
+ /// `IN_ONESHOT`
+ const ONESHOT = c::IN_ONESHOT;
+ /// `IN_ONLYDIR`
+ const ONLYDIR = c::IN_ONLYDIR;
+ }
+}
+
+/// `inotify_init1(flags)`—Creates a new inotify object.
+///
+/// Use the [`CreateFlags::CLOEXEC`] flag to prevent the resulting file
+/// descriptor from being implicitly passed across `exec` boundaries.
+#[doc(alias = "inotify_init1")]
+pub fn inotify_init(flags: CreateFlags) -> io::Result<OwnedFd> {
+ // SAFETY: `inotify_init1` has no safety preconditions.
+ unsafe { ret_owned_fd(c::inotify_init1(flags.bits())) }
+}
+
+/// `inotify_add_watch(self, path, flags)`—Adds a watch to inotify
+///
+/// This registers or updates a watch for the filesystem path `path`
+/// and returns a watch descriptor corresponding to this watch.
+///
+/// Note: Due to the existence of hardlinks, providing two
+/// different paths to this method may result in it returning
+/// the same watch descriptor. An application should keep track of this
+/// externally to avoid logic errors.
+pub fn inotify_add_watch<P: crate::path::Arg>(
+ inot: BorrowedFd<'_>,
+ path: P,
+ flags: WatchFlags,
+) -> io::Result<i32> {
+ let path = path.as_cow_c_str().unwrap();
+ // SAFETY: The fd and path we are passing is guaranteed valid by the type
+ // system.
+ unsafe {
+ ret_c_int(c::inotify_add_watch(
+ borrowed_fd(inot),
+ c_str(&path),
+ flags.bits(),
+ ))
+ }
+}
+
+/// `inotify_rm_watch(self, wd)`—Removes a watch from this inotify
+///
+/// The watch descriptor provided should have previously been returned
+/// by [`inotify_add_watch`] and not previously have been removed.
+#[doc(alias = "inotify_rm_watch")]
+pub fn inotify_remove_watch(inot: BorrowedFd<'_>, wd: i32) -> io::Result<()> {
+ // Android's `inotify_rm_watch` takes u32 despite `inotify_add_watch` is i32.
+ #[cfg(target_os = "android")]
+ let wd = wd as u32;
+ // SAFETY: The fd is valid and closing an arbitrary wd is valid.
+ unsafe { ret(c::inotify_rm_watch(borrowed_fd(inot), wd)) }
+}
diff --git a/vendor/rustix/src/backend/libc/fs/makedev.rs b/vendor/rustix/src/backend/libc/fs/makedev.rs
index 08ecd872e..afe942a59 100644
--- a/vendor/rustix/src/backend/libc/fs/makedev.rs
+++ b/vendor/rustix/src/backend/libc/fs/makedev.rs
@@ -2,7 +2,12 @@
use super::super::c;
use crate::fs::Dev;
-#[cfg(not(any(target_os = "android", target_os = "emscripten")))]
+#[cfg(not(any(
+ apple,
+ target_os = "aix",
+ target_os = "android",
+ target_os = "emscripten",
+)))]
#[inline]
pub(crate) fn makedev(maj: u32, min: u32) -> Dev {
c::makedev(maj, min)
@@ -11,7 +16,6 @@ pub(crate) fn makedev(maj: u32, min: u32) -> Dev {
#[cfg(all(target_os = "android", not(target_pointer_width = "32")))]
#[inline]
pub(crate) fn makedev(maj: u32, min: u32) -> Dev {
- // Android's `makedev` oddly has signed argument types.
c::makedev(maj, min)
}
@@ -33,7 +37,27 @@ pub(crate) fn makedev(maj: u32, min: u32) -> Dev {
Dev::from(c::makedev(maj, min))
}
-#[cfg(not(any(target_os = "android", target_os = "emscripten")))]
+#[cfg(apple)]
+#[inline]
+pub(crate) fn makedev(maj: u32, min: u32) -> Dev {
+ // Apple's `makedev` oddly has signed argument types and is `unsafe`.
+ unsafe { c::makedev(maj as i32, min as i32) }
+}
+
+#[cfg(target_os = "aix")]
+#[inline]
+pub(crate) fn makedev(maj: u32, min: u32) -> Dev {
+ // AIX's `makedev` oddly is `unsafe`.
+ unsafe { c::makedev(maj, min) }
+}
+
+#[cfg(not(any(
+ apple,
+ freebsdlike,
+ netbsdlike,
+ target_os = "android",
+ target_os = "emscripten",
+)))]
#[inline]
pub(crate) fn major(dev: Dev) -> u32 {
unsafe { c::major(dev) }
@@ -61,7 +85,13 @@ pub(crate) fn major(dev: Dev) -> u32 {
unsafe { c::major(dev as u32) }
}
-#[cfg(not(any(target_os = "android", target_os = "emscripten")))]
+#[cfg(not(any(
+ apple,
+ freebsdlike,
+ netbsdlike,
+ target_os = "android",
+ target_os = "emscripten",
+)))]
#[inline]
pub(crate) fn minor(dev: Dev) -> u32 {
unsafe { c::minor(dev) }
diff --git a/vendor/rustix/src/backend/libc/fs/mod.rs b/vendor/rustix/src/backend/libc/fs/mod.rs
index d0fc08765..54a48103c 100644
--- a/vendor/rustix/src/backend/libc/fs/mod.rs
+++ b/vendor/rustix/src/backend/libc/fs/mod.rs
@@ -1,18 +1,8 @@
#[cfg(not(target_os = "redox"))]
pub(crate) mod dir;
-#[cfg(not(any(
- target_os = "dragonfly",
- target_os = "haiku",
- target_os = "freebsd",
- target_os = "illumos",
- target_os = "ios",
- target_os = "macos",
- target_os = "netbsd",
- target_os = "openbsd",
- target_os = "redox",
- target_os = "solaris",
- target_os = "wasi",
-)))]
+#[cfg(any(target_os = "android", target_os = "linux"))]
+pub mod inotify;
+#[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))]
pub(crate) mod makedev;
#[cfg(not(windows))]
pub(crate) mod syscalls;
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())) }
+}
diff --git a/vendor/rustix/src/backend/libc/fs/types.rs b/vendor/rustix/src/backend/libc/fs/types.rs
index 8d8ec08bf..f635f2cca 100644
--- a/vendor/rustix/src/backend/libc/fs/types.rs
+++ b/vendor/rustix/src/backend/libc/fs/types.rs
@@ -40,11 +40,16 @@ bitflags! {
/// `AT_EMPTY_PATH`
#[cfg(any(
target_os = "android",
+ target_os = "freebsd",
target_os = "fuchsia",
target_os = "linux",
))]
const EMPTY_PATH = c::AT_EMPTY_PATH;
+ /// `AT_RESOLVE_BENEATH`
+ #[cfg(target_os = "freebsd")]
+ const RESOLVE_BENEATH = c::AT_RESOLVE_BENEATH;
+
/// `AT_EACCESS`
#[cfg(not(any(target_os = "emscripten", target_os = "android")))]
const EACCESS = c::AT_EACCESS;
@@ -147,6 +152,32 @@ impl Mode {
}
}
+impl From<RawMode> for Mode {
+ /// Support conversions from raw mode values to `Mode`.
+ ///
+ /// ```
+ /// use rustix::fs::{Mode, RawMode};
+ /// assert_eq!(Mode::from(0o700), Mode::RWXU);
+ /// ```
+ #[inline]
+ fn from(st_mode: RawMode) -> Self {
+ Self::from_raw_mode(st_mode)
+ }
+}
+
+impl From<Mode> for RawMode {
+ /// Support conversions from `Mode to raw mode values.
+ ///
+ /// ```
+ /// use rustix::fs::{Mode, RawMode};
+ /// assert_eq!(RawMode::from(Mode::RWXU), 0o700);
+ /// ```
+ #[inline]
+ fn from(mode: Mode) -> Self {
+ mode.as_raw_mode()
+ }
+}
+
bitflags! {
/// `O_*` constants for use with [`openat`].
///
@@ -175,7 +206,7 @@ bitflags! {
const DIRECTORY = c::O_DIRECTORY;
/// `O_DSYNC`
- #[cfg(not(any(target_os = "dragonfly", target_os = "freebsd", target_os = "redox")))]
+ #[cfg(not(any(target_os = "dragonfly", target_os = "redox")))]
const DSYNC = c::O_DSYNC;
/// `O_EXCL`
@@ -183,13 +214,8 @@ bitflags! {
/// `O_FSYNC`
#[cfg(any(
- target_os = "dragonfly",
- target_os = "freebsd",
- target_os = "ios",
+ bsd,
all(target_os = "linux", not(target_env = "musl")),
- target_os = "macos",
- target_os = "netbsd",
- target_os = "openbsd",
))]
const FSYNC = c::O_FSYNC;
@@ -214,11 +240,10 @@ bitflags! {
/// `O_RSYNC`
#[cfg(any(
+ netbsdlike,
target_os = "android",
target_os = "emscripten",
target_os = "linux",
- target_os = "netbsd",
- target_os = "openbsd",
target_os = "wasi",
))]
const RSYNC = c::O_RSYNC;
@@ -234,6 +259,7 @@ bitflags! {
#[cfg(any(
target_os = "android",
target_os = "emscripten",
+ target_os = "freebsd",
target_os = "fuchsia",
target_os = "linux",
target_os = "redox",
@@ -259,10 +285,29 @@ bitflags! {
target_os = "linux",
))]
const NOATIME = c::O_NOATIME;
+
+ /// `O_DIRECT`
+ #[cfg(any(
+ target_os = "android",
+ target_os = "emscripten",
+ target_os = "freebsd",
+ target_os = "fuchsia",
+ target_os = "linux",
+ target_os = "netbsd",
+ ))]
+ const DIRECT = c::O_DIRECT;
+
+ /// `O_RESOLVE_BENEATH`
+ #[cfg(target_os = "freebsd")]
+ const RESOLVE_BENEATH = c::O_RESOLVE_BENEATH;
+
+ /// `O_EMPTY_PATH`
+ #[cfg(target_os = "freebsd")]
+ const EMPTY_PATH = c::O_EMPTY_PATH;
}
}
-#[cfg(any(target_os = "ios", target_os = "macos"))]
+#[cfg(apple)]
bitflags! {
/// `CLONE_*` constants for use with [`fclonefileat`].
///
@@ -276,7 +321,7 @@ bitflags! {
}
}
-#[cfg(any(target_os = "ios", target_os = "macos"))]
+#[cfg(apple)]
mod copyfile {
pub(super) const ACL: u32 = 1 << 0;
pub(super) const STAT: u32 = 1 << 1;
@@ -287,7 +332,7 @@ mod copyfile {
pub(super) const ALL: u32 = METADATA | DATA;
}
-#[cfg(any(target_os = "ios", target_os = "macos"))]
+#[cfg(apple)]
bitflags! {
/// `COPYFILE_*` constants.
pub struct CopyfileFlags: c::c_uint {
@@ -427,12 +472,7 @@ impl FileType {
}
/// Construct a `FileType` from the `d_type` field of a `c::dirent`.
- #[cfg(not(any(
- target_os = "haiku",
- target_os = "illumos",
- target_os = "redox",
- target_os = "solaris"
- )))]
+ #[cfg(not(any(solarish, target_os = "haiku", target_os = "redox")))]
pub(crate) const fn from_dirent_d_type(d_type: u8) -> Self {
match d_type {
c::DT_REG => Self::RegularFile,
@@ -454,15 +494,12 @@ impl FileType {
///
/// [`fadvise`]: crate::fs::fadvise
#[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",
)))]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[repr(u32)]
@@ -502,40 +539,28 @@ bitflags! {
const HUGETLB = c::MFD_HUGETLB;
/// `MFD_HUGE_64KB`
- #[cfg(any(target_os = "android", target_os = "linux"))]
const HUGE_64KB = c::MFD_HUGE_64KB;
/// `MFD_HUGE_512JB`
- #[cfg(any(target_os = "android", target_os = "linux"))]
const HUGE_512KB = c::MFD_HUGE_512KB;
/// `MFD_HUGE_1MB`
- #[cfg(any(target_os = "android", target_os = "linux"))]
const HUGE_1MB = c::MFD_HUGE_1MB;
/// `MFD_HUGE_2MB`
- #[cfg(any(target_os = "android", target_os = "linux"))]
const HUGE_2MB = c::MFD_HUGE_2MB;
/// `MFD_HUGE_8MB`
- #[cfg(any(target_os = "android", target_os = "linux"))]
const HUGE_8MB = c::MFD_HUGE_8MB;
/// `MFD_HUGE_16MB`
- #[cfg(any(target_os = "android", target_os = "linux"))]
const HUGE_16MB = c::MFD_HUGE_16MB;
/// `MFD_HUGE_32MB`
- #[cfg(any(target_os = "android", target_os = "linux"))]
const HUGE_32MB = c::MFD_HUGE_32MB;
/// `MFD_HUGE_256MB`
- #[cfg(any(target_os = "android", target_os = "linux"))]
const HUGE_256MB = c::MFD_HUGE_256MB;
/// `MFD_HUGE_512MB`
- #[cfg(any(target_os = "android", target_os = "linux"))]
const HUGE_512MB = c::MFD_HUGE_512MB;
/// `MFD_HUGE_1GB`
- #[cfg(any(target_os = "android", target_os = "linux"))]
const HUGE_1GB = c::MFD_HUGE_1GB;
/// `MFD_HUGE_2GB`
- #[cfg(any(target_os = "android", target_os = "linux"))]
const HUGE_2GB = c::MFD_HUGE_2GB;
/// `MFD_HUGE_16GB`
- #[cfg(any(target_os = "android", target_os = "linux"))]
const HUGE_16GB = c::MFD_HUGE_16GB;
}
}
@@ -676,14 +701,7 @@ bitflags! {
}
}
-#[cfg(not(any(
- target_os = "aix",
- target_os = "illumos",
- target_os = "netbsd",
- target_os = "openbsd",
- target_os = "redox",
- target_os = "solaris",
-)))]
+#[cfg(not(any(netbsdlike, solarish, target_os = "aix", target_os = "redox")))]
bitflags! {
/// `FALLOC_FL_*` constants for use with [`fallocate`].
///
@@ -691,41 +709,26 @@ bitflags! {
pub struct FallocateFlags: i32 {
/// `FALLOC_FL_KEEP_SIZE`
#[cfg(not(any(
+ bsd,
target_os = "aix",
- target_os = "dragonfly",
- target_os = "freebsd",
target_os = "haiku",
- target_os = "ios",
- target_os = "macos",
- target_os = "netbsd",
- target_os = "openbsd",
target_os = "wasi",
)))]
const KEEP_SIZE = c::FALLOC_FL_KEEP_SIZE;
/// `FALLOC_FL_PUNCH_HOLE`
#[cfg(not(any(
+ bsd,
target_os = "aix",
- target_os = "dragonfly",
- target_os = "freebsd",
target_os = "haiku",
- target_os = "ios",
- target_os = "macos",
- target_os = "netbsd",
- target_os = "openbsd",
target_os = "wasi",
)))]
const PUNCH_HOLE = c::FALLOC_FL_PUNCH_HOLE;
/// `FALLOC_FL_NO_HIDE_STALE`
#[cfg(not(any(
+ bsd,
target_os = "aix",
- target_os = "dragonfly",
- target_os = "freebsd",
target_os = "haiku",
- target_os = "ios",
target_os = "linux",
- target_os = "macos",
- target_os = "netbsd",
- target_os = "openbsd",
target_os = "emscripten",
target_os = "fuchsia",
target_os = "wasi",
@@ -733,56 +736,36 @@ bitflags! {
const NO_HIDE_STALE = c::FALLOC_FL_NO_HIDE_STALE;
/// `FALLOC_FL_COLLAPSE_RANGE`
#[cfg(not(any(
+ bsd,
target_os = "aix",
- target_os = "dragonfly",
- target_os = "freebsd",
target_os = "haiku",
- target_os = "ios",
- target_os = "macos",
- target_os = "netbsd",
- target_os = "openbsd",
target_os = "emscripten",
target_os = "wasi",
)))]
const COLLAPSE_RANGE = c::FALLOC_FL_COLLAPSE_RANGE;
/// `FALLOC_FL_ZERO_RANGE`
#[cfg(not(any(
+ bsd,
target_os = "aix",
- target_os = "dragonfly",
- target_os = "freebsd",
target_os = "haiku",
- target_os = "ios",
- target_os = "macos",
- target_os = "netbsd",
- target_os = "openbsd",
target_os = "emscripten",
target_os = "wasi",
)))]
const ZERO_RANGE = c::FALLOC_FL_ZERO_RANGE;
/// `FALLOC_FL_INSERT_RANGE`
#[cfg(not(any(
+ bsd,
target_os = "aix",
- target_os = "dragonfly",
- target_os = "freebsd",
target_os = "haiku",
- target_os = "ios",
- target_os = "macos",
- target_os = "netbsd",
- target_os = "openbsd",
target_os = "emscripten",
target_os = "wasi",
)))]
const INSERT_RANGE = c::FALLOC_FL_INSERT_RANGE;
/// `FALLOC_FL_UNSHARE_RANGE`
#[cfg(not(any(
+ bsd,
target_os = "aix",
- target_os = "dragonfly",
- target_os = "freebsd",
target_os = "haiku",
- target_os = "ios",
- target_os = "macos",
- target_os = "netbsd",
- target_os = "openbsd",
target_os = "emscripten",
target_os = "wasi",
)))]
@@ -790,13 +773,7 @@ bitflags! {
}
}
-#[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")))]
bitflags! {
/// `ST_*` constants for use with [`StatVfs`].
pub struct StatVfsMountFlags: u64 {
@@ -836,10 +813,11 @@ bitflags! {
}
}
-/// `LOCK_*` constants for use with [`flock`]
+/// `LOCK_*` constants for use with [`flock`] and [`fcntl_lock`].
///
/// [`flock`]: crate::fs::flock
-#[cfg(not(any(target_os = "solaris", target_os = "wasi")))]
+/// [`fcntl_lock`]: crate::fs::fcntl_lock
+#[cfg(not(target_os = "wasi"))]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(i32)]
pub enum FlockOperation {
@@ -861,12 +839,7 @@ pub enum FlockOperation {
///
/// [`statat`]: crate::fs::statat
/// [`fstat`]: crate::fs::fstat
-#[cfg(not(any(
- target_os = "android",
- target_os = "linux",
- target_os = "emscripten",
- target_os = "l4re",
-)))]
+#[cfg(not(linux_like))]
pub type Stat = c::stat;
/// `struct stat` for use with [`statat`] and [`fstat`].
@@ -921,15 +894,11 @@ pub struct Stat {
/// [`statfs`]: crate::fs::statfs
/// [`fstatfs`]: crate::fs::fstatfs
#[cfg(not(any(
- target_os = "android",
- target_os = "emscripten",
+ linux_like,
+ solarish,
target_os = "haiku",
- target_os = "illumos",
- target_os = "linux",
- target_os = "l4re",
target_os = "netbsd",
target_os = "redox",
- target_os = "solaris",
target_os = "wasi",
)))]
#[allow(clippy::module_name_repetitions)]
@@ -939,25 +908,14 @@ pub type StatFs = c::statfs;
///
/// [`statfs`]: crate::fs::statfs
/// [`fstatfs`]: crate::fs::fstatfs
-#[cfg(any(
- target_os = "android",
- target_os = "linux",
- target_os = "emscripten",
- target_os = "l4re",
-))]
+#[cfg(linux_like)]
pub type StatFs = c::statfs64;
/// `struct statvfs` for use with [`statvfs`] and [`fstatvfs`].
///
/// [`statvfs`]: crate::fs::statvfs
/// [`fstatvfs`]: crate::fs::fstatvfs
-#[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")))]
#[allow(missing_docs)]
pub struct StatVfs {
pub f_bsize: u64,
@@ -1081,36 +1039,112 @@ pub type FsWord = u64;
#[cfg(all(target_os = "linux", target_arch = "s390x"))]
pub type FsWord = u32;
-#[cfg(not(target_os = "redox"))]
-pub use c::{UTIME_NOW, UTIME_OMIT};
-
-/// `PROC_SUPER_MAGIC`—The magic number for the procfs filesystem.
-#[cfg(all(
- any(target_os = "android", target_os = "linux"),
- not(target_env = "musl"),
-))]
-pub const PROC_SUPER_MAGIC: FsWord = c::PROC_SUPER_MAGIC as FsWord;
-
-/// `NFS_SUPER_MAGIC`—The magic number for the NFS filesystem.
-#[cfg(all(
- any(target_os = "android", target_os = "linux"),
- not(target_env = "musl"),
-))]
-pub const NFS_SUPER_MAGIC: FsWord = c::NFS_SUPER_MAGIC as FsWord;
-
-/// `PROC_SUPER_MAGIC`—The magic number for the procfs filesystem.
-#[cfg(all(any(target_os = "android", target_os = "linux"), target_env = "musl"))]
-pub const PROC_SUPER_MAGIC: FsWord = 0x0000_9fa0;
-
-/// `NFS_SUPER_MAGIC`—The magic number for the NFS filesystem.
-#[cfg(all(any(target_os = "android", target_os = "linux"), target_env = "musl"))]
-pub const NFS_SUPER_MAGIC: FsWord = 0x0000_6969;
-
/// `copyfile_state_t`—State for use with [`fcopyfile`].
///
/// [`fcopyfile`]: crate::fs::fcopyfile
-#[cfg(any(target_os = "ios", target_os = "macos"))]
+#[cfg(apple)]
#[allow(non_camel_case_types)]
#[repr(transparent)]
#[derive(Copy, Clone)]
pub struct copyfile_state_t(pub(crate) *mut c::c_void);
+
+#[cfg(any(target_os = "android", target_os = "linux"))]
+bitflags! {
+ /// `MS_*` constants for use with [`mount`].
+ ///
+ /// [`mount`]: crate::fs::mount
+ pub struct MountFlags: c::c_ulong {
+ /// `MS_BIND`
+ const BIND = c::MS_BIND;
+
+ /// `MS_DIRSYNC`
+ const DIRSYNC = c::MS_DIRSYNC;
+
+ /// `MS_LAZYTIME`
+ const LAZYTIME = c::MS_LAZYTIME;
+
+ /// `MS_MANDLOCK`
+ #[doc(alias = "MANDLOCK")]
+ const PERMIT_MANDATORY_FILE_LOCKING = c::MS_MANDLOCK;
+
+ /// `MS_NOATIME`
+ const NOATIME = c::MS_NOATIME;
+
+ /// `MS_NODEV`
+ const NODEV = c::MS_NODEV;
+
+ /// `MS_NODIRATIME`
+ const NODIRATIME = c::MS_NODIRATIME;
+
+ /// `MS_NOEXEC`
+ const NOEXEC = c::MS_NOEXEC;
+
+ /// `MS_NOSUID`
+ const NOSUID = c::MS_NOSUID;
+
+ /// `MS_RDONLY`
+ const RDONLY = c::MS_RDONLY;
+
+ /// `MS_REC`
+ const REC = c::MS_REC;
+
+ /// `MS_RELATIME`
+ const RELATIME = c::MS_RELATIME;
+
+ /// `MS_SILENT`
+ const SILENT = c::MS_SILENT;
+
+ /// `MS_STRICTATIME`
+ const STRICTATIME = c::MS_STRICTATIME;
+
+ /// `MS_SYNCHRONOUS`
+ const SYNCHRONOUS = c::MS_SYNCHRONOUS;
+ }
+}
+
+#[cfg(any(target_os = "android", target_os = "linux"))]
+bitflags! {
+ /// `MS_*` constants for use with [`change_mount`].
+ ///
+ /// [`change_mount`]: crate::fs::mount::change_mount.
+ pub struct MountPropagationFlags: c::c_ulong {
+ /// `MS_SHARED`
+ const SHARED = c::MS_SHARED;
+ /// `MS_PRIVATE`
+ const PRIVATE = c::MS_PRIVATE;
+ /// `MS_SLAVE`
+ const SLAVE = c::MS_SLAVE;
+ /// `MS_UNBINDABLE`
+ const UNBINDABLE = c::MS_UNBINDABLE;
+ /// `MS_REC`
+ const REC = c::MS_REC;
+ }
+}
+
+#[cfg(any(target_os = "android", target_os = "linux"))]
+bitflags! {
+ pub(crate) struct InternalMountFlags: c::c_ulong {
+ const REMOUNT = c::MS_REMOUNT;
+ const MOVE = c::MS_MOVE;
+ }
+}
+
+#[cfg(any(target_os = "android", target_os = "linux"))]
+pub(crate) struct MountFlagsArg(pub(crate) c::c_ulong);
+
+#[cfg(any(target_os = "android", target_os = "linux"))]
+bitflags! {
+ /// `MNT_*` constants for use with [`unmount`].
+ ///
+ /// [`unmount`]: crate::fs::mount::unmount
+ pub struct UnmountFlags: c::c_int {
+ /// `MNT_FORCE`
+ const FORCE = c::MNT_FORCE;
+ /// `MNT_DETACH`
+ const DETACH = c::MNT_DETACH;
+ /// `MNT_EXPIRE`
+ const EXPIRE = c::MNT_EXPIRE;
+ /// `UMOUNT_NOFOLLOW`
+ const NOFOLLOW = c::UMOUNT_NOFOLLOW;
+ }
+}