| 1 | From e85b536ab4fb20736791d5d474a916f86d57ca05 Mon Sep 17 00:00:00 2001
|
| 2 | From: Patrycja Rosa <[email protected]>
|
| 3 | Date: Sun, 18 Oct 2026 21:59:13 +0200
|
| 4 | Subject: [PATCH] rustix-statx.patch
|
| 5 |
|
| 6 | backport of https://github.com/bytecodealliance/rustix/commit/ded795bab5f620ff9fd4045f114f6a14b5bb8e71
|
| 7 | ---
|
| 8 | third_party/rust/rustix/src/backend/libc/c.rs | 51 ++++++++++---------
|
| 9 | .../rustix/src/backend/libc/fs/syscalls.rs | 9 ++++
|
| 10 | third_party/rust/rustix/src/net/types.rs | 5 +-
|
| 11 | 3 files changed, 37 insertions(+), 28 deletions(-)
|
| 12 |
|
| 13 | diff --git a/third_party/rust/rustix/src/backend/libc/c.rs b/third_party/rust/rustix/src/backend/libc/c.rs
|
| 14 | index 5eeff953f4c14..fb748979faa97 100644
|
| 15 | |
| 16 | |
| 17 | @@ -474,30 +474,8 @@ mod readwrite_pv64v2 {
|
| 18 | ))]
|
| 19 | pub(super) use readwrite_pv64v2::{preadv64v2 as preadv2, pwritev64v2 as pwritev2};
|
| 20 |
|
| 21 | -// Rust's libc crate lacks statx for Non-glibc targets.
|
| 22 | -#[cfg(feature = "fs")]
|
| 23 | -#[cfg(all(
|
| 24 | - linux_like,
|
| 25 | - linux_raw_dep,
|
| 26 | - not(any(
|
| 27 | - target_os = "emscripten",
|
| 28 | - target_env = "gnu",
|
| 29 | - all(target_arch = "loongarch64", target_env = "musl")
|
| 30 | - ))
|
| 31 | -))]
|
| 32 | -mod statx_flags {
|
| 33 | - pub(crate) use linux_raw_sys::general::{
|
| 34 | - STATX_ALL, STATX_ATIME, STATX_BASIC_STATS, STATX_BLOCKS, STATX_BTIME, STATX_CTIME,
|
| 35 | - STATX_DIOALIGN, STATX_GID, STATX_INO, STATX_MNT_ID, STATX_MODE, STATX_MTIME, STATX_NLINK,
|
| 36 | - STATX_SIZE, STATX_TYPE, STATX_UID,
|
| 37 | - };
|
| 38 | -
|
| 39 | - pub(crate) use linux_raw_sys::general::{
|
| 40 | - STATX_ATTR_APPEND, STATX_ATTR_AUTOMOUNT, STATX_ATTR_COMPRESSED, STATX_ATTR_DAX,
|
| 41 | - STATX_ATTR_ENCRYPTED, STATX_ATTR_IMMUTABLE, STATX_ATTR_MOUNT_ROOT, STATX_ATTR_NODUMP,
|
| 42 | - STATX_ATTR_VERITY,
|
| 43 | - };
|
| 44 | -}
|
| 45 | +// Rust's libc crate > v0.2.189 may also define these constants,
|
| 46 | +// so we use an explicit import.
|
| 47 | #[cfg(feature = "fs")]
|
| 48 | #[cfg(all(
|
| 49 | linux_like,
|
| 50 | @@ -509,7 +487,30 @@ mod statx_flags {
|
| 51 | all(target_arch = "loongarch64", target_env = "musl")
|
| 52 | ))
|
| 53 | ))]
|
| 54 | -pub(crate) use statx_flags::*;
|
| 55 | +pub(crate) use linux_raw_sys::general::{
|
| 56 | + STATX_ALL, STATX_ATIME, STATX_BASIC_STATS, STATX_BLOCKS, STATX_BTIME, STATX_CTIME,
|
| 57 | + STATX_DIOALIGN, STATX_GID, STATX_INO, STATX_MNT_ID, STATX_MODE, STATX_MTIME, STATX_NLINK,
|
| 58 | + STATX_SIZE, STATX_TYPE, STATX_UID,
|
| 59 | +};
|
| 60 | +
|
| 61 | +// Rust's libc crate > v0.2.189 may also define these constants,
|
| 62 | +// so we use an explicit import.
|
| 63 | +#[cfg(feature = "fs")]
|
| 64 | +#[cfg(all(
|
| 65 | + linux_like,
|
| 66 | + linux_raw_dep,
|
| 67 | + not(any(
|
| 68 | + target_os = "android",
|
| 69 | + target_os = "emscripten",
|
| 70 | + target_env = "gnu",
|
| 71 | + all(target_arch = "loongarch64", target_env = "musl")
|
| 72 | + ))
|
| 73 | +))]
|
| 74 | +pub(crate) use linux_raw_sys::general::{
|
| 75 | + STATX_ATTR_APPEND, STATX_ATTR_AUTOMOUNT, STATX_ATTR_COMPRESSED, STATX_ATTR_DAX,
|
| 76 | + STATX_ATTR_ENCRYPTED, STATX_ATTR_IMMUTABLE, STATX_ATTR_MOUNT_ROOT, STATX_ATTR_NODUMP,
|
| 77 | + STATX_ATTR_VERITY,
|
| 78 | +};
|
| 79 |
|
| 80 | #[cfg(feature = "fs")]
|
| 81 | #[cfg(target_os = "android")]
|
| 82 | diff --git a/third_party/rust/rustix/src/backend/libc/fs/syscalls.rs b/third_party/rust/rustix/src/backend/libc/fs/syscalls.rs
|
| 83 | index 71bc8b0abf3f7..1a5ea4fa64697 100644
|
| 84 | |
| 85 | |
| 86 | @@ -941,6 +941,7 @@ pub(crate) fn utimensat(
|
| 87 | c::c_int
|
| 88 | ) -> c::c_int
|
| 89 | }
|
| 90 | + #[cfg(not(any(target_os = "tvos", target_os = "watchos")))]
|
| 91 | extern "C" {
|
| 92 | fn setattrlist(
|
| 93 | path: *const ffi::c_char,
|
| 94 | @@ -950,6 +951,7 @@ pub(crate) fn utimensat(
|
| 95 | options: c::c_ulong,
|
| 96 | ) -> c::c_int;
|
| 97 | }
|
| 98 | + #[cfg(not(any(target_os = "tvos", target_os = "watchos")))]
|
| 99 | const FSOPT_NOFOLLOW: c::c_ulong = 0x0000_0001;
|
| 100 |
|
| 101 | // If we have `utimensat`, use it.
|
| 102 | @@ -962,8 +964,14 @@ pub(crate) fn utimensat(
|
| 103 | ));
|
| 104 | }
|
| 105 |
|
| 106 | + // Return `NOSYS` on platforms where `utimensat` cannot be emulated
|
| 107 | + // because `fork` is unavailable.
|
| 108 | + #[cfg(any(target_os = "tvos", target_os = "watchos"))]
|
| 109 | + return Err(io::Errno::NOSYS);
|
| 110 | +
|
| 111 | // Convert `times`. We only need this in the child, but do it before
|
| 112 | // calling `fork` because it might fail.
|
| 113 | + #[cfg(not(any(target_os = "tvos", target_os = "watchos")))]
|
| 114 | let (attrbuf_size, times, attrs) = times_to_attrlist(times)?;
|
| 115 |
|
| 116 | // `setattrlistat` was introduced in 10.13 along with `utimensat`, so
|
| 117 | @@ -971,6 +979,7 @@ pub(crate) fn utimensat(
|
| 118 | // Emulate it using `fork`, and `fchdir` and [`setattrlist`].
|
| 119 | //
|
| 120 | // [`setattrlist`]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setattrlist.2.html
|
| 121 | + #[cfg(not(any(target_os = "tvos", target_os = "watchos")))]
|
| 122 | match c::fork() {
|
| 123 | -1 => Err(io::Errno::IO),
|
| 124 | 0 => {
|
| 125 | diff --git a/third_party/rust/rustix/src/net/types.rs b/third_party/rust/rustix/src/net/types.rs
|
| 126 | index 370f2468fb8f7..534f6bb0a3a16 100644
|
| 127 | |
| 128 | |
| 129 | @@ -740,7 +740,7 @@ impl AddressFamily {
|
| 130 | #[cfg(target_os = "freebsd")]
|
| 131 | pub const SLOW: Self = Self(c::AF_SLOW as _);
|
| 132 | /// `AF_SYS_CONTROL`
|
| 133 | - #[cfg(apple)]
|
| 134 | + #[cfg(target_os = "macos")]
|
| 135 | pub const SYS_CONTROL: Self = Self(c::AF_SYS_CONTROL as _);
|
| 136 | /// `AF_SYSTEM`
|
| 137 | #[cfg(apple)]
|
| 138 | @@ -1116,6 +1116,7 @@ pub mod ipproto {
|
| 139 | }
|
| 140 |
|
| 141 | /// `SYSPROTO_*` constants.
|
| 142 | +#[cfg(target_os = "macos")]
|
| 143 | pub mod sysproto {
|
| 144 | #[cfg(apple)]
|
| 145 | use {
|
| 146 | @@ -1124,11 +1125,9 @@ pub mod sysproto {
|
| 147 | };
|
| 148 |
|
| 149 | /// `SYSPROTO_EVENT`
|
| 150 | - #[cfg(apple)]
|
| 151 | pub const EVENT: Protocol = Protocol(new_raw_protocol(c::SYSPROTO_EVENT as _));
|
| 152 |
|
| 153 | /// `SYSPROTO_CONTROL`
|
| 154 | - #[cfg(apple)]
|
| 155 | pub const CONTROL: Protocol = Protocol(new_raw_protocol(c::SYSPROTO_CONTROL as _));
|
| 156 | }
|
| 157 |
|
| 158 | --
|
| 159 | 2.56.0
|
| 160 |
|