1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#![no_std]
#![cfg(target_os = "linux")]
#![deny(warnings)]
use libc::syscall;
use libc::{c_char, c_int, c_uint};
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct statx_timestamp {
pub tv_sec: i64,
pub tv_nsec: u32,
__reserved: i32,
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct statx {
pub stx_mask: u32,
pub stx_blksize: u32,
pub stx_attributes: u64,
pub stx_nlink: u32,
pub stx_uid: u32,
pub stx_gid: u32,
pub stx_mode: u16,
__spare0: [u16; 1],
pub stx_ino: u64,
pub stx_size: u64,
pub stx_blocks: u64,
pub stx_attributes_mask: u64,
pub stx_atime: statx_timestamp, pub stx_btime: statx_timestamp, pub stx_ctime: statx_timestamp, pub stx_mtime: statx_timestamp, pub stx_rdev_major: u32,
pub stx_rdev_minor: u32,
pub stx_dev_major: u32,
pub stx_dev_minor: u32,
__spare2: [u64; 14],
}
mod syscall;
pub use syscall::SYS_statx;
pub const AT_FDCWD: c_int = -100;
pub const AT_SYMLINK_NOFOLLOW: c_int = 0x100;
pub const AT_REMOVEDIR: c_int = 0x200;
pub const AT_SYMLINK_FOLLOW: c_int = 0x400;
pub const AT_NO_AUTOMOUNT: c_int = 0x800;
pub const AT_EMPTY_PATH: c_int = 0x1000;
pub const AT_STATX_SYNC_AS_STAT: c_int = 0x0000;
pub const AT_STATX_FORCE_SYNC: c_int = 0x2000;
pub const AT_STATX_SYNC_TYPE: c_int = 0x6000;
pub const AT_STATX_DONT_SYNC: c_int = 0x4000;
pub const STATX_TYPE: c_uint = 0x0000_0001;
pub const STATX_MODE: c_uint = 0x0000_0002;
pub const STATX_NLINK: c_uint = 0x0000_0004;
pub const STATX_UID: c_uint = 0x0000_0008;
pub const STATX_GID: c_uint = 0x0000_0010;
pub const STATX_ATIME: c_uint = 0x0000_0020;
pub const STATX_MTIME: c_uint = 0x0000_0040;
pub const STATX_CTIME: c_uint = 0x0000_0080;
pub const STATX_INO: c_uint = 0x0000_0100;
pub const STATX_SIZE: c_uint = 0x0000_0200;
pub const STATX_BLOCKS: c_uint = 0x0000_0400;
pub const STATX_BASIC_STATS: c_uint = 0x0000_07ff;
pub const STATX_BTIME: c_uint = 0x0000_0800;
pub const STATX_ALL: c_uint = 0x0000_0fff;
pub const STATX__RESERVED: c_uint = 0x8000_0000;
pub const STATX_ATTR_COMPRESSED: c_int = 0x0000_0004;
pub const STATX_ATTR_IMMUTABLE: c_int = 0x0000_0010;
pub const STATX_ATTR_APPEND: c_int = 0x0000_0020;
pub const STATX_ATTR_NODUMP: c_int = 0x0000_0040;
pub const STATX_ATTR_ENCRYPTED: c_int = 0x0000_0800;
pub const STATX_ATTR_AUTOMOUNT: c_int = 0x0000_1000;
pub unsafe fn statx(
dirfd: c_int,
pathname: *const c_char,
flags: c_int,
mask: c_uint,
statxbuf: *mut statx,
) -> c_int {
syscall(SYS_statx, dirfd, pathname, flags, mask, statxbuf) as c_int
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn check_struct_layout() {
use core::mem::size_of;
use memoffset::offset_of;
assert_eq!(size_of::<statx>(), 0x100);
assert_eq!(size_of::<statx_timestamp>(), 16);
assert_eq!(offset_of!(statx, stx_mask), 0);
assert_eq!(offset_of!(statx, stx_nlink), 0x10);
assert_eq!(offset_of!(statx, stx_ino), 0x20);
assert_eq!(offset_of!(statx, stx_atime), 0x40);
assert_eq!(offset_of!(statx, stx_rdev_major), 0x80);
assert_eq!(offset_of!(statx, __spare2), 0x90);
}
}