Skip to content

Commit 57b620b

Browse files
authored
Merge pull request #3978 from neuschaefer/statx-unify
linux_like: Unify statx definitions
2 parents 400f73f + e46bbe4 commit 57b620b

File tree

3 files changed

+89
-111
lines changed

3 files changed

+89
-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! {
@@ -4163,13 +4130,6 @@ extern "C" {
41634130
newpath: *const ::c_char,
41644131
flags: ::c_uint,
41654132
) -> ::c_int;
4166-
pub fn statx(
4167-
dirfd: ::c_int,
4168-
pathname: *const c_char,
4169-
flags: ::c_int,
4170-
mask: ::c_uint,
4171-
statxbuf: *mut statx,
4172-
) -> ::c_int;
41734133
}
41744134

41754135
cfg_if! {

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,
@@ -1168,37 +1135,6 @@ pub const M_PERTURB: ::c_int = -6;
11681135
pub const M_ARENA_TEST: ::c_int = -7;
11691136
pub const M_ARENA_MAX: ::c_int = -8;
11701137

1171-
pub const AT_STATX_SYNC_TYPE: ::c_int = 0x6000;
1172-
pub const AT_STATX_SYNC_AS_STAT: ::c_int = 0x0000;
1173-
pub const AT_STATX_FORCE_SYNC: ::c_int = 0x2000;
1174-
pub const AT_STATX_DONT_SYNC: ::c_int = 0x4000;
1175-
pub const STATX_TYPE: ::c_uint = 0x0001;
1176-
pub const STATX_MODE: ::c_uint = 0x0002;
1177-
pub const STATX_NLINK: ::c_uint = 0x0004;
1178-
pub const STATX_UID: ::c_uint = 0x0008;
1179-
pub const STATX_GID: ::c_uint = 0x0010;
1180-
pub const STATX_ATIME: ::c_uint = 0x0020;
1181-
pub const STATX_MTIME: ::c_uint = 0x0040;
1182-
pub const STATX_CTIME: ::c_uint = 0x0080;
1183-
pub const STATX_INO: ::c_uint = 0x0100;
1184-
pub const STATX_SIZE: ::c_uint = 0x0200;
1185-
pub const STATX_BLOCKS: ::c_uint = 0x0400;
1186-
pub const STATX_BASIC_STATS: ::c_uint = 0x07ff;
1187-
pub const STATX_BTIME: ::c_uint = 0x0800;
1188-
pub const STATX_MNT_ID: ::c_uint = 0x1000;
1189-
pub const STATX_DIOALIGN: ::c_uint = 0x2000;
1190-
pub const STATX_ALL: ::c_uint = 0x0fff;
1191-
pub const STATX__RESERVED: ::c_int = 0x80000000;
1192-
pub const STATX_ATTR_COMPRESSED: ::c_int = 0x0004;
1193-
pub const STATX_ATTR_IMMUTABLE: ::c_int = 0x0010;
1194-
pub const STATX_ATTR_APPEND: ::c_int = 0x0020;
1195-
pub const STATX_ATTR_NODUMP: ::c_int = 0x0040;
1196-
pub const STATX_ATTR_ENCRYPTED: ::c_int = 0x0800;
1197-
pub const STATX_ATTR_AUTOMOUNT: ::c_int = 0x1000;
1198-
pub const STATX_ATTR_MOUNT_ROOT: ::c_int = 0x2000;
1199-
pub const STATX_ATTR_VERITY: ::c_int = 0x00100000;
1200-
pub const STATX_ATTR_DAX: ::c_int = 0x00200000;
1201-
12021138
pub const SOMAXCONN: ::c_int = 4096;
12031139

12041140
// linux/mount.h
@@ -1404,13 +1340,6 @@ extern "C" {
14041340
pub fn getpt() -> ::c_int;
14051341
pub fn mallopt(param: ::c_int, value: ::c_int) -> ::c_int;
14061342
pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::timezone) -> ::c_int;
1407-
pub fn statx(
1408-
dirfd: ::c_int,
1409-
pathname: *const c_char,
1410-
flags: ::c_int,
1411-
mask: ::c_uint,
1412-
statxbuf: *mut statx,
1413-
) -> ::c_int;
14141343
pub fn getentropy(buf: *mut ::c_void, buflen: ::size_t) -> ::c_int;
14151344
pub fn getrandom(buf: *mut ::c_void, buflen: ::size_t, flags: ::c_uint) -> ::ssize_t;
14161345
pub fn getauxval(type_: ::c_ulong) -> ::c_ulong;

src/unix/linux_like/mod.rs

+89
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,45 @@ s! {
205205
}
206206
}
207207

208+
cfg_if! {
209+
if #[cfg(any(target_env = "gnu", target_os = "android"))] {
210+
s! {
211+
pub struct statx {
212+
pub stx_mask: ::__u32,
213+
pub stx_blksize: ::__u32,
214+
pub stx_attributes: ::__u64,
215+
pub stx_nlink: ::__u32,
216+
pub stx_uid: ::__u32,
217+
pub stx_gid: ::__u32,
218+
pub stx_mode: ::__u16,
219+
__statx_pad1: [::__u16; 1],
220+
pub stx_ino: ::__u64,
221+
pub stx_size: ::__u64,
222+
pub stx_blocks: ::__u64,
223+
pub stx_attributes_mask: ::__u64,
224+
pub stx_atime: statx_timestamp,
225+
pub stx_btime: statx_timestamp,
226+
pub stx_ctime: statx_timestamp,
227+
pub stx_mtime: statx_timestamp,
228+
pub stx_rdev_major: ::__u32,
229+
pub stx_rdev_minor: ::__u32,
230+
pub stx_dev_major: ::__u32,
231+
pub stx_dev_minor: ::__u32,
232+
pub stx_mnt_id: ::__u64,
233+
pub stx_dio_mem_align: ::__u32,
234+
pub stx_dio_offset_align: ::__u32,
235+
__statx_pad3: [::__u64; 12],
236+
}
237+
238+
pub struct statx_timestamp {
239+
pub tv_sec: ::__s64,
240+
pub tv_nsec: ::__u32,
241+
__statx_timestamp_pad1: [::__s32; 1],
242+
}
243+
}
244+
}
245+
}
246+
208247
s_no_extra_traits! {
209248
#[cfg_attr(
210249
any(
@@ -1529,6 +1568,41 @@ cfg_if! {
15291568
}
15301569
}
15311570

1571+
cfg_if! {
1572+
if #[cfg(any(target_env = "gnu", target_os = "android"))] {
1573+
pub const AT_STATX_SYNC_TYPE: ::c_int = 0x6000;
1574+
pub const AT_STATX_SYNC_AS_STAT: ::c_int = 0x0000;
1575+
pub const AT_STATX_FORCE_SYNC: ::c_int = 0x2000;
1576+
pub const AT_STATX_DONT_SYNC: ::c_int = 0x4000;
1577+
pub const STATX_TYPE: ::c_uint = 0x0001;
1578+
pub const STATX_MODE: ::c_uint = 0x0002;
1579+
pub const STATX_NLINK: ::c_uint = 0x0004;
1580+
pub const STATX_UID: ::c_uint = 0x0008;
1581+
pub const STATX_GID: ::c_uint = 0x0010;
1582+
pub const STATX_ATIME: ::c_uint = 0x0020;
1583+
pub const STATX_MTIME: ::c_uint = 0x0040;
1584+
pub const STATX_CTIME: ::c_uint = 0x0080;
1585+
pub const STATX_INO: ::c_uint = 0x0100;
1586+
pub const STATX_SIZE: ::c_uint = 0x0200;
1587+
pub const STATX_BLOCKS: ::c_uint = 0x0400;
1588+
pub const STATX_BASIC_STATS: ::c_uint = 0x07ff;
1589+
pub const STATX_BTIME: ::c_uint = 0x0800;
1590+
pub const STATX_ALL: ::c_uint = 0x0fff;
1591+
pub const STATX_MNT_ID: ::c_uint = 0x1000;
1592+
pub const STATX_DIOALIGN: ::c_uint = 0x2000;
1593+
pub const STATX__RESERVED: ::c_int = 0x80000000;
1594+
pub const STATX_ATTR_COMPRESSED: ::c_int = 0x0004;
1595+
pub const STATX_ATTR_IMMUTABLE: ::c_int = 0x0010;
1596+
pub const STATX_ATTR_APPEND: ::c_int = 0x0020;
1597+
pub const STATX_ATTR_NODUMP: ::c_int = 0x0040;
1598+
pub const STATX_ATTR_ENCRYPTED: ::c_int = 0x0800;
1599+
pub const STATX_ATTR_AUTOMOUNT: ::c_int = 0x1000;
1600+
pub const STATX_ATTR_MOUNT_ROOT: ::c_int = 0x2000;
1601+
pub const STATX_ATTR_VERITY: ::c_int = 0x100000;
1602+
pub const STATX_ATTR_DAX: ::c_int = 0x200000;
1603+
}
1604+
}
1605+
15321606
const_fn! {
15331607
{const} fn CMSG_ALIGN(len: usize) -> usize {
15341608
len + ::mem::size_of::<usize>() - 1 & !(::mem::size_of::<usize>() - 1)
@@ -1888,6 +1962,21 @@ cfg_if! {
18881962
}
18891963
}
18901964

1965+
// The statx syscall, available on some libcs.
1966+
cfg_if! {
1967+
if #[cfg(any(target_env = "gnu", target_os = "android"))] {
1968+
extern "C" {
1969+
pub fn statx(
1970+
dirfd: ::c_int,
1971+
pathname: *const ::c_char,
1972+
flags: ::c_int,
1973+
mask: ::c_uint,
1974+
statxbuf: *mut statx,
1975+
) -> ::c_int;
1976+
}
1977+
}
1978+
}
1979+
18911980
cfg_if! {
18921981
if #[cfg(target_os = "emscripten")] {
18931982
mod emscripten;

0 commit comments

Comments
 (0)