1 use crate::backend::c; 2 use bitflags::bitflags; 3 4 bitflags! { 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 28 bitflags! { 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 69 bitflags! { 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 128 impl Mode { 129 /// Construct a `Mode` from the mode bits of the `st_mode` field of a 130 /// `Mode`. 131 #[inline] from_raw_mode(st_mode: RawMode) -> Self132 pub const fn from_raw_mode(st_mode: RawMode) -> Self { 133 Self::from_bits_truncate(st_mode) 134 } 135 136 /// Construct an `st_mode` value from a `Mode`. 137 #[inline] as_raw_mode(self) -> RawMode138 pub const fn as_raw_mode(self) -> RawMode { 139 self.bits() 140 } 141 } 142 143 impl 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] from(st_mode: RawMode) -> Self151 fn from(st_mode: RawMode) -> Self { 152 Self::from_raw_mode(st_mode) 153 } 154 } 155 156 impl 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] from(mode: Mode) -> Self164 fn from(mode: Mode) -> Self { 165 mode.as_raw_mode() 166 } 167 } 168 169 bitflags! { 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 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> 254 const _ = !0; 255 } 256 } 257 258 bitflags! { 259 /// `RESOLVE_*` constants for use with [`openat2`]. 260 /// 261 /// [`openat2`]: crate::fs::openat2 262 #[repr(transparent)] 263 #[derive(Default, Copy, Clone, Eq, PartialEq, Hash, Debug)] 264 pub struct ResolveFlags: u64 { 265 /// `RESOLVE_NO_XDEV` 266 const NO_XDEV = linux_raw_sys::general::RESOLVE_NO_XDEV as u64; 267 268 /// `RESOLVE_NO_MAGICLINKS` 269 const NO_MAGICLINKS = linux_raw_sys::general::RESOLVE_NO_MAGICLINKS as u64; 270 271 /// `RESOLVE_NO_SYMLINKS` 272 const NO_SYMLINKS = linux_raw_sys::general::RESOLVE_NO_SYMLINKS as u64; 273 274 /// `RESOLVE_BENEATH` 275 const BENEATH = linux_raw_sys::general::RESOLVE_BENEATH as u64; 276 277 /// `RESOLVE_IN_ROOT` 278 const IN_ROOT = linux_raw_sys::general::RESOLVE_IN_ROOT as u64; 279 280 /// `RESOLVE_CACHED` (since Linux 5.12) 281 const CACHED = linux_raw_sys::general::RESOLVE_CACHED as u64; 282 283 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> 284 const _ = !0; 285 } 286 } 287 288 bitflags! { 289 /// `RENAME_*` constants for use with [`renameat_with`]. 290 /// 291 /// [`renameat_with`]: crate::fs::renameat_with 292 #[repr(transparent)] 293 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 294 pub struct RenameFlags: c::c_uint { 295 /// `RENAME_EXCHANGE` 296 const EXCHANGE = linux_raw_sys::general::RENAME_EXCHANGE; 297 298 /// `RENAME_NOREPLACE` 299 const NOREPLACE = linux_raw_sys::general::RENAME_NOREPLACE; 300 301 /// `RENAME_WHITEOUT` 302 const WHITEOUT = linux_raw_sys::general::RENAME_WHITEOUT; 303 304 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> 305 const _ = !0; 306 } 307 } 308 309 /// `S_IF*` constants for use with [`mknodat`] and [`Stat`]'s `st_mode` field. 310 /// 311 /// [`mknodat`]: crate::fs::mknodat 312 /// [`Stat`]: crate::fs::Stat 313 #[derive(Clone, Copy, Debug, PartialEq, Eq)] 314 pub enum FileType { 315 /// `S_IFREG` 316 RegularFile = linux_raw_sys::general::S_IFREG as isize, 317 318 /// `S_IFDIR` 319 Directory = linux_raw_sys::general::S_IFDIR as isize, 320 321 /// `S_IFLNK` 322 Symlink = linux_raw_sys::general::S_IFLNK as isize, 323 324 /// `S_IFIFO` 325 #[doc(alias = "IFO")] 326 Fifo = linux_raw_sys::general::S_IFIFO as isize, 327 328 /// `S_IFSOCK` 329 Socket = linux_raw_sys::general::S_IFSOCK as isize, 330 331 /// `S_IFCHR` 332 CharacterDevice = linux_raw_sys::general::S_IFCHR as isize, 333 334 /// `S_IFBLK` 335 BlockDevice = linux_raw_sys::general::S_IFBLK as isize, 336 337 /// An unknown filesystem object. 338 Unknown, 339 } 340 341 impl FileType { 342 /// Construct a `FileType` from the `S_IFMT` bits of the `st_mode` field of 343 /// a `Stat`. 344 #[inline] from_raw_mode(st_mode: RawMode) -> Self345 pub const fn from_raw_mode(st_mode: RawMode) -> Self { 346 match st_mode & linux_raw_sys::general::S_IFMT { 347 linux_raw_sys::general::S_IFREG => Self::RegularFile, 348 linux_raw_sys::general::S_IFDIR => Self::Directory, 349 linux_raw_sys::general::S_IFLNK => Self::Symlink, 350 linux_raw_sys::general::S_IFIFO => Self::Fifo, 351 linux_raw_sys::general::S_IFSOCK => Self::Socket, 352 linux_raw_sys::general::S_IFCHR => Self::CharacterDevice, 353 linux_raw_sys::general::S_IFBLK => Self::BlockDevice, 354 _ => Self::Unknown, 355 } 356 } 357 358 /// Construct an `st_mode` value from a `FileType`. 359 #[inline] as_raw_mode(self) -> RawMode360 pub const fn as_raw_mode(self) -> RawMode { 361 match self { 362 Self::RegularFile => linux_raw_sys::general::S_IFREG, 363 Self::Directory => linux_raw_sys::general::S_IFDIR, 364 Self::Symlink => linux_raw_sys::general::S_IFLNK, 365 Self::Fifo => linux_raw_sys::general::S_IFIFO, 366 Self::Socket => linux_raw_sys::general::S_IFSOCK, 367 Self::CharacterDevice => linux_raw_sys::general::S_IFCHR, 368 Self::BlockDevice => linux_raw_sys::general::S_IFBLK, 369 Self::Unknown => linux_raw_sys::general::S_IFMT, 370 } 371 } 372 373 /// Construct a `FileType` from the `d_type` field of a `c::dirent`. 374 #[inline] from_dirent_d_type(d_type: u8) -> Self375 pub(crate) const fn from_dirent_d_type(d_type: u8) -> Self { 376 match d_type as u32 { 377 linux_raw_sys::general::DT_REG => Self::RegularFile, 378 linux_raw_sys::general::DT_DIR => Self::Directory, 379 linux_raw_sys::general::DT_LNK => Self::Symlink, 380 linux_raw_sys::general::DT_SOCK => Self::Socket, 381 linux_raw_sys::general::DT_FIFO => Self::Fifo, 382 linux_raw_sys::general::DT_CHR => Self::CharacterDevice, 383 linux_raw_sys::general::DT_BLK => Self::BlockDevice, 384 // linux_raw_sys::general::DT_UNKNOWN | 385 _ => Self::Unknown, 386 } 387 } 388 } 389 390 /// `POSIX_FADV_*` constants for use with [`fadvise`]. 391 /// 392 /// [`fadvise`]: crate::fs::fadvise 393 #[derive(Debug, Copy, Clone, Eq, PartialEq)] 394 #[repr(u32)] 395 pub enum Advice { 396 /// `POSIX_FADV_NORMAL` 397 Normal = linux_raw_sys::general::POSIX_FADV_NORMAL, 398 399 /// `POSIX_FADV_SEQUENTIAL` 400 Sequential = linux_raw_sys::general::POSIX_FADV_SEQUENTIAL, 401 402 /// `POSIX_FADV_RANDOM` 403 Random = linux_raw_sys::general::POSIX_FADV_RANDOM, 404 405 /// `POSIX_FADV_NOREUSE` 406 NoReuse = linux_raw_sys::general::POSIX_FADV_NOREUSE, 407 408 /// `POSIX_FADV_WILLNEED` 409 WillNeed = linux_raw_sys::general::POSIX_FADV_WILLNEED, 410 411 /// `POSIX_FADV_DONTNEED` 412 DontNeed = linux_raw_sys::general::POSIX_FADV_DONTNEED, 413 } 414 415 bitflags! { 416 /// `MFD_*` constants for use with [`memfd_create`]. 417 /// 418 /// [`memfd_create`]: crate::fs::memfd_create 419 #[repr(transparent)] 420 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 421 pub struct MemfdFlags: c::c_uint { 422 /// `MFD_CLOEXEC` 423 const CLOEXEC = linux_raw_sys::general::MFD_CLOEXEC; 424 425 /// `MFD_ALLOW_SEALING` 426 const ALLOW_SEALING = linux_raw_sys::general::MFD_ALLOW_SEALING; 427 428 /// `MFD_HUGETLB` (since Linux 4.14) 429 const HUGETLB = linux_raw_sys::general::MFD_HUGETLB; 430 431 /// `MFD_HUGE_64KB` 432 const HUGE_64KB = linux_raw_sys::general::MFD_HUGE_64KB; 433 /// `MFD_HUGE_512JB` 434 const HUGE_512KB = linux_raw_sys::general::MFD_HUGE_512KB; 435 /// `MFD_HUGE_1MB` 436 const HUGE_1MB = linux_raw_sys::general::MFD_HUGE_1MB; 437 /// `MFD_HUGE_2MB` 438 const HUGE_2MB = linux_raw_sys::general::MFD_HUGE_2MB; 439 /// `MFD_HUGE_8MB` 440 const HUGE_8MB = linux_raw_sys::general::MFD_HUGE_8MB; 441 /// `MFD_HUGE_16MB` 442 const HUGE_16MB = linux_raw_sys::general::MFD_HUGE_16MB; 443 /// `MFD_HUGE_32MB` 444 const HUGE_32MB = linux_raw_sys::general::MFD_HUGE_32MB; 445 /// `MFD_HUGE_256MB` 446 const HUGE_256MB = linux_raw_sys::general::MFD_HUGE_256MB; 447 /// `MFD_HUGE_512MB` 448 const HUGE_512MB = linux_raw_sys::general::MFD_HUGE_512MB; 449 /// `MFD_HUGE_1GB` 450 const HUGE_1GB = linux_raw_sys::general::MFD_HUGE_1GB; 451 /// `MFD_HUGE_2GB` 452 const HUGE_2GB = linux_raw_sys::general::MFD_HUGE_2GB; 453 /// `MFD_HUGE_16GB` 454 const HUGE_16GB = linux_raw_sys::general::MFD_HUGE_16GB; 455 456 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> 457 const _ = !0; 458 } 459 } 460 461 bitflags! { 462 /// `F_SEAL_*` constants for use with [`fcntl_add_seals`] and 463 /// [`fcntl_get_seals`]. 464 /// 465 /// [`fcntl_add_seals`]: crate::fs::fcntl_add_seals 466 /// [`fcntl_get_seals`]: crate::fs::fcntl_get_seals 467 #[repr(transparent)] 468 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 469 pub struct SealFlags: u32 { 470 /// `F_SEAL_SEAL`. 471 const SEAL = linux_raw_sys::general::F_SEAL_SEAL; 472 /// `F_SEAL_SHRINK`. 473 const SHRINK = linux_raw_sys::general::F_SEAL_SHRINK; 474 /// `F_SEAL_GROW`. 475 const GROW = linux_raw_sys::general::F_SEAL_GROW; 476 /// `F_SEAL_WRITE`. 477 const WRITE = linux_raw_sys::general::F_SEAL_WRITE; 478 /// `F_SEAL_FUTURE_WRITE` (since Linux 5.1) 479 const FUTURE_WRITE = linux_raw_sys::general::F_SEAL_FUTURE_WRITE; 480 481 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> 482 const _ = !0; 483 } 484 } 485 486 bitflags! { 487 /// `STATX_*` constants for use with [`statx`]. 488 /// 489 /// [`statx`]: crate::fs::statx 490 #[repr(transparent)] 491 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 492 pub struct StatxFlags: u32 { 493 /// `STATX_TYPE` 494 const TYPE = linux_raw_sys::general::STATX_TYPE; 495 496 /// `STATX_MODE` 497 const MODE = linux_raw_sys::general::STATX_MODE; 498 499 /// `STATX_NLINK` 500 const NLINK = linux_raw_sys::general::STATX_NLINK; 501 502 /// `STATX_UID` 503 const UID = linux_raw_sys::general::STATX_UID; 504 505 /// `STATX_GID` 506 const GID = linux_raw_sys::general::STATX_GID; 507 508 /// `STATX_ATIME` 509 const ATIME = linux_raw_sys::general::STATX_ATIME; 510 511 /// `STATX_MTIME` 512 const MTIME = linux_raw_sys::general::STATX_MTIME; 513 514 /// `STATX_CTIME` 515 const CTIME = linux_raw_sys::general::STATX_CTIME; 516 517 /// `STATX_INO` 518 const INO = linux_raw_sys::general::STATX_INO; 519 520 /// `STATX_SIZE` 521 const SIZE = linux_raw_sys::general::STATX_SIZE; 522 523 /// `STATX_BLOCKS` 524 const BLOCKS = linux_raw_sys::general::STATX_BLOCKS; 525 526 /// `STATX_BASIC_STATS` 527 const BASIC_STATS = linux_raw_sys::general::STATX_BASIC_STATS; 528 529 /// `STATX_BTIME` 530 const BTIME = linux_raw_sys::general::STATX_BTIME; 531 532 /// `STATX_MNT_ID` (since Linux 5.8) 533 const MNT_ID = linux_raw_sys::general::STATX_MNT_ID; 534 535 /// `STATX_DIOALIGN` (since Linux 6.1) 536 const DIOALIGN = linux_raw_sys::general::STATX_DIOALIGN; 537 538 /// `STATX_ALL` 539 const ALL = linux_raw_sys::general::STATX_ALL; 540 541 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> 542 const _ = !0; 543 } 544 } 545 546 bitflags! { 547 /// `FALLOC_FL_*` constants for use with [`fallocate`]. 548 /// 549 /// [`fallocate`]: crate::fs::fallocate 550 #[repr(transparent)] 551 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 552 pub struct FallocateFlags: u32 { 553 /// `FALLOC_FL_KEEP_SIZE` 554 const KEEP_SIZE = linux_raw_sys::general::FALLOC_FL_KEEP_SIZE; 555 /// `FALLOC_FL_PUNCH_HOLE` 556 const PUNCH_HOLE = linux_raw_sys::general::FALLOC_FL_PUNCH_HOLE; 557 /// `FALLOC_FL_NO_HIDE_STALE` 558 const NO_HIDE_STALE = linux_raw_sys::general::FALLOC_FL_NO_HIDE_STALE; 559 /// `FALLOC_FL_COLLAPSE_RANGE` 560 const COLLAPSE_RANGE = linux_raw_sys::general::FALLOC_FL_COLLAPSE_RANGE; 561 /// `FALLOC_FL_ZERO_RANGE` 562 const ZERO_RANGE = linux_raw_sys::general::FALLOC_FL_ZERO_RANGE; 563 /// `FALLOC_FL_INSERT_RANGE` 564 const INSERT_RANGE = linux_raw_sys::general::FALLOC_FL_INSERT_RANGE; 565 /// `FALLOC_FL_UNSHARE_RANGE` 566 const UNSHARE_RANGE = linux_raw_sys::general::FALLOC_FL_UNSHARE_RANGE; 567 568 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> 569 const _ = !0; 570 } 571 } 572 573 bitflags! { 574 /// `ST_*` constants for use with [`StatVfs`]. 575 #[repr(transparent)] 576 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 577 pub struct StatVfsMountFlags: u64 { 578 /// `ST_MANDLOCK` 579 const MANDLOCK = linux_raw_sys::general::MS_MANDLOCK as u64; 580 581 /// `ST_NOATIME` 582 const NOATIME = linux_raw_sys::general::MS_NOATIME as u64; 583 584 /// `ST_NODEV` 585 const NODEV = linux_raw_sys::general::MS_NODEV as u64; 586 587 /// `ST_NODIRATIME` 588 const NODIRATIME = linux_raw_sys::general::MS_NODIRATIME as u64; 589 590 /// `ST_NOEXEC` 591 const NOEXEC = linux_raw_sys::general::MS_NOEXEC as u64; 592 593 /// `ST_NOSUID` 594 const NOSUID = linux_raw_sys::general::MS_NOSUID as u64; 595 596 /// `ST_RDONLY` 597 const RDONLY = linux_raw_sys::general::MS_RDONLY as u64; 598 599 /// `ST_RELATIME` 600 const RELATIME = linux_raw_sys::general::MS_RELATIME as u64; 601 602 /// `ST_SYNCHRONOUS` 603 const SYNCHRONOUS = linux_raw_sys::general::MS_SYNCHRONOUS as u64; 604 605 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> 606 const _ = !0; 607 } 608 } 609 610 /// `LOCK_*` constants for use with [`flock`] and [`fcntl_lock`]. 611 /// 612 /// [`flock`]: crate::fs::flock 613 /// [`fcntl_lock`]: crate::fs::fcntl_lock 614 #[derive(Clone, Copy, Debug, PartialEq, Eq)] 615 #[repr(u32)] 616 pub enum FlockOperation { 617 /// `LOCK_SH` 618 LockShared = linux_raw_sys::general::LOCK_SH, 619 /// `LOCK_EX` 620 LockExclusive = linux_raw_sys::general::LOCK_EX, 621 /// `LOCK_UN` 622 Unlock = linux_raw_sys::general::LOCK_UN, 623 /// `LOCK_SH | LOCK_NB` 624 NonBlockingLockShared = linux_raw_sys::general::LOCK_SH | linux_raw_sys::general::LOCK_NB, 625 /// `LOCK_EX | LOCK_NB` 626 NonBlockingLockExclusive = linux_raw_sys::general::LOCK_EX | linux_raw_sys::general::LOCK_NB, 627 /// `LOCK_UN | LOCK_NB` 628 NonBlockingUnlock = linux_raw_sys::general::LOCK_UN | linux_raw_sys::general::LOCK_NB, 629 } 630 631 /// `struct stat` for use with [`statat`] and [`fstat`]. 632 /// 633 /// [`statat`]: crate::fs::statat 634 /// [`fstat`]: crate::fs::fstat 635 // On 32-bit, and mips64, Linux's `struct stat64` has a 32-bit `st_mtime` and 636 // friends, so we use our own struct, populated from `statx` where possible, to 637 // avoid the y2038 bug. 638 #[cfg(any( 639 target_pointer_width = "32", 640 target_arch = "mips64", 641 target_arch = "mips64r6" 642 ))] 643 #[repr(C)] 644 #[derive(Debug, Copy, Clone)] 645 #[allow(missing_docs)] 646 pub struct Stat { 647 pub st_dev: u64, 648 pub st_mode: u32, 649 pub st_nlink: u32, 650 pub st_uid: u32, 651 pub st_gid: u32, 652 pub st_rdev: u64, 653 pub st_size: i64, 654 pub st_blksize: u32, 655 pub st_blocks: u64, 656 #[deprecated(note = "Use `rustix::fs::StatExt::atime` instead.")] 657 pub st_atime: u64, 658 pub st_atime_nsec: u32, 659 #[deprecated(note = "Use `rustix::fs::StatExt::mtime` instead.")] 660 pub st_mtime: u64, 661 pub st_mtime_nsec: u32, 662 #[deprecated(note = "Use `rustix::fs::StatExt::ctime` instead.")] 663 pub st_ctime: u64, 664 pub st_ctime_nsec: u32, 665 pub st_ino: u64, 666 } 667 668 /// `struct stat` for use with [`statat`] and [`fstat`]. 669 /// 670 /// [`statat`]: crate::fs::statat 671 /// [`fstat`]: crate::fs::fstat 672 #[cfg(all( 673 target_pointer_width = "64", 674 not(target_arch = "mips64"), 675 not(target_arch = "mips64r6") 676 ))] 677 pub type Stat = linux_raw_sys::general::stat; 678 679 /// `struct statfs` for use with [`statfs`] and [`fstatfs`]. 680 /// 681 /// [`statfs`]: crate::fs::statfs 682 /// [`fstatfs`]: crate::fs::fstatfs 683 #[allow(clippy::module_name_repetitions)] 684 pub type StatFs = linux_raw_sys::general::statfs64; 685 686 /// `struct statvfs` for use with [`statvfs`] and [`fstatvfs`]. 687 /// 688 /// [`statvfs`]: crate::fs::statvfs 689 /// [`fstatvfs`]: crate::fs::fstatvfs 690 #[allow(missing_docs)] 691 pub struct StatVfs { 692 pub f_bsize: u64, 693 pub f_frsize: u64, 694 pub f_blocks: u64, 695 pub f_bfree: u64, 696 pub f_bavail: u64, 697 pub f_files: u64, 698 pub f_ffree: u64, 699 pub f_favail: u64, 700 pub f_fsid: u64, 701 pub f_flag: StatVfsMountFlags, 702 pub f_namemax: u64, 703 } 704 705 /// `struct statx` for use with [`statx`]. 706 /// 707 /// [`statx`]: crate::fs::statx 708 pub type Statx = linux_raw_sys::general::statx; 709 710 /// `struct statx_timestamp` for use with [`Statx`]. 711 pub type StatxTimestamp = linux_raw_sys::general::statx_timestamp; 712 713 /// `mode_t` 714 #[cfg(not(any( 715 target_arch = "x86", 716 target_arch = "sparc", 717 target_arch = "avr", 718 target_arch = "arm", 719 )))] 720 pub type RawMode = linux_raw_sys::general::__kernel_mode_t; 721 722 /// `mode_t` 723 #[cfg(any( 724 target_arch = "x86", 725 target_arch = "sparc", 726 target_arch = "avr", 727 target_arch = "arm", 728 ))] 729 // Don't use `__kernel_mode_t` since it's `u16` which differs from `st_size`. 730 pub type RawMode = c::c_uint; 731 732 /// `dev_t` 733 // Within the kernel the dev_t is 32-bit, but userspace uses a 64-bit field. 734 pub type Dev = u64; 735 736 /// `__fsword_t` 737 #[cfg(not(any(target_arch = "mips64", target_arch = "mips64r6")))] 738 pub type FsWord = linux_raw_sys::general::__fsword_t; 739 740 /// `__fsword_t` 741 #[cfg(any(target_arch = "mips64", target_arch = "mips64r6"))] 742 pub type FsWord = i64; 743