1use crate::backend::c;
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: c::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: c::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`], [`chmodat`], and [`fchmod`].
71 ///
72 /// [`openat`]: crate::fs::openat
73 /// [`chmodat`]: crate::fs::chmodat
74 /// [`fchmod`]: crate::fs::fchmod
75 #[repr(transparent)]
76 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
77 pub struct Mode: RawMode {
78 /// `S_IRWXU`
79 const RWXU = linux_raw_sys::general::S_IRWXU;
80
81 /// `S_IRUSR`
82 const RUSR = linux_raw_sys::general::S_IRUSR;
83
84 /// `S_IWUSR`
85 const WUSR = linux_raw_sys::general::S_IWUSR;
86
87 /// `S_IXUSR`
88 const XUSR = linux_raw_sys::general::S_IXUSR;
89
90 /// `S_IRWXG`
91 const RWXG = linux_raw_sys::general::S_IRWXG;
92
93 /// `S_IRGRP`
94 const RGRP = linux_raw_sys::general::S_IRGRP;
95
96 /// `S_IWGRP`
97 const WGRP = linux_raw_sys::general::S_IWGRP;
98
99 /// `S_IXGRP`
100 const XGRP = linux_raw_sys::general::S_IXGRP;
101
102 /// `S_IRWXO`
103 const RWXO = linux_raw_sys::general::S_IRWXO;
104
105 /// `S_IROTH`
106 const ROTH = linux_raw_sys::general::S_IROTH;
107
108 /// `S_IWOTH`
109 const WOTH = linux_raw_sys::general::S_IWOTH;
110
111 /// `S_IXOTH`
112 const XOTH = linux_raw_sys::general::S_IXOTH;
113
114 /// `S_ISUID`
115 const SUID = linux_raw_sys::general::S_ISUID;
116
117 /// `S_ISGID`
118 const SGID = linux_raw_sys::general::S_ISGID;
119
120 /// `S_ISVTX`
121 const SVTX = linux_raw_sys::general::S_ISVTX;
122
123 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
124 const _ = !0;
125 }
126}
127
128impl Mode {
129 /// Construct a `Mode` from the mode bits of the `st_mode` field of a
130 /// `Mode`.
131 #[inline]
132 pub const fn from_raw_mode(st_mode: RawMode) -> Self {
133 Self::from_bits_truncate(bits:st_mode & !linux_raw_sys::general::S_IFMT)
134 }
135
136 /// Construct an `st_mode` value from a `Mode`.
137 #[inline]
138 pub const fn as_raw_mode(self) -> RawMode {
139 self.bits()
140 }
141}
142
143impl From<RawMode> for Mode {
144 /// Support conversions from raw mode values to `Mode`.
145 ///
146 /// ```
147 /// use rustix::fs::{Mode, RawMode};
148 /// assert_eq!(Mode::from(0o700), Mode::RWXU);
149 /// ```
150 #[inline]
151 fn from(st_mode: RawMode) -> Self {
152 Self::from_raw_mode(st_mode)
153 }
154}
155
156impl From<Mode> for RawMode {
157 /// Support conversions from `Mode` to raw mode values.
158 ///
159 /// ```
160 /// use rustix::fs::{Mode, RawMode};
161 /// assert_eq!(RawMode::from(Mode::RWXU), 0o700);
162 /// ```
163 #[inline]
164 fn from(mode: Mode) -> Self {
165 mode.as_raw_mode()
166 }
167}
168
169bitflags! {
170 /// `O_*` constants for use with [`openat`].
171 ///
172 /// [`openat`]: crate::fs::openat
173 #[repr(transparent)]
174 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
175 pub struct OFlags: c::c_uint {
176 /// `O_ACCMODE`
177 const ACCMODE = linux_raw_sys::general::O_ACCMODE;
178
179 /// Similar to `ACCMODE`, but just includes the read/write flags, and
180 /// no other flags.
181 ///
182 /// On some platforms, `PATH` may be included in `ACCMODE`, when
183 /// sometimes we really just want the read/write bits. Caution is
184 /// indicated, as the presence of `PATH` may mean that the read/write
185 /// bits don't have their usual meaning.
186 const RWMODE = linux_raw_sys::general::O_RDONLY |
187 linux_raw_sys::general::O_WRONLY |
188 linux_raw_sys::general::O_RDWR;
189
190 /// `O_APPEND`
191 const APPEND = linux_raw_sys::general::O_APPEND;
192
193 /// `O_CREAT`
194 #[doc(alias = "CREAT")]
195 const CREATE = linux_raw_sys::general::O_CREAT;
196
197 /// `O_DIRECTORY`
198 const DIRECTORY = linux_raw_sys::general::O_DIRECTORY;
199
200 /// `O_DSYNC`.
201 const DSYNC = linux_raw_sys::general::O_SYNC;
202
203 /// `O_EXCL`
204 const EXCL = linux_raw_sys::general::O_EXCL;
205
206 /// `O_FSYNC`.
207 const FSYNC = linux_raw_sys::general::O_SYNC;
208
209 /// `O_NOFOLLOW`
210 const NOFOLLOW = linux_raw_sys::general::O_NOFOLLOW;
211
212 /// `O_NONBLOCK`
213 const NONBLOCK = linux_raw_sys::general::O_NONBLOCK;
214
215 /// `O_RDONLY`
216 const RDONLY = linux_raw_sys::general::O_RDONLY;
217
218 /// `O_WRONLY`
219 const WRONLY = linux_raw_sys::general::O_WRONLY;
220
221 /// `O_RDWR`
222 ///
223 /// This is not equal to `RDONLY | WRONLY`. It's a distinct flag.
224 const RDWR = linux_raw_sys::general::O_RDWR;
225
226 /// `O_NOCTTY`
227 const NOCTTY = linux_raw_sys::general::O_NOCTTY;
228
229 /// `O_RSYNC`.
230 const RSYNC = linux_raw_sys::general::O_SYNC;
231
232 /// `O_SYNC`
233 const SYNC = linux_raw_sys::general::O_SYNC;
234
235 /// `O_TRUNC`
236 const TRUNC = linux_raw_sys::general::O_TRUNC;
237
238 /// `O_PATH`
239 const PATH = linux_raw_sys::general::O_PATH;
240
241 /// `O_CLOEXEC`
242 const CLOEXEC = linux_raw_sys::general::O_CLOEXEC;
243
244 /// `O_TMPFILE`
245 const TMPFILE = linux_raw_sys::general::O_TMPFILE;
246
247 /// `O_NOATIME`
248 const NOATIME = linux_raw_sys::general::O_NOATIME;
249
250 /// `O_DIRECT`
251 const DIRECT = linux_raw_sys::general::O_DIRECT;
252
253 /// `O_LARGEFILE`
254 ///
255 /// Note that rustix and/or libc will automatically set this flag when appropriate on
256 /// `open(2)` and friends, thus typical users do not need to care about it.
257 /// It will may be reported in return of `fcntl_getfl`, though.
258 const LARGEFILE = linux_raw_sys::general::O_LARGEFILE;
259
260 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
261 const _ = !0;
262 }
263}
264
265bitflags! {
266 /// `RESOLVE_*` constants for use with [`openat2`].
267 ///
268 /// [`openat2`]: crate::fs::openat2
269 #[repr(transparent)]
270 #[derive(Default, Copy, Clone, Eq, PartialEq, Hash, Debug)]
271 pub struct ResolveFlags: u64 {
272 /// `RESOLVE_NO_XDEV`
273 const NO_XDEV = linux_raw_sys::general::RESOLVE_NO_XDEV as u64;
274
275 /// `RESOLVE_NO_MAGICLINKS`
276 const NO_MAGICLINKS = linux_raw_sys::general::RESOLVE_NO_MAGICLINKS as u64;
277
278 /// `RESOLVE_NO_SYMLINKS`
279 const NO_SYMLINKS = linux_raw_sys::general::RESOLVE_NO_SYMLINKS as u64;
280
281 /// `RESOLVE_BENEATH`
282 const BENEATH = linux_raw_sys::general::RESOLVE_BENEATH as u64;
283
284 /// `RESOLVE_IN_ROOT`
285 const IN_ROOT = linux_raw_sys::general::RESOLVE_IN_ROOT as u64;
286
287 /// `RESOLVE_CACHED` (since Linux 5.12)
288 const CACHED = linux_raw_sys::general::RESOLVE_CACHED as u64;
289
290 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
291 const _ = !0;
292 }
293}
294
295bitflags! {
296 /// `RENAME_*` constants for use with [`renameat_with`].
297 ///
298 /// [`renameat_with`]: crate::fs::renameat_with
299 #[repr(transparent)]
300 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
301 pub struct RenameFlags: c::c_uint {
302 /// `RENAME_EXCHANGE`
303 const EXCHANGE = linux_raw_sys::general::RENAME_EXCHANGE;
304
305 /// `RENAME_NOREPLACE`
306 const NOREPLACE = linux_raw_sys::general::RENAME_NOREPLACE;
307
308 /// `RENAME_WHITEOUT`
309 const WHITEOUT = linux_raw_sys::general::RENAME_WHITEOUT;
310
311 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
312 const _ = !0;
313 }
314}
315
316/// `S_IF*` constants for use with [`mknodat`] and [`Stat`]'s `st_mode` field.
317///
318/// [`mknodat`]: crate::fs::mknodat
319/// [`Stat`]: crate::fs::Stat
320#[derive(Clone, Copy, Debug, PartialEq, Eq)]
321pub enum FileType {
322 /// `S_IFREG`
323 RegularFile = linux_raw_sys::general::S_IFREG as isize,
324
325 /// `S_IFDIR`
326 Directory = linux_raw_sys::general::S_IFDIR as isize,
327
328 /// `S_IFLNK`
329 Symlink = linux_raw_sys::general::S_IFLNK as isize,
330
331 /// `S_IFIFO`
332 #[doc(alias = "IFO")]
333 Fifo = linux_raw_sys::general::S_IFIFO as isize,
334
335 /// `S_IFSOCK`
336 Socket = linux_raw_sys::general::S_IFSOCK as isize,
337
338 /// `S_IFCHR`
339 CharacterDevice = linux_raw_sys::general::S_IFCHR as isize,
340
341 /// `S_IFBLK`
342 BlockDevice = linux_raw_sys::general::S_IFBLK as isize,
343
344 /// An unknown filesystem object.
345 Unknown,
346}
347
348impl FileType {
349 /// Construct a `FileType` from the `S_IFMT` bits of the `st_mode` field of
350 /// a `Stat`.
351 #[inline]
352 pub const fn from_raw_mode(st_mode: RawMode) -> Self {
353 match st_mode & linux_raw_sys::general::S_IFMT {
354 linux_raw_sys::general::S_IFREG => Self::RegularFile,
355 linux_raw_sys::general::S_IFDIR => Self::Directory,
356 linux_raw_sys::general::S_IFLNK => Self::Symlink,
357 linux_raw_sys::general::S_IFIFO => Self::Fifo,
358 linux_raw_sys::general::S_IFSOCK => Self::Socket,
359 linux_raw_sys::general::S_IFCHR => Self::CharacterDevice,
360 linux_raw_sys::general::S_IFBLK => Self::BlockDevice,
361 _ => Self::Unknown,
362 }
363 }
364
365 /// Construct an `st_mode` value from a `FileType`.
366 #[inline]
367 pub const fn as_raw_mode(self) -> RawMode {
368 match self {
369 Self::RegularFile => linux_raw_sys::general::S_IFREG,
370 Self::Directory => linux_raw_sys::general::S_IFDIR,
371 Self::Symlink => linux_raw_sys::general::S_IFLNK,
372 Self::Fifo => linux_raw_sys::general::S_IFIFO,
373 Self::Socket => linux_raw_sys::general::S_IFSOCK,
374 Self::CharacterDevice => linux_raw_sys::general::S_IFCHR,
375 Self::BlockDevice => linux_raw_sys::general::S_IFBLK,
376 Self::Unknown => linux_raw_sys::general::S_IFMT,
377 }
378 }
379
380 /// Construct a `FileType` from the `d_type` field of a `c::dirent`.
381 #[inline]
382 pub(crate) const fn from_dirent_d_type(d_type: u8) -> Self {
383 match d_type as u32 {
384 linux_raw_sys::general::DT_REG => Self::RegularFile,
385 linux_raw_sys::general::DT_DIR => Self::Directory,
386 linux_raw_sys::general::DT_LNK => Self::Symlink,
387 linux_raw_sys::general::DT_SOCK => Self::Socket,
388 linux_raw_sys::general::DT_FIFO => Self::Fifo,
389 linux_raw_sys::general::DT_CHR => Self::CharacterDevice,
390 linux_raw_sys::general::DT_BLK => Self::BlockDevice,
391 // linux_raw_sys::general::DT_UNKNOWN |
392 _ => Self::Unknown,
393 }
394 }
395}
396
397/// `POSIX_FADV_*` constants for use with [`fadvise`].
398///
399/// [`fadvise`]: crate::fs::fadvise
400#[derive(Debug, Copy, Clone, Eq, PartialEq)]
401#[repr(u32)]
402pub enum Advice {
403 /// `POSIX_FADV_NORMAL`
404 Normal = linux_raw_sys::general::POSIX_FADV_NORMAL,
405
406 /// `POSIX_FADV_SEQUENTIAL`
407 Sequential = linux_raw_sys::general::POSIX_FADV_SEQUENTIAL,
408
409 /// `POSIX_FADV_RANDOM`
410 Random = linux_raw_sys::general::POSIX_FADV_RANDOM,
411
412 /// `POSIX_FADV_NOREUSE`
413 NoReuse = linux_raw_sys::general::POSIX_FADV_NOREUSE,
414
415 /// `POSIX_FADV_WILLNEED`
416 WillNeed = linux_raw_sys::general::POSIX_FADV_WILLNEED,
417
418 /// `POSIX_FADV_DONTNEED`
419 DontNeed = linux_raw_sys::general::POSIX_FADV_DONTNEED,
420}
421
422bitflags! {
423 /// `MFD_*` constants for use with [`memfd_create`].
424 ///
425 /// [`memfd_create`]: crate::fs::memfd_create
426 #[repr(transparent)]
427 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
428 pub struct MemfdFlags: c::c_uint {
429 /// `MFD_CLOEXEC`
430 const CLOEXEC = linux_raw_sys::general::MFD_CLOEXEC;
431
432 /// `MFD_ALLOW_SEALING`
433 const ALLOW_SEALING = linux_raw_sys::general::MFD_ALLOW_SEALING;
434
435 /// `MFD_HUGETLB` (since Linux 4.14)
436 const HUGETLB = linux_raw_sys::general::MFD_HUGETLB;
437
438 /// `MFD_NOEXEC_SEAL` (since Linux 6.3)
439 const NOEXEC_SEAL = linux_raw_sys::general::MFD_NOEXEC_SEAL;
440 /// `MFD_EXEC` (since Linux 6.3)
441 const EXEC = linux_raw_sys::general::MFD_EXEC;
442
443 /// `MFD_HUGE_64KB`
444 const HUGE_64KB = linux_raw_sys::general::MFD_HUGE_64KB;
445 /// `MFD_HUGE_512KB`
446 const HUGE_512KB = linux_raw_sys::general::MFD_HUGE_512KB;
447 /// `MFD_HUGE_1MB`
448 const HUGE_1MB = linux_raw_sys::general::MFD_HUGE_1MB;
449 /// `MFD_HUGE_2MB`
450 const HUGE_2MB = linux_raw_sys::general::MFD_HUGE_2MB;
451 /// `MFD_HUGE_8MB`
452 const HUGE_8MB = linux_raw_sys::general::MFD_HUGE_8MB;
453 /// `MFD_HUGE_16MB`
454 const HUGE_16MB = linux_raw_sys::general::MFD_HUGE_16MB;
455 /// `MFD_HUGE_32MB`
456 const HUGE_32MB = linux_raw_sys::general::MFD_HUGE_32MB;
457 /// `MFD_HUGE_256MB`
458 const HUGE_256MB = linux_raw_sys::general::MFD_HUGE_256MB;
459 /// `MFD_HUGE_512MB`
460 const HUGE_512MB = linux_raw_sys::general::MFD_HUGE_512MB;
461 /// `MFD_HUGE_1GB`
462 const HUGE_1GB = linux_raw_sys::general::MFD_HUGE_1GB;
463 /// `MFD_HUGE_2GB`
464 const HUGE_2GB = linux_raw_sys::general::MFD_HUGE_2GB;
465 /// `MFD_HUGE_16GB`
466 const HUGE_16GB = linux_raw_sys::general::MFD_HUGE_16GB;
467
468 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
469 const _ = !0;
470 }
471}
472
473bitflags! {
474 /// `F_SEAL_*` constants for use with [`fcntl_add_seals`] and
475 /// [`fcntl_get_seals`].
476 ///
477 /// [`fcntl_add_seals`]: crate::fs::fcntl_add_seals
478 /// [`fcntl_get_seals`]: crate::fs::fcntl_get_seals
479 #[repr(transparent)]
480 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
481 pub struct SealFlags: u32 {
482 /// `F_SEAL_SEAL`.
483 const SEAL = linux_raw_sys::general::F_SEAL_SEAL;
484 /// `F_SEAL_SHRINK`.
485 const SHRINK = linux_raw_sys::general::F_SEAL_SHRINK;
486 /// `F_SEAL_GROW`.
487 const GROW = linux_raw_sys::general::F_SEAL_GROW;
488 /// `F_SEAL_WRITE`.
489 const WRITE = linux_raw_sys::general::F_SEAL_WRITE;
490 /// `F_SEAL_FUTURE_WRITE` (since Linux 5.1)
491 const FUTURE_WRITE = linux_raw_sys::general::F_SEAL_FUTURE_WRITE;
492
493 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
494 const _ = !0;
495 }
496}
497
498bitflags! {
499 /// `STATX_*` constants for use with [`statx`].
500 ///
501 /// [`statx`]: crate::fs::statx
502 #[repr(transparent)]
503 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
504 pub struct StatxFlags: u32 {
505 /// `STATX_TYPE`
506 const TYPE = linux_raw_sys::general::STATX_TYPE;
507
508 /// `STATX_MODE`
509 const MODE = linux_raw_sys::general::STATX_MODE;
510
511 /// `STATX_NLINK`
512 const NLINK = linux_raw_sys::general::STATX_NLINK;
513
514 /// `STATX_UID`
515 const UID = linux_raw_sys::general::STATX_UID;
516
517 /// `STATX_GID`
518 const GID = linux_raw_sys::general::STATX_GID;
519
520 /// `STATX_ATIME`
521 const ATIME = linux_raw_sys::general::STATX_ATIME;
522
523 /// `STATX_MTIME`
524 const MTIME = linux_raw_sys::general::STATX_MTIME;
525
526 /// `STATX_CTIME`
527 const CTIME = linux_raw_sys::general::STATX_CTIME;
528
529 /// `STATX_INO`
530 const INO = linux_raw_sys::general::STATX_INO;
531
532 /// `STATX_SIZE`
533 const SIZE = linux_raw_sys::general::STATX_SIZE;
534
535 /// `STATX_BLOCKS`
536 const BLOCKS = linux_raw_sys::general::STATX_BLOCKS;
537
538 /// `STATX_BASIC_STATS`
539 const BASIC_STATS = linux_raw_sys::general::STATX_BASIC_STATS;
540
541 /// `STATX_BTIME`
542 const BTIME = linux_raw_sys::general::STATX_BTIME;
543
544 /// `STATX_MNT_ID` (since Linux 5.8)
545 const MNT_ID = linux_raw_sys::general::STATX_MNT_ID;
546
547 /// `STATX_DIOALIGN` (since Linux 6.1)
548 const DIOALIGN = linux_raw_sys::general::STATX_DIOALIGN;
549
550 /// `STATX_ALL`
551 const ALL = linux_raw_sys::general::STATX_ALL;
552
553 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
554 const _ = !0;
555 }
556}
557
558bitflags! {
559 /// `FALLOC_FL_*` constants for use with [`fallocate`].
560 ///
561 /// [`fallocate`]: crate::fs::fallocate
562 #[repr(transparent)]
563 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
564 pub struct FallocateFlags: u32 {
565 /// `FALLOC_FL_KEEP_SIZE`
566 const KEEP_SIZE = linux_raw_sys::general::FALLOC_FL_KEEP_SIZE;
567 /// `FALLOC_FL_PUNCH_HOLE`
568 const PUNCH_HOLE = linux_raw_sys::general::FALLOC_FL_PUNCH_HOLE;
569 /// `FALLOC_FL_NO_HIDE_STALE`
570 const NO_HIDE_STALE = linux_raw_sys::general::FALLOC_FL_NO_HIDE_STALE;
571 /// `FALLOC_FL_COLLAPSE_RANGE`
572 const COLLAPSE_RANGE = linux_raw_sys::general::FALLOC_FL_COLLAPSE_RANGE;
573 /// `FALLOC_FL_ZERO_RANGE`
574 const ZERO_RANGE = linux_raw_sys::general::FALLOC_FL_ZERO_RANGE;
575 /// `FALLOC_FL_INSERT_RANGE`
576 const INSERT_RANGE = linux_raw_sys::general::FALLOC_FL_INSERT_RANGE;
577 /// `FALLOC_FL_UNSHARE_RANGE`
578 const UNSHARE_RANGE = linux_raw_sys::general::FALLOC_FL_UNSHARE_RANGE;
579
580 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
581 const _ = !0;
582 }
583}
584
585bitflags! {
586 /// `ST_*` constants for use with [`StatVfs`].
587 #[repr(transparent)]
588 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
589 pub struct StatVfsMountFlags: u64 {
590 /// `ST_MANDLOCK`
591 const MANDLOCK = linux_raw_sys::general::MS_MANDLOCK as u64;
592
593 /// `ST_NOATIME`
594 const NOATIME = linux_raw_sys::general::MS_NOATIME as u64;
595
596 /// `ST_NODEV`
597 const NODEV = linux_raw_sys::general::MS_NODEV as u64;
598
599 /// `ST_NODIRATIME`
600 const NODIRATIME = linux_raw_sys::general::MS_NODIRATIME as u64;
601
602 /// `ST_NOEXEC`
603 const NOEXEC = linux_raw_sys::general::MS_NOEXEC as u64;
604
605 /// `ST_NOSUID`
606 const NOSUID = linux_raw_sys::general::MS_NOSUID as u64;
607
608 /// `ST_RDONLY`
609 const RDONLY = linux_raw_sys::general::MS_RDONLY as u64;
610
611 /// `ST_RELATIME`
612 const RELATIME = linux_raw_sys::general::MS_RELATIME as u64;
613
614 /// `ST_SYNCHRONOUS`
615 const SYNCHRONOUS = linux_raw_sys::general::MS_SYNCHRONOUS as u64;
616
617 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
618 const _ = !0;
619 }
620}
621
622/// `LOCK_*` constants for use with [`flock`] and [`fcntl_lock`].
623///
624/// [`flock`]: crate::fs::flock
625/// [`fcntl_lock`]: crate::fs::fcntl_lock
626#[derive(Clone, Copy, Debug, PartialEq, Eq)]
627#[repr(u32)]
628pub enum FlockOperation {
629 /// `LOCK_SH`
630 LockShared = linux_raw_sys::general::LOCK_SH,
631 /// `LOCK_EX`
632 LockExclusive = linux_raw_sys::general::LOCK_EX,
633 /// `LOCK_UN`
634 Unlock = linux_raw_sys::general::LOCK_UN,
635 /// `LOCK_SH | LOCK_NB`
636 NonBlockingLockShared = linux_raw_sys::general::LOCK_SH | linux_raw_sys::general::LOCK_NB,
637 /// `LOCK_EX | LOCK_NB`
638 NonBlockingLockExclusive = linux_raw_sys::general::LOCK_EX | linux_raw_sys::general::LOCK_NB,
639 /// `LOCK_UN | LOCK_NB`
640 NonBlockingUnlock = linux_raw_sys::general::LOCK_UN | linux_raw_sys::general::LOCK_NB,
641}
642
643/// `struct stat` for use with [`statat`] and [`fstat`].
644///
645/// [`statat`]: crate::fs::statat
646/// [`fstat`]: crate::fs::fstat
647// On 32-bit, and mips64, Linux's `struct stat64` has a 32-bit `st_mtime` and
648// friends, so we use our own struct, populated from `statx` where possible, to
649// avoid the y2038 bug.
650#[cfg(any(
651 target_pointer_width = "32",
652 target_arch = "mips64",
653 target_arch = "mips64r6"
654))]
655#[repr(C)]
656#[derive(Debug, Copy, Clone)]
657#[allow(missing_docs)]
658pub struct Stat {
659 pub st_dev: u64,
660 pub st_mode: u32,
661 pub st_nlink: u32,
662 pub st_uid: u32,
663 pub st_gid: u32,
664 pub st_rdev: u64,
665 pub st_size: i64,
666 pub st_blksize: u32,
667 pub st_blocks: u64,
668 #[deprecated(note = "Use `rustix::fs::StatExt::atime` instead.")]
669 pub st_atime: u64,
670 pub st_atime_nsec: u32,
671 #[deprecated(note = "Use `rustix::fs::StatExt::mtime` instead.")]
672 pub st_mtime: u64,
673 pub st_mtime_nsec: u32,
674 #[deprecated(note = "Use `rustix::fs::StatExt::ctime` instead.")]
675 pub st_ctime: u64,
676 pub st_ctime_nsec: u32,
677 pub st_ino: u64,
678}
679
680/// `struct stat` for use with [`statat`] and [`fstat`].
681///
682/// [`statat`]: crate::fs::statat
683/// [`fstat`]: crate::fs::fstat
684#[cfg(all(
685 target_pointer_width = "64",
686 not(target_arch = "mips64"),
687 not(target_arch = "mips64r6")
688))]
689pub type Stat = linux_raw_sys::general::stat;
690
691/// `struct statfs` for use with [`statfs`] and [`fstatfs`].
692///
693/// [`statfs`]: crate::fs::statfs
694/// [`fstatfs`]: crate::fs::fstatfs
695#[allow(clippy::module_name_repetitions)]
696pub type StatFs = linux_raw_sys::general::statfs64;
697
698/// `struct statvfs` for use with [`statvfs`] and [`fstatvfs`].
699///
700/// [`statvfs`]: crate::fs::statvfs
701/// [`fstatvfs`]: crate::fs::fstatvfs
702#[allow(missing_docs)]
703pub struct StatVfs {
704 pub f_bsize: u64,
705 pub f_frsize: u64,
706 pub f_blocks: u64,
707 pub f_bfree: u64,
708 pub f_bavail: u64,
709 pub f_files: u64,
710 pub f_ffree: u64,
711 pub f_favail: u64,
712 pub f_fsid: u64,
713 pub f_flag: StatVfsMountFlags,
714 pub f_namemax: u64,
715}
716
717/// `struct statx` for use with [`statx`].
718///
719/// [`statx`]: crate::fs::statx
720pub type Statx = linux_raw_sys::general::statx;
721
722/// `struct statx_timestamp` for use with [`Statx`].
723pub type StatxTimestamp = linux_raw_sys::general::statx_timestamp;
724
725/// `mode_t`
726#[cfg(not(any(
727 target_arch = "x86",
728 target_arch = "sparc",
729 target_arch = "avr",
730 target_arch = "arm",
731)))]
732pub type RawMode = linux_raw_sys::general::__kernel_mode_t;
733
734/// `mode_t`
735#[cfg(any(
736 target_arch = "x86",
737 target_arch = "sparc",
738 target_arch = "avr",
739 target_arch = "arm",
740))]
741// Don't use `__kernel_mode_t` since it's `u16` which differs from `st_size`.
742pub type RawMode = c::c_uint;
743
744/// `dev_t`
745// Within the kernel the `dev_t` is 32-bit, but userspace uses a 64-bit field.
746pub type Dev = u64;
747
748/// `__fsword_t`
749#[cfg(not(any(target_arch = "mips64", target_arch = "mips64r6")))]
750pub type FsWord = linux_raw_sys::general::__fsword_t;
751
752/// `__fsword_t`
753#[cfg(any(target_arch = "mips64", target_arch = "mips64r6"))]
754pub type FsWord = i64;
755