linux_stat/raw/
aarch64.rs

1#![allow(non_camel_case_types, non_upper_case_globals)]
2
3use linux_syscalls::Sysno;
4
5use crate::{Dev, Dev64, Timestamp};
6
7pub const SYS_FSTATAT: Sysno = Sysno::fstatat;
8
9/// `fstatat()` file informations representation.
10#[repr(C)]
11#[derive(Copy, Clone)]
12pub struct stat {
13    st_dev: Dev64,
14    st_ino: u64,
15    st_mode: u32,
16    st_nlink: u32,
17    st_uid: u32,
18    st_gid: u32,
19    st_rdev: Dev64,
20    __pad0: u64,
21    st_size: i64,
22    st_blksize: i32,
23    st_blocks: i64,
24    st_atime: i64,
25    st_atime_nsec: u32,
26    __pad1: u32,
27    st_mtime: i64,
28    st_mtime_nsec: u32,
29    __pad2: u32,
30    st_ctime: i64,
31    st_ctime_nsec: u32,
32    __pad3: [u32; 3],
33}
34
35impl stat {
36    /// Returns the device on which this file (inode) resides.
37    #[inline]
38    pub const fn dev(&self) -> Dev {
39        Dev::B64(self.st_dev)
40    }
41
42    /// Returns the inode number of the file.
43    #[inline]
44    pub const fn inode(&self) -> u64 {
45        self.st_ino
46    }
47
48    /// Returns the number of hard links on a file.
49    #[inline]
50    pub const fn nlink(&self) -> u32 {
51        self.st_nlink
52    }
53
54    #[inline]
55    pub(crate) const fn raw_mode(&self) -> u16 {
56        self.st_mode as u16
57    }
58
59    /// Returns the user ID of the owner of the file.
60    #[inline]
61    pub const fn uid(&self) -> u32 {
62        self.st_uid
63    }
64
65    /// Returns the ID of the group owner of the file.
66    #[inline]
67    pub const fn gid(&self) -> u32 {
68        self.st_gid
69    }
70
71    /// Returns the device that this file (inode) represents if the file is of
72    /// block or character device type
73    #[inline]
74    pub const fn rdev(&self) -> Dev {
75        Dev::B64(self.st_rdev)
76    }
77
78    /// Returns the size of the file (if it is a regular file or a symbolic
79    /// link) in bytes. The size of a symbolic link is the length of
80    /// the pathname it contains, without a terminating null byte.
81    #[inline]
82    pub const fn size(&self) -> i64 {
83        self.st_size
84    }
85
86    /// Returns the "preferred" block size for efficient filesystem I/O.
87    /// (Writing to a file in smaller chunks may cause an inefficient
88    /// read-modify-rewrite.)
89    #[inline]
90    pub const fn block_size(&self) -> i32 {
91        self.st_blksize
92    }
93
94    /// Returns the number of blocks allocated to the file on the medium, in
95    /// 512-byte units. (This may be smaller than stx_size/512 when the
96    /// file has holes.)
97    #[inline]
98    pub const fn blocks(&self) -> i64 {
99        self.st_blocks
100    }
101
102    /// Returns the file's last access timestamp.
103    #[inline]
104    pub const fn atime(&self) -> Timestamp {
105        Timestamp {
106            secs: self.st_atime,
107            nsecs: self.st_atime_nsec,
108        }
109    }
110
111    /// Returns the file's last modification timestamp.
112    #[inline]
113    pub const fn mtime(&self) -> Timestamp {
114        Timestamp {
115            secs: self.st_mtime,
116            nsecs: self.st_mtime_nsec,
117        }
118    }
119
120    /// Returns the file's last status change timestamp.
121    #[inline]
122    pub const fn ctime(&self) -> Timestamp {
123        Timestamp {
124            secs: self.st_ctime,
125            nsecs: self.st_ctime_nsec,
126        }
127    }
128
129    #[doc(hidden)]
130    pub fn uninit() -> core::mem::MaybeUninit<Self> {
131        let mut res = core::mem::MaybeUninit::uninit();
132        unsafe {
133            let buf: &mut Self = &mut *res.as_mut_ptr();
134            buf.__pad0 = 0;
135            buf.__pad1 = 0;
136            buf.__pad2 = 0;
137            core::ptr::write_bytes(
138                &mut buf.__pad3[0] as *mut u32 as *mut u8,
139                0,
140                core::mem::size_of_val(&buf.__pad3),
141            );
142        }
143        res
144    }
145}