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