Skip to content

Commit 5e9dc4e

Browse files
committedNov 13, 2024
linux_like: Unify statx definitions
The statx system call and corresponding constants are defined by the Linux kernel and don't depend on the libc or architecture. The only difference is whether a libc exports the statx syscall wrapper or not. We can thus unify the statx definitions for all Linux "like" platforms: GNU (glibc), Android (bionic), and (in a later commit) musl. Plain u64 (or uint64_t in C) can't be used for the statx fields because bionic defines them as __u64, and provides incompatible definitions of uint64_t and __u64.
1 parent c025f57 commit 5e9dc4e

File tree

3 files changed

+81
-111
lines changed

3 files changed

+81
-111
lines changed
 

‎src/unix/linux_like/android/mod.rs

-40
Original file line numberDiff line numberDiff line change
@@ -515,39 +515,6 @@ s! {
515515
pub ifr6_prefixlen: u32,
516516
pub ifr6_ifindex: ::c_int,
517517
}
518-
519-
pub struct statx {
520-
pub stx_mask: ::__u32,
521-
pub stx_blksize: ::__u32,
522-
pub stx_attributes: ::__u64,
523-
pub stx_nlink: ::__u32,
524-
pub stx_uid: ::__u32,
525-
pub stx_gid: ::__u32,
526-
pub stx_mode: ::__u16,
527-
__statx_pad1: [::__u16; 1],
528-
pub stx_ino: ::__u64,
529-
pub stx_size: ::__u64,
530-
pub stx_blocks: ::__u64,
531-
pub stx_attributes_mask: ::__u64,
532-
pub stx_atime: ::statx_timestamp,
533-
pub stx_btime: ::statx_timestamp,
534-
pub stx_ctime: ::statx_timestamp,
535-
pub stx_mtime: ::statx_timestamp,
536-
pub stx_rdev_major: ::__u32,
537-
pub stx_rdev_minor: ::__u32,
538-
pub stx_dev_major: ::__u32,
539-
pub stx_dev_minor: ::__u32,
540-
pub stx_mnt_id: ::__u64,
541-
pub stx_dio_mem_align: ::__u32,
542-
pub stx_dio_offset_align: ::__u32,
543-
__statx_pad3: [::__u64; 12],
544-
}
545-
546-
pub struct statx_timestamp {
547-
pub tv_sec: ::__s64,
548-
pub tv_nsec: ::__u32,
549-
pub __reserved: ::__s32,
550-
}
551518
}
552519

553520
s_no_extra_traits! {
@@ -4161,13 +4128,6 @@ extern "C" {
41614128
newpath: *const ::c_char,
41624129
flags: ::c_uint,
41634130
) -> ::c_int;
4164-
pub fn statx(
4165-
dirfd: ::c_int,
4166-
pathname: *const c_char,
4167-
flags: ::c_int,
4168-
mask: ::c_uint,
4169-
statxbuf: *mut statx,
4170-
) -> ::c_int;
41714131

41724132
pub fn klogctl(syslog_type: ::c_int, bufp: *mut ::c_char, len: ::c_int) -> ::c_int;
41734133
}

‎src/unix/linux_like/linux/gnu/mod.rs

-71
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,6 @@ cfg_if! {
1616
}
1717

1818
s! {
19-
pub struct statx {
20-
pub stx_mask: u32,
21-
pub stx_blksize: u32,
22-
pub stx_attributes: u64,
23-
pub stx_nlink: u32,
24-
pub stx_uid: u32,
25-
pub stx_gid: u32,
26-
pub stx_mode: u16,
27-
__statx_pad1: [u16; 1],
28-
pub stx_ino: u64,
29-
pub stx_size: u64,
30-
pub stx_blocks: u64,
31-
pub stx_attributes_mask: u64,
32-
pub stx_atime: ::statx_timestamp,
33-
pub stx_btime: ::statx_timestamp,
34-
pub stx_ctime: ::statx_timestamp,
35-
pub stx_mtime: ::statx_timestamp,
36-
pub stx_rdev_major: u32,
37-
pub stx_rdev_minor: u32,
38-
pub stx_dev_major: u32,
39-
pub stx_dev_minor: u32,
40-
pub stx_mnt_id: u64,
41-
pub stx_dio_mem_align: u32,
42-
pub stx_dio_offset_align: u32,
43-
__statx_pad3: [u64; 12],
44-
}
45-
46-
pub struct statx_timestamp {
47-
pub tv_sec: i64,
48-
pub tv_nsec: u32,
49-
pub __statx_timestamp_pad1: [i32; 1],
50-
}
51-
5219
pub struct aiocb {
5320
pub aio_fildes: ::c_int,
5421
pub aio_lio_opcode: ::c_int,
@@ -1149,37 +1116,6 @@ pub const M_PERTURB: ::c_int = -6;
11491116
pub const M_ARENA_TEST: ::c_int = -7;
11501117
pub const M_ARENA_MAX: ::c_int = -8;
11511118

1152-
pub const AT_STATX_SYNC_TYPE: ::c_int = 0x6000;
1153-
pub const AT_STATX_SYNC_AS_STAT: ::c_int = 0x0000;
1154-
pub const AT_STATX_FORCE_SYNC: ::c_int = 0x2000;
1155-
pub const AT_STATX_DONT_SYNC: ::c_int = 0x4000;
1156-
pub const STATX_TYPE: ::c_uint = 0x0001;
1157-
pub const STATX_MODE: ::c_uint = 0x0002;
1158-
pub const STATX_NLINK: ::c_uint = 0x0004;
1159-
pub const STATX_UID: ::c_uint = 0x0008;
1160-
pub const STATX_GID: ::c_uint = 0x0010;
1161-
pub const STATX_ATIME: ::c_uint = 0x0020;
1162-
pub const STATX_MTIME: ::c_uint = 0x0040;
1163-
pub const STATX_CTIME: ::c_uint = 0x0080;
1164-
pub const STATX_INO: ::c_uint = 0x0100;
1165-
pub const STATX_SIZE: ::c_uint = 0x0200;
1166-
pub const STATX_BLOCKS: ::c_uint = 0x0400;
1167-
pub const STATX_BASIC_STATS: ::c_uint = 0x07ff;
1168-
pub const STATX_BTIME: ::c_uint = 0x0800;
1169-
pub const STATX_MNT_ID: ::c_uint = 0x1000;
1170-
pub const STATX_DIOALIGN: ::c_uint = 0x2000;
1171-
pub const STATX_ALL: ::c_uint = 0x0fff;
1172-
pub const STATX__RESERVED: ::c_int = 0x80000000;
1173-
pub const STATX_ATTR_COMPRESSED: ::c_int = 0x0004;
1174-
pub const STATX_ATTR_IMMUTABLE: ::c_int = 0x0010;
1175-
pub const STATX_ATTR_APPEND: ::c_int = 0x0020;
1176-
pub const STATX_ATTR_NODUMP: ::c_int = 0x0040;
1177-
pub const STATX_ATTR_ENCRYPTED: ::c_int = 0x0800;
1178-
pub const STATX_ATTR_AUTOMOUNT: ::c_int = 0x1000;
1179-
pub const STATX_ATTR_MOUNT_ROOT: ::c_int = 0x2000;
1180-
pub const STATX_ATTR_VERITY: ::c_int = 0x00100000;
1181-
pub const STATX_ATTR_DAX: ::c_int = 0x00200000;
1182-
11831119
pub const SOMAXCONN: ::c_int = 4096;
11841120

11851121
// linux/mount.h
@@ -1384,13 +1320,6 @@ extern "C" {
13841320
pub fn getpt() -> ::c_int;
13851321
pub fn mallopt(param: ::c_int, value: ::c_int) -> ::c_int;
13861322
pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::timezone) -> ::c_int;
1387-
pub fn statx(
1388-
dirfd: ::c_int,
1389-
pathname: *const c_char,
1390-
flags: ::c_int,
1391-
mask: ::c_uint,
1392-
statxbuf: *mut statx,
1393-
) -> ::c_int;
13941323
pub fn getentropy(buf: *mut ::c_void, buflen: ::size_t) -> ::c_int;
13951324
pub fn getrandom(buf: *mut ::c_void, buflen: ::size_t, flags: ::c_uint) -> ::ssize_t;
13961325
pub fn getauxval(type_: ::c_ulong) -> ::c_ulong;

‎src/unix/linux_like/mod.rs

+81
Original file line numberDiff line numberDiff line change
@@ -1886,6 +1886,87 @@ cfg_if! {
18861886
}
18871887
}
18881888

1889+
// The statx syscall, available on some libcs.
1890+
cfg_if! {
1891+
if #[cfg(any(target_env = "gnu", target_os = "android"))] {
1892+
pub const AT_STATX_SYNC_TYPE: ::c_int = 0x6000;
1893+
pub const AT_STATX_SYNC_AS_STAT: ::c_int = 0x0000;
1894+
pub const AT_STATX_FORCE_SYNC: ::c_int = 0x2000;
1895+
pub const AT_STATX_DONT_SYNC: ::c_int = 0x4000;
1896+
pub const STATX_TYPE: ::c_uint = 0x0001;
1897+
pub const STATX_MODE: ::c_uint = 0x0002;
1898+
pub const STATX_NLINK: ::c_uint = 0x0004;
1899+
pub const STATX_UID: ::c_uint = 0x0008;
1900+
pub const STATX_GID: ::c_uint = 0x0010;
1901+
pub const STATX_ATIME: ::c_uint = 0x0020;
1902+
pub const STATX_MTIME: ::c_uint = 0x0040;
1903+
pub const STATX_CTIME: ::c_uint = 0x0080;
1904+
pub const STATX_INO: ::c_uint = 0x0100;
1905+
pub const STATX_SIZE: ::c_uint = 0x0200;
1906+
pub const STATX_BLOCKS: ::c_uint = 0x0400;
1907+
pub const STATX_BASIC_STATS: ::c_uint = 0x07ff;
1908+
pub const STATX_BTIME: ::c_uint = 0x0800;
1909+
pub const STATX_ALL: ::c_uint = 0x0fff;
1910+
pub const STATX_MNT_ID: ::c_uint = 0x1000;
1911+
pub const STATX_DIOALIGN: ::c_uint = 0x2000;
1912+
pub const STATX__RESERVED: ::c_int = 0x80000000;
1913+
pub const STATX_ATTR_COMPRESSED: ::c_int = 0x0004;
1914+
pub const STATX_ATTR_IMMUTABLE: ::c_int = 0x0010;
1915+
pub const STATX_ATTR_APPEND: ::c_int = 0x0020;
1916+
pub const STATX_ATTR_NODUMP: ::c_int = 0x0040;
1917+
pub const STATX_ATTR_ENCRYPTED: ::c_int = 0x0800;
1918+
pub const STATX_ATTR_AUTOMOUNT: ::c_int = 0x1000;
1919+
pub const STATX_ATTR_MOUNT_ROOT: ::c_int = 0x2000;
1920+
pub const STATX_ATTR_VERITY: ::c_int = 0x100000;
1921+
pub const STATX_ATTR_DAX: ::c_int = 0x200000;
1922+
1923+
extern "C" {
1924+
pub fn statx(
1925+
dirfd: ::c_int,
1926+
pathname: *const ::c_char,
1927+
flags: ::c_int,
1928+
mask: ::c_uint,
1929+
statxbuf: *mut statx,
1930+
) -> ::c_int;
1931+
}
1932+
1933+
s! {
1934+
pub struct statx {
1935+
pub stx_mask: ::__u32,
1936+
pub stx_blksize: ::__u32,
1937+
pub stx_attributes: ::__u64,
1938+
pub stx_nlink: ::__u32,
1939+
pub stx_uid: ::__u32,
1940+
pub stx_gid: ::__u32,
1941+
pub stx_mode: ::__u16,
1942+
__statx_pad1: [::__u16; 1],
1943+
pub stx_ino: ::__u64,
1944+
pub stx_size: ::__u64,
1945+
pub stx_blocks: ::__u64,
1946+
pub stx_attributes_mask: ::__u64,
1947+
pub stx_atime: statx_timestamp,
1948+
pub stx_btime: statx_timestamp,
1949+
pub stx_ctime: statx_timestamp,
1950+
pub stx_mtime: statx_timestamp,
1951+
pub stx_rdev_major: ::__u32,
1952+
pub stx_rdev_minor: ::__u32,
1953+
pub stx_dev_major: ::__u32,
1954+
pub stx_dev_minor: ::__u32,
1955+
pub stx_mnt_id: ::__u64,
1956+
pub stx_dio_mem_align: ::__u32,
1957+
pub stx_dio_offset_align: ::__u32,
1958+
__statx_pad3: [::__u64; 12],
1959+
}
1960+
1961+
pub struct statx_timestamp {
1962+
pub tv_sec: ::__s64,
1963+
pub tv_nsec: ::__u32,
1964+
__statx_timestamp_pad1: [::__s32; 1],
1965+
}
1966+
}
1967+
}
1968+
}
1969+
18891970
cfg_if! {
18901971
if #[cfg(target_os = "emscripten")] {
18911972
mod emscripten;

0 commit comments

Comments
 (0)