diff options
Diffstat (limited to 'vendor/rustix/src/fs')
-rw-r--r-- | vendor/rustix/src/fs/abs.rs | 33 | ||||
-rw-r--r-- | vendor/rustix/src/fs/at.rs | 380 | ||||
-rw-r--r-- | vendor/rustix/src/fs/constants.rs | 19 | ||||
-rw-r--r-- | vendor/rustix/src/fs/copy_file_range.rs | 20 | ||||
-rw-r--r-- | vendor/rustix/src/fs/cwd.rs | 32 | ||||
-rw-r--r-- | vendor/rustix/src/fs/dir.rs | 5 | ||||
-rw-r--r-- | vendor/rustix/src/fs/fadvise.rs | 19 | ||||
-rw-r--r-- | vendor/rustix/src/fs/fcntl.rs | 131 | ||||
-rw-r--r-- | vendor/rustix/src/fs/fcntl_darwin.rs | 24 | ||||
-rw-r--r-- | vendor/rustix/src/fs/fcopyfile.rs | 90 | ||||
-rw-r--r-- | vendor/rustix/src/fs/fd.rs | 301 | ||||
-rw-r--r-- | vendor/rustix/src/fs/file_type.rs | 4 | ||||
-rw-r--r-- | vendor/rustix/src/fs/getpath.rs | 14 | ||||
-rw-r--r-- | vendor/rustix/src/fs/makedev.rs | 35 | ||||
-rw-r--r-- | vendor/rustix/src/fs/memfd_create.rs | 15 | ||||
-rw-r--r-- | vendor/rustix/src/fs/mod.rs | 196 | ||||
-rw-r--r-- | vendor/rustix/src/fs/openat2.rs | 23 | ||||
-rw-r--r-- | vendor/rustix/src/fs/sendfile.rs | 19 | ||||
-rw-r--r-- | vendor/rustix/src/fs/statx.rs | 91 |
19 files changed, 1451 insertions, 0 deletions
diff --git a/vendor/rustix/src/fs/abs.rs b/vendor/rustix/src/fs/abs.rs new file mode 100644 index 000000000..25556304b --- /dev/null +++ b/vendor/rustix/src/fs/abs.rs @@ -0,0 +1,33 @@ +//! POSIX-style filesystem functions which operate on bare paths. + +#[cfg(not(any( + target_os = "illumos", + target_os = "netbsd", + target_os = "redox", + target_os = "wasi", +)))] +use crate::fs::StatFs; +#[cfg(not(any( + target_os = "illumos", + target_os = "netbsd", + target_os = "redox", + target_os = "wasi", +)))] +use crate::{imp, io, path}; + +/// `statfs`—Queries filesystem metadata. +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/statfs.2.html +#[cfg(not(any( + target_os = "illumos", + target_os = "netbsd", + target_os = "redox", + target_os = "wasi", +)))] +#[inline] +pub fn statfs<P: path::Arg>(path: P) -> io::Result<StatFs> { + path.into_with_c_str(imp::fs::syscalls::statfs) +} diff --git a/vendor/rustix/src/fs/at.rs b/vendor/rustix/src/fs/at.rs new file mode 100644 index 000000000..2ecd90324 --- /dev/null +++ b/vendor/rustix/src/fs/at.rs @@ -0,0 +1,380 @@ +//! POSIX-style `*at` functions. +//! +//! The `dirfd` argument to these functions may be a file descriptor for a +//! directory, or the special value returned by [`cwd`]. +//! +//! [`cwd`]: crate::fs::cwd + +use crate::ffi::{CStr, CString}; +#[cfg(not(target_os = "illumos"))] +use crate::fs::Access; +#[cfg(any(target_os = "ios", target_os = "macos"))] +use crate::fs::CloneFlags; +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "wasi")))] +use crate::fs::FileType; +#[cfg(any(target_os = "android", target_os = "linux"))] +use crate::fs::RenameFlags; +use crate::fs::{AtFlags, Mode, OFlags, Stat, Timestamps}; +use crate::io::{self, OwnedFd}; +use crate::path::SMALL_PATH_BUFFER_SIZE; +#[cfg(not(target_os = "wasi"))] +use crate::process::{Gid, Uid}; +use crate::{imp, path}; +use alloc::vec::Vec; +use imp::fd::{AsFd, BorrowedFd}; +use imp::time::types::Nsecs; + +pub use imp::fs::types::{Dev, RawMode}; + +/// `UTIME_NOW` for use with [`utimensat`]. +/// +/// [`utimensat`]: crate::fs::utimensat +#[cfg(not(target_os = "redox"))] +pub const UTIME_NOW: Nsecs = imp::fs::types::UTIME_NOW as Nsecs; + +/// `UTIME_OMIT` for use with [`utimensat`]. +/// +/// [`utimensat`]: crate::fs::utimensat +#[cfg(not(target_os = "redox"))] +pub const UTIME_OMIT: Nsecs = imp::fs::types::UTIME_OMIT as Nsecs; + +/// `openat(dirfd, path, oflags, mode)`—Opens a file. +/// +/// POSIX guarantees that `openat` will use the lowest unused file descriptor, +/// however it is not safe in general to rely on this, as file descriptors may +/// be unexpectedly allocated on other threads or in libraries. +/// +/// The `Mode` argument is only significant when creating a file. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/openat.html +/// [Linux]: https://man7.org/linux/man-pages/man2/open.2.html +#[inline] +pub fn openat<P: path::Arg, Fd: AsFd>( + dirfd: Fd, + path: P, + oflags: OFlags, + create_mode: Mode, +) -> io::Result<OwnedFd> { + path.into_with_c_str(|path| imp::fs::syscalls::openat(dirfd.as_fd(), path, oflags, create_mode)) +} + +/// `readlinkat(fd, path)`—Reads the contents of a symlink. +/// +/// If `reuse` is non-empty, reuse its buffer to store the result if possible. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/readlinkat.html +/// [Linux]: https://man7.org/linux/man-pages/man2/readlinkat.2.html +#[inline] +pub fn readlinkat<P: path::Arg, Fd: AsFd, B: Into<Vec<u8>>>( + dirfd: Fd, + path: P, + reuse: B, +) -> io::Result<CString> { + path.into_with_c_str(|path| _readlinkat(dirfd.as_fd(), path, reuse.into())) +} + +fn _readlinkat(dirfd: BorrowedFd<'_>, path: &CStr, mut buffer: Vec<u8>) -> io::Result<CString> { + // This code would benefit from having a better way to read into + // uninitialized memory, but that requires `unsafe`. + buffer.clear(); + buffer.reserve(SMALL_PATH_BUFFER_SIZE); + buffer.resize(buffer.capacity(), 0_u8); + + loop { + let nread = imp::fs::syscalls::readlinkat(dirfd.as_fd(), path, &mut buffer)?; + + let nread = nread as usize; + assert!(nread <= buffer.len()); + if nread < buffer.len() { + buffer.resize(nread, 0_u8); + return Ok(CString::new(buffer).unwrap()); + } + buffer.reserve(1); // use `Vec` reallocation strategy to grow capacity exponentially + buffer.resize(buffer.capacity(), 0_u8); + } +} + +/// `mkdirat(fd, path, mode)`—Creates a directory. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/mkdirat.html +/// [Linux]: https://man7.org/linux/man-pages/man2/mkdirat.2.html +#[inline] +pub fn mkdirat<P: path::Arg, Fd: AsFd>(dirfd: Fd, path: P, mode: Mode) -> io::Result<()> { + path.into_with_c_str(|path| imp::fs::syscalls::mkdirat(dirfd.as_fd(), path, mode)) +} + +/// `linkat(old_dirfd, old_path, new_dirfd, new_path, flags)`—Creates a hard +/// link. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/linkat.html +/// [Linux]: https://man7.org/linux/man-pages/man2/linkat.2.html +#[inline] +pub fn linkat<P: path::Arg, Q: path::Arg, PFd: AsFd, QFd: AsFd>( + old_dirfd: PFd, + old_path: P, + new_dirfd: QFd, + new_path: Q, + flags: AtFlags, +) -> io::Result<()> { + old_path.into_with_c_str(|old_path| { + new_path.into_with_c_str(|new_path| { + imp::fs::syscalls::linkat( + old_dirfd.as_fd(), + old_path, + new_dirfd.as_fd(), + new_path, + flags, + ) + }) + }) +} + +/// `unlinkat(fd, path, flags)`—Unlinks a file or remove a directory. +/// +/// With the [`REMOVEDIR`] flag, this removes a directory. This is in place +/// of a `rmdirat` function. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [`REMOVEDIR`]: AtFlags::REMOVEDIR +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/unlinkat.html +/// [Linux]: https://man7.org/linux/man-pages/man2/unlinkat.2.html +#[inline] +pub fn unlinkat<P: path::Arg, Fd: AsFd>(dirfd: Fd, path: P, flags: AtFlags) -> io::Result<()> { + path.into_with_c_str(|path| imp::fs::syscalls::unlinkat(dirfd.as_fd(), path, flags)) +} + +/// `renameat(old_dirfd, old_path, new_dirfd, new_path)`—Renames a file or +/// directory. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/renameat.html +/// [Linux]: https://man7.org/linux/man-pages/man2/renameat.2.html +#[inline] +pub fn renameat<P: path::Arg, Q: path::Arg, PFd: AsFd, QFd: AsFd>( + old_dirfd: PFd, + old_path: P, + new_dirfd: QFd, + new_path: Q, +) -> io::Result<()> { + old_path.into_with_c_str(|old_path| { + new_path.into_with_c_str(|new_path| { + imp::fs::syscalls::renameat(old_dirfd.as_fd(), old_path, new_dirfd.as_fd(), new_path) + }) + }) +} + +/// `renameat2(old_dirfd, old_path, new_dirfd, new_path, flags)`—Renames a +/// file or directory. +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/renameat2.2.html +#[cfg(any(target_os = "android", target_os = "linux"))] +#[inline] +#[doc(alias = "renameat2")] +pub fn renameat_with<P: path::Arg, Q: path::Arg, PFd: AsFd, QFd: AsFd>( + old_dirfd: PFd, + old_path: P, + new_dirfd: QFd, + new_path: Q, + flags: RenameFlags, +) -> io::Result<()> { + old_path.into_with_c_str(|old_path| { + new_path.into_with_c_str(|new_path| { + imp::fs::syscalls::renameat2( + old_dirfd.as_fd(), + old_path, + new_dirfd.as_fd(), + new_path, + flags, + ) + }) + }) +} + +/// `symlinkat(old_dirfd, old_path, new_dirfd, new_path)`—Creates a symlink. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/symlinkat.html +/// [Linux]: https://man7.org/linux/man-pages/man2/symlinkat.2.html +#[inline] +pub fn symlinkat<P: path::Arg, Q: path::Arg, Fd: AsFd>( + old_path: P, + new_dirfd: Fd, + new_path: Q, +) -> io::Result<()> { + old_path.into_with_c_str(|old_path| { + new_path.into_with_c_str(|new_path| { + imp::fs::syscalls::symlinkat(old_path, new_dirfd.as_fd(), new_path) + }) + }) +} + +/// `fstatat(dirfd, path, flags)`—Queries metadata for a file or directory. +/// +/// [`Mode::from_raw_mode`] and [`FileType::from_raw_mode`] may be used to +/// interpret the `st_mode` field. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fstatat.html +/// [Linux]: https://man7.org/linux/man-pages/man2/fstatat.2.html +/// [`Mode::from_raw_mode`]: crate::fs::Mode::from_raw_mode +/// [`FileType::from_raw_mode`]: crate::fs::FileType::from_raw_mode +#[inline] +#[doc(alias = "fstatat")] +pub fn statat<P: path::Arg, Fd: AsFd>(dirfd: Fd, path: P, flags: AtFlags) -> io::Result<Stat> { + path.into_with_c_str(|path| imp::fs::syscalls::statat(dirfd.as_fd(), path, flags)) +} + +/// `faccessat(dirfd, path, access, flags)`—Tests permissions for a file or +/// directory. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/faccessat.html +/// [Linux]: https://man7.org/linux/man-pages/man2/faccessat.2.html +#[cfg(not(target_os = "illumos"))] +#[inline] +#[doc(alias = "faccessat")] +pub fn accessat<P: path::Arg, Fd: AsFd>( + dirfd: Fd, + path: P, + access: Access, + flags: AtFlags, +) -> io::Result<()> { + path.into_with_c_str(|path| imp::fs::syscalls::accessat(dirfd.as_fd(), path, access, flags)) +} + +/// `utimensat(dirfd, path, times, flags)`—Sets file or directory timestamps. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/utimensat.html +/// [Linux]: https://man7.org/linux/man-pages/man2/utimensat.2.html +#[inline] +pub fn utimensat<P: path::Arg, Fd: AsFd>( + dirfd: Fd, + path: P, + times: &Timestamps, + flags: AtFlags, +) -> io::Result<()> { + path.into_with_c_str(|path| imp::fs::syscalls::utimensat(dirfd.as_fd(), path, times, flags)) +} + +/// `fchmodat(dirfd, path, mode, 0)`—Sets file or directory permissions. +/// +/// The flags argument is fixed to 0, so `AT_SYMLINK_NOFOLLOW` is not +/// supported. <details>Platform support for this flag varies widely.</details> +/// +/// This implementation does not support `O_PATH` file descriptors, even on +/// platforms where the host libc emulates it. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fchmodat.html +/// [Linux]: https://man7.org/linux/man-pages/man2/fchmodat.2.html +#[cfg(not(target_os = "wasi"))] +#[inline] +#[doc(alias = "fchmodat")] +pub fn chmodat<P: path::Arg, Fd: AsFd>(dirfd: Fd, path: P, mode: Mode) -> io::Result<()> { + path.into_with_c_str(|path| imp::fs::syscalls::chmodat(dirfd.as_fd(), path, mode)) +} + +/// `fclonefileat(src, dst_dir, dst, flags)`—Efficiently copies between files. +/// +/// # References +/// - [Apple] +/// +/// [Apple]: https://opensource.apple.com/source/xnu/xnu-3789.21.4/bsd/man/man2/clonefile.2.auto.html +#[cfg(any(target_os = "ios", target_os = "macos"))] +#[inline] +pub fn fclonefileat<Fd: AsFd, DstFd: AsFd, P: path::Arg>( + src: Fd, + dst_dir: DstFd, + dst: P, + flags: CloneFlags, +) -> io::Result<()> { + dst.into_with_c_str(|dst| { + imp::fs::syscalls::fclonefileat(src.as_fd(), dst_dir.as_fd(), &dst, flags) + }) +} + +/// `mknodat(dirfd, path, mode, dev)`—Creates special or normal files. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/mknodat.html +/// [Linux]: https://man7.org/linux/man-pages/man2/mknodat.2.html +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "wasi")))] +#[inline] +pub fn mknodat<P: path::Arg, Fd: AsFd>( + dirfd: Fd, + path: P, + file_type: FileType, + mode: Mode, + dev: Dev, +) -> io::Result<()> { + path.into_with_c_str(|path| { + imp::fs::syscalls::mknodat(dirfd.as_fd(), path, file_type, mode, dev) + }) +} + +/// `fchownat(dirfd, path, owner, group, flags)`—Sets file or directory +/// ownership. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fchownat.html +/// [Linux]: https://man7.org/linux/man-pages/man2/fchownat.2.html +#[cfg(not(any(target_os = "wasi")))] +#[inline] +pub fn chownat<P: path::Arg, Fd: AsFd>( + dirfd: Fd, + path: P, + owner: Option<Uid>, + group: Option<Gid>, + flags: AtFlags, +) -> io::Result<()> { + path.into_with_c_str(|path| { + imp::fs::syscalls::chownat(dirfd.as_fd(), path, owner, group, flags) + }) +} diff --git a/vendor/rustix/src/fs/constants.rs b/vendor/rustix/src/fs/constants.rs new file mode 100644 index 000000000..b6893a92e --- /dev/null +++ b/vendor/rustix/src/fs/constants.rs @@ -0,0 +1,19 @@ +//! Filesystem API constants, translated into `bitflags` constants. + +use crate::imp; + +pub use imp::fs::types::{Access, FdFlags, Mode, OFlags}; + +#[cfg(not(target_os = "redox"))] +pub use imp::fs::types::AtFlags; + +#[cfg(any(target_os = "ios", target_os = "macos"))] +pub use imp::fs::types::{CloneFlags, CopyfileFlags}; + +#[cfg(any(target_os = "android", target_os = "linux"))] +pub use imp::fs::types::{RenameFlags, ResolveFlags}; + +#[cfg(not(target_os = "redox"))] +pub use imp::fs::types::Dev; + +pub use imp::time::types::{Nsecs, Secs, Timespec}; diff --git a/vendor/rustix/src/fs/copy_file_range.rs b/vendor/rustix/src/fs/copy_file_range.rs new file mode 100644 index 000000000..b12190472 --- /dev/null +++ b/vendor/rustix/src/fs/copy_file_range.rs @@ -0,0 +1,20 @@ +use crate::{imp, io}; +use imp::fd::AsFd; + +/// `copy_file_range(fd_in, off_in, fd_out, off_out, len, 0)`—Copies data +/// from one file to another. +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/copy_file_range.2.html +#[inline] +pub fn copy_file_range<InFd: AsFd, OutFd: AsFd>( + fd_in: InFd, + off_in: Option<&mut u64>, + fd_out: OutFd, + off_out: Option<&mut u64>, + len: u64, +) -> io::Result<u64> { + imp::fs::syscalls::copy_file_range(fd_in.as_fd(), off_in, fd_out.as_fd(), off_out, len) +} diff --git a/vendor/rustix/src/fs/cwd.rs b/vendor/rustix/src/fs/cwd.rs new file mode 100644 index 000000000..95f97f85d --- /dev/null +++ b/vendor/rustix/src/fs/cwd.rs @@ -0,0 +1,32 @@ +//! The `cwd` function, representing the current working directory. +//! +//! # Safety +//! +//! This file uses `AT_FDCWD`, which is a raw file descriptor, but which is +//! always valid. + +#![allow(unsafe_code)] + +use crate::imp; +use imp::fd::{BorrowedFd, RawFd}; + +/// `AT_FDCWD`—Returns a handle representing the current working directory. +/// +/// This returns a file descriptor which refers to the process current +/// directory which can be used as the directory argument in `*at` +/// functions such as [`openat`]. +/// +/// # References +/// - [POSIX] +/// +/// [`openat`]: crate::fs::openat +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/fcntl.h.html +#[inline] +#[doc(alias = "AT_FDCWD")] +pub const fn cwd() -> BorrowedFd<'static> { + let at_fdcwd = imp::io::types::AT_FDCWD as RawFd; + + // Safety: `AT_FDCWD` is a reserved value that is never dynamically + // allocated, so it'll remain valid for the duration of `'static`. + unsafe { BorrowedFd::<'static>::borrow_raw(at_fdcwd) } +} diff --git a/vendor/rustix/src/fs/dir.rs b/vendor/rustix/src/fs/dir.rs new file mode 100644 index 000000000..f9d7ff871 --- /dev/null +++ b/vendor/rustix/src/fs/dir.rs @@ -0,0 +1,5 @@ +//! `Dir` and `Entry`. + +use crate::imp; + +pub use imp::fs::dir::{Dir, DirEntry}; diff --git a/vendor/rustix/src/fs/fadvise.rs b/vendor/rustix/src/fs/fadvise.rs new file mode 100644 index 000000000..ead3ad9a3 --- /dev/null +++ b/vendor/rustix/src/fs/fadvise.rs @@ -0,0 +1,19 @@ +use crate::{imp, io}; +use imp::fd::AsFd; + +pub use imp::fs::types::Advice; + +/// `posix_fadvise(fd, offset, len, advice)`—Declares an expected access +/// pattern for a file. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_fadvise.html +/// [Linux]: https://man7.org/linux/man-pages/man2/posix_fadvise.2.html +#[inline] +#[doc(alias = "posix_fadvise")] +pub fn fadvise<Fd: AsFd>(fd: Fd, offset: u64, len: u64, advice: Advice) -> io::Result<()> { + imp::fs::syscalls::fadvise(fd.as_fd(), offset, len, advice) +} diff --git a/vendor/rustix/src/fs/fcntl.rs b/vendor/rustix/src/fs/fcntl.rs new file mode 100644 index 000000000..7f89873b5 --- /dev/null +++ b/vendor/rustix/src/fs/fcntl.rs @@ -0,0 +1,131 @@ +//! The Unix `fcntl` function is effectively lots of different functions +//! hidden behind a single dynamic dispatch interface. In order to provide +//! a type-safe API, rustix makes them all separate functions so that they +//! can have dedicated static type signatures. + +use crate::imp; +use crate::io::{self, OwnedFd}; +use imp::fd::{AsFd, RawFd}; +use imp::fs::types::{FdFlags, OFlags}; + +/// `fcntl(fd, F_GETFD)`—Returns a file descriptor's flags. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html +/// [Linux]: https://man7.org/linux/man-pages/man2/fcntl.2.html +#[inline] +#[doc(alias = "F_GETFD")] +pub fn fcntl_getfd<Fd: AsFd>(fd: Fd) -> io::Result<FdFlags> { + imp::fs::syscalls::fcntl_getfd(fd.as_fd()) +} + +/// `fcntl(fd, F_SETFD, flags)`—Sets a file descriptor's flags. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html +/// [Linux]: https://man7.org/linux/man-pages/man2/fcntl.2.html +#[inline] +#[doc(alias = "F_SETFD")] +pub fn fcntl_setfd<Fd: AsFd>(fd: Fd, flags: FdFlags) -> io::Result<()> { + imp::fs::syscalls::fcntl_setfd(fd.as_fd(), flags) +} + +/// `fcntl(fd, F_GETFL)`—Returns a file descriptor's access mode and status. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html +/// [Linux]: https://man7.org/linux/man-pages/man2/fcntl.2.html +#[inline] +#[doc(alias = "F_GETFL")] +pub fn fcntl_getfl<Fd: AsFd>(fd: Fd) -> io::Result<OFlags> { + imp::fs::syscalls::fcntl_getfl(fd.as_fd()) +} + +/// `fcntl(fd, F_SETFL, flags)`—Sets a file descriptor's status. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html +/// [Linux]: https://man7.org/linux/man-pages/man2/fcntl.2.html +#[inline] +#[doc(alias = "F_SETFL")] +pub fn fcntl_setfl<Fd: AsFd>(fd: Fd, flags: OFlags) -> io::Result<()> { + imp::fs::syscalls::fcntl_setfl(fd.as_fd(), flags) +} + +/// `fcntl(fd, F_GET_SEALS)` +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/fcntl.2.html +#[cfg(any( + target_os = "android", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "linux", +))] +#[inline] +#[doc(alias = "F_GET_SEALS")] +pub fn fcntl_get_seals<Fd: AsFd>(fd: Fd) -> io::Result<SealFlags> { + imp::fs::syscalls::fcntl_get_seals(fd.as_fd()) +} + +#[cfg(any( + target_os = "android", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "linux", +))] +pub use imp::fs::types::SealFlags; + +/// `fcntl(fd, F_ADD_SEALS)` +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/fcntl.2.html +#[cfg(any( + target_os = "android", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "linux", +))] +#[inline] +#[doc(alias = "F_ADD_SEALS")] +pub fn fcntl_add_seals<Fd: AsFd>(fd: Fd, seals: SealFlags) -> io::Result<()> { + imp::fs::syscalls::fcntl_add_seals(fd.as_fd(), seals) +} + +/// `fcntl(fd, F_DUPFD_CLOEXEC)`—Creates a new `OwnedFd` instance, with value +/// at least `min`, that has `O_CLOEXEC` set and that shares the same +/// underlying [file description] as `fd`. +/// +/// POSIX guarantees that `F_DUPFD_CLOEXEC` will use the lowest unused file +/// descriptor which is at least `min`, however it is not safe in general to +/// rely on this, as file descriptors may be unexpectedly allocated on other +/// threads or in libraries. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html +/// [Linux]: https://man7.org/linux/man-pages/man2/fcntl.2.html +#[cfg(not(target_os = "wasi"))] +#[inline] +#[doc(alias = "F_DUPFD_CLOEXEC")] +pub fn fcntl_dupfd_cloexec<Fd: AsFd>(fd: Fd, min: RawFd) -> io::Result<OwnedFd> { + imp::fs::syscalls::fcntl_dupfd_cloexec(fd.as_fd(), min) +} diff --git a/vendor/rustix/src/fs/fcntl_darwin.rs b/vendor/rustix/src/fs/fcntl_darwin.rs new file mode 100644 index 000000000..17d8f844f --- /dev/null +++ b/vendor/rustix/src/fs/fcntl_darwin.rs @@ -0,0 +1,24 @@ +use crate::{imp, io}; +use imp::fd::AsFd; + +/// `fcntl(fd, F_RDADVISE, radvisory { offset, len })` +/// +/// # References +/// - [Apple] +/// +/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fcntl.2.html +#[inline] +pub fn fcntl_rdadvise<Fd: AsFd>(fd: Fd, offset: u64, len: u64) -> io::Result<()> { + imp::fs::syscalls::fcntl_rdadvise(fd.as_fd(), offset, len) +} + +/// `fcntl(fd, F_FULLFSYNC)` +/// +/// # References +/// - [Apple] +/// +/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fcntl.2.html +#[inline] +pub fn fcntl_fullfsync<Fd: AsFd>(fd: Fd) -> io::Result<()> { + imp::fs::syscalls::fcntl_fullfsync(fd.as_fd()) +} diff --git a/vendor/rustix/src/fs/fcopyfile.rs b/vendor/rustix/src/fs/fcopyfile.rs new file mode 100644 index 000000000..c5b00ce10 --- /dev/null +++ b/vendor/rustix/src/fs/fcopyfile.rs @@ -0,0 +1,90 @@ +use crate::fs::CopyfileFlags; +use crate::{imp, io}; +use imp::fd::AsFd; + +/// `copyfile_state_t` +pub use imp::fs::types::copyfile_state_t; + +/// `fcopyfile(from, to, state, flags)` +/// +/// # Safety +/// +/// The `state` operand must be allocated with `copyfile_state_alloc` and not +/// yet freed with `copyfile_state_free`. +/// +/// # References +/// - [Apple] +/// +/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/fcopyfile.3.html +#[inline] +pub unsafe fn fcopyfile<FromFd: AsFd, ToFd: AsFd>( + from: FromFd, + to: ToFd, + state: copyfile_state_t, + flags: CopyfileFlags, +) -> io::Result<()> { + imp::fs::syscalls::fcopyfile(from.as_fd(), to.as_fd(), state, flags) +} + +/// `copyfile_state_alloc()` +/// +/// # References +/// - [Apple] +/// +/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/fcopyfile.3.html +#[inline] +pub fn copyfile_state_alloc() -> io::Result<copyfile_state_t> { + imp::fs::syscalls::copyfile_state_alloc() +} + +/// `copyfile_state_free(state)` +/// +/// # Safety +/// +/// The `state` operand must be allocated with `copyfile_state_alloc` and not +/// yet freed with `copyfile_state_free`. +/// +/// # References +/// - [Apple] +/// +/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/fcopyfile.3.html +#[inline] +pub unsafe fn copyfile_state_free(state: copyfile_state_t) -> io::Result<()> { + imp::fs::syscalls::copyfile_state_free(state) +} + +/// `copyfile_state_get(state, COPYFILE_STATE_COPIED)` +/// +/// # Safety +/// +/// The `state` operand must be allocated with `copyfile_state_alloc` and not +/// yet freed with `copyfile_state_free`. +/// +/// # References +/// - [Apple] +/// +/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/fcopyfile.3.html +#[inline] +pub unsafe fn copyfile_state_get_copied(state: copyfile_state_t) -> io::Result<u64> { + imp::fs::syscalls::copyfile_state_get_copied(state) +} + +/// `copyfile_state_get(state, flags, dst)` +/// +/// # Safety +/// +/// The `state` operand must be allocated with `copyfile_state_alloc` and not +/// yet freed with `copyfile_state_free`. +/// +/// # References +/// - [Apple] +/// +/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/fcopyfile.3.html +#[inline] +pub unsafe fn copyfile_state_get( + state: copyfile_state_t, + flag: u32, + dst: *mut core::ffi::c_void, +) -> io::Result<()> { + imp::fs::syscalls::copyfile_state_get(state, flag, dst) +} diff --git a/vendor/rustix/src/fs/fd.rs b/vendor/rustix/src/fs/fd.rs new file mode 100644 index 000000000..b41579fb8 --- /dev/null +++ b/vendor/rustix/src/fs/fd.rs @@ -0,0 +1,301 @@ +//! Functions which operate on file descriptors. + +#[cfg(not(target_os = "wasi"))] +use crate::fs::Mode; +use crate::io::SeekFrom; +#[cfg(not(target_os = "wasi"))] +use crate::process::{Gid, Uid}; +use crate::{imp, io}; +use imp::fd::{AsFd, BorrowedFd}; + +#[cfg(not(target_os = "wasi"))] +pub use imp::fs::types::FlockOperation; + +#[cfg(not(any( + target_os = "dragonfly", + target_os = "illumos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use imp::fs::types::FallocateFlags; + +pub use imp::fs::types::Stat; + +#[cfg(not(any( + target_os = "illumos", + target_os = "netbsd", + target_os = "redox", + target_os = "wasi", +)))] +pub use imp::fs::types::StatFs; + +#[cfg(any(target_os = "android", target_os = "linux"))] +pub use imp::fs::types::FsWord; + +/// Timestamps used by [`utimensat`] and [`futimens`]. +/// +/// [`utimensat`]: crate::fs::utimensat +/// [`futimens`]: crate::fs::futimens +// This is `repr(C)` and specifically laid out to match the representation used +// by `utimensat` and `futimens`, which expect 2-element arrays of timestamps. +#[repr(C)] +#[derive(Clone, Debug)] +pub struct Timestamps { + /// The timestamp of the last access to a filesystem object. + pub last_access: crate::fs::Timespec, + + /// The timestamp of the last modification of a filesystem object. + pub last_modification: crate::fs::Timespec, +} + +/// The filesystem magic number for procfs. +/// +/// See [the `fstatfs` man page] for more information. +/// +/// [the `fstatfs` man page]: https://man7.org/linux/man-pages/man2/fstatfs.2.html#DESCRIPTION +#[cfg(any(target_os = "android", target_os = "linux"))] +pub const PROC_SUPER_MAGIC: FsWord = imp::fs::types::PROC_SUPER_MAGIC; + +/// The filesystem magic number for NFS. +/// +/// See [the `fstatfs` man page] for more information. +/// +/// [the `fstatfs` man page]: https://man7.org/linux/man-pages/man2/fstatfs.2.html#DESCRIPTION +#[cfg(any(target_os = "android", target_os = "linux"))] +pub const NFS_SUPER_MAGIC: FsWord = imp::fs::types::NFS_SUPER_MAGIC; + +/// `lseek(fd, offset, whence)`—Repositions a file descriptor within a file. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/lseek.html +/// [Linux]: https://man7.org/linux/man-pages/man2/lseek.2.html +#[inline] +pub fn seek<Fd: AsFd>(fd: Fd, pos: SeekFrom) -> io::Result<u64> { + imp::fs::syscalls::seek(fd.as_fd(), pos) +} + +/// `lseek(fd, 0, SEEK_CUR)`—Returns the current position within a file. +/// +/// Return the current position of the file descriptor. This is a subset of +/// the functionality of `seek`, but this interface makes it easier for users +/// to declare their intent not to mutate any state. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/lseek.html +/// [Linux]: https://man7.org/linux/man-pages/man2/lseek.2.html +#[inline] +pub fn tell<Fd: AsFd>(fd: Fd) -> io::Result<u64> { + imp::fs::syscalls::tell(fd.as_fd()) +} + +/// `fchmod(fd)`—Sets open file or directory permissions. +/// +/// This implementation does not support `O_PATH` file descriptors, even on +/// platforms where the host libc emulates it. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fchmod.html +/// [Linux]: https://man7.org/linux/man-pages/man2/fchmod.2.html +#[cfg(not(target_os = "wasi"))] +#[inline] +pub fn fchmod<Fd: AsFd>(fd: Fd, mode: Mode) -> io::Result<()> { + imp::fs::syscalls::fchmod(fd.as_fd(), mode) +} + +/// `fchown(fd)`—Sets open file or directory ownership. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fchown.html +/// [Linux]: https://man7.org/linux/man-pages/man2/fchown.2.html +#[cfg(not(target_os = "wasi"))] +#[inline] +pub fn fchown<Fd: AsFd>(fd: Fd, owner: Option<Uid>, group: Option<Gid>) -> io::Result<()> { + imp::fs::syscalls::fchown(fd.as_fd(), owner, group) +} + +/// `fstat(fd)`—Queries metadata for an open file or directory. +/// +/// [`Mode::from_raw_mode`] and [`FileType::from_raw_mode`] may be used to +/// interpret the `st_mode` field. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fstat.html +/// [Linux]: https://man7.org/linux/man-pages/man2/fstat.2.html +/// [`Mode::from_raw_mode`]: crate::fs::Mode::from_raw_mode +/// [`FileType::from_raw_mode`]: crate::fs::FileType::from_raw_mode +#[inline] +pub fn fstat<Fd: AsFd>(fd: Fd) -> io::Result<Stat> { + imp::fs::syscalls::fstat(fd.as_fd()) +} + +/// `fstatfs(fd)`—Queries filesystem statistics for an open file or directory. +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/fstatfs.2.html +#[cfg(not(any( + target_os = "illumos", + target_os = "netbsd", + target_os = "redox", + target_os = "wasi", +)))] // not implemented in libc for netbsd yet +#[inline] +pub fn fstatfs<Fd: AsFd>(fd: Fd) -> io::Result<StatFs> { + imp::fs::syscalls::fstatfs(fd.as_fd()) +} + +/// `futimens(fd, times)`—Sets timestamps for an open file or directory. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/futimens.html +/// [Linux]: https://man7.org/linux/man-pages/man2/utimensat.2.html +#[inline] +pub fn futimens<Fd: AsFd>(fd: Fd, times: &Timestamps) -> io::Result<()> { + imp::fs::syscalls::futimens(fd.as_fd(), times) +} + +/// `fallocate(fd, mode, offset, len)`—Adjusts file allocation. +/// +/// This is a more general form of `posix_fallocate`, adding a `mode` argument +/// which modifies the behavior. On platforms which only support +/// `posix_fallocate` and not the more general form, no `FallocateFlags` values +/// are defined so it will always be empty. +/// +/// # References +/// - [POSIX] +/// - [Linux `fallocate`] +/// - [Linux `posix_fallocate`] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html +/// [Linux `fallocate`]: https://man7.org/linux/man-pages/man2/fallocate.2.html +/// [Linux `posix_fallocate`]: https://man7.org/linux/man-pages/man3/posix_fallocate.3.html +#[cfg(not(any( + target_os = "dragonfly", + target_os = "illumos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] // not implemented in libc for netbsd yet +#[inline] +#[doc(alias = "posix_fallocate")] +pub fn fallocate<Fd: AsFd>(fd: Fd, mode: FallocateFlags, offset: u64, len: u64) -> io::Result<()> { + imp::fs::syscalls::fallocate(fd.as_fd(), mode, offset, len) +} + +/// `fcntl(fd, F_GETFL) & O_ACCMODE` +/// +/// Returns a pair of booleans indicating whether the file descriptor is +/// readable and/or writable, respectively. This is only reliable on files; for +/// example, it doesn't reflect whether sockets have been shut down; for +/// general I/O handle support, use [`io::is_read_write`]. +#[inline] +pub fn is_file_read_write<Fd: AsFd>(fd: Fd) -> io::Result<(bool, bool)> { + _is_file_read_write(fd.as_fd()) +} + +pub(crate) fn _is_file_read_write(fd: BorrowedFd<'_>) -> io::Result<(bool, bool)> { + let mode = imp::fs::syscalls::fcntl_getfl(fd)?; + + // Check for `O_PATH`. + #[cfg(any( + target_os = "android", + target_os = "fuchsia", + target_os = "linux", + target_os = "emscripten", + ))] + if mode.contains(crate::fs::OFlags::PATH) { + return Ok((false, false)); + } + + // Use `RWMODE` rather than `ACCMODE` as `ACCMODE` may include `O_PATH`. + // We handled `O_PATH` above. + match mode & crate::fs::OFlags::RWMODE { + crate::fs::OFlags::RDONLY => Ok((true, false)), + crate::fs::OFlags::RDWR => Ok((true, true)), + crate::fs::OFlags::WRONLY => Ok((false, true)), + _ => unreachable!(), + } +} + +/// `fsync(fd)`—Ensures that file data and metadata is written to the +/// underlying storage device. +/// +/// On iOS and macOS this isn't sufficient to ensure that data has reached +/// persistent storage; use [`fcntl_fullfsync`] to ensure that. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html +/// [Linux]: https://man7.org/linux/man-pages/man2/fsync.2.html +/// [`fcntl_fullfsync`]: https://docs.rs/rustix/*/x86_64-apple-darwin/rustix/fs/fn.fcntl_fullfsync.html +#[inline] +pub fn fsync<Fd: AsFd>(fd: Fd) -> io::Result<()> { + imp::fs::syscalls::fsync(fd.as_fd()) +} + +/// `fdatasync(fd)`—Ensures that file data is written to the underlying +/// storage device. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fdatasync.html +/// [Linux]: https://man7.org/linux/man-pages/man2/fdatasync.2.html +#[cfg(not(any( + target_os = "dragonfly", + target_os = "ios", + target_os = "macos", + target_os = "redox", +)))] +#[inline] +pub fn fdatasync<Fd: AsFd>(fd: Fd) -> io::Result<()> { + imp::fs::syscalls::fdatasync(fd.as_fd()) +} + +/// `ftruncate(fd, length)`—Sets the length of a file. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html +/// [Linux]: https://man7.org/linux/man-pages/man2/ftruncate.2.html +#[inline] +pub fn ftruncate<Fd: AsFd>(fd: Fd, length: u64) -> io::Result<()> { + imp::fs::syscalls::ftruncate(fd.as_fd(), length) +} + +/// `flock(fd, operation)`—Acquire or release an advisory lock on an open file. +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/flock.2.html +#[cfg(not(target_os = "wasi"))] +#[inline] +pub fn flock<Fd: AsFd>(fd: Fd, operation: FlockOperation) -> io::Result<()> { + imp::fs::syscalls::flock(fd.as_fd(), operation) +} diff --git a/vendor/rustix/src/fs/file_type.rs b/vendor/rustix/src/fs/file_type.rs new file mode 100644 index 000000000..75935c794 --- /dev/null +++ b/vendor/rustix/src/fs/file_type.rs @@ -0,0 +1,4 @@ +use crate::imp; + +/// `S_IF*` constants. +pub use imp::fs::types::FileType; diff --git a/vendor/rustix/src/fs/getpath.rs b/vendor/rustix/src/fs/getpath.rs new file mode 100644 index 000000000..bc40890d1 --- /dev/null +++ b/vendor/rustix/src/fs/getpath.rs @@ -0,0 +1,14 @@ +use crate::ffi::CString; +use crate::{imp, io}; +use imp::fd::AsFd; + +/// `fcntl(fd, F_GETPATH)` +/// +/// # References +/// - [Apple] +/// +/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fcntl.2.html +#[inline] +pub fn getpath<Fd: AsFd>(fd: Fd) -> io::Result<CString> { + imp::fs::syscalls::getpath(fd.as_fd()) +} diff --git a/vendor/rustix/src/fs/makedev.rs b/vendor/rustix/src/fs/makedev.rs new file mode 100644 index 000000000..75cc42540 --- /dev/null +++ b/vendor/rustix/src/fs/makedev.rs @@ -0,0 +1,35 @@ +use crate::fs::Dev; +use crate::imp; + +/// `makedev(maj, min)` +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man3/makedev.3.html +#[inline] +pub fn makedev(maj: u32, min: u32) -> Dev { + imp::fs::makedev::makedev(maj, min) +} + +/// `minor(dev)` +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man3/minor.3.html +#[inline] +pub fn minor(dev: Dev) -> u32 { + imp::fs::makedev::minor(dev) +} + +/// `major(dev)` +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man3/major.3.html +#[inline] +pub fn major(dev: Dev) -> u32 { + imp::fs::makedev::major(dev) +} diff --git a/vendor/rustix/src/fs/memfd_create.rs b/vendor/rustix/src/fs/memfd_create.rs new file mode 100644 index 000000000..74b432739 --- /dev/null +++ b/vendor/rustix/src/fs/memfd_create.rs @@ -0,0 +1,15 @@ +use crate::io::{self, OwnedFd}; +use crate::{imp, path}; + +pub use imp::fs::types::MemfdFlags; + +/// `memfd_create(path, flags)` +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/memfd_create.2.html +#[inline] +pub fn memfd_create<P: path::Arg>(path: P, flags: MemfdFlags) -> io::Result<OwnedFd> { + path.into_with_c_str(|path| imp::fs::syscalls::memfd_create(path, flags)) +} diff --git a/vendor/rustix/src/fs/mod.rs b/vendor/rustix/src/fs/mod.rs new file mode 100644 index 000000000..49b9c3b51 --- /dev/null +++ b/vendor/rustix/src/fs/mod.rs @@ -0,0 +1,196 @@ +//! Filesystem operations. + +#[cfg(feature = "fs")] +mod abs; +#[cfg(not(target_os = "redox"))] +#[cfg(any(feature = "fs", feature = "procfs"))] +mod at; +mod constants; +#[cfg(any(target_os = "android", target_os = "linux"))] +mod copy_file_range; +#[cfg(not(target_os = "redox"))] +mod cwd; +#[cfg(not(target_os = "redox"))] +#[cfg(any(feature = "fs", feature = "procfs"))] +mod dir; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +mod fadvise; +pub(crate) mod fcntl; +#[cfg(any(target_os = "ios", target_os = "macos"))] +mod fcntl_darwin; +#[cfg(any(target_os = "ios", target_os = "macos"))] +mod fcopyfile; +pub(crate) mod fd; +mod file_type; +#[cfg(any(target_os = "ios", target_os = "macos"))] +mod getpath; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", + target_os = "wasi", +)))] +mod makedev; +#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))] +mod memfd_create; +#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(feature = "fs")] +mod openat2; +#[cfg(target_os = "linux")] +mod sendfile; +#[cfg(any(target_os = "android", target_os = "linux"))] +mod statx; + +#[cfg(not(any( + target_os = "illumos", + target_os = "netbsd", + target_os = "redox", + target_os = "wasi", +)))] +#[cfg(feature = "fs")] +pub use abs::statfs; +#[cfg(not(any(target_os = "illumos", target_os = "redox")))] +#[cfg(feature = "fs")] +pub use at::accessat; +#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(feature = "fs")] +pub use at::fclonefileat; +#[cfg(not(any( + target_os = "ios", + target_os = "macos", + target_os = "redox", + target_os = "wasi", +)))] +#[cfg(feature = "fs")] +pub use at::mknodat; +#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(feature = "fs")] +pub use at::renameat_with; +#[cfg(not(any(target_os = "redox", target_os = "wasi")))] +#[cfg(feature = "fs")] +pub use at::{chmodat, chownat}; +#[cfg(not(target_os = "redox"))] +#[cfg(any(feature = "fs", feature = "procfs"))] +pub use at::{ + linkat, mkdirat, openat, readlinkat, renameat, statat, symlinkat, unlinkat, utimensat, RawMode, + UTIME_NOW, UTIME_OMIT, +}; +#[cfg(any(target_os = "ios", target_os = "macos"))] +pub use constants::CloneFlags; +/// `copyfile_flags_t` +#[cfg(any(target_os = "ios", target_os = "macos"))] +pub use constants::CopyfileFlags; +#[cfg(any(target_os = "android", target_os = "linux"))] +pub use constants::RenameFlags; +#[cfg(any(target_os = "android", target_os = "linux"))] +pub use constants::ResolveFlags; +pub use constants::{Access, FdFlags, Mode, Nsecs, OFlags, Secs, Timespec}; +#[cfg(not(target_os = "redox"))] +pub use constants::{AtFlags, Dev}; +#[cfg(any(target_os = "android", target_os = "linux"))] +pub use copy_file_range::copy_file_range; +#[cfg(not(target_os = "redox"))] +pub use cwd::cwd; +#[cfg(not(target_os = "redox"))] +#[cfg(any(feature = "fs", feature = "procfs"))] +pub use dir::{Dir, DirEntry}; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use fadvise::{fadvise, Advice}; +#[cfg(not(target_os = "wasi"))] +pub use fcntl::fcntl_dupfd_cloexec; +#[cfg(any( + target_os = "android", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "linux", +))] +pub use fcntl::{fcntl_add_seals, fcntl_get_seals, SealFlags}; +pub use fcntl::{fcntl_getfd, fcntl_getfl, fcntl_setfd, fcntl_setfl}; +#[cfg(any(target_os = "ios", target_os = "macos"))] +pub use fcntl_darwin::{fcntl_fullfsync, fcntl_rdadvise}; +#[cfg(any(target_os = "ios", target_os = "macos"))] +pub use fcopyfile::{ + copyfile_state_alloc, copyfile_state_free, copyfile_state_get, copyfile_state_get_copied, + copyfile_state_t, fcopyfile, +}; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "ios", + target_os = "macos", + target_os = "redox", +)))] +pub use fd::fdatasync; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "illumos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", +)))] +pub use fd::{fallocate, FallocateFlags}; +#[cfg(not(target_os = "wasi"))] +pub use fd::{fchmod, fchown, flock, FlockOperation}; +pub use fd::{fstat, fsync, ftruncate, futimens, is_file_read_write, seek, tell, Stat, Timestamps}; +#[cfg(not(any( + target_os = "illumos", + target_os = "netbsd", + target_os = "redox", + target_os = "wasi", +)))] +// not implemented in libc for netbsd yet +pub use fd::{fstatfs, StatFs}; +#[cfg(any(target_os = "android", target_os = "linux"))] +pub use fd::{FsWord, NFS_SUPER_MAGIC, PROC_SUPER_MAGIC}; +pub use file_type::FileType; +#[cfg(any(target_os = "ios", target_os = "macos"))] +pub use getpath::getpath; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", + target_os = "wasi", +)))] +pub use makedev::{major, makedev, minor}; +#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))] +pub use memfd_create::{memfd_create, MemfdFlags}; +#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(feature = "fs")] +pub use openat2::openat2; +#[cfg(target_os = "linux")] +pub use sendfile::sendfile; +#[cfg(any(target_os = "android", target_os = "linux"))] +pub use statx::{statx, Statx, StatxFlags, StatxTimestamp}; + +/// Re-export types common to POSIX-ish platforms. +#[cfg(feature = "std")] +#[cfg(unix)] +pub use std::os::unix::fs::{DirEntryExt, FileExt, FileTypeExt, MetadataExt, OpenOptionsExt}; +#[cfg(feature = "std")] +#[cfg(target_os = "wasi")] +pub use std::os::wasi::fs::{DirEntryExt, FileExt, FileTypeExt, MetadataExt, OpenOptionsExt}; diff --git a/vendor/rustix/src/fs/openat2.rs b/vendor/rustix/src/fs/openat2.rs new file mode 100644 index 000000000..d6f77357b --- /dev/null +++ b/vendor/rustix/src/fs/openat2.rs @@ -0,0 +1,23 @@ +use crate::io::{self, OwnedFd}; +use crate::{imp, path}; +use imp::fd::AsFd; +use imp::fs::types::{Mode, OFlags, ResolveFlags}; + +/// `openat2(dirfd, path, OpenHow { oflags, mode, resolve }, sizeof(OpenHow))` +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/openat2.2.html +#[inline] +pub fn openat2<Fd: AsFd, P: path::Arg>( + dirfd: Fd, + path: P, + oflags: OFlags, + mode: Mode, + resolve: ResolveFlags, +) -> io::Result<OwnedFd> { + path.into_with_c_str(|path| { + imp::fs::syscalls::openat2(dirfd.as_fd(), path, oflags, mode, resolve) + }) +} diff --git a/vendor/rustix/src/fs/sendfile.rs b/vendor/rustix/src/fs/sendfile.rs new file mode 100644 index 000000000..a4d8c24d4 --- /dev/null +++ b/vendor/rustix/src/fs/sendfile.rs @@ -0,0 +1,19 @@ +use crate::{imp, io}; +use imp::fd::AsFd; + +/// `sendfile(out_fd, in_fd, offset, count)` +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/sendfile.2.html +#[cfg(any(target_os = "android", target_os = "linux"))] +#[inline] +pub fn sendfile<OutFd: AsFd, InFd: AsFd>( + out_fd: OutFd, + in_fd: InFd, + offset: Option<&mut u64>, + count: usize, +) -> io::Result<usize> { + imp::fs::syscalls::sendfile(out_fd.as_fd(), in_fd.as_fd(), offset, count) +} diff --git a/vendor/rustix/src/fs/statx.rs b/vendor/rustix/src/fs/statx.rs new file mode 100644 index 000000000..fa1d36779 --- /dev/null +++ b/vendor/rustix/src/fs/statx.rs @@ -0,0 +1,91 @@ +//! Linux `statx`. + +use crate::fd::{AsFd, BorrowedFd}; +use crate::ffi::CStr; +use crate::fs::AtFlags; +use crate::{imp, io, path}; +use core::sync::atomic::{AtomicU8, Ordering}; + +pub use imp::fs::types::{Statx, StatxFlags, StatxTimestamp}; + +/// `statx(dirfd, path, flags, mask, statxbuf)` +/// +/// This function returns [`io::Errno::NOSYS`] if `statx` is not available on +/// the platform, such as Linux before 4.11. This also includes older Docker +/// versions where the actual syscall fails with different error codes; Rustix +/// handles this and translates them into `NOSYS`. +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/statx.2.html +#[inline] +pub fn statx<P: path::Arg, Fd: AsFd>( + dirfd: Fd, + path: P, + flags: AtFlags, + mask: StatxFlags, +) -> io::Result<Statx> { + path.into_with_c_str(|path| _statx(dirfd.as_fd(), path, flags, mask)) +} + +// Linux kernel prior to 4.11 old versions of Docker don't support `statx`. We +// store the availability in a global to avoid unnecessary syscalls. +// +// 0: Unknown +// 1: Not available +// 2: Available +static STATX_STATE: AtomicU8 = AtomicU8::new(0); + +#[inline] +fn _statx( + dirfd: BorrowedFd<'_>, + path: &CStr, + flags: AtFlags, + mask: StatxFlags, +) -> io::Result<Statx> { + match STATX_STATE.load(Ordering::Relaxed) { + 0 => statx_init(dirfd, path, flags, mask), + 1 => Err(io::Errno::NOSYS), + _ => imp::fs::syscalls::statx(dirfd, path, flags, mask), + } +} + +/// The first `statx` call. We don't know if `statx` is available yet. +fn statx_init( + dirfd: BorrowedFd<'_>, + path: &CStr, + flags: AtFlags, + mask: StatxFlags, +) -> io::Result<Statx> { + match imp::fs::syscalls::statx(dirfd, path, flags, mask) { + Err(io::Errno::NOSYS) => statx_error_nosys(), + Err(io::Errno::PERM) => statx_error_perm(), + result => { + STATX_STATE.store(2, Ordering::Relaxed); + result + } + } +} + +/// The first `statx` call failed with `NOSYS` (or something we're treating +/// like `NOSYS`). +#[cold] +fn statx_error_nosys() -> io::Result<Statx> { + STATX_STATE.store(1, Ordering::Relaxed); + Err(io::Errno::NOSYS) +} + +/// The first `statx` call failed with `PERM`. +#[cold] +fn statx_error_perm() -> io::Result<Statx> { + // Some old versions of Docker have `statx` fail with `PERM` when it isn't + // recognized. Check whether `statx` really is available, and if so, fail + // with `PERM`, and if not, treat it like `NOSYS`. + if imp::fs::syscalls::is_statx_available() { + STATX_STATE.store(2, Ordering::Relaxed); + Err(io::Errno::PERM) + } else { + statx_error_nosys() + } +} |