xref: /drstd/src/std/os/freebsd/fs.rs (revision 86982c5e9b2eaa583327251616ee822c36288824)
1 use crate::std::fs::Metadata;
2 use crate::std::sys_common::AsInner;
3 use dlibc;
4 
5 #[allow(deprecated)]
6 use crate::std::os::freebsd::raw;
7 
8 /// OS-specific extensions to [`fs::Metadata`].
9 ///
10 /// [`fs::Metadata`]: crate::std::fs::Metadata
11 pub trait MetadataExt {
12     /// Gain a reference to the underlying `stat` structure which contains
13     /// the raw information returned by the OS.
14     ///
15     /// The contents of the returned `stat` are **not** consistent across
16     /// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the
17     /// cross-Unix abstractions contained within the raw stat.
18     #[deprecated(
19         since = "1.8.0",
20         note = "deprecated in favor of the accessor \
21                 methods of this trait"
22     )]
23     #[allow(deprecated)]
24     fn as_raw_stat(&self) -> &raw::stat;
25 
26     fn st_dev(&self) -> u64;
27     fn st_ino(&self) -> u64;
28     fn st_mode(&self) -> u32;
29     fn st_nlink(&self) -> u64;
30     fn st_uid(&self) -> u32;
31     fn st_gid(&self) -> u32;
32     fn st_rdev(&self) -> u64;
33     fn st_size(&self) -> u64;
34     fn st_atime(&self) -> i64;
35     fn st_atime_nsec(&self) -> i64;
36     fn st_mtime(&self) -> i64;
37     fn st_mtime_nsec(&self) -> i64;
38     fn st_ctime(&self) -> i64;
39     fn st_ctime_nsec(&self) -> i64;
40     fn st_birthtime(&self) -> i64;
41     fn st_birthtime_nsec(&self) -> i64;
42     fn st_blksize(&self) -> u64;
43     fn st_blocks(&self) -> u64;
44     fn st_flags(&self) -> u32;
45     fn st_gen(&self) -> u32;
46     fn st_lspare(&self) -> u32;
47 }
48 
49 impl MetadataExt for Metadata {
50     #[allow(deprecated)]
51     fn as_raw_stat(&self) -> &raw::stat {
52         // The methods below use dlibc::stat, so they work fine when libc is built with FreeBSD 12 ABI.
53         // This method would just return nonsense.
54         #[cfg(freebsd12)]
55         panic!("as_raw_stat not supported with FreeBSD 12 ABI");
56         #[cfg(not(freebsd12))]
57         unsafe {
58             &*(self.as_inner().as_inner() as *const dlibc::stat as *const raw::stat)
59         }
60     }
61     fn st_dev(&self) -> u64 {
62         self.as_inner().as_inner().st_dev as u64
63     }
64     fn st_ino(&self) -> u64 {
65         self.as_inner().as_inner().st_ino as u64
66     }
67     fn st_mode(&self) -> u32 {
68         self.as_inner().as_inner().st_mode as u32
69     }
70     fn st_nlink(&self) -> u64 {
71         self.as_inner().as_inner().st_nlink as u64
72     }
73     fn st_uid(&self) -> u32 {
74         self.as_inner().as_inner().st_uid as u32
75     }
76     fn st_gid(&self) -> u32 {
77         self.as_inner().as_inner().st_gid as u32
78     }
79     fn st_rdev(&self) -> u64 {
80         self.as_inner().as_inner().st_rdev as u64
81     }
82     fn st_size(&self) -> u64 {
83         self.as_inner().as_inner().st_size as u64
84     }
85     fn st_atime(&self) -> i64 {
86         self.as_inner().as_inner().st_atime as i64
87     }
88     fn st_atime_nsec(&self) -> i64 {
89         self.as_inner().as_inner().st_atime_nsec as i64
90     }
91     fn st_mtime(&self) -> i64 {
92         self.as_inner().as_inner().st_mtime as i64
93     }
94     fn st_mtime_nsec(&self) -> i64 {
95         self.as_inner().as_inner().st_mtime_nsec as i64
96     }
97     fn st_ctime(&self) -> i64 {
98         self.as_inner().as_inner().st_ctime as i64
99     }
100     fn st_ctime_nsec(&self) -> i64 {
101         self.as_inner().as_inner().st_ctime_nsec as i64
102     }
103     fn st_birthtime(&self) -> i64 {
104         self.as_inner().as_inner().st_birthtime as i64
105     }
106     fn st_birthtime_nsec(&self) -> i64 {
107         self.as_inner().as_inner().st_birthtime_nsec as i64
108     }
109     fn st_blksize(&self) -> u64 {
110         self.as_inner().as_inner().st_blksize as u64
111     }
112     fn st_blocks(&self) -> u64 {
113         self.as_inner().as_inner().st_blocks as u64
114     }
115     fn st_gen(&self) -> u32 {
116         self.as_inner().as_inner().st_gen as u32
117     }
118     fn st_flags(&self) -> u32 {
119         self.as_inner().as_inner().st_flags as u32
120     }
121     #[cfg(freebsd12)]
122     fn st_lspare(&self) -> u32 {
123         panic!("st_lspare not supported with FreeBSD 12 ABI");
124     }
125     #[cfg(not(freebsd12))]
126     fn st_lspare(&self) -> u32 {
127         self.as_inner().as_inner().st_lspare as u32
128     }
129 }
130