Skip to content

Commit d56ca22

Browse files
committed
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.
1 parent 7f2e466 commit d56ca22

File tree

3 files changed

+48
-80
lines changed

3 files changed

+48
-80
lines changed

src/unix/linux_like/android/mod.rs

Lines changed: 0 additions & 40 deletions
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! {
@@ -4158,13 +4125,6 @@ extern "C" {
41584125
newpath: *const ::c_char,
41594126
flags: ::c_uint,
41604127
) -> ::c_int;
4161-
pub fn statx(
4162-
dirfd: ::c_int,
4163-
pathname: *const c_char,
4164-
flags: ::c_int,
4165-
mask: ::c_uint,
4166-
statxbuf: *mut statx,
4167-
) -> ::c_int;
41684128

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

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

Lines changed: 0 additions & 40 deletions
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,
@@ -1360,13 +1327,6 @@ extern "C" {
13601327
pub fn getpt() -> ::c_int;
13611328
pub fn mallopt(param: ::c_int, value: ::c_int) -> ::c_int;
13621329
pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::timezone) -> ::c_int;
1363-
pub fn statx(
1364-
dirfd: ::c_int,
1365-
pathname: *const c_char,
1366-
flags: ::c_int,
1367-
mask: ::c_uint,
1368-
statxbuf: *mut statx,
1369-
) -> ::c_int;
13701330
pub fn getentropy(buf: *mut ::c_void, buflen: ::size_t) -> ::c_int;
13711331
pub fn getrandom(buf: *mut ::c_void, buflen: ::size_t, flags: ::c_uint) -> ::ssize_t;
13721332
pub fn getauxval(type_: ::c_ulong) -> ::c_ulong;

src/unix/linux_like/mod.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,39 @@ s! {
204204
pub msg_hdr: ::msghdr,
205205
pub msg_len: ::c_uint,
206206
}
207+
208+
pub struct statx {
209+
pub stx_mask: u32,
210+
pub stx_blksize: u32,
211+
pub stx_attributes: u64,
212+
pub stx_nlink: u32,
213+
pub stx_uid: u32,
214+
pub stx_gid: u32,
215+
pub stx_mode: u16,
216+
__statx_pad1: [u16; 1],
217+
pub stx_ino: u64,
218+
pub stx_size: u64,
219+
pub stx_blocks: u64,
220+
pub stx_attributes_mask: u64,
221+
pub stx_atime: statx_timestamp,
222+
pub stx_btime: statx_timestamp,
223+
pub stx_ctime: statx_timestamp,
224+
pub stx_mtime: statx_timestamp,
225+
pub stx_rdev_major: u32,
226+
pub stx_rdev_minor: u32,
227+
pub stx_dev_major: u32,
228+
pub stx_dev_minor: u32,
229+
pub stx_mnt_id: u64,
230+
pub stx_dio_mem_align: u32,
231+
pub stx_dio_offset_align: u32,
232+
__statx_pad3: [u64; 12],
233+
}
234+
235+
pub struct statx_timestamp {
236+
pub tv_sec: i64,
237+
pub tv_nsec: u32,
238+
__statx_timestamp_pad1: [i32; 1],
239+
}
207240
}
208241

209242
s_no_extra_traits! {
@@ -1886,6 +1919,21 @@ cfg_if! {
18861919
}
18871920
}
18881921

1922+
// The statx syscall, available on some libcs.
1923+
cfg_if! {
1924+
if #[cfg(any(target_env = "gnu", target_os = "android"))] {
1925+
extern "C" {
1926+
pub fn statx(
1927+
dirfd: ::c_int,
1928+
pathname: *const c_char,
1929+
flags: ::c_int,
1930+
mask: ::c_uint,
1931+
statxbuf: *mut statx,
1932+
) -> ::c_int;
1933+
}
1934+
}
1935+
}
1936+
18891937
cfg_if! {
18901938
if #[cfg(target_os = "emscripten")] {
18911939
mod emscripten;

0 commit comments

Comments
 (0)