main.rs 1.5 KB

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