diff --git a/Cargo.toml b/Cargo.toml index 53dacf72b..55c9b49d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ rustc-std-workspace-alloc = { version = "1.0.0", optional = true } # not aliased [target.'cfg(all(not(rustix_use_libc), not(miri), target_os = "linux", any(target_endian = "little", any(target_arch = "s390x", target_arch = "powerpc")), any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc"), all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "s390x"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64"))))'.dependencies] linux-raw-sys = { version = "0.11.0", default-features = false, features = ["auxvec", "general", "errno", "ioctl", "no_std", "elf"] } libc_errno = { package = "errno", version = "0.3.10", default-features = false, optional = true } -libc = { version = "0.2.181", default-features = false, optional = true } +libc = { version = "0.2.182", default-features = false, optional = true } # Dependencies for platforms where only libc is supported: # @@ -43,7 +43,7 @@ libc = { version = "0.2.181", default-features = false, optional = true } # backend, so enable its dependencies unconditionally. [target.'cfg(all(not(windows), any(rustix_use_libc, miri, not(all(target_os = "linux", any(target_endian = "little", any(target_arch = "s390x", target_arch = "powerpc")), any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc"), all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "s390x"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64")))))))'.dependencies] libc_errno = { package = "errno", version = "0.3.10", default-features = false } -libc = { version = "0.2.181", default-features = false } +libc = { version = "0.2.182", default-features = false } # Additional dependencies for Linux and Android with the libc backend: # diff --git a/src/backend/libc/fs/syscalls.rs b/src/backend/libc/fs/syscalls.rs index 8cbd3a2c1..71bc8b0ab 100644 --- a/src/backend/libc/fs/syscalls.rs +++ b/src/backend/libc/fs/syscalls.rs @@ -33,7 +33,7 @@ use crate::fs::FallocateFlags; use crate::fs::FlockOperation; #[cfg(any(linux_kernel, target_os = "freebsd"))] use crate::fs::MemfdFlags; -#[cfg(any(linux_kernel, apple))] +#[cfg(any(linux_kernel, apple, target_os = "redox"))] use crate::fs::RenameFlags; #[cfg(any(linux_kernel, target_os = "freebsd", target_os = "fuchsia"))] use crate::fs::SealFlags; @@ -448,7 +448,6 @@ pub(crate) fn rename(old_path: &CStr, new_path: &CStr) -> io::Result<()> { unsafe { ret(c::rename(c_str(old_path), c_str(new_path))) } } -#[cfg(not(target_os = "redox"))] pub(crate) fn renameat( old_dirfd: BorrowedFd<'_>, old_path: &CStr, @@ -493,6 +492,25 @@ pub(crate) fn renameat( } } +#[cfg(target_os = "redox")] +pub(crate) fn renameat2( + old_dirfd: BorrowedFd<'_>, + old_path: &CStr, + new_dirfd: BorrowedFd<'_>, + new_path: &CStr, + flags: RenameFlags, +) -> io::Result<()> { + unsafe { + ret(c::renameat2( + borrowed_fd(old_dirfd), + c_str(old_path), + borrowed_fd(new_dirfd), + c_str(new_path), + flags.bits(), + )) + } +} + #[cfg(all(target_os = "linux", target_env = "gnu"))] pub(crate) fn renameat2( old_dirfd: BorrowedFd<'_>, diff --git a/src/backend/libc/fs/types.rs b/src/backend/libc/fs/types.rs index d570c5b28..b8944ad7c 100644 --- a/src/backend/libc/fs/types.rs +++ b/src/backend/libc/fs/types.rs @@ -508,6 +508,22 @@ bitflags! { } } +#[cfg(target_os = "redox")] +bitflags! { + /// `RENAME_*` constants for use with [`renameat_with`]. + /// + /// [`renameat_with`]: crate::fs::renameat_with + #[repr(transparent)] + #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] + pub struct RenameFlags: ffi::c_uint { + /// `RENAME_NOREPLACE` + const NOREPLACE = bitcast!(c::RENAME_NOREPLACE); + + /// + const _ = !0; + } +} + #[cfg(apple)] bitflags! { /// `RENAME_*` constants for use with [`renameat_with`]. diff --git a/src/fs/at.rs b/src/fs/at.rs index bddb53473..f35ce5aca 100644 --- a/src/fs/at.rs +++ b/src/fs/at.rs @@ -12,11 +12,11 @@ use crate::buffer::Buffer; use crate::fd::OwnedFd; #[cfg(not(any(target_os = "espidf", target_os = "horizon", target_os = "vita")))] use crate::fs::Access; -#[cfg(not(target_os = "espidf"))] +#[cfg(not(any(target_os = "espidf", target_os = "redox")))] use crate::fs::AtFlags; #[cfg(apple)] use crate::fs::CloneFlags; -#[cfg(any(linux_kernel, apple))] +#[cfg(any(linux_kernel, apple, target_os = "redox"))] use crate::fs::RenameFlags; #[cfg(not(target_os = "espidf"))] use crate::fs::Stat; @@ -73,6 +73,7 @@ pub const UTIME_OMIT: Nsecs = backend::c::UTIME_OMIT as Nsecs; /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/openat.html /// [Linux]: https://man7.org/linux/man-pages/man2/openat.2.html +#[cfg(not(target_os = "redox"))] #[inline] pub fn openat( dirfd: Fd, @@ -95,7 +96,7 @@ pub fn openat( /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/readlinkat.html /// [Linux]: https://man7.org/linux/man-pages/man2/readlinkat.2.html -#[cfg(feature = "alloc")] +#[cfg(all(feature = "alloc", not(target_os = "redox")))] #[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] #[inline] pub fn readlinkat>>( @@ -106,7 +107,7 @@ pub fn readlinkat>>( path.into_with_c_str(|path| _readlinkat(dirfd.as_fd(), path, reuse.into())) } -#[cfg(feature = "alloc")] +#[cfg(all(feature = "alloc", not(target_os = "redox")))] #[allow(unsafe_code)] fn _readlinkat(dirfd: BorrowedFd<'_>, path: &CStr, mut buffer: Vec) -> io::Result { buffer.clear(); @@ -170,6 +171,7 @@ fn _readlinkat(dirfd: BorrowedFd<'_>, path: &CStr, mut buffer: Vec) -> io::R /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/readlinkat.html /// [Linux]: https://man7.org/linux/man-pages/man2/readlinkat.2.html +#[cfg(not(target_os = "redox"))] #[inline] pub fn readlinkat_raw>( dirfd: Fd, @@ -192,6 +194,7 @@ pub fn readlinkat_raw>( /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/mkdirat.html /// [Linux]: https://man7.org/linux/man-pages/man2/mkdirat.2.html +#[cfg(not(target_os = "redox"))] #[inline] pub fn mkdirat(dirfd: Fd, path: P, mode: Mode) -> io::Result<()> { path.into_with_c_str(|path| backend::fs::syscalls::mkdirat(dirfd.as_fd(), path, mode)) @@ -206,7 +209,7 @@ pub fn mkdirat(dirfd: Fd, path: P, mode: Mode) -> io::Re /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/linkat.html /// [Linux]: https://man7.org/linux/man-pages/man2/linkat.2.html -#[cfg(not(target_os = "espidf"))] +#[cfg(not(any(target_os = "espidf", target_os = "redox")))] #[inline] pub fn linkat( old_dirfd: PFd, @@ -240,7 +243,7 @@ pub fn linkat( /// [`REMOVEDIR`]: AtFlags::REMOVEDIR /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/unlinkat.html /// [Linux]: https://man7.org/linux/man-pages/man2/unlinkat.2.html -#[cfg(not(target_os = "espidf"))] +#[cfg(not(any(target_os = "espidf", target_os = "redox")))] #[inline] pub fn unlinkat(dirfd: Fd, path: P, flags: AtFlags) -> io::Result<()> { path.into_with_c_str(|path| backend::fs::syscalls::unlinkat(dirfd.as_fd(), path, flags)) @@ -286,7 +289,7 @@ pub fn renameat( /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man2/renameat2.2.html -#[cfg(any(apple, linux_kernel))] +#[cfg(any(apple, linux_kernel, target_os = "redox"))] #[inline] #[doc(alias = "renameat2")] #[doc(alias = "renameatx_np")] @@ -318,6 +321,7 @@ pub fn renameat_with( /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/symlinkat.html /// [Linux]: https://man7.org/linux/man-pages/man2/symlinkat.2.html +#[cfg(not(target_os = "redox"))] #[inline] pub fn symlinkat( old_path: P, @@ -344,7 +348,7 @@ pub fn symlinkat( /// [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 -#[cfg(not(target_os = "espidf"))] +#[cfg(not(any(target_os = "espidf", target_os = "redox")))] #[inline] #[doc(alias = "fstatat")] pub fn statat(dirfd: Fd, path: P, flags: AtFlags) -> io::Result { @@ -367,7 +371,12 @@ pub fn statat(dirfd: Fd, path: P, flags: AtFlags) -> io: /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/faccessat.html /// [Linux]: https://man7.org/linux/man-pages/man2/faccessat.2.html -#[cfg(not(any(target_os = "espidf", target_os = "horizon", target_os = "vita")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "horizon", + target_os = "vita", + target_os = "redox" +)))] #[inline] #[doc(alias = "faccessat")] pub fn accessat( @@ -387,7 +396,12 @@ pub fn accessat( /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/utimensat.html /// [Linux]: https://man7.org/linux/man-pages/man2/utimensat.2.html -#[cfg(not(any(target_os = "espidf", target_os = "horizon", target_os = "vita")))] +#[cfg(not(any( + target_os = "espidf", + target_os = "horizon", + target_os = "vita", + target_os = "redox" +)))] #[inline] pub fn utimensat( dirfd: Fd, @@ -410,7 +424,7 @@ pub fn utimensat( /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/fchmodat.html /// [Linux]: https://man7.org/linux/man-pages/man2/fchmodat.2.html -#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi", target_os = "redox")))] #[inline] #[doc(alias = "fchmodat")] pub fn chmodat( @@ -454,7 +468,8 @@ pub fn fclonefileat( target_os = "espidf", target_os = "horizon", target_os = "vita", - target_os = "wasi" + target_os = "wasi", + target_os = "redox", )))] #[inline] pub fn mknodat( @@ -480,7 +495,8 @@ pub fn mknodat( target_os = "espidf", target_os = "horizon", target_os = "vita", - target_os = "wasi" + target_os = "wasi", + target_os = "redox", )))] #[inline] pub fn mkfifoat(dirfd: Fd, path: P, mode: Mode) -> io::Result<()> { @@ -496,7 +512,7 @@ pub fn mkfifoat(dirfd: Fd, path: P, mode: Mode) -> io::R /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/fchownat.html /// [Linux]: https://man7.org/linux/man-pages/man2/fchownat.2.html -#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] +#[cfg(not(any(target_os = "espidf", target_os = "wasi", target_os = "redox")))] #[inline] #[doc(alias = "fchownat")] pub fn chownat( diff --git a/src/fs/mod.rs b/src/fs/mod.rs index 35ca17af0..5dbd7cbb8 100644 --- a/src/fs/mod.rs +++ b/src/fs/mod.rs @@ -1,7 +1,6 @@ //! Filesystem operations. mod abs; -#[cfg(not(target_os = "redox"))] mod at; mod constants; #[cfg(linux_kernel)] @@ -51,7 +50,7 @@ mod raw_dir; mod seek_from; #[cfg(target_os = "linux")] mod sendfile; -#[cfg(not(any(target_os = "espidf", target_os = "redox")))] +#[cfg(not(target_os = "espidf"))] mod special; #[cfg(linux_kernel)] mod statx; @@ -67,7 +66,6 @@ mod sync; mod xattr; pub use abs::*; -#[cfg(not(target_os = "redox"))] pub use at::*; pub use constants::*; #[cfg(linux_kernel)] @@ -115,7 +113,7 @@ pub use raw_dir::{RawDir, RawDirEntry}; pub use seek_from::SeekFrom; #[cfg(target_os = "linux")] pub use sendfile::sendfile; -#[cfg(not(any(target_os = "espidf", target_os = "redox")))] +#[cfg(not(target_os = "espidf"))] pub use special::*; #[cfg(linux_kernel)] pub use statx::*; diff --git a/tests/fs/renameat.rs b/tests/fs/renameat.rs index 128950965..19510cf99 100644 --- a/tests/fs/renameat.rs +++ b/tests/fs/renameat.rs @@ -4,7 +4,7 @@ fn same(a: &Stat, b: &Stat) -> bool { a.st_ino == b.st_ino && a.st_dev == b.st_dev } -#[cfg(linux_kernel)] +#[cfg(any(linux_kernel, target_os = "redox"))] const DIR_OPEN_FLAGS: OFlags = OFlags::RDONLY.union(OFlags::PATH); #[cfg(apple)] const DIR_OPEN_FLAGS: OFlags = OFlags::RDONLY; @@ -34,7 +34,7 @@ fn test_rename() { access(tmp.path().join("bar"), Access::EXISTS).unwrap(); } -#[cfg(any(linux_kernel, apple))] +#[cfg(any(linux_kernel, apple, target_os = "redox"))] #[test] fn test_renameat() { use rustix::fs::{accessat, openat, renameat, statat, Access, AtFlags, Mode, CWD}; @@ -58,7 +58,7 @@ fn test_renameat() { /// Like `test_renameat` but the file already exists, so `renameat` /// overwrites it. -#[cfg(any(linux_kernel, apple))] +#[cfg(any(linux_kernel, apple, target_os = "redox"))] #[test] fn test_renameat_overwrite() { use rustix::fs::{openat, renameat, statat, AtFlags, Mode, CWD}; @@ -74,7 +74,7 @@ fn test_renameat_overwrite() { assert!(same(&before, &renamed)); } -#[cfg(any(linux_kernel, apple))] +#[cfg(any(linux_kernel, apple, target_os = "redox"))] #[test] fn test_renameat_with() { use rustix::fs::{openat, renameat_with, statat, AtFlags, Mode, RenameFlags, CWD};