Skip to main content

rustix/backend/linux_raw/fs/
types.rs

1use crate::ffi;
2#[allow(unused_imports)]
3use crate::types::Padding;
4use bitflags::bitflags;
5
6bitflags! {
7    /// `*_OK` constants for use with [`accessat`].
8    ///
9    /// [`accessat`]: fn.accessat.html
10    #[repr(transparent)]
11    #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
12    pub struct Access: ffi::c_uint {
13        /// `R_OK`
14        const READ_OK = linux_raw_sys::general::R_OK;
15
16        /// `W_OK`
17        const WRITE_OK = linux_raw_sys::general::W_OK;
18
19        /// `X_OK`
20        const EXEC_OK = linux_raw_sys::general::X_OK;
21
22        /// `F_OK`
23        const EXISTS = linux_raw_sys::general::F_OK;
24
25        /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
26        const _ = !0;
27    }
28}
29
30bitflags! {
31    /// `AT_*` constants for use with [`openat`], [`statat`], and other `*at`
32    /// functions.
33    ///
34    /// [`openat`]: crate::fs::openat
35    /// [`statat`]: crate::fs::statat
36    #[repr(transparent)]
37    #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
38    pub struct AtFlags: ffi::c_uint {
39        /// `AT_SYMLINK_NOFOLLOW`
40        const SYMLINK_NOFOLLOW = linux_raw_sys::general::AT_SYMLINK_NOFOLLOW;
41
42        /// `AT_EACCESS`
43        const EACCESS = linux_raw_sys::general::AT_EACCESS;
44
45        /// `AT_REMOVEDIR`
46        const REMOVEDIR = linux_raw_sys::general::AT_REMOVEDIR;
47
48        /// `AT_SYMLINK_FOLLOW`
49        const SYMLINK_FOLLOW = linux_raw_sys::general::AT_SYMLINK_FOLLOW;
50
51        /// `AT_NO_AUTOMOUNT`
52        const NO_AUTOMOUNT = linux_raw_sys::general::AT_NO_AUTOMOUNT;
53
54        /// `AT_EMPTY_PATH`
55        const EMPTY_PATH = linux_raw_sys::general::AT_EMPTY_PATH;
56
57        /// `AT_STATX_SYNC_AS_STAT`
58        const STATX_SYNC_AS_STAT = linux_raw_sys::general::AT_STATX_SYNC_AS_STAT;
59
60        /// `AT_STATX_FORCE_SYNC`
61        const STATX_FORCE_SYNC = linux_raw_sys::general::AT_STATX_FORCE_SYNC;
62
63        /// `AT_STATX_DONT_SYNC`
64        const STATX_DONT_SYNC = linux_raw_sys::general::AT_STATX_DONT_SYNC;
65
66        /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
67        const _ = !0;
68    }
69}
70
71bitflags! {
72    /// `S_I*` constants for use with [`openat`], [`openat2`], [`chmodat`], and [`fchmod`].
73    ///
74    /// [`openat`]: crate::fs::openat
75    /// [`openat2`]: crate::fs::openat2
76    /// [`chmodat`]: crate::fs::chmodat
77    /// [`fchmod`]: crate::fs::fchmod
78    #[repr(transparent)]
79    #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
80    pub struct Mode: RawMode {
81        /// `S_IRWXU`
82        const RWXU = linux_raw_sys::general::S_IRWXU;
83
84        /// `S_IRUSR`
85        const RUSR = linux_raw_sys::general::S_IRUSR;
86
87        /// `S_IWUSR`
88        const WUSR = linux_raw_sys::general::S_IWUSR;
89
90        /// `S_IXUSR`
91        const XUSR = linux_raw_sys::general::S_IXUSR;
92
93        /// `S_IRWXG`
94        const RWXG = linux_raw_sys::general::S_IRWXG;
95
96        /// `S_IRGRP`
97        const RGRP = linux_raw_sys::general::S_IRGRP;
98
99        /// `S_IWGRP`
100        const WGRP = linux_raw_sys::general::S_IWGRP;
101
102        /// `S_IXGRP`
103        const XGRP = linux_raw_sys::general::S_IXGRP;
104
105        /// `S_IRWXO`
106        const RWXO = linux_raw_sys::general::S_IRWXO;
107
108        /// `S_IROTH`
109        const ROTH = linux_raw_sys::general::S_IROTH;
110
111        /// `S_IWOTH`
112        const WOTH = linux_raw_sys::general::S_IWOTH;
113
114        /// `S_IXOTH`
115        const XOTH = linux_raw_sys::general::S_IXOTH;
116
117        /// `S_ISUID`
118        const SUID = linux_raw_sys::general::S_ISUID;
119
120        /// `S_ISGID`
121        const SGID = linux_raw_sys::general::S_ISGID;
122
123        /// `S_ISVTX`
124        const SVTX = linux_raw_sys::general::S_ISVTX;
125
126        /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
127        const _ = !0;
128    }
129}
130
131impl Mode {
132    /// Construct a `Mode` from the mode bits of the `st_mode` field of a
133    /// `Mode`.
134    #[inline]
135    pub const fn from_raw_mode(st_mode: RawMode) -> Self {
136        Self::from_bits_truncate(st_mode & !linux_raw_sys::general::S_IFMT)
137    }
138
139    /// Construct an `st_mode` value from a `Mode`.
140    #[inline]
141    pub const fn as_raw_mode(self) -> RawMode {
142        self.bits()
143    }
144}
145
146impl From<RawMode> for Mode {
147    /// Support conversions from raw mode values to `Mode`.
148    ///
149    /// ```
150    /// use rustix::fs::{Mode, RawMode};
151    /// assert_eq!(Mode::from(0o700), Mode::RWXU);
152    /// ```
153    #[inline]
154    fn from(st_mode: RawMode) -> Self {
155        Self::from_raw_mode(st_mode)
156    }
157}
158
159impl From<Mode> for RawMode {
160    /// Support conversions from `Mode` to raw mode values.
161    ///
162    /// ```
163    /// use rustix::fs::{Mode, RawMode};
164    /// assert_eq!(RawMode::from(Mode::RWXU), 0o700);
165    /// ```
166    #[inline]
167    fn from(mode: Mode) -> Self {
168        mode.as_raw_mode()
169    }
170}
171
172bitflags! {
173    /// `O_*` constants for use with [`openat`].
174    ///
175    /// [`openat`]: crate::fs::openat
176    #[repr(transparent)]
177    #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
178    pub struct OFlags: ffi::c_uint {
179        /// `O_ACCMODE`
180        const ACCMODE = linux_raw_sys::general::O_ACCMODE;
181
182        /// Similar to `ACCMODE`, but just includes the read/write flags, and
183        /// no other flags.
184        ///
185        /// On some platforms, `PATH` may be included in `ACCMODE`, when
186        /// sometimes we really just want the read/write bits. Caution is
187        /// indicated, as the presence of `PATH` may mean that the read/write
188        /// bits don't have their usual meaning.
189        const RWMODE = linux_raw_sys::general::O_RDONLY |
190                       linux_raw_sys::general::O_WRONLY |
191                       linux_raw_sys::general::O_RDWR;
192
193        /// `O_APPEND`
194        const APPEND = linux_raw_sys::general::O_APPEND;
195
196        /// `O_CREAT`
197        #[doc(alias = "CREAT")]
198        const CREATE = linux_raw_sys::general::O_CREAT;
199
200        /// `O_DIRECTORY`
201        const DIRECTORY = linux_raw_sys::general::O_DIRECTORY;
202
203        /// `O_DSYNC`
204        const DSYNC = linux_raw_sys::general::O_SYNC;
205
206        /// `O_EXCL`
207        const EXCL = linux_raw_sys::general::O_EXCL;
208
209        /// `O_FSYNC`
210        const FSYNC = linux_raw_sys::general::O_SYNC;
211
212        /// `O_NOFOLLOW`
213        const NOFOLLOW = linux_raw_sys::general::O_NOFOLLOW;
214
215        /// `O_NONBLOCK`
216        const NONBLOCK = linux_raw_sys::general::O_NONBLOCK;
217
218        /// `O_RDONLY`
219        const RDONLY = linux_raw_sys::general::O_RDONLY;
220
221        /// `O_WRONLY`
222        const WRONLY = linux_raw_sys::general::O_WRONLY;
223
224        /// `O_RDWR`
225        ///
226        /// This is not equal to `RDONLY | WRONLY`. It's a distinct flag.
227        const RDWR = linux_raw_sys::general::O_RDWR;
228
229        /// `O_NOCTTY`
230        const NOCTTY = linux_raw_sys::general::O_NOCTTY;
231
232        /// `O_RSYNC`
233        const RSYNC = linux_raw_sys::general::O_SYNC;
234
235        /// `O_SYNC`
236        const SYNC = linux_raw_sys::general::O_SYNC;
237
238        /// `O_TRUNC`
239        const TRUNC = linux_raw_sys::general::O_TRUNC;
240
241        /// `O_PATH`
242        const PATH = linux_raw_sys::general::O_PATH;
243
244        /// `O_CLOEXEC`
245        const CLOEXEC = linux_raw_sys::general::O_CLOEXEC;
246
247        /// `O_TMPFILE`
248        const TMPFILE = linux_raw_sys::general::O_TMPFILE;
249
250        /// `O_NOATIME`
251        const NOATIME = linux_raw_sys::general::O_NOATIME;
252
253        /// `O_DIRECT`
254        const DIRECT = linux_raw_sys::general::O_DIRECT;
255
256        /// `O_LARGEFILE`
257        ///
258        /// Rustix and/or libc will automatically set this flag when
259        /// appropriate in the [`rustix::fs::open`] family of functions, so
260        /// typical users do not need to care about it. It may be reported in
261        /// the return of `fcntl_getfl`, though.
262        const LARGEFILE = linux_raw_sys::general::O_LARGEFILE;
263
264        /// `O_ASYNC`, `FASYNC`
265        ///
266        /// This flag can't be used with the [`rustix::fs::open`] family of
267        /// functions, use [`rustix::fs::fcntl_setfl`] instead.
268        const ASYNC = linux_raw_sys::general::FASYNC;
269
270        /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
271        const _ = !0;
272    }
273}
274
275bitflags! {
276    /// `RESOLVE_*` constants for use with [`openat2`].
277    ///
278    /// [`openat2`]: crate::fs::openat2
279    #[repr(transparent)]
280    #[derive(Default, Copy, Clone, Eq, PartialEq, Hash, Debug)]
281    pub struct ResolveFlags: u64 {
282        /// `RESOLVE_NO_XDEV`
283        const NO_XDEV = linux_raw_sys::general::RESOLVE_NO_XDEV as u64;
284
285        /// `RESOLVE_NO_MAGICLINKS`
286        const NO_MAGICLINKS = linux_raw_sys::general::RESOLVE_NO_MAGICLINKS as u64;
287
288        /// `RESOLVE_NO_SYMLINKS`
289        const NO_SYMLINKS = linux_raw_sys::general::RESOLVE_NO_SYMLINKS as u64;
290
291        /// `RESOLVE_BENEATH`
292        const BENEATH = linux_raw_sys::general::RESOLVE_BENEATH as u64;
293
294        /// `RESOLVE_IN_ROOT`
295        const IN_ROOT = linux_raw_sys::general::RESOLVE_IN_ROOT as u64;
296
297        /// `RESOLVE_CACHED` (since Linux 5.12)
298        const CACHED = linux_raw_sys::general::RESOLVE_CACHED as u64;
299
300        /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
301        const _ = !0;
302    }
303}
304
305bitflags! {
306    /// `RENAME_*` constants for use with [`renameat_with`].
307    ///
308    /// [`renameat_with`]: crate::fs::renameat_with
309    #[repr(transparent)]
310    #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
311    pub struct RenameFlags: ffi::c_uint {
312        /// `RENAME_EXCHANGE`
313        const EXCHANGE = linux_raw_sys::general::RENAME_EXCHANGE;
314
315        /// `RENAME_NOREPLACE`
316        const NOREPLACE = linux_raw_sys::general::RENAME_NOREPLACE;
317
318        /// `RENAME_WHITEOUT`
319        const WHITEOUT = linux_raw_sys::general::RENAME_WHITEOUT;
320
321        /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
322        const _ = !0;
323    }
324}
325
326/// `S_IF*` constants for use with [`mknodat`] and [`Stat`]'s `st_mode` field.
327///
328/// [`mknodat`]: crate::fs::mknodat
329/// [`Stat`]: crate::fs::Stat
330#[derive(Clone, Copy, Debug, PartialEq, Eq)]
331pub enum FileType {
332    /// `S_IFREG`
333    RegularFile = linux_raw_sys::general::S_IFREG as isize,
334
335    /// `S_IFDIR`
336    Directory = linux_raw_sys::general::S_IFDIR as isize,
337
338    /// `S_IFLNK`
339    Symlink = linux_raw_sys::general::S_IFLNK as isize,
340
341    /// `S_IFIFO`
342    #[doc(alias = "IFO")]
343    Fifo = linux_raw_sys::general::S_IFIFO as isize,
344
345    /// `S_IFSOCK`
346    Socket = linux_raw_sys::general::S_IFSOCK as isize,
347
348    /// `S_IFCHR`
349    CharacterDevice = linux_raw_sys::general::S_IFCHR as isize,
350
351    /// `S_IFBLK`
352    BlockDevice = linux_raw_sys::general::S_IFBLK as isize,
353
354    /// An unknown filesystem object.
355    Unknown,
356}
357
358impl FileType {
359    /// Construct a `FileType` from the `S_IFMT` bits of the `st_mode` field of
360    /// a `Stat`.
361    #[inline]
362    pub const fn from_raw_mode(st_mode: RawMode) -> Self {
363        match st_mode & linux_raw_sys::general::S_IFMT {
364            linux_raw_sys::general::S_IFREG => Self::RegularFile,
365            linux_raw_sys::general::S_IFDIR => Self::Directory,
366            linux_raw_sys::general::S_IFLNK => Self::Symlink,
367            linux_raw_sys::general::S_IFIFO => Self::Fifo,
368            linux_raw_sys::general::S_IFSOCK => Self::Socket,
369            linux_raw_sys::general::S_IFCHR => Self::CharacterDevice,
370            linux_raw_sys::general::S_IFBLK => Self::BlockDevice,
371            _ => Self::Unknown,
372        }
373    }
374
375    /// Construct an `st_mode` value from a `FileType`.
376    #[inline]
377    pub const fn as_raw_mode(self) -> RawMode {
378        match self {
379            Self::RegularFile => linux_raw_sys::general::S_IFREG,
380            Self::Directory => linux_raw_sys::general::S_IFDIR,
381            Self::Symlink => linux_raw_sys::general::S_IFLNK,
382            Self::Fifo => linux_raw_sys::general::S_IFIFO,
383            Self::Socket => linux_raw_sys::general::S_IFSOCK,
384            Self::CharacterDevice => linux_raw_sys::general::S_IFCHR,
385            Self::BlockDevice => linux_raw_sys::general::S_IFBLK,
386            Self::Unknown => linux_raw_sys::general::S_IFMT,
387        }
388    }
389
390    /// Construct a `FileType` from the `d_type` field of a `c::dirent`.
391    #[inline]
392    pub(crate) const fn from_dirent_d_type(d_type: u8) -> Self {
393        match d_type as u32 {
394            linux_raw_sys::general::DT_REG => Self::RegularFile,
395            linux_raw_sys::general::DT_DIR => Self::Directory,
396            linux_raw_sys::general::DT_LNK => Self::Symlink,
397            linux_raw_sys::general::DT_SOCK => Self::Socket,
398            linux_raw_sys::general::DT_FIFO => Self::Fifo,
399            linux_raw_sys::general::DT_CHR => Self::CharacterDevice,
400            linux_raw_sys::general::DT_BLK => Self::BlockDevice,
401            // linux_raw_sys::general::DT_UNKNOWN |
402            _ => Self::Unknown,
403        }
404    }
405}
406
407/// `POSIX_FADV_*` constants for use with [`fadvise`].
408///
409/// [`fadvise`]: crate::fs::fadvise
410#[derive(Debug, Copy, Clone, Eq, PartialEq)]
411#[repr(u32)]
412pub enum Advice {
413    /// `POSIX_FADV_NORMAL`
414    Normal = linux_raw_sys::general::POSIX_FADV_NORMAL,
415
416    /// `POSIX_FADV_SEQUENTIAL`
417    Sequential = linux_raw_sys::general::POSIX_FADV_SEQUENTIAL,
418
419    /// `POSIX_FADV_RANDOM`
420    Random = linux_raw_sys::general::POSIX_FADV_RANDOM,
421
422    /// `POSIX_FADV_NOREUSE`
423    NoReuse = linux_raw_sys::general::POSIX_FADV_NOREUSE,
424
425    /// `POSIX_FADV_WILLNEED`
426    WillNeed = linux_raw_sys::general::POSIX_FADV_WILLNEED,
427
428    /// `POSIX_FADV_DONTNEED`
429    DontNeed = linux_raw_sys::general::POSIX_FADV_DONTNEED,
430}
431
432bitflags! {
433    /// `MFD_*` constants for use with [`memfd_create`].
434    ///
435    /// [`memfd_create`]: crate::fs::memfd_create
436    #[repr(transparent)]
437    #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
438    pub struct MemfdFlags: ffi::c_uint {
439        /// `MFD_CLOEXEC`
440        const CLOEXEC = linux_raw_sys::general::MFD_CLOEXEC;
441
442        /// `MFD_ALLOW_SEALING`
443        const ALLOW_SEALING = linux_raw_sys::general::MFD_ALLOW_SEALING;
444
445        /// `MFD_HUGETLB` (since Linux 4.14)
446        const HUGETLB = linux_raw_sys::general::MFD_HUGETLB;
447
448        /// `MFD_NOEXEC_SEAL` (since Linux 6.3)
449        const NOEXEC_SEAL = linux_raw_sys::general::MFD_NOEXEC_SEAL;
450        /// `MFD_EXEC` (since Linux 6.3)
451        const EXEC = linux_raw_sys::general::MFD_EXEC;
452
453        /// `MFD_HUGE_64KB`
454        const HUGE_64KB = linux_raw_sys::general::MFD_HUGE_64KB;
455        /// `MFD_HUGE_512KB`
456        const HUGE_512KB = linux_raw_sys::general::MFD_HUGE_512KB;
457        /// `MFD_HUGE_1MB`
458        const HUGE_1MB = linux_raw_sys::general::MFD_HUGE_1MB;
459        /// `MFD_HUGE_2MB`
460        const HUGE_2MB = linux_raw_sys::general::MFD_HUGE_2MB;
461        /// `MFD_HUGE_8MB`
462        const HUGE_8MB = linux_raw_sys::general::MFD_HUGE_8MB;
463        /// `MFD_HUGE_16MB`
464        const HUGE_16MB = linux_raw_sys::general::MFD_HUGE_16MB;
465        /// `MFD_HUGE_32MB`
466        const HUGE_32MB = linux_raw_sys::general::MFD_HUGE_32MB;
467        /// `MFD_HUGE_256MB`
468        const HUGE_256MB = linux_raw_sys::general::MFD_HUGE_256MB;
469        /// `MFD_HUGE_512MB`
470        const HUGE_512MB = linux_raw_sys::general::MFD_HUGE_512MB;
471        /// `MFD_HUGE_1GB`
472        const HUGE_1GB = linux_raw_sys::general::MFD_HUGE_1GB;
473        /// `MFD_HUGE_2GB`
474        const HUGE_2GB = linux_raw_sys::general::MFD_HUGE_2GB;
475        /// `MFD_HUGE_16GB`
476        const HUGE_16GB = linux_raw_sys::general::MFD_HUGE_16GB;
477
478        /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
479        const _ = !0;
480    }
481}
482
483bitflags! {
484    /// `F_SEAL_*` constants for use with [`fcntl_add_seals`] and
485    /// [`fcntl_get_seals`].
486    ///
487    /// [`fcntl_add_seals`]: crate::fs::fcntl_add_seals
488    /// [`fcntl_get_seals`]: crate::fs::fcntl_get_seals
489    #[repr(transparent)]
490    #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
491    pub struct SealFlags: u32 {
492        /// `F_SEAL_SEAL`
493        const SEAL = linux_raw_sys::general::F_SEAL_SEAL;
494        /// `F_SEAL_SHRINK`
495        const SHRINK = linux_raw_sys::general::F_SEAL_SHRINK;
496        /// `F_SEAL_GROW`
497        const GROW = linux_raw_sys::general::F_SEAL_GROW;
498        /// `F_SEAL_WRITE`
499        const WRITE = linux_raw_sys::general::F_SEAL_WRITE;
500        /// `F_SEAL_FUTURE_WRITE` (since Linux 5.1)
501        const FUTURE_WRITE = linux_raw_sys::general::F_SEAL_FUTURE_WRITE;
502        /// `F_SEAL_EXEC` (since Linux 6.3)
503        const EXEC = linux_raw_sys::general::F_SEAL_EXEC;
504
505        /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
506        const _ = !0;
507    }
508}
509
510bitflags! {
511    /// `FALLOC_FL_*` constants for use with [`fallocate`].
512    ///
513    /// [`fallocate`]: crate::fs::fallocate
514    #[repr(transparent)]
515    #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
516    pub struct FallocateFlags: u32 {
517        /// `FALLOC_FL_KEEP_SIZE`
518        const KEEP_SIZE = linux_raw_sys::general::FALLOC_FL_KEEP_SIZE;
519        /// `FALLOC_FL_PUNCH_HOLE`
520        const PUNCH_HOLE = linux_raw_sys::general::FALLOC_FL_PUNCH_HOLE;
521        /// `FALLOC_FL_NO_HIDE_STALE`
522        const NO_HIDE_STALE = linux_raw_sys::general::FALLOC_FL_NO_HIDE_STALE;
523        /// `FALLOC_FL_COLLAPSE_RANGE`
524        const COLLAPSE_RANGE = linux_raw_sys::general::FALLOC_FL_COLLAPSE_RANGE;
525        /// `FALLOC_FL_ZERO_RANGE`
526        const ZERO_RANGE = linux_raw_sys::general::FALLOC_FL_ZERO_RANGE;
527        /// `FALLOC_FL_INSERT_RANGE`
528        const INSERT_RANGE = linux_raw_sys::general::FALLOC_FL_INSERT_RANGE;
529        /// `FALLOC_FL_UNSHARE_RANGE`
530        const UNSHARE_RANGE = linux_raw_sys::general::FALLOC_FL_UNSHARE_RANGE;
531
532        /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
533        const _ = !0;
534    }
535}
536
537bitflags! {
538    /// `ST_*` constants for use with [`StatVfs`].
539    ///
540    /// These are the values the kernel reports in `statfs`'s `f_flags`,
541    /// which `statvfs` passes through unconverted. linux-raw-sys does not
542    /// define the `ST_*` names, and they are not all equal to the `MS_*`
543    /// ones: `ST_RELATIME` is `0x1000`, while `MS_RELATIME` is `1 << 21`.
544    #[repr(transparent)]
545    #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
546    pub struct StatVfsMountFlags: u64 {
547        /// `ST_MANDLOCK`
548        const MANDLOCK = 0x0040;
549
550        /// `ST_NOATIME`
551        const NOATIME = 0x0400;
552
553        /// `ST_NODEV`
554        const NODEV = 0x0004;
555
556        /// `ST_NODIRATIME`
557        const NODIRATIME = 0x0800;
558
559        /// `ST_NOEXEC`
560        const NOEXEC = 0x0008;
561
562        /// `ST_NOSUID`
563        const NOSUID = 0x0002;
564
565        /// `ST_RDONLY`
566        const RDONLY = 0x0001;
567
568        /// `ST_RELATIME`
569        const RELATIME = 0x1000;
570
571        /// `ST_SYNCHRONOUS`
572        const SYNCHRONOUS = 0x0010;
573
574        /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
575        const _ = !0;
576    }
577}
578
579/// `LOCK_*` constants for use with [`flock`] and [`fcntl_lock`].
580///
581/// [`flock`]: crate::fs::flock
582/// [`fcntl_lock`]: crate::fs::fcntl_lock
583#[derive(Clone, Copy, Debug, PartialEq, Eq)]
584#[repr(u32)]
585pub enum FlockOperation {
586    /// `LOCK_SH`
587    LockShared = linux_raw_sys::general::LOCK_SH,
588    /// `LOCK_EX`
589    LockExclusive = linux_raw_sys::general::LOCK_EX,
590    /// `LOCK_UN`
591    Unlock = linux_raw_sys::general::LOCK_UN,
592    /// `LOCK_SH | LOCK_NB`
593    NonBlockingLockShared = linux_raw_sys::general::LOCK_SH | linux_raw_sys::general::LOCK_NB,
594    /// `LOCK_EX | LOCK_NB`
595    NonBlockingLockExclusive = linux_raw_sys::general::LOCK_EX | linux_raw_sys::general::LOCK_NB,
596    /// `LOCK_UN | LOCK_NB`
597    NonBlockingUnlock = linux_raw_sys::general::LOCK_UN | linux_raw_sys::general::LOCK_NB,
598}
599
600/// `struct stat` for use with [`statat`] and [`fstat`].
601///
602/// [`statat`]: crate::fs::statat
603/// [`fstat`]: crate::fs::fstat
604// On 32-bit with `struct stat64` and mips64 with `struct stat`, Linux's
605// `st_mtime` and friends are 32-bit, so we use our own struct, populated from
606// `statx` where possible, to avoid the y2038 bug.
607#[cfg(any(
608    target_pointer_width = "32",
609    target_arch = "mips64",
610    target_arch = "mips64r6"
611))]
612#[derive(Debug, Copy, Clone)]
613#[allow(missing_docs)]
614#[non_exhaustive]
615pub struct Stat {
616    pub st_dev: u64,
617    pub st_mode: u32,
618    pub st_nlink: u32,
619    pub st_uid: u32,
620    pub st_gid: u32,
621    pub st_rdev: u64,
622    pub st_size: i64,
623    pub st_blksize: u32,
624    pub st_blocks: u64,
625    pub st_atime: i64,
626    pub st_atime_nsec: u32,
627    pub st_mtime: i64,
628    pub st_mtime_nsec: u32,
629    pub st_ctime: i64,
630    pub st_ctime_nsec: u32,
631    pub st_ino: u64,
632}
633
634/// `struct stat` for use with [`statat`] and [`fstat`].
635///
636/// [`statat`]: crate::fs::statat
637/// [`fstat`]: crate::fs::fstat
638#[repr(C)]
639#[derive(Debug, Copy, Clone)]
640#[allow(missing_docs)]
641#[non_exhaustive]
642#[cfg(target_arch = "x86_64")]
643pub struct Stat {
644    pub st_dev: ffi::c_ulong,
645    pub st_ino: ffi::c_ulong,
646    pub st_nlink: ffi::c_ulong,
647    pub st_mode: ffi::c_uint,
648    pub st_uid: ffi::c_uint,
649    pub st_gid: ffi::c_uint,
650    pub(crate) __pad0: Padding<ffi::c_uint>,
651    pub st_rdev: ffi::c_ulong,
652    pub st_size: ffi::c_long,
653    pub st_blksize: ffi::c_long,
654    pub st_blocks: ffi::c_long,
655    pub st_atime: ffi::c_long,
656    pub st_atime_nsec: ffi::c_ulong,
657    pub st_mtime: ffi::c_long,
658    pub st_mtime_nsec: ffi::c_ulong,
659    pub st_ctime: ffi::c_long,
660    pub st_ctime_nsec: ffi::c_ulong,
661    pub(crate) __unused: Padding<[ffi::c_long; 3]>,
662}
663#[repr(C)]
664#[derive(Debug, Copy, Clone)]
665#[allow(missing_docs)]
666#[non_exhaustive]
667#[cfg(target_arch = "aarch64")]
668pub struct Stat {
669    pub st_dev: ffi::c_ulong,
670    pub st_ino: ffi::c_ulong,
671    pub st_mode: ffi::c_uint,
672    pub st_nlink: ffi::c_uint,
673    pub st_uid: ffi::c_uint,
674    pub st_gid: ffi::c_uint,
675    pub st_rdev: ffi::c_ulong,
676    pub(crate) __pad1: Padding<ffi::c_ulong>,
677    pub st_size: ffi::c_long,
678    pub st_blksize: ffi::c_int,
679    pub(crate) __pad2: Padding<ffi::c_int>,
680    pub st_blocks: ffi::c_long,
681    pub st_atime: ffi::c_long,
682    pub st_atime_nsec: ffi::c_ulong,
683    pub st_mtime: ffi::c_long,
684    pub st_mtime_nsec: ffi::c_ulong,
685    pub st_ctime: ffi::c_long,
686    pub st_ctime_nsec: ffi::c_ulong,
687    pub(crate) __unused4: Padding<ffi::c_uint>,
688    pub(crate) __unused5: Padding<ffi::c_uint>,
689}
690#[repr(C)]
691#[derive(Debug, Copy, Clone)]
692#[allow(missing_docs)]
693#[non_exhaustive]
694#[cfg(target_arch = "riscv64")]
695pub struct Stat {
696    pub st_dev: ffi::c_ulong,
697    pub st_ino: ffi::c_ulong,
698    pub st_mode: ffi::c_uint,
699    pub st_nlink: ffi::c_uint,
700    pub st_uid: ffi::c_uint,
701    pub st_gid: ffi::c_uint,
702    pub st_rdev: ffi::c_ulong,
703    pub(crate) __pad1: Padding<ffi::c_ulong>,
704    pub st_size: ffi::c_long,
705    pub st_blksize: ffi::c_int,
706    pub(crate) __pad2: Padding<ffi::c_int>,
707    pub st_blocks: ffi::c_long,
708    pub st_atime: ffi::c_long,
709    pub st_atime_nsec: ffi::c_ulong,
710    pub st_mtime: ffi::c_long,
711    pub st_mtime_nsec: ffi::c_ulong,
712    pub st_ctime: ffi::c_long,
713    pub st_ctime_nsec: ffi::c_ulong,
714    pub(crate) __unused4: Padding<ffi::c_uint>,
715    pub(crate) __unused5: Padding<ffi::c_uint>,
716}
717// This follows `stat`. powerpc64 defines a `stat64` but it's not used.
718#[repr(C)]
719#[derive(Debug, Copy, Clone)]
720#[allow(missing_docs)]
721#[non_exhaustive]
722#[cfg(target_arch = "powerpc64")]
723pub struct Stat {
724    pub st_dev: ffi::c_ulong,
725    pub st_ino: ffi::c_ulong,
726    pub st_nlink: ffi::c_ulong,
727    pub st_mode: ffi::c_uint,
728    pub st_uid: ffi::c_uint,
729    pub st_gid: ffi::c_uint,
730    pub st_rdev: ffi::c_ulong,
731    pub st_size: ffi::c_long,
732    pub st_blksize: ffi::c_ulong,
733    pub st_blocks: ffi::c_ulong,
734    pub st_atime: ffi::c_long,
735    pub st_atime_nsec: ffi::c_ulong,
736    pub st_mtime: ffi::c_long,
737    pub st_mtime_nsec: ffi::c_ulong,
738    pub st_ctime: ffi::c_long,
739    pub st_ctime_nsec: ffi::c_ulong,
740    pub(crate) __unused4: Padding<ffi::c_ulong>,
741    pub(crate) __unused5: Padding<ffi::c_ulong>,
742    pub(crate) __unused6: Padding<ffi::c_ulong>,
743}
744#[repr(C)]
745#[derive(Debug, Copy, Clone)]
746#[allow(missing_docs)]
747#[non_exhaustive]
748#[cfg(target_arch = "s390x")]
749pub struct Stat {
750    pub st_dev: ffi::c_ulong,
751    pub st_ino: ffi::c_ulong,
752    pub st_nlink: ffi::c_ulong,
753    pub st_mode: ffi::c_uint,
754    pub st_uid: ffi::c_uint,
755    pub st_gid: ffi::c_uint,
756    pub(crate) __pad1: Padding<ffi::c_uint>,
757    pub st_rdev: ffi::c_ulong,
758    pub st_size: ffi::c_long, // Linux has `c_ulong` but we make it signed.
759    pub st_atime: ffi::c_long,
760    pub st_atime_nsec: ffi::c_ulong,
761    pub st_mtime: ffi::c_long,
762    pub st_mtime_nsec: ffi::c_ulong,
763    pub st_ctime: ffi::c_long,
764    pub st_ctime_nsec: ffi::c_ulong,
765    pub st_blksize: ffi::c_ulong,
766    pub st_blocks: ffi::c_long,
767    pub(crate) __unused: Padding<[ffi::c_ulong; 3]>,
768}
769
770/// `struct statfs` for use with [`statfs`] and [`fstatfs`].
771///
772/// [`statfs`]: crate::fs::statfs
773/// [`fstatfs`]: crate::fs::fstatfs
774#[allow(clippy::module_name_repetitions)]
775#[repr(C)]
776#[cfg_attr(target_arch = "arm", repr(packed(4)))]
777#[derive(Debug, Copy, Clone)]
778#[allow(missing_docs)]
779#[non_exhaustive]
780pub struct StatFs {
781    pub f_type: FsWord,
782    #[cfg(not(any(target_arch = "arm", target_arch = "s390x")))]
783    pub f_bsize: ffi::c_long,
784    #[cfg(any(target_arch = "arm", target_arch = "s390x"))]
785    pub f_bsize: ffi::c_uint,
786    pub f_blocks: u64,
787    pub f_bfree: u64,
788    pub f_bavail: u64,
789    pub f_files: u64,
790    pub f_ffree: u64,
791    pub f_fsid: Fsid,
792    #[cfg(not(any(target_arch = "arm", target_arch = "s390x")))]
793    pub f_namelen: ffi::c_long,
794    #[cfg(any(target_arch = "arm", target_arch = "s390x"))]
795    pub f_namelen: ffi::c_uint,
796    #[cfg(not(any(target_arch = "arm", target_arch = "s390x")))]
797    pub f_frsize: ffi::c_long,
798    #[cfg(any(target_arch = "arm", target_arch = "s390x"))]
799    pub f_frsize: ffi::c_uint,
800    #[cfg(not(any(target_arch = "arm", target_arch = "s390x")))]
801    pub f_flags: ffi::c_long,
802    #[cfg(any(target_arch = "arm", target_arch = "s390x"))]
803    pub f_flags: ffi::c_uint,
804    #[cfg(not(target_arch = "s390x"))]
805    pub(crate) f_spare: Padding<[ffi::c_long; 4]>,
806    #[cfg(target_arch = "s390x")]
807    pub(crate) f_spare: Padding<[ffi::c_uint; 5]>,
808}
809
810/// `fsid_t` for use with [`StatFs`].
811#[repr(C)]
812#[derive(Debug, Copy, Clone)]
813#[allow(missing_docs)]
814pub struct Fsid {
815    pub(crate) val: [ffi::c_int; 2],
816}
817
818/// `struct statvfs` for use with [`statvfs`] and [`fstatvfs`].
819///
820/// [`statvfs`]: crate::fs::statvfs
821/// [`fstatvfs`]: crate::fs::fstatvfs
822#[allow(missing_docs)]
823pub struct StatVfs {
824    pub f_bsize: u64,
825    pub f_frsize: u64,
826    pub f_blocks: u64,
827    pub f_bfree: u64,
828    pub f_bavail: u64,
829    pub f_files: u64,
830    pub f_ffree: u64,
831    pub f_favail: u64,
832    pub f_fsid: u64,
833    pub f_flag: StatVfsMountFlags,
834    pub f_namemax: u64,
835}
836
837/// `mode_t`
838pub type RawMode = ffi::c_uint;
839
840/// `dev_t`
841// Within the kernel the `dev_t` is 32-bit, but userspace uses a 64-bit field.
842pub type Dev = u64;
843
844/// `__fsword_t`
845#[cfg(not(any(
846    target_arch = "mips64",
847    target_arch = "mips64r6",
848    target_arch = "s390x"
849)))]
850pub type FsWord = ffi::c_long;
851
852/// `__fsword_t`
853#[cfg(any(target_arch = "mips64", target_arch = "mips64r6"))]
854pub type FsWord = i64;
855
856/// `__fsword_t`
857#[cfg(target_arch = "s390x")]
858pub type FsWord = u32;