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