Skip to content

Commit f9fc21d

Browse files
gurchetansinghgsingh408
authored andcommitted
rustix: improve for musl build without linux-raw-sys
Android likes to build host tools (adb, Cuttlefish, ..) via musl, using the same hermetic tree as for Bionic build. And linux-raw-sys isn't in that hermetic tree, so add support for the libc-backend.
1 parent eee6356 commit f9fc21d

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/backend/libc/fs/syscalls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,10 +2071,10 @@ pub(crate) fn statx(
20712071
// doesn't represent all the known flags.
20722072
//
20732073
// [it's deprecated]: https://patchwork.kernel.org/project/linux-fsdevel/patch/20200505095915.11275-7-mszeredi@redhat.com/
2074-
#[cfg(any(not(linux_raw_dep), not(target_env = "musl")))]
2074+
#[cfg(not(target_env = "musl"))]
20752075
const STATX__RESERVED: u32 = c::STATX__RESERVED as u32;
20762076
#[cfg(target_env = "musl")]
2077-
const STATX__RESERVED: u32 = linux_raw_sys::general::STATX__RESERVED;
2077+
const STATX__RESERVED: u32 = 0x80000000;
20782078
if (mask.bits() & STATX__RESERVED) == STATX__RESERVED {
20792079
return Err(io::Errno::INVAL);
20802080
}

src/fs/statx.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use crate::fd::AsFd;
44
use crate::fs::AtFlags;
55
use crate::{backend, io, path};
6+
#[cfg(any(linux_raw_dep, not(target_env = "musl")))]
67
use backend::c;
78
use bitflags::bitflags;
89

@@ -275,3 +276,36 @@ mod compat {
275276
}
276277
}
277278
}
279+
280+
// These are the actual values for the constants, needed for the fallback implementation.
281+
// TODO(https://github.com/bytecodealliance/rustix/issues/1589): try to upstream these
282+
// constants to libc.
283+
#[cfg(all(not(linux_raw_dep), target_env = "musl"))]
284+
mod c {
285+
pub const STATX_TYPE: u32 = 0x00000001;
286+
pub const STATX_MODE: u32 = 0x00000002;
287+
pub const STATX_NLINK: u32 = 0x00000004;
288+
pub const STATX_UID: u32 = 0x00000008;
289+
pub const STATX_GID: u32 = 0x00000010;
290+
pub const STATX_ATIME: u32 = 0x00000020;
291+
pub const STATX_MTIME: u32 = 0x00000040;
292+
pub const STATX_CTIME: u32 = 0x00000080;
293+
pub const STATX_INO: u32 = 0x00000100;
294+
pub const STATX_SIZE: u32 = 0x00000200;
295+
pub const STATX_BLOCKS: u32 = 0x00000400;
296+
pub const STATX_BASIC_STATS: u32 = 0x000007ff;
297+
pub const STATX_BTIME: u32 = 0x00000800;
298+
pub const STATX_MNT_ID: u32 = 0x00001000;
299+
pub const STATX_DIOALIGN: u32 = 0x00002000; // Deprecated, but here for completeness
300+
pub const STATX_ALL: u32 = 0x00000fff; // Note: Doesn't include newer flags
301+
302+
pub const STATX_ATTR_COMPRESSED: u64 = 0x00000004;
303+
pub const STATX_ATTR_IMMUTABLE: u64 = 0x00000010;
304+
pub const STATX_ATTR_APPEND: u64 = 0x00000020;
305+
pub const STATX_ATTR_NODUMP: u64 = 0x00000040;
306+
pub const STATX_ATTR_ENCRYPTED: u64 = 0x00000800;
307+
pub const STATX_ATTR_AUTOMOUNT: u64 = 0x00001000;
308+
pub const STATX_ATTR_MOUNT_ROOT: u64 = 0x00020000;
309+
pub const STATX_ATTR_VERITY: u64 = 0x00100000;
310+
pub const STATX_ATTR_DAX: u64 = 0x00200000;
311+
}

0 commit comments

Comments
 (0)