rustix/backend/linux_raw/fs/
types.rs1use crate::backend::c;
2use bitflags::bitflags;
3
4bitflags! {
5 #[repr(transparent)]
9 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
10 pub struct Access: c::c_uint {
11 const READ_OK = linux_raw_sys::general::R_OK;
13
14 const WRITE_OK = linux_raw_sys::general::W_OK;
16
17 const EXEC_OK = linux_raw_sys::general::X_OK;
19
20 const EXISTS = linux_raw_sys::general::F_OK;
22
23 const _ = !0;
25 }
26}
27
28bitflags! {
29 #[repr(transparent)]
35 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
36 pub struct AtFlags: c::c_uint {
37 const SYMLINK_NOFOLLOW = linux_raw_sys::general::AT_SYMLINK_NOFOLLOW;
39
40 const EACCESS = linux_raw_sys::general::AT_EACCESS;
42
43 const REMOVEDIR = linux_raw_sys::general::AT_REMOVEDIR;
45
46 const SYMLINK_FOLLOW = linux_raw_sys::general::AT_SYMLINK_FOLLOW;
48
49 const NO_AUTOMOUNT = linux_raw_sys::general::AT_NO_AUTOMOUNT;
51
52 const EMPTY_PATH = linux_raw_sys::general::AT_EMPTY_PATH;
54
55 const STATX_SYNC_AS_STAT = linux_raw_sys::general::AT_STATX_SYNC_AS_STAT;
57
58 const STATX_FORCE_SYNC = linux_raw_sys::general::AT_STATX_FORCE_SYNC;
60
61 const STATX_DONT_SYNC = linux_raw_sys::general::AT_STATX_DONT_SYNC;
63
64 const _ = !0;
66 }
67}
68
69bitflags! {
70 #[repr(transparent)]
76 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
77 pub struct Mode: RawMode {
78 const RWXU = linux_raw_sys::general::S_IRWXU;
80
81 const RUSR = linux_raw_sys::general::S_IRUSR;
83
84 const WUSR = linux_raw_sys::general::S_IWUSR;
86
87 const XUSR = linux_raw_sys::general::S_IXUSR;
89
90 const RWXG = linux_raw_sys::general::S_IRWXG;
92
93 const RGRP = linux_raw_sys::general::S_IRGRP;
95
96 const WGRP = linux_raw_sys::general::S_IWGRP;
98
99 const XGRP = linux_raw_sys::general::S_IXGRP;
101
102 const RWXO = linux_raw_sys::general::S_IRWXO;
104
105 const ROTH = linux_raw_sys::general::S_IROTH;
107
108 const WOTH = linux_raw_sys::general::S_IWOTH;
110
111 const XOTH = linux_raw_sys::general::S_IXOTH;
113
114 const SUID = linux_raw_sys::general::S_ISUID;
116
117 const SGID = linux_raw_sys::general::S_ISGID;
119
120 const SVTX = linux_raw_sys::general::S_ISVTX;
122
123 const _ = !0;
125 }
126}
127
128impl Mode {
129 #[inline]
132 pub const fn from_raw_mode(st_mode: RawMode) -> Self {
133 Self::from_bits_truncate(st_mode & !linux_raw_sys::general::S_IFMT)
134 }
135
136 #[inline]
138 pub const fn as_raw_mode(self) -> RawMode {
139 self.bits()
140 }
141}
142
143impl From<RawMode> for Mode {
144 #[inline]
151 fn from(st_mode: RawMode) -> Self {
152 Self::from_raw_mode(st_mode)
153 }
154}
155
156impl From<Mode> for RawMode {
157 #[inline]
164 fn from(mode: Mode) -> Self {
165 mode.as_raw_mode()
166 }
167}
168
169bitflags! {
170 #[repr(transparent)]
174 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
175 pub struct OFlags: c::c_uint {
176 const ACCMODE = linux_raw_sys::general::O_ACCMODE;
178
179 const RWMODE = linux_raw_sys::general::O_RDONLY |
187 linux_raw_sys::general::O_WRONLY |
188 linux_raw_sys::general::O_RDWR;
189
190 const APPEND = linux_raw_sys::general::O_APPEND;
192
193 #[doc(alias = "CREAT")]
195 const CREATE = linux_raw_sys::general::O_CREAT;
196
197 const DIRECTORY = linux_raw_sys::general::O_DIRECTORY;
199
200 const DSYNC = linux_raw_sys::general::O_SYNC;
202
203 const EXCL = linux_raw_sys::general::O_EXCL;
205
206 const FSYNC = linux_raw_sys::general::O_SYNC;
208
209 const NOFOLLOW = linux_raw_sys::general::O_NOFOLLOW;
211
212 const NONBLOCK = linux_raw_sys::general::O_NONBLOCK;
214
215 const RDONLY = linux_raw_sys::general::O_RDONLY;
217
218 const WRONLY = linux_raw_sys::general::O_WRONLY;
220
221 const RDWR = linux_raw_sys::general::O_RDWR;
225
226 const NOCTTY = linux_raw_sys::general::O_NOCTTY;
228
229 const RSYNC = linux_raw_sys::general::O_SYNC;
231
232 const SYNC = linux_raw_sys::general::O_SYNC;
234
235 const TRUNC = linux_raw_sys::general::O_TRUNC;
237
238 const PATH = linux_raw_sys::general::O_PATH;
240
241 const CLOEXEC = linux_raw_sys::general::O_CLOEXEC;
243
244 const TMPFILE = linux_raw_sys::general::O_TMPFILE;
246
247 const NOATIME = linux_raw_sys::general::O_NOATIME;
249
250 const DIRECT = linux_raw_sys::general::O_DIRECT;
252
253 const LARGEFILE = linux_raw_sys::general::O_LARGEFILE;
259
260 const _ = !0;
262 }
263}
264
265bitflags! {
266 #[repr(transparent)]
270 #[derive(Default, Copy, Clone, Eq, PartialEq, Hash, Debug)]
271 pub struct ResolveFlags: u64 {
272 const NO_XDEV = linux_raw_sys::general::RESOLVE_NO_XDEV as u64;
274
275 const NO_MAGICLINKS = linux_raw_sys::general::RESOLVE_NO_MAGICLINKS as u64;
277
278 const NO_SYMLINKS = linux_raw_sys::general::RESOLVE_NO_SYMLINKS as u64;
280
281 const BENEATH = linux_raw_sys::general::RESOLVE_BENEATH as u64;
283
284 const IN_ROOT = linux_raw_sys::general::RESOLVE_IN_ROOT as u64;
286
287 const CACHED = linux_raw_sys::general::RESOLVE_CACHED as u64;
289
290 const _ = !0;
292 }
293}
294
295bitflags! {
296 #[repr(transparent)]
300 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
301 pub struct RenameFlags: c::c_uint {
302 const EXCHANGE = linux_raw_sys::general::RENAME_EXCHANGE;
304
305 const NOREPLACE = linux_raw_sys::general::RENAME_NOREPLACE;
307
308 const WHITEOUT = linux_raw_sys::general::RENAME_WHITEOUT;
310
311 const _ = !0;
313 }
314}
315
316#[derive(Clone, Copy, Debug, PartialEq, Eq)]
321pub enum FileType {
322 RegularFile = linux_raw_sys::general::S_IFREG as isize,
324
325 Directory = linux_raw_sys::general::S_IFDIR as isize,
327
328 Symlink = linux_raw_sys::general::S_IFLNK as isize,
330
331 #[doc(alias = "IFO")]
333 Fifo = linux_raw_sys::general::S_IFIFO as isize,
334
335 Socket = linux_raw_sys::general::S_IFSOCK as isize,
337
338 CharacterDevice = linux_raw_sys::general::S_IFCHR as isize,
340
341 BlockDevice = linux_raw_sys::general::S_IFBLK as isize,
343
344 Unknown,
346}
347
348impl FileType {
349 #[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 #[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 #[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 _ => Self::Unknown,
393 }
394 }
395}
396
397#[derive(Debug, Copy, Clone, Eq, PartialEq)]
401#[repr(u32)]
402pub enum Advice {
403 Normal = linux_raw_sys::general::POSIX_FADV_NORMAL,
405
406 Sequential = linux_raw_sys::general::POSIX_FADV_SEQUENTIAL,
408
409 Random = linux_raw_sys::general::POSIX_FADV_RANDOM,
411
412 NoReuse = linux_raw_sys::general::POSIX_FADV_NOREUSE,
414
415 WillNeed = linux_raw_sys::general::POSIX_FADV_WILLNEED,
417
418 DontNeed = linux_raw_sys::general::POSIX_FADV_DONTNEED,
420}
421
422bitflags! {
423 #[repr(transparent)]
427 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
428 pub struct MemfdFlags: c::c_uint {
429 const CLOEXEC = linux_raw_sys::general::MFD_CLOEXEC;
431
432 const ALLOW_SEALING = linux_raw_sys::general::MFD_ALLOW_SEALING;
434
435 const HUGETLB = linux_raw_sys::general::MFD_HUGETLB;
437
438 const NOEXEC_SEAL = linux_raw_sys::general::MFD_NOEXEC_SEAL;
440 const EXEC = linux_raw_sys::general::MFD_EXEC;
442
443 const HUGE_64KB = linux_raw_sys::general::MFD_HUGE_64KB;
445 const HUGE_512KB = linux_raw_sys::general::MFD_HUGE_512KB;
447 const HUGE_1MB = linux_raw_sys::general::MFD_HUGE_1MB;
449 const HUGE_2MB = linux_raw_sys::general::MFD_HUGE_2MB;
451 const HUGE_8MB = linux_raw_sys::general::MFD_HUGE_8MB;
453 const HUGE_16MB = linux_raw_sys::general::MFD_HUGE_16MB;
455 const HUGE_32MB = linux_raw_sys::general::MFD_HUGE_32MB;
457 const HUGE_256MB = linux_raw_sys::general::MFD_HUGE_256MB;
459 const HUGE_512MB = linux_raw_sys::general::MFD_HUGE_512MB;
461 const HUGE_1GB = linux_raw_sys::general::MFD_HUGE_1GB;
463 const HUGE_2GB = linux_raw_sys::general::MFD_HUGE_2GB;
465 const HUGE_16GB = linux_raw_sys::general::MFD_HUGE_16GB;
467
468 const _ = !0;
470 }
471}
472
473bitflags! {
474 #[repr(transparent)]
480 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
481 pub struct SealFlags: u32 {
482 const SEAL = linux_raw_sys::general::F_SEAL_SEAL;
484 const SHRINK = linux_raw_sys::general::F_SEAL_SHRINK;
486 const GROW = linux_raw_sys::general::F_SEAL_GROW;
488 const WRITE = linux_raw_sys::general::F_SEAL_WRITE;
490 const FUTURE_WRITE = linux_raw_sys::general::F_SEAL_FUTURE_WRITE;
492
493 const _ = !0;
495 }
496}
497
498bitflags! {
499 #[repr(transparent)]
503 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
504 pub struct StatxFlags: u32 {
505 const TYPE = linux_raw_sys::general::STATX_TYPE;
507
508 const MODE = linux_raw_sys::general::STATX_MODE;
510
511 const NLINK = linux_raw_sys::general::STATX_NLINK;
513
514 const UID = linux_raw_sys::general::STATX_UID;
516
517 const GID = linux_raw_sys::general::STATX_GID;
519
520 const ATIME = linux_raw_sys::general::STATX_ATIME;
522
523 const MTIME = linux_raw_sys::general::STATX_MTIME;
525
526 const CTIME = linux_raw_sys::general::STATX_CTIME;
528
529 const INO = linux_raw_sys::general::STATX_INO;
531
532 const SIZE = linux_raw_sys::general::STATX_SIZE;
534
535 const BLOCKS = linux_raw_sys::general::STATX_BLOCKS;
537
538 const BASIC_STATS = linux_raw_sys::general::STATX_BASIC_STATS;
540
541 const BTIME = linux_raw_sys::general::STATX_BTIME;
543
544 const MNT_ID = linux_raw_sys::general::STATX_MNT_ID;
546
547 const DIOALIGN = linux_raw_sys::general::STATX_DIOALIGN;
549
550 const ALL = linux_raw_sys::general::STATX_ALL;
552
553 const _ = !0;
555 }
556}
557
558bitflags! {
559 #[repr(transparent)]
563 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
564 pub struct FallocateFlags: u32 {
565 const KEEP_SIZE = linux_raw_sys::general::FALLOC_FL_KEEP_SIZE;
567 const PUNCH_HOLE = linux_raw_sys::general::FALLOC_FL_PUNCH_HOLE;
569 const NO_HIDE_STALE = linux_raw_sys::general::FALLOC_FL_NO_HIDE_STALE;
571 const COLLAPSE_RANGE = linux_raw_sys::general::FALLOC_FL_COLLAPSE_RANGE;
573 const ZERO_RANGE = linux_raw_sys::general::FALLOC_FL_ZERO_RANGE;
575 const INSERT_RANGE = linux_raw_sys::general::FALLOC_FL_INSERT_RANGE;
577 const UNSHARE_RANGE = linux_raw_sys::general::FALLOC_FL_UNSHARE_RANGE;
579
580 const _ = !0;
582 }
583}
584
585bitflags! {
586 #[repr(transparent)]
588 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
589 pub struct StatVfsMountFlags: u64 {
590 const MANDLOCK = linux_raw_sys::general::MS_MANDLOCK as u64;
592
593 const NOATIME = linux_raw_sys::general::MS_NOATIME as u64;
595
596 const NODEV = linux_raw_sys::general::MS_NODEV as u64;
598
599 const NODIRATIME = linux_raw_sys::general::MS_NODIRATIME as u64;
601
602 const NOEXEC = linux_raw_sys::general::MS_NOEXEC as u64;
604
605 const NOSUID = linux_raw_sys::general::MS_NOSUID as u64;
607
608 const RDONLY = linux_raw_sys::general::MS_RDONLY as u64;
610
611 const RELATIME = linux_raw_sys::general::MS_RELATIME as u64;
613
614 const SYNCHRONOUS = linux_raw_sys::general::MS_SYNCHRONOUS as u64;
616
617 const _ = !0;
619 }
620}
621
622#[derive(Clone, Copy, Debug, PartialEq, Eq)]
627#[repr(u32)]
628pub enum FlockOperation {
629 LockShared = linux_raw_sys::general::LOCK_SH,
631 LockExclusive = linux_raw_sys::general::LOCK_EX,
633 Unlock = linux_raw_sys::general::LOCK_UN,
635 NonBlockingLockShared = linux_raw_sys::general::LOCK_SH | linux_raw_sys::general::LOCK_NB,
637 NonBlockingLockExclusive = linux_raw_sys::general::LOCK_EX | linux_raw_sys::general::LOCK_NB,
639 NonBlockingUnlock = linux_raw_sys::general::LOCK_UN | linux_raw_sys::general::LOCK_NB,
641}
642
643#[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#[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#[allow(clippy::module_name_repetitions)]
696pub type StatFs = linux_raw_sys::general::statfs64;
697
698#[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
717pub type Statx = linux_raw_sys::general::statx;
721
722pub type StatxTimestamp = linux_raw_sys::general::statx_timestamp;
724
725#[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#[cfg(any(
736 target_arch = "x86",
737 target_arch = "sparc",
738 target_arch = "avr",
739 target_arch = "arm",
740))]
741pub type RawMode = c::c_uint;
743
744pub type Dev = u64;
747
748#[cfg(not(any(target_arch = "mips64", target_arch = "mips64r6")))]
750pub type FsWord = linux_raw_sys::general::__fsword_t;
751
752#[cfg(any(target_arch = "mips64", target_arch = "mips64r6"))]
754pub type FsWord = i64;