Skip to main content

rustix/backend/linux_raw/fs/
types.rs

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