xref: /DragonOS/user/apps/test_statx/src/main.rs (revision f5b2038871d3441e1c7f32439ff422957e7ab828)
1 use libc::syscall;
2 use libc::AT_FDCWD;
3 use std::ffi::CString;
4 
5 #[derive(Debug, Clone, Copy)]
6 #[repr(C)]
7 pub struct Statx {
8     pub stx_mask: u32,
9     pub stx_blksize: u32,
10     pub stx_attributes: u64,
11     pub stx_nlink: u32,
12     pub stx_uid: u32,
13     pub stx_gid: u32,
14     pub stx_mode: u16,
15     __statx_pad1: [u16; 1],
16     pub stx_ino: u64,
17     pub stx_size: u64,
18     pub stx_blocks: u64,
19     pub stx_attributes_mask: u64,
20     pub stx_atime: StatxTimestamp,
21     pub stx_btime: StatxTimestamp,
22     pub stx_ctime: StatxTimestamp,
23     pub stx_mtime: StatxTimestamp,
24     pub stx_rdev_major: u32,
25     pub stx_rdev_minor: u32,
26     pub stx_dev_major: u32,
27     pub stx_dev_minor: u32,
28     pub stx_mnt_id: u64,
29     pub stx_dio_mem_align: u32,
30     pub stx_dio_offset_align: u32,
31     __statx_pad3: [u64; 12],
32 }
33 
34 #[derive(Debug, Clone, Copy)]
35 #[repr(C)]
36 pub struct StatxTimestamp {
37     pub tv_sec: i64,
38     pub tv_nsec: u32,
39     pub __statx_timestamp_pad1: [i32; 1],
40 }
41 
42 fn main() {
43     let path = CString::new("/bin/about.elf").expect("Failed to create CString");
44     let mut statxbuf: Statx = unsafe { std::mem::zeroed() };
45     let x = sc::nr::STATX as i64;
46 
47     let result = unsafe {
48         syscall(
49             x,
50             AT_FDCWD,
51             path.as_ptr(),
52             libc::AT_SYMLINK_NOFOLLOW,
53             0x7ff,
54             &mut statxbuf,
55         )
56     };
57 
58     if result != -1 {
59         println!("statx succeeded: {:?}", statxbuf);
60     } else {
61         eprintln!("statx failed");
62     }
63 }
64