#![no_std]
#![deny(warnings)]
use libc::syscall;
use libc::{__s32, __u16, __u32, __u64, c_char, c_int, c_long, c_uint};
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct statx_timestamp {
pub tv_sec: i64,
pub tc_nsec: __u32,
pub __reserved: __s32,
}
#[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,
pub __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,
pub __spare2: [__u64; 14],
}
#[allow(non_upper_case_globals)]
pub const SYS_statx: c_long = 332;
pub const AT_STATX_SYNC_AS_STAT: c_uint = 0x0000_0000;
pub const AT_STATX_FORCE_SYNC: c_uint = 0x0000_2000;
pub const AT_STATX_DONT_SYNC: c_uint = 0x0000_4000;
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: __u64 = 0x0000_0004;
pub const STATX_ATTR_IMMUTABLE: __u64 = 0x0000_0010;
pub const STATX_ATTR_APPEND: __u64 = 0x0000_0020;
pub const STATX_ATTR_NODUMP: __u64 = 0x0000_0040;
pub const STATX_ATTR_ENCRYPTED: __u64 = 0x0000_0800;
pub const STATX_ATTR_AUTOMOUNT: __u64 = 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 memoffset::offset_of;
use core::mem::size_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);
}
}