Skip to content

Commit 99c8050

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 95cdffb commit 99c8050

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/backend/libc/fs/syscalls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,10 +2053,10 @@ pub(crate) fn statx(
20532053
// doesn't represent all the known flags.
20542054
//
20552055
// [it's deprecated]: https://patchwork.kernel.org/project/linux-fsdevel/patch/20200505095915.11275-7-mszeredi@redhat.com/
2056-
#[cfg(any(not(linux_raw_dep), not(target_env = "musl")))]
2056+
#[cfg(not(target_env = "musl"))]
20572057
const STATX__RESERVED: u32 = c::STATX__RESERVED as u32;
20582058
#[cfg(target_env = "musl")]
2059-
const STATX__RESERVED: u32 = linux_raw_sys::general::STATX__RESERVED;
2059+
const STATX__RESERVED: u32 = 0x80000000;
20602060
if (mask.bits() & STATX__RESERVED) == STATX__RESERVED {
20612061
return Err(io::Errno::INVAL);
20622062
}

src/fs/statx.rs

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

0 commit comments

Comments
 (0)