1 #![stable(feature = "metadata_ext", since = "1.1.0")]
3 use crate::fs
::Metadata
;
4 use crate::sys_common
::AsInner
;
7 use crate::os
::linux
::raw
;
9 /// OS-specific extensions to [`fs::Metadata`].
11 /// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html
12 #[stable(feature = "metadata_ext", since = "1.1.0")]
13 pub trait MetadataExt
{
14 /// Gain a reference to the underlying `stat` structure which contains
15 /// the raw information returned by the OS.
17 /// The contents of the returned [`stat`] are **not** consistent across
18 /// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the
19 /// cross-Unix abstractions contained within the raw stat.
21 /// [`stat`]: ../../../../std/os/linux/raw/struct.stat.html
28 /// use std::os::linux::fs::MetadataExt;
30 /// fn main() -> io::Result<()> {
31 /// let meta = fs::metadata("some_file")?;
32 /// let stat = meta.as_raw_stat();
36 #[stable(feature = "metadata_ext", since = "1.1.0")]
37 #[rustc_deprecated(since = "1.8.0", reason = "other methods of this trait are now prefered")]
39 fn as_raw_stat(&self) -> &raw
::stat
;
41 /// Returns the device ID on which this file resides.
48 /// use std::os::linux::fs::MetadataExt;
50 /// fn main() -> io::Result<()> {
51 /// let meta = fs::metadata("some_file")?;
52 /// println!("{}", meta.st_dev());
56 #[stable(feature = "metadata_ext2", since = "1.8.0")]
57 fn st_dev(&self) -> u64;
58 /// Returns the inode number.
65 /// use std::os::linux::fs::MetadataExt;
67 /// fn main() -> io::Result<()> {
68 /// let meta = fs::metadata("some_file")?;
69 /// println!("{}", meta.st_ino());
73 #[stable(feature = "metadata_ext2", since = "1.8.0")]
74 fn st_ino(&self) -> u64;
75 /// Returns the file type and mode.
82 /// use std::os::linux::fs::MetadataExt;
84 /// fn main() -> io::Result<()> {
85 /// let meta = fs::metadata("some_file")?;
86 /// println!("{}", meta.st_mode());
90 #[stable(feature = "metadata_ext2", since = "1.8.0")]
91 fn st_mode(&self) -> u32;
92 /// Returns the number of hard links to file.
99 /// use std::os::linux::fs::MetadataExt;
101 /// fn main() -> io::Result<()> {
102 /// let meta = fs::metadata("some_file")?;
103 /// println!("{}", meta.st_nlink());
107 #[stable(feature = "metadata_ext2", since = "1.8.0")]
108 fn st_nlink(&self) -> u64;
109 /// Returns the user ID of the file owner.
116 /// use std::os::linux::fs::MetadataExt;
118 /// fn main() -> io::Result<()> {
119 /// let meta = fs::metadata("some_file")?;
120 /// println!("{}", meta.st_uid());
124 #[stable(feature = "metadata_ext2", since = "1.8.0")]
125 fn st_uid(&self) -> u32;
126 /// Returns the group ID of the file owner.
133 /// use std::os::linux::fs::MetadataExt;
135 /// fn main() -> io::Result<()> {
136 /// let meta = fs::metadata("some_file")?;
137 /// println!("{}", meta.st_gid());
141 #[stable(feature = "metadata_ext2", since = "1.8.0")]
142 fn st_gid(&self) -> u32;
143 /// Returns the device ID that this file represents. Only relevant for special file.
150 /// use std::os::linux::fs::MetadataExt;
152 /// fn main() -> io::Result<()> {
153 /// let meta = fs::metadata("some_file")?;
154 /// println!("{}", meta.st_rdev());
158 #[stable(feature = "metadata_ext2", since = "1.8.0")]
159 fn st_rdev(&self) -> u64;
160 /// Returns the size of the file (if it is a regular file or a symbolic link) in bytes.
162 /// The size of a symbolic link is the length of the pathname it contains,
163 /// without a terminating null byte.
170 /// use std::os::linux::fs::MetadataExt;
172 /// fn main() -> io::Result<()> {
173 /// let meta = fs::metadata("some_file")?;
174 /// println!("{}", meta.st_size());
178 #[stable(feature = "metadata_ext2", since = "1.8.0")]
179 fn st_size(&self) -> u64;
180 /// Returns the last access time of the file, in seconds since Unix Epoch.
187 /// use std::os::linux::fs::MetadataExt;
189 /// fn main() -> io::Result<()> {
190 /// let meta = fs::metadata("some_file")?;
191 /// println!("{}", meta.st_atime());
195 #[stable(feature = "metadata_ext2", since = "1.8.0")]
196 fn st_atime(&self) -> i64;
197 /// Returns the last access time of the file, in nanoseconds since [`st_atime`].
199 /// [`st_atime`]: #tymethod.st_atime
206 /// use std::os::linux::fs::MetadataExt;
208 /// fn main() -> io::Result<()> {
209 /// let meta = fs::metadata("some_file")?;
210 /// println!("{}", meta.st_atime_nsec());
214 #[stable(feature = "metadata_ext2", since = "1.8.0")]
215 fn st_atime_nsec(&self) -> i64;
216 /// Returns the last modification time of the file, in seconds since Unix Epoch.
223 /// use std::os::linux::fs::MetadataExt;
225 /// fn main() -> io::Result<()> {
226 /// let meta = fs::metadata("some_file")?;
227 /// println!("{}", meta.st_mtime());
231 #[stable(feature = "metadata_ext2", since = "1.8.0")]
232 fn st_mtime(&self) -> i64;
233 /// Returns the last modification time of the file, in nanoseconds since [`st_mtime`].
235 /// [`st_mtime`]: #tymethod.st_mtime
242 /// use std::os::linux::fs::MetadataExt;
244 /// fn main() -> io::Result<()> {
245 /// let meta = fs::metadata("some_file")?;
246 /// println!("{}", meta.st_mtime_nsec());
250 #[stable(feature = "metadata_ext2", since = "1.8.0")]
251 fn st_mtime_nsec(&self) -> i64;
252 /// Returns the last status change time of the file, in seconds since Unix Epoch.
259 /// use std::os::linux::fs::MetadataExt;
261 /// fn main() -> io::Result<()> {
262 /// let meta = fs::metadata("some_file")?;
263 /// println!("{}", meta.st_ctime());
267 #[stable(feature = "metadata_ext2", since = "1.8.0")]
268 fn st_ctime(&self) -> i64;
269 /// Returns the last status change time of the file, in nanoseconds since [`st_ctime`].
271 /// [`st_ctime`]: #tymethod.st_ctime
278 /// use std::os::linux::fs::MetadataExt;
280 /// fn main() -> io::Result<()> {
281 /// let meta = fs::metadata("some_file")?;
282 /// println!("{}", meta.st_ctime_nsec());
286 #[stable(feature = "metadata_ext2", since = "1.8.0")]
287 fn st_ctime_nsec(&self) -> i64;
288 /// Returns the "preferred" blocksize for efficient filesystem I/O.
295 /// use std::os::linux::fs::MetadataExt;
297 /// fn main() -> io::Result<()> {
298 /// let meta = fs::metadata("some_file")?;
299 /// println!("{}", meta.st_blksize());
303 #[stable(feature = "metadata_ext2", since = "1.8.0")]
304 fn st_blksize(&self) -> u64;
305 /// Returns the number of blocks allocated to the file, 512-byte units.
312 /// use std::os::linux::fs::MetadataExt;
314 /// fn main() -> io::Result<()> {
315 /// let meta = fs::metadata("some_file")?;
316 /// println!("{}", meta.st_blocks());
320 #[stable(feature = "metadata_ext2", since = "1.8.0")]
321 fn st_blocks(&self) -> u64;
324 #[stable(feature = "metadata_ext", since = "1.1.0")]
325 impl MetadataExt
for Metadata
{
327 fn as_raw_stat(&self) -> &raw
::stat
{
328 unsafe { &*(self.as_inner().as_inner() as *const libc::stat64 as *const raw::stat) }
330 fn st_dev(&self) -> u64 {
331 self.as_inner().as_inner().st_dev
as u64
333 fn st_ino(&self) -> u64 {
334 self.as_inner().as_inner().st_ino
as u64
336 fn st_mode(&self) -> u32 {
337 self.as_inner().as_inner().st_mode
as u32
339 fn st_nlink(&self) -> u64 {
340 self.as_inner().as_inner().st_nlink
as u64
342 fn st_uid(&self) -> u32 {
343 self.as_inner().as_inner().st_uid
as u32
345 fn st_gid(&self) -> u32 {
346 self.as_inner().as_inner().st_gid
as u32
348 fn st_rdev(&self) -> u64 {
349 self.as_inner().as_inner().st_rdev
as u64
351 fn st_size(&self) -> u64 {
352 self.as_inner().as_inner().st_size
as u64
354 fn st_atime(&self) -> i64 {
355 self.as_inner().as_inner().st_atime
as i64
357 fn st_atime_nsec(&self) -> i64 {
358 self.as_inner().as_inner().st_atime_nsec
as i64
360 fn st_mtime(&self) -> i64 {
361 self.as_inner().as_inner().st_mtime
as i64
363 fn st_mtime_nsec(&self) -> i64 {
364 self.as_inner().as_inner().st_mtime_nsec
as i64
366 fn st_ctime(&self) -> i64 {
367 self.as_inner().as_inner().st_ctime
as i64
369 fn st_ctime_nsec(&self) -> i64 {
370 self.as_inner().as_inner().st_ctime_nsec
as i64
372 fn st_blksize(&self) -> u64 {
373 self.as_inner().as_inner().st_blksize
as u64
375 fn st_blocks(&self) -> u64 {
376 self.as_inner().as_inner().st_blocks
as u64