diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
commit | dc0db358abe19481e475e10c32149b53370f1a1c (patch) | |
tree | ab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/rustix/src/fs | |
parent | Releasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip |
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustix/src/fs')
-rw-r--r-- | vendor/rustix/src/fs/abs.rs | 214 | ||||
-rw-r--r-- | vendor/rustix/src/fs/at.rs | 88 | ||||
-rw-r--r-- | vendor/rustix/src/fs/constants.rs | 4 | ||||
-rw-r--r-- | vendor/rustix/src/fs/cwd.rs | 21 | ||||
-rw-r--r-- | vendor/rustix/src/fs/fcntl.rs | 21 | ||||
-rw-r--r-- | vendor/rustix/src/fs/fd.rs | 35 | ||||
-rw-r--r-- | vendor/rustix/src/fs/id.rs | 1 | ||||
-rw-r--r-- | vendor/rustix/src/fs/ioctl.rs | 50 | ||||
-rw-r--r-- | vendor/rustix/src/fs/makedev.rs | 2 | ||||
-rw-r--r-- | vendor/rustix/src/fs/mod.rs | 48 | ||||
-rw-r--r-- | vendor/rustix/src/fs/raw_dir.rs | 38 | ||||
-rw-r--r-- | vendor/rustix/src/fs/seek_from.rs | 48 | ||||
-rw-r--r-- | vendor/rustix/src/fs/sendfile.rs | 2 | ||||
-rw-r--r-- | vendor/rustix/src/fs/statx.rs | 10 | ||||
-rw-r--r-- | vendor/rustix/src/fs/xattr.rs | 2 |
15 files changed, 454 insertions, 130 deletions
diff --git a/vendor/rustix/src/fs/abs.rs b/vendor/rustix/src/fs/abs.rs index 314895006..83531a4e7 100644 --- a/vendor/rustix/src/fs/abs.rs +++ b/vendor/rustix/src/fs/abs.rs @@ -1,5 +1,7 @@ //! POSIX-style filesystem functions which operate on bare paths. +use crate::fd::OwnedFd; +use crate::ffi::{CStr, CString}; #[cfg(not(any( solarish, target_os = "haiku", @@ -9,10 +11,214 @@ )))] use crate::fs::StatFs; #[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))] -use { - crate::fs::StatVfs, - crate::{backend, io, path}, -}; +use crate::fs::StatVfs; +use crate::fs::{Access, Mode, OFlags, Stat}; +use crate::path::SMALL_PATH_BUFFER_SIZE; +use crate::{backend, io, path}; +use alloc::vec::Vec; + +/// `open(path, oflags, mode)`—Opens a file. +/// +/// POSIX guarantees that `open` 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/open.html +/// [Linux]: https://man7.org/linux/man-pages/man2/open.2.html +#[inline] +pub fn open<P: path::Arg>(path: P, flags: OFlags, mode: Mode) -> io::Result<OwnedFd> { + path.into_with_c_str(|path| backend::fs::syscalls::open(path, flags, mode)) +} + +/// `chmod(path, mode)`—Sets file or directory permissions. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/chmod.html +/// [Linux]: https://man7.org/linux/man-pages/man2/chmod.2.html +#[cfg(not(target_os = "wasi"))] +#[inline] +pub fn chmod<P: path::Arg>(path: P, mode: Mode) -> io::Result<()> { + path.into_with_c_str(|path| backend::fs::syscalls::chmod(path, mode)) +} + +/// `stat(path)`—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/stat.html +/// [Linux]: https://man7.org/linux/man-pages/man2/stat.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 stat<P: path::Arg>(path: P) -> io::Result<Stat> { + path.into_with_c_str(backend::fs::syscalls::stat) +} + +/// `lstat(path)`—Queries metadata for a file or directory, without following +/// symlinks. +/// +/// [`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/lstat.html +/// [Linux]: https://man7.org/linux/man-pages/man2/lstat.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 lstat<P: path::Arg>(path: P) -> io::Result<Stat> { + path.into_with_c_str(backend::fs::syscalls::lstat) +} + +/// `readlink(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/readlink.html +/// [Linux]: https://man7.org/linux/man-pages/man2/readlink.2.html +#[inline] +pub fn readlink<P: path::Arg, B: Into<Vec<u8>>>(path: P, reuse: B) -> io::Result<CString> { + path.into_with_c_str(|path| _readlink(path, reuse.into())) +} + +fn _readlink(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 = backend::fs::syscalls::readlink(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); + } +} + +/// `rename(old_path, new_path)`—Renames a file or directory. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/rename.html +/// [Linux]: https://man7.org/linux/man-pages/man2/rename.2.html +#[inline] +pub fn rename<P: path::Arg, Q: path::Arg>(old_path: P, new_path: Q) -> io::Result<()> { + old_path.into_with_c_str(|old_path| { + new_path.into_with_c_str(|new_path| backend::fs::syscalls::rename(old_path, new_path)) + }) +} + +/// `unlink(path)`—Unlinks a file. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/unlink.html +/// [Linux]: https://man7.org/linux/man-pages/man2/unlink.2.html +#[inline] +pub fn unlink<P: path::Arg>(path: P) -> io::Result<()> { + path.into_with_c_str(backend::fs::syscalls::unlink) +} + +/// `rmdir(path)`—Removes a directory. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/rmdir.html +/// [Linux]: https://man7.org/linux/man-pages/man2/rmdir.2.html +#[inline] +pub fn rmdir<P: path::Arg>(path: P) -> io::Result<()> { + path.into_with_c_str(backend::fs::syscalls::rmdir) +} + +/// `link(old_path, new_path)`—Creates a hard link. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html +/// [Linux]: https://man7.org/linux/man-pages/man2/link.2.html +#[inline] +pub fn link<P: path::Arg, Q: path::Arg>(old_path: P, new_path: Q) -> io::Result<()> { + old_path.into_with_c_str(|old_path| { + new_path.into_with_c_str(|new_path| backend::fs::syscalls::link(old_path, new_path)) + }) +} + +/// `symlink(old_path, new_path)`—Creates a symlink. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/symlink.html +/// [Linux]: https://man7.org/linux/man-pages/man2/symlink.2.html +#[inline] +pub fn symlink<P: path::Arg, Q: path::Arg>(old_path: P, new_path: Q) -> io::Result<()> { + old_path.into_with_c_str(|old_path| { + new_path.into_with_c_str(|new_path| backend::fs::syscalls::symlink(old_path, new_path)) + }) +} + +/// `mkdir(path, mode)`—Creates a directory. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/mkdir.html +/// [Linux]: https://man7.org/linux/man-pages/man2/mkdir.2.html +#[inline] +pub fn mkdir<P: path::Arg>(path: P, mode: Mode) -> io::Result<()> { + path.into_with_c_str(|path| backend::fs::syscalls::mkdir(path, mode)) +} + +/// `access(path, access)`—Tests permissions for a file or directory. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/access.html +/// [Linux]: https://man7.org/linux/man-pages/man2/access.2.html +#[inline] +pub fn access<P: path::Arg>(path: P, access: Access) -> io::Result<()> { + path.into_with_c_str(|path| backend::fs::syscalls::access(path, access)) +} /// `statfs`—Queries filesystem metadata. /// diff --git a/vendor/rustix/src/fs/at.rs b/vendor/rustix/src/fs/at.rs index 2314cf763..0c99cc30a 100644 --- a/vendor/rustix/src/fs/at.rs +++ b/vendor/rustix/src/fs/at.rs @@ -1,9 +1,9 @@ //! 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`]. +//! directory, or the special value [`CWD`]. //! -//! [`cwd`]: crate::fs::cwd +//! [`cwd`]: crate::fs::cwd::CWD use crate::fd::OwnedFd; use crate::ffi::{CStr, CString}; @@ -11,16 +11,16 @@ use crate::ffi::{CStr, CString}; use crate::fs::CloneFlags; #[cfg(not(any(apple, target_os = "wasi")))] use crate::fs::FileType; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] use crate::fs::RenameFlags; use crate::fs::{Access, AtFlags, Mode, OFlags, Stat, Timestamps}; -use crate::path::SMALL_PATH_BUFFER_SIZE; #[cfg(not(target_os = "wasi"))] -use crate::process::{Gid, Uid}; +use crate::fs::{Gid, Uid}; +use crate::path::SMALL_PATH_BUFFER_SIZE; +use crate::timespec::Nsecs; use crate::{backend, io, path}; use alloc::vec::Vec; use backend::fd::{AsFd, BorrowedFd}; -use backend::time::types::Nsecs; pub use backend::fs::types::{Dev, RawMode}; @@ -49,7 +49,7 @@ pub const UTIME_OMIT: Nsecs = backend::c::UTIME_OMIT as Nsecs; /// - [Linux] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/openat.html -/// [Linux]: https://man7.org/linux/man-pages/man2/open.2.html +/// [Linux]: https://man7.org/linux/man-pages/man2/openat.2.html #[inline] pub fn openat<P: path::Arg, Fd: AsFd>( dirfd: Fd, @@ -64,7 +64,7 @@ pub fn openat<P: path::Arg, Fd: AsFd>( /// `readlinkat(fd, path)`—Reads the contents of a symlink. /// -/// If `reuse` is non-empty, reuse its buffer to store the result if possible. +/// If `reuse` already has available capacity, reuse it if possible. /// /// # References /// - [POSIX] @@ -81,24 +81,44 @@ pub fn readlinkat<P: path::Arg, Fd: AsFd, B: Into<Vec<u8>>>( path.into_with_c_str(|path| _readlinkat(dirfd.as_fd(), path, reuse.into())) } +#[allow(unsafe_code)] 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 = backend::fs::syscalls::readlinkat(dirfd.as_fd(), path, &mut buffer)?; + let nread = + backend::fs::syscalls::readlinkat(dirfd.as_fd(), path, buffer.spare_capacity_mut())?; + + debug_assert!(nread <= buffer.capacity()); + if nread < buffer.capacity() { + // SAFETY from the man page: + // "On success, these calls return the number of bytes placed in buf." + unsafe { + buffer.set_len(nread); + } - let nread = nread as usize; - assert!(nread <= buffer.len()); - if nread < buffer.len() { - buffer.resize(nread, 0_u8); - return Ok(CString::new(buffer).unwrap()); + // SAFETY: + // - "readlink places the contents of the symbolic link pathname in the buffer + // buf" + // - [POSIX definition 3.271: Pathname]: "A string that is used to identify a + // file." + // - [POSIX definition 3.375: String]: "A contiguous sequence of bytes + // terminated by and including the first null byte." + // - "readlink does not append a terminating null byte to buf." + // + // Thus, there will be no NUL bytes in the string. + // + // [POSIX definition 3.271: Pathname]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_271 + // [POSIX definition 3.375: String]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_375 + unsafe { + return Ok(CString::from_vec_unchecked(buffer)); + } } - buffer.reserve(1); // use `Vec` reallocation strategy to grow capacity exponentially - buffer.resize(buffer.capacity(), 0_u8); + + buffer.reserve(buffer.capacity() + 1); // use `Vec` reallocation + // strategy to grow capacity + // exponentially } } @@ -197,7 +217,7 @@ pub fn renameat<P: path::Arg, Q: path::Arg, PFd: AsFd, QFd: AsFd>( /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man2/renameat2.2.html -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] #[inline] #[doc(alias = "renameat2")] pub fn renameat_with<P: path::Arg, Q: path::Arg, PFd: AsFd, QFd: AsFd>( @@ -263,6 +283,13 @@ pub fn statat<P: path::Arg, Fd: AsFd>(dirfd: Fd, path: P, flags: AtFlags) -> io: /// `faccessat(dirfd, path, access, flags)`—Tests permissions for a file or /// directory. /// +/// On Linux before 5.8, this function uses the `faccessat` system call which +/// doesn't support any flags. This function emulates support for the +/// [`AtFlags::EACCESS`] flag by checking whether the uid and gid of the +/// process match the effective uid and gid, in which case the `EACCESS` flag +/// can be ignored. In Linux 5.8 and beyond `faccessat2` is used, which +/// supports flags. +/// /// # References /// - [POSIX] /// - [Linux] @@ -298,23 +325,6 @@ pub fn utimensat<P: path::Arg, Fd: AsFd>( path.into_with_c_str(|path| backend::fs::syscalls::utimensat(dirfd.as_fd(), path, times, flags)) } -/// `fchmodat(dirfd, path, mode, 0)`—Sets file or directory permissions. -/// -/// See `fchmodat_with` for a version that does take flags. -/// -/// # 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<()> { - chmodat_with(dirfd, path, mode, AtFlags::empty()) -} - /// `fchmodat(dirfd, path, mode, flags)`—Sets file or directory permissions. /// /// Platform support for flags varies widely, for example on Linux @@ -329,8 +339,8 @@ pub fn chmodat<P: path::Arg, Fd: AsFd>(dirfd: Fd, path: P, mode: Mode) -> io::Re /// [Linux]: https://man7.org/linux/man-pages/man2/fchmodat.2.html #[cfg(not(target_os = "wasi"))] #[inline] -#[doc(alias = "fchmodat_with")] -pub fn chmodat_with<P: path::Arg, Fd: AsFd>( +#[doc(alias = "fchmodat")] +pub fn chmodat<P: path::Arg, Fd: AsFd>( dirfd: Fd, path: P, mode: Mode, diff --git a/vendor/rustix/src/fs/constants.rs b/vendor/rustix/src/fs/constants.rs index 3ccc383bb..ef677aa49 100644 --- a/vendor/rustix/src/fs/constants.rs +++ b/vendor/rustix/src/fs/constants.rs @@ -11,7 +11,7 @@ pub use backend::fs::types::AtFlags; #[cfg(apple)] pub use backend::fs::types::{CloneFlags, CopyfileFlags}; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] pub use backend::fs::types::*; -pub use backend::time::types::{Nsecs, Secs, Timespec}; +pub use crate::timespec::{Nsecs, Secs, Timespec}; diff --git a/vendor/rustix/src/fs/cwd.rs b/vendor/rustix/src/fs/cwd.rs index 0abd75df6..2745060a1 100644 --- a/vendor/rustix/src/fs/cwd.rs +++ b/vendor/rustix/src/fs/cwd.rs @@ -8,23 +8,32 @@ #![allow(unsafe_code)] use crate::backend; +use backend::c; use backend::fd::{BorrowedFd, RawFd}; -/// `AT_FDCWD`—Returns a handle representing the current working directory. +/// `AT_FDCWD`—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`]. +/// This is 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] +// SAFETY: `AT_FDCWD` is a reserved value that is never dynamically +// allocated, so it'll remain valid for the duration of `'static`. #[doc(alias = "AT_FDCWD")] +#[cfg(not(target_os = "haiku"))] // Haiku needs <https://github.com/rust-lang/rust/pull/112371> +pub const CWD: BorrowedFd<'static> = + unsafe { BorrowedFd::<'static>::borrow_raw(c::AT_FDCWD as RawFd) }; + +/// Return the value of [`CWD`]. +#[deprecated(note = "Use `CWD` in place of `cwd()`.")] +#[cfg(not(target_os = "haiku"))] // Haiku needs <https://github.com/rust-lang/rust/pull/112371> pub const fn cwd() -> BorrowedFd<'static> { - let at_fdcwd = backend::io::types::AT_FDCWD as RawFd; + let at_fdcwd = c::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`. diff --git a/vendor/rustix/src/fs/fcntl.rs b/vendor/rustix/src/fs/fcntl.rs index 0f557ef7f..91816aaa2 100644 --- a/vendor/rustix/src/fs/fcntl.rs +++ b/vendor/rustix/src/fs/fcntl.rs @@ -55,24 +55,14 @@ pub fn fcntl_setfl<Fd: AsFd>(fd: Fd, flags: OFlags) -> io::Result<()> { /// - [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", -))] +#[cfg(any(linux_kernel, target_os = "freebsd", target_os = "fuchsia"))] #[inline] #[doc(alias = "F_GET_SEALS")] pub fn fcntl_get_seals<Fd: AsFd>(fd: Fd) -> io::Result<SealFlags> { backend::fs::syscalls::fcntl_get_seals(fd.as_fd()) } -#[cfg(any( - target_os = "android", - target_os = "freebsd", - target_os = "fuchsia", - target_os = "linux", -))] +#[cfg(any(linux_kernel, target_os = "freebsd", target_os = "fuchsia"))] pub use backend::fs::types::SealFlags; /// `fcntl(fd, F_ADD_SEALS)` @@ -81,12 +71,7 @@ pub use backend::fs::types::SealFlags; /// - [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", -))] +#[cfg(any(linux_kernel, target_os = "freebsd", target_os = "fuchsia"))] #[inline] #[doc(alias = "F_ADD_SEALS")] pub fn fcntl_add_seals<Fd: AsFd>(fd: Fd, seals: SealFlags) -> io::Result<()> { diff --git a/vendor/rustix/src/fs/fd.rs b/vendor/rustix/src/fs/fd.rs index 81e56d909..d0d50073e 100644 --- a/vendor/rustix/src/fs/fd.rs +++ b/vendor/rustix/src/fs/fd.rs @@ -2,9 +2,9 @@ #[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::fs::{Gid, Uid}; +use crate::fs::{OFlags, SeekFrom, Timespec}; use crate::{backend, io}; use backend::fd::{AsFd, BorrowedFd}; @@ -34,7 +34,7 @@ pub use backend::fs::types::StatFs; #[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))] pub use backend::fs::types::{StatVfs, StatVfsMountFlags}; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] pub use backend::fs::types::FsWord; /// Timestamps used by [`utimensat`] and [`futimens`]. @@ -47,10 +47,10 @@ pub use backend::fs::types::FsWord; #[derive(Clone, Debug)] pub struct Timestamps { /// The timestamp of the last access to a filesystem object. - pub last_access: crate::fs::Timespec, + pub last_access: Timespec, /// The timestamp of the last modification of a filesystem object. - pub last_modification: crate::fs::Timespec, + pub last_modification: Timespec, } /// The filesystem magic number for procfs. @@ -58,7 +58,7 @@ pub struct Timestamps { /// See [the `fstatfs` manual page] for more information. /// /// [the `fstatfs` manual page]: https://man7.org/linux/man-pages/man2/fstatfs.2.html#DESCRIPTION -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] pub const PROC_SUPER_MAGIC: FsWord = backend::c::PROC_SUPER_MAGIC as FsWord; /// The filesystem magic number for NFS. @@ -66,7 +66,7 @@ pub const PROC_SUPER_MAGIC: FsWord = backend::c::PROC_SUPER_MAGIC as FsWord; /// See [the `fstatfs` manual page] for more information. /// /// [the `fstatfs` manual page]: https://man7.org/linux/man-pages/man2/fstatfs.2.html#DESCRIPTION -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] pub const NFS_SUPER_MAGIC: FsWord = backend::c::NFS_SUPER_MAGIC as FsWord; /// `lseek(fd, offset, whence)`—Repositions a file descriptor within a file. @@ -143,7 +143,7 @@ pub fn fchown<Fd: AsFd>(fd: Fd, owner: Option<Uid>, group: Option<Gid>) -> io::R /// /// [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 +/// [`Mode::from_raw_mode`]: 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> { @@ -247,22 +247,17 @@ pub(crate) fn _is_file_read_write(fd: BorrowedFd<'_>) -> io::Result<(bool, bool) let mode = backend::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) { + #[cfg(any(linux_kernel, target_os = "fuchsia", target_os = "emscripten"))] + if mode.contains(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)), + match mode & OFlags::RWMODE { + OFlags::RDONLY => Ok((true, false)), + OFlags::RDWR => Ok((true, true)), + OFlags::WRONLY => Ok((false, true)), _ => unreachable!(), } } @@ -336,7 +331,7 @@ pub fn flock<Fd: AsFd>(fd: Fd, operation: FlockOperation) -> io::Result<()> { /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man2/syncfs.2.html -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] #[inline] pub fn syncfs<Fd: AsFd>(fd: Fd) -> io::Result<()> { backend::fs::syscalls::syncfs(fd.as_fd()) diff --git a/vendor/rustix/src/fs/id.rs b/vendor/rustix/src/fs/id.rs new file mode 100644 index 000000000..1fc2ef81f --- /dev/null +++ b/vendor/rustix/src/fs/id.rs @@ -0,0 +1 @@ +pub use crate::ugid::{Gid, Uid}; diff --git a/vendor/rustix/src/fs/ioctl.rs b/vendor/rustix/src/fs/ioctl.rs new file mode 100644 index 000000000..28e0c8588 --- /dev/null +++ b/vendor/rustix/src/fs/ioctl.rs @@ -0,0 +1,50 @@ +//! Filesystem-oriented `ioctl` functions. + +#[cfg(linux_kernel)] +use { + crate::fd::AsFd, + crate::{backend, io}, +}; + +/// `ioctl(fd, BLKSSZGET)`—Returns the logical block size of a block device. +/// +/// This is mentioned in the [Linux `openat` manual page]. +/// +/// [Linux `openat` manual page]: https://man7.org/linux/man-pages/man2/openat.2.html +#[cfg(linux_kernel)] +#[inline] +#[doc(alias = "BLKSSZGET")] +pub fn ioctl_blksszget<Fd: AsFd>(fd: Fd) -> io::Result<u32> { + backend::fs::syscalls::ioctl_blksszget(fd.as_fd()) +} + +/// `ioctl(fd, BLKPBSZGET)`—Returns the physical block size of a block device. +#[cfg(linux_kernel)] +#[inline] +#[doc(alias = "BLKPBSZGET")] +pub fn ioctl_blkpbszget<Fd: AsFd>(fd: Fd) -> io::Result<u32> { + backend::fs::syscalls::ioctl_blkpbszget(fd.as_fd()) +} + +/// `ioctl(fd, FICLONE, src_fd)`—Share data between open files. +/// +/// This ioctl is not available on Sparc platforms +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/ioctl_ficlone.2.html +#[cfg(all(linux_kernel, not(any(target_arch = "sparc", target_arch = "sparc64"))))] +#[inline] +#[doc(alias = "FICLONE")] +pub fn ioctl_ficlone<Fd: AsFd, SrcFd: AsFd>(fd: Fd, src_fd: SrcFd) -> io::Result<()> { + backend::fs::syscalls::ioctl_ficlone(fd.as_fd(), src_fd.as_fd()) +} + +/// `ioctl(fd, EXT4_IOC_RESIZE_FS, blocks)`—Resize ext4 filesystem on fd. +#[cfg(linux_kernel)] +#[inline] +#[doc(alias = "EXT4_IOC_RESIZE_FS")] +pub fn ext4_ioc_resize_fs<Fd: AsFd>(fd: Fd, blocks: u64) -> io::Result<()> { + backend::fs::syscalls::ext4_ioc_resize_fs(fd.as_fd(), blocks) +} diff --git a/vendor/rustix/src/fs/makedev.rs b/vendor/rustix/src/fs/makedev.rs index 36aef6d66..5793058ff 100644 --- a/vendor/rustix/src/fs/makedev.rs +++ b/vendor/rustix/src/fs/makedev.rs @@ -18,7 +18,6 @@ pub fn makedev(maj: u32, min: u32) -> Dev { /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man3/minor.3.html -#[cfg(not(bsd))] #[inline] pub fn minor(dev: Dev) -> u32 { backend::fs::makedev::minor(dev) @@ -30,7 +29,6 @@ pub fn minor(dev: Dev) -> u32 { /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man3/major.3.html -#[cfg(not(bsd))] #[inline] pub fn major(dev: Dev) -> u32 { backend::fs::makedev::major(dev) diff --git a/vendor/rustix/src/fs/mod.rs b/vendor/rustix/src/fs/mod.rs index e28ddab6f..fc2c3368b 100644 --- a/vendor/rustix/src/fs/mod.rs +++ b/vendor/rustix/src/fs/mod.rs @@ -4,7 +4,7 @@ mod abs; #[cfg(not(target_os = "redox"))] mod at; mod constants; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] mod copy_file_range; #[cfg(not(target_os = "redox"))] mod cwd; @@ -28,41 +28,46 @@ pub(crate) mod fd; mod file_type; #[cfg(apple)] mod getpath; -#[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))] +#[cfg(not(target_os = "wasi"))] // WASI doesn't have get[gpu]id. +mod id; +#[cfg(not(target_os = "wasi"))] +mod ioctl; +#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))] mod makedev; -#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))] +#[cfg(any(linux_kernel, target_os = "freebsd"))] mod memfd_create; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] mod mount; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] mod openat2; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] mod raw_dir; +mod seek_from; #[cfg(target_os = "linux")] mod sendfile; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] mod statx; #[cfg(not(any(target_os = "redox", target_os = "wasi")))] mod sync; -#[cfg(any(apple, target_os = "android", target_os = "linux"))] +#[cfg(any(apple, linux_kernel))] mod xattr; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] pub use crate::backend::fs::inotify; pub use abs::*; #[cfg(not(target_os = "redox"))] pub use at::*; pub use constants::*; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] pub use copy_file_range::copy_file_range; #[cfg(not(target_os = "redox"))] -pub use cwd::cwd; +pub use cwd::*; #[cfg(not(target_os = "redox"))] pub use dir::{Dir, DirEntry}; #[cfg(not(any( apple, - solarish, netbsdlike, + solarish, target_os = "dragonfly", target_os = "haiku", target_os = "redox", @@ -77,23 +82,28 @@ pub use fd::*; pub use file_type::FileType; #[cfg(apple)] pub use getpath::getpath; -#[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))] +#[cfg(not(target_os = "wasi"))] +pub use id::*; +#[cfg(not(target_os = "wasi"))] +pub use ioctl::*; +#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))] pub use makedev::*; -#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))] +#[cfg(any(linux_kernel, target_os = "freebsd"))] pub use memfd_create::{memfd_create, MemfdFlags}; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] pub use mount::*; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] pub use openat2::openat2; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] pub use raw_dir::{RawDir, RawDirEntry}; +pub use seek_from::SeekFrom; #[cfg(target_os = "linux")] pub use sendfile::sendfile; -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] pub use statx::{statx, Statx, StatxFlags, StatxTimestamp}; #[cfg(not(any(target_os = "redox", target_os = "wasi")))] pub use sync::sync; -#[cfg(any(apple, target_os = "android", target_os = "linux"))] +#[cfg(any(apple, linux_kernel))] pub use xattr::*; /// Re-export types common to POSIX-ish platforms. diff --git a/vendor/rustix/src/fs/raw_dir.rs b/vendor/rustix/src/fs/raw_dir.rs index bad0bf97b..3131e0649 100644 --- a/vendor/rustix/src/fs/raw_dir.rs +++ b/vendor/rustix/src/fs/raw_dir.rs @@ -40,12 +40,17 @@ impl<'buf, Fd: AsFd> RawDir<'buf, Fd> { /// /// Using the heap: /// - /// ```notrust - /// # // The `notrust` above can be removed when we can depend on Rust 1.60. + /// ``` /// # use std::mem::MaybeUninit; - /// # use rustix::fs::{cwd, Mode, OFlags, openat, RawDir}; + /// # use rustix::fs::{CWD, Mode, OFlags, openat, RawDir}; /// - /// let fd = openat(cwd(), ".", OFlags::RDONLY | OFlags::DIRECTORY, Mode::empty()).unwrap(); + /// let fd = openat( + /// CWD, + /// ".", + /// OFlags::RDONLY | OFlags::DIRECTORY | OFlags::CLOEXEC, + /// Mode::empty(), + /// ) + /// .unwrap(); /// /// let mut buf = Vec::with_capacity(8192); /// let mut iter = RawDir::new(fd, buf.spare_capacity_mut()); @@ -59,12 +64,12 @@ impl<'buf, Fd: AsFd> RawDir<'buf, Fd> { /// /// ``` /// # use std::mem::MaybeUninit; - /// # use rustix::fs::{cwd, Mode, OFlags, openat, RawDir}; + /// # use rustix::fs::{CWD, Mode, OFlags, openat, RawDir}; /// /// let fd = openat( - /// cwd(), + /// CWD, /// ".", - /// OFlags::RDONLY | OFlags::DIRECTORY, + /// OFlags::RDONLY | OFlags::DIRECTORY | OFlags::CLOEXEC, /// Mode::empty(), /// ) /// .unwrap(); @@ -83,12 +88,18 @@ impl<'buf, Fd: AsFd> RawDir<'buf, Fd> { /// arbitrarily large file names: /// /// ```notrust - /// # // The `notrust` above can be removed when we can depend on Rust 1.60. + /// # // The `notrust` above can be removed when we can depend on Rust 1.65. /// # use std::mem::MaybeUninit; - /// # use rustix::fs::{cwd, Mode, OFlags, openat, RawDir}; + /// # use rustix::fs::{CWD, Mode, OFlags, openat, RawDir}; /// # use rustix::io::Errno; /// - /// let fd = openat(cwd(), ".", OFlags::RDONLY | OFlags::DIRECTORY, Mode::empty()).unwrap(); + /// let fd = openat( + /// CWD, + /// ".", + /// OFlags::RDONLY | OFlags::DIRECTORY | OFlags::CLOEXEC, + /// Mode::empty(), + /// ) + /// .unwrap(); /// /// let mut buf = Vec::with_capacity(8192); /// 'read: loop { @@ -127,8 +138,7 @@ impl<'buf, Fd: AsFd> RawDir<'buf, Fd> { /// A raw directory entry, similar to `std::fs::DirEntry`. /// -/// Note that unlike the std version, this may represent the `.` or `..` -/// entries. +/// Unlike the std version, this may represent the `.` or `..` entries. pub struct RawDirEntry<'a> { file_name: &'a CStr, file_type: u8, @@ -176,8 +186,8 @@ impl<'a> RawDirEntry<'a> { } impl<'buf, Fd: AsFd> RawDir<'buf, Fd> { - /// Identical to [Iterator::next] except that [Iterator::Item] borrows from - /// self. + /// Identical to [`Iterator::next`] except that [`Iterator::Item`] borrows + /// from self. /// /// Note: this interface will be broken to implement a stdlib iterator API /// with GAT support once one becomes available. diff --git a/vendor/rustix/src/fs/seek_from.rs b/vendor/rustix/src/fs/seek_from.rs new file mode 100644 index 000000000..cca23ed62 --- /dev/null +++ b/vendor/rustix/src/fs/seek_from.rs @@ -0,0 +1,48 @@ +//! The following is derived from Rust's +//! library/std/src/io/mod.rs at revision +//! dca3f1b786efd27be3b325ed1e01e247aa589c3b. + +/// Enumeration of possible methods to seek within an I/O object. +/// +/// It is used by the [`Seek`] trait. +/// +/// [`Seek`]: std::io::Seek +#[derive(Copy, PartialEq, Eq, Clone, Debug)] +#[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] +pub enum SeekFrom { + /// Sets the offset to the provided number of bytes. + #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] + Start(#[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] u64), + + /// Sets the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error + /// to seek before byte 0. + #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] + End(#[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] i64), + + /// Sets the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error + /// to seek before byte 0. + #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] + Current(#[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] i64), + + /// Sets the offset to the current position plus the specified number of bytes, + /// plus the distance to the next byte which is not in a hole. + /// + /// If the offset is in a hole at the end of the file, the seek will produce + /// an `NXIO` error. + #[cfg(any(freebsdlike, target_os = "linux", target_os = "solaris"))] + Data(i64), + + /// Sets the offset to the current position plus the specified number of bytes, + /// plus the distance to the next byte which is in a hole. + /// + /// If there is no hole past the offset, it will be set to the end of the file + /// i.e. there is an implicit hole at the end of any file. + #[cfg(any(freebsdlike, target_os = "linux", target_os = "solaris"))] + Hole(i64), +} diff --git a/vendor/rustix/src/fs/sendfile.rs b/vendor/rustix/src/fs/sendfile.rs index 472ad37b2..7f5c8482d 100644 --- a/vendor/rustix/src/fs/sendfile.rs +++ b/vendor/rustix/src/fs/sendfile.rs @@ -7,7 +7,7 @@ use backend::fd::AsFd; /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man2/sendfile.2.html -#[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(linux_kernel)] #[inline] pub fn sendfile<OutFd: AsFd, InFd: AsFd>( out_fd: OutFd, diff --git a/vendor/rustix/src/fs/statx.rs b/vendor/rustix/src/fs/statx.rs index 121f9270a..32ae84ed3 100644 --- a/vendor/rustix/src/fs/statx.rs +++ b/vendor/rustix/src/fs/statx.rs @@ -42,8 +42,8 @@ mod compat { use backend::fs::types::{Statx, StatxFlags}; - // 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. + // 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 @@ -92,9 +92,9 @@ mod compat { /// 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`. + // 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 backend::fs::syscalls::is_statx_available() { STATX_STATE.store(2, Ordering::Relaxed); Err(io::Errno::PERM) diff --git a/vendor/rustix/src/fs/xattr.rs b/vendor/rustix/src/fs/xattr.rs index e50841b49..01fe7d569 100644 --- a/vendor/rustix/src/fs/xattr.rs +++ b/vendor/rustix/src/fs/xattr.rs @@ -6,6 +6,8 @@ use bitflags::bitflags; bitflags! { /// `XATTR_*` constants for use with [`setxattr`], and other `*setxattr` /// functions. + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct XattrFlags: c::c_uint { /// `XATTR_CREATE` const CREATE = c::XATTR_CREATE as c::c_uint; |