Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ 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:
#
# On all other Unix-family platforms, and under Miri, we always use the libc
# 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:
#
Expand Down
22 changes: 20 additions & 2 deletions src/backend/libc/fs/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<'_>,
Expand Down
16 changes: 16 additions & 0 deletions src/backend/libc/fs/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
const _ = !0;
}
}

#[cfg(apple)]
bitflags! {
/// `RENAME_*` constants for use with [`renameat_with`].
Expand Down
44 changes: 30 additions & 14 deletions src/fs/at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<P: path::Arg, Fd: AsFd>(
dirfd: Fd,
Expand All @@ -95,7 +96,7 @@ pub fn openat<P: path::Arg, Fd: AsFd>(
///
/// [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<P: path::Arg, Fd: AsFd, B: Into<Vec<u8>>>(
Expand All @@ -106,7 +107,7 @@ 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()))
}

#[cfg(feature = "alloc")]
#[cfg(all(feature = "alloc", not(target_os = "redox")))]
#[allow(unsafe_code)]
fn _readlinkat(dirfd: BorrowedFd<'_>, path: &CStr, mut buffer: Vec<u8>) -> io::Result<CString> {
buffer.clear();
Expand Down Expand Up @@ -170,6 +171,7 @@ fn _readlinkat(dirfd: BorrowedFd<'_>, path: &CStr, mut buffer: Vec<u8>) -> 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<P: path::Arg, Fd: AsFd, Buf: Buffer<u8>>(
dirfd: Fd,
Expand All @@ -192,6 +194,7 @@ pub fn readlinkat_raw<P: path::Arg, Fd: AsFd, Buf: Buffer<u8>>(
///
/// [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<P: path::Arg, Fd: AsFd>(dirfd: Fd, path: P, mode: Mode) -> io::Result<()> {
path.into_with_c_str(|path| backend::fs::syscalls::mkdirat(dirfd.as_fd(), path, mode))
Expand All @@ -206,7 +209,7 @@ pub fn mkdirat<P: path::Arg, Fd: AsFd>(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<P: path::Arg, Q: path::Arg, PFd: AsFd, QFd: AsFd>(
old_dirfd: PFd,
Expand Down Expand Up @@ -240,7 +243,7 @@ pub fn linkat<P: path::Arg, Q: path::Arg, PFd: AsFd, QFd: AsFd>(
/// [`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<P: path::Arg, Fd: AsFd>(dirfd: Fd, path: P, flags: AtFlags) -> io::Result<()> {
path.into_with_c_str(|path| backend::fs::syscalls::unlinkat(dirfd.as_fd(), path, flags))
Expand Down Expand Up @@ -286,7 +289,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(apple, linux_kernel))]
#[cfg(any(apple, linux_kernel, target_os = "redox"))]
#[inline]
#[doc(alias = "renameat2")]
#[doc(alias = "renameatx_np")]
Expand Down Expand Up @@ -318,6 +321,7 @@ pub fn renameat_with<P: path::Arg, Q: path::Arg, PFd: AsFd, QFd: AsFd>(
///
/// [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<P: path::Arg, Q: path::Arg, Fd: AsFd>(
old_path: P,
Expand All @@ -344,7 +348,7 @@ pub fn symlinkat<P: path::Arg, Q: path::Arg, Fd: AsFd>(
/// [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<P: path::Arg, Fd: AsFd>(dirfd: Fd, path: P, flags: AtFlags) -> io::Result<Stat> {
Expand All @@ -367,7 +371,12 @@ pub fn statat<P: path::Arg, Fd: AsFd>(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<P: path::Arg, Fd: AsFd>(
Expand All @@ -387,7 +396,12 @@ pub fn accessat<P: path::Arg, Fd: AsFd>(
///
/// [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<P: path::Arg, Fd: AsFd>(
dirfd: Fd,
Expand All @@ -410,7 +424,7 @@ pub fn utimensat<P: path::Arg, Fd: AsFd>(
///
/// [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<P: path::Arg, Fd: AsFd>(
Expand Down Expand Up @@ -454,7 +468,8 @@ pub fn fclonefileat<Fd: AsFd, DstFd: AsFd, P: path::Arg>(
target_os = "espidf",
target_os = "horizon",
target_os = "vita",
target_os = "wasi"
target_os = "wasi",
target_os = "redox",
)))]
#[inline]
pub fn mknodat<P: path::Arg, Fd: AsFd>(
Expand All @@ -480,7 +495,8 @@ pub fn mknodat<P: path::Arg, Fd: AsFd>(
target_os = "espidf",
target_os = "horizon",
target_os = "vita",
target_os = "wasi"
target_os = "wasi",
target_os = "redox",
)))]
#[inline]
pub fn mkfifoat<P: path::Arg, Fd: AsFd>(dirfd: Fd, path: P, mode: Mode) -> io::Result<()> {
Expand All @@ -496,7 +512,7 @@ pub fn mkfifoat<P: path::Arg, Fd: AsFd>(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<P: path::Arg, Fd: AsFd>(
Expand Down
6 changes: 2 additions & 4 deletions src/fs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Filesystem operations.

mod abs;
#[cfg(not(target_os = "redox"))]
mod at;
mod constants;
#[cfg(linux_kernel)]
Expand Down Expand Up @@ -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;
Expand All @@ -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)]
Expand Down Expand Up @@ -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::*;
Expand Down
8 changes: 4 additions & 4 deletions tests/fs/renameat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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};
Expand All @@ -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};
Expand All @@ -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};
Expand Down
Loading