1 use super::super::c; 2 use bitflags::bitflags; 3 4 bitflags! { 5 /// `*_OK` constants for use with [`accessat`]. 6 /// 7 /// [`accessat`]: fn.accessat.html 8 pub struct Access: c::c_int { 9 /// `R_OK` 10 const READ_OK = c::R_OK; 11 12 /// `W_OK` 13 const WRITE_OK = c::W_OK; 14 15 /// `X_OK` 16 const EXEC_OK = c::X_OK; 17 18 /// `F_OK` 19 const EXISTS = c::F_OK; 20 } 21 } 22 23 #[cfg(not(target_os = "redox"))] 24 bitflags! { 25 /// `AT_*` constants for use with [`openat`], [`statat`], and other `*at` 26 /// functions. 27 /// 28 /// [`openat`]: crate::fs::openat 29 /// [`statat`]: crate::fs::statat 30 pub struct AtFlags: c::c_int { 31 /// `AT_REMOVEDIR` 32 const REMOVEDIR = c::AT_REMOVEDIR; 33 34 /// `AT_SYMLINK_FOLLOW` 35 const SYMLINK_FOLLOW = c::AT_SYMLINK_FOLLOW; 36 37 /// `AT_SYMLINK_NOFOLLOW` 38 const SYMLINK_NOFOLLOW = c::AT_SYMLINK_NOFOLLOW; 39 40 /// `AT_EMPTY_PATH` 41 #[cfg(any( 42 target_os = "android", 43 target_os = "fuchsia", 44 target_os = "linux", 45 ))] 46 const EMPTY_PATH = c::AT_EMPTY_PATH; 47 48 /// `AT_EACCESS` 49 #[cfg(not(any(target_os = "emscripten", target_os = "android")))] 50 const EACCESS = c::AT_EACCESS; 51 52 /// `AT_STATX_SYNC_AS_STAT` 53 #[cfg(all(target_os = "linux", target_env = "gnu"))] 54 const STATX_SYNC_AS_STAT = c::AT_STATX_SYNC_AS_STAT; 55 56 /// `AT_STATX_FORCE_SYNC` 57 #[cfg(all(target_os = "linux", target_env = "gnu"))] 58 const STATX_FORCE_SYNC = c::AT_STATX_FORCE_SYNC; 59 60 /// `AT_STATX_DONT_SYNC` 61 #[cfg(all(target_os = "linux", target_env = "gnu"))] 62 const STATX_DONT_SYNC = c::AT_STATX_DONT_SYNC; 63 } 64 } 65 66 bitflags! { 67 /// `S_I*` constants for use with [`openat`], [`chmodat`], and [`fchmod`]. 68 /// 69 /// [`openat`]: crate::fs::openat 70 /// [`chmodat`]: crate::fs::chmodat 71 /// [`fchmod`]: crate::fs::fchmod 72 pub struct Mode: RawMode { 73 /// `S_IRWXU` 74 #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. 75 const RWXU = c::S_IRWXU as RawMode; 76 77 /// `S_IRUSR` 78 #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. 79 const RUSR = c::S_IRUSR as RawMode; 80 81 /// `S_IWUSR` 82 #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. 83 const WUSR = c::S_IWUSR as RawMode; 84 85 /// `S_IXUSR` 86 #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. 87 const XUSR = c::S_IXUSR as RawMode; 88 89 /// `S_IRWXG` 90 #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. 91 const RWXG = c::S_IRWXG as RawMode; 92 93 /// `S_IRGRP` 94 #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. 95 const RGRP = c::S_IRGRP as RawMode; 96 97 /// `S_IWGRP` 98 #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. 99 const WGRP = c::S_IWGRP as RawMode; 100 101 /// `S_IXGRP` 102 #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. 103 const XGRP = c::S_IXGRP as RawMode; 104 105 /// `S_IRWXO` 106 #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. 107 const RWXO = c::S_IRWXO as RawMode; 108 109 /// `S_IROTH` 110 #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. 111 const ROTH = c::S_IROTH as RawMode; 112 113 /// `S_IWOTH` 114 #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. 115 const WOTH = c::S_IWOTH as RawMode; 116 117 /// `S_IXOTH` 118 #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. 119 const XOTH = c::S_IXOTH as RawMode; 120 121 /// `S_ISUID` 122 #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. 123 const SUID = c::S_ISUID as RawMode; 124 125 /// `S_ISGID` 126 #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. 127 const SGID = c::S_ISGID as RawMode; 128 129 /// `S_ISVTX` 130 #[cfg(not(target_os = "wasi"))] // WASI doesn't have Unix-style mode flags. 131 const SVTX = c::S_ISVTX as RawMode; 132 } 133 } 134 135 impl Mode { 136 /// Construct a `Mode` from the mode bits of the `st_mode` field of 137 /// a `Stat`. 138 #[inline] from_raw_mode(st_mode: RawMode) -> Self139 pub const fn from_raw_mode(st_mode: RawMode) -> Self { 140 Self::from_bits_truncate(st_mode) 141 } 142 143 /// Construct an `st_mode` value from `Stat`. 144 #[inline] as_raw_mode(self) -> RawMode145 pub const fn as_raw_mode(self) -> RawMode { 146 self.bits() 147 } 148 } 149 150 bitflags! { 151 /// `O_*` constants for use with [`openat`]. 152 /// 153 /// [`openat`]: crate::fs::openat 154 pub struct OFlags: c::c_int { 155 /// `O_ACCMODE` 156 const ACCMODE = c::O_ACCMODE; 157 158 /// Similar to `ACCMODE`, but just includes the read/write flags, and 159 /// no other flags. 160 /// 161 /// Some implementations include `O_PATH` in `O_ACCMODE`, when 162 /// sometimes we really just want the read/write bits. Caution is 163 /// indicated, as the presence of `O_PATH` may mean that the read/write 164 /// bits don't have their usual meaning. 165 const RWMODE = c::O_RDONLY | c::O_WRONLY | c::O_RDWR; 166 167 /// `O_APPEND` 168 const APPEND = c::O_APPEND; 169 170 /// `O_CREAT` 171 #[doc(alias = "CREAT")] 172 const CREATE = c::O_CREAT; 173 174 /// `O_DIRECTORY` 175 const DIRECTORY = c::O_DIRECTORY; 176 177 /// `O_DSYNC` 178 #[cfg(not(any(target_os = "dragonfly", target_os = "freebsd", target_os = "redox")))] 179 const DSYNC = c::O_DSYNC; 180 181 /// `O_EXCL` 182 const EXCL = c::O_EXCL; 183 184 /// `O_FSYNC` 185 #[cfg(any( 186 target_os = "dragonfly", 187 target_os = "freebsd", 188 target_os = "ios", 189 all(target_os = "linux", not(target_env = "musl")), 190 target_os = "macos", 191 target_os = "netbsd", 192 target_os = "openbsd", 193 ))] 194 const FSYNC = c::O_FSYNC; 195 196 /// `O_NOFOLLOW` 197 const NOFOLLOW = c::O_NOFOLLOW; 198 199 /// `O_NONBLOCK` 200 const NONBLOCK = c::O_NONBLOCK; 201 202 /// `O_RDONLY` 203 const RDONLY = c::O_RDONLY; 204 205 /// `O_WRONLY` 206 const WRONLY = c::O_WRONLY; 207 208 /// `O_RDWR` 209 const RDWR = c::O_RDWR; 210 211 /// `O_NOCTTY` 212 #[cfg(not(target_os = "redox"))] 213 const NOCTTY = c::O_NOCTTY; 214 215 /// `O_RSYNC` 216 #[cfg(any( 217 target_os = "android", 218 target_os = "emscripten", 219 target_os = "linux", 220 target_os = "netbsd", 221 target_os = "openbsd", 222 target_os = "wasi", 223 ))] 224 const RSYNC = c::O_RSYNC; 225 226 /// `O_SYNC` 227 #[cfg(not(target_os = "redox"))] 228 const SYNC = c::O_SYNC; 229 230 /// `O_TRUNC` 231 const TRUNC = c::O_TRUNC; 232 233 /// `O_PATH` 234 #[cfg(any( 235 target_os = "android", 236 target_os = "emscripten", 237 target_os = "fuchsia", 238 target_os = "linux", 239 target_os = "redox", 240 ))] 241 const PATH = c::O_PATH; 242 243 /// `O_CLOEXEC` 244 const CLOEXEC = c::O_CLOEXEC; 245 246 /// `O_TMPFILE` 247 #[cfg(any( 248 target_os = "android", 249 target_os = "emscripten", 250 target_os = "fuchsia", 251 target_os = "linux", 252 ))] 253 const TMPFILE = c::O_TMPFILE; 254 255 /// `O_NOATIME` 256 #[cfg(any( 257 target_os = "android", 258 target_os = "fuchsia", 259 target_os = "linux", 260 ))] 261 const NOATIME = c::O_NOATIME; 262 263 /// `O_DIRECT` 264 #[cfg(any( 265 target_os = "android", 266 target_os = "emscripten", 267 target_os = "freebsd", 268 target_os = "fuchsia", 269 target_os = "linux", 270 target_os = "netbsd", 271 ))] 272 const DIRECT = c::O_DIRECT; 273 } 274 } 275 276 #[cfg(any(target_os = "ios", target_os = "macos"))] 277 bitflags! { 278 /// `CLONE_*` constants for use with [`fclonefileat`]. 279 /// 280 /// [`fclonefileat`]: crate::fs::fclonefileat 281 pub struct CloneFlags: c::c_int { 282 /// `CLONE_NOFOLLOW` 283 const NOFOLLOW = 1; 284 285 /// `CLONE_NOOWNERCOPY` 286 const NOOWNERCOPY = 2; 287 } 288 } 289 290 #[cfg(any(target_os = "ios", target_os = "macos"))] 291 mod copyfile { 292 pub(super) const ACL: u32 = 1 << 0; 293 pub(super) const STAT: u32 = 1 << 1; 294 pub(super) const XATTR: u32 = 1 << 2; 295 pub(super) const DATA: u32 = 1 << 3; 296 pub(super) const SECURITY: u32 = STAT | ACL; 297 pub(super) const METADATA: u32 = SECURITY | XATTR; 298 pub(super) const ALL: u32 = METADATA | DATA; 299 } 300 301 #[cfg(any(target_os = "ios", target_os = "macos"))] 302 bitflags! { 303 /// `COPYFILE_*` constants. 304 pub struct CopyfileFlags: c::c_uint { 305 /// `COPYFILE_ACL` 306 const ACL = copyfile::ACL; 307 308 /// `COPYFILE_STAT` 309 const STAT = copyfile::STAT; 310 311 /// `COPYFILE_XATTR` 312 const XATTR = copyfile::XATTR; 313 314 /// `COPYFILE_DATA` 315 const DATA = copyfile::DATA; 316 317 /// `COPYFILE_SECURITY` 318 const SECURITY = copyfile::SECURITY; 319 320 /// `COPYFILE_METADATA` 321 const METADATA = copyfile::METADATA; 322 323 /// `COPYFILE_ALL` 324 const ALL = copyfile::ALL; 325 } 326 } 327 328 #[cfg(any(target_os = "android", target_os = "linux"))] 329 bitflags! { 330 /// `RESOLVE_*` constants for use with [`openat2`]. 331 /// 332 /// [`openat2`]: crate::fs::openat2 333 #[derive(Default)] 334 pub struct ResolveFlags: u64 { 335 /// `RESOLVE_NO_XDEV` 336 const NO_XDEV = 0x01; 337 338 /// `RESOLVE_NO_MAGICLINKS` 339 const NO_MAGICLINKS = 0x02; 340 341 /// `RESOLVE_NO_SYMLINKS` 342 const NO_SYMLINKS = 0x04; 343 344 /// `RESOLVE_BENEATH` 345 const BENEATH = 0x08; 346 347 /// `RESOLVE_IN_ROOT` 348 const IN_ROOT = 0x10; 349 350 /// `RESOLVE_CACHED` (since Linux 5.12) 351 const CACHED = 0x20; 352 } 353 } 354 355 #[cfg(any(target_os = "android", target_os = "linux"))] 356 bitflags! { 357 /// `RENAME_*` constants for use with [`renameat_with`]. 358 /// 359 /// [`renameat_with`]: crate::fs::renameat_with 360 pub struct RenameFlags: c::c_uint { 361 /// `RENAME_EXCHANGE` 362 const EXCHANGE = c::RENAME_EXCHANGE as _; 363 364 /// `RENAME_NOREPLACE` 365 const NOREPLACE = c::RENAME_NOREPLACE as _; 366 367 /// `RENAME_WHITEOUT` 368 const WHITEOUT = c::RENAME_WHITEOUT as _; 369 } 370 } 371 372 /// `S_IF*` constants for use with [`mknodat`] and [`Stat`]'s `st_mode` field. 373 /// 374 /// [`mknodat`]: crate::fs::mknodat 375 /// [`Stat`]: crate::fs::Stat 376 #[derive(Clone, Copy, Debug, PartialEq, Eq)] 377 pub enum FileType { 378 /// `S_IFREG` 379 RegularFile = c::S_IFREG as isize, 380 381 /// `S_IFDIR` 382 Directory = c::S_IFDIR as isize, 383 384 /// `S_IFLNK` 385 Symlink = c::S_IFLNK as isize, 386 387 /// `S_IFIFO` 388 #[cfg(not(target_os = "wasi"))] // TODO: Use WASI's `S_IFIFO`. 389 #[doc(alias = "IFO")] 390 Fifo = c::S_IFIFO as isize, 391 392 /// `S_IFSOCK` 393 #[cfg(not(target_os = "wasi"))] // TODO: Use WASI's `S_IFSOCK`. 394 Socket = c::S_IFSOCK as isize, 395 396 /// `S_IFCHR` 397 CharacterDevice = c::S_IFCHR as isize, 398 399 /// `S_IFBLK` 400 BlockDevice = c::S_IFBLK as isize, 401 402 /// An unknown filesystem object. 403 Unknown, 404 } 405 406 impl FileType { 407 /// Construct a `FileType` from the `S_IFMT` bits of the `st_mode` field of 408 /// a `Stat`. from_raw_mode(st_mode: RawMode) -> Self409 pub const fn from_raw_mode(st_mode: RawMode) -> Self { 410 match (st_mode as c::mode_t) & c::S_IFMT { 411 c::S_IFREG => Self::RegularFile, 412 c::S_IFDIR => Self::Directory, 413 c::S_IFLNK => Self::Symlink, 414 #[cfg(not(target_os = "wasi"))] // TODO: Use WASI's `S_IFIFO`. 415 c::S_IFIFO => Self::Fifo, 416 #[cfg(not(target_os = "wasi"))] // TODO: Use WASI's `S_IFSOCK`. 417 c::S_IFSOCK => Self::Socket, 418 c::S_IFCHR => Self::CharacterDevice, 419 c::S_IFBLK => Self::BlockDevice, 420 _ => Self::Unknown, 421 } 422 } 423 424 /// Construct an `st_mode` value from `Stat`. as_raw_mode(self) -> RawMode425 pub const fn as_raw_mode(self) -> RawMode { 426 match self { 427 Self::RegularFile => c::S_IFREG as RawMode, 428 Self::Directory => c::S_IFDIR as RawMode, 429 Self::Symlink => c::S_IFLNK as RawMode, 430 #[cfg(not(target_os = "wasi"))] // TODO: Use WASI's `S_IFIFO`. 431 Self::Fifo => c::S_IFIFO as RawMode, 432 #[cfg(not(target_os = "wasi"))] // TODO: Use WASI's `S_IFSOCK`. 433 Self::Socket => c::S_IFSOCK as RawMode, 434 Self::CharacterDevice => c::S_IFCHR as RawMode, 435 Self::BlockDevice => c::S_IFBLK as RawMode, 436 Self::Unknown => c::S_IFMT as RawMode, 437 } 438 } 439 440 /// Construct a `FileType` from the `d_type` field of a `c::dirent`. 441 #[cfg(not(any( 442 target_os = "haiku", 443 target_os = "illumos", 444 target_os = "redox", 445 target_os = "solaris" 446 )))] from_dirent_d_type(d_type: u8) -> Self447 pub(crate) const fn from_dirent_d_type(d_type: u8) -> Self { 448 match d_type { 449 c::DT_REG => Self::RegularFile, 450 c::DT_DIR => Self::Directory, 451 c::DT_LNK => Self::Symlink, 452 #[cfg(not(target_os = "wasi"))] // TODO: Use WASI's `DT_SOCK`. 453 c::DT_SOCK => Self::Socket, 454 #[cfg(not(target_os = "wasi"))] // TODO: Use WASI's `DT_FIFO`. 455 c::DT_FIFO => Self::Fifo, 456 c::DT_CHR => Self::CharacterDevice, 457 c::DT_BLK => Self::BlockDevice, 458 // c::DT_UNKNOWN | 459 _ => Self::Unknown, 460 } 461 } 462 } 463 464 /// `POSIX_FADV_*` constants for use with [`fadvise`]. 465 /// 466 /// [`fadvise`]: crate::fs::fadvise 467 #[cfg(not(any( 468 target_os = "dragonfly", 469 target_os = "haiku", 470 target_os = "illumos", 471 target_os = "ios", 472 target_os = "macos", 473 target_os = "netbsd", 474 target_os = "openbsd", 475 target_os = "redox", 476 target_os = "solaris", 477 )))] 478 #[derive(Debug, Copy, Clone, Eq, PartialEq)] 479 #[repr(u32)] 480 pub enum Advice { 481 /// `POSIX_FADV_NORMAL` 482 Normal = c::POSIX_FADV_NORMAL as c::c_uint, 483 484 /// `POSIX_FADV_SEQUENTIAL` 485 Sequential = c::POSIX_FADV_SEQUENTIAL as c::c_uint, 486 487 /// `POSIX_FADV_RANDOM` 488 Random = c::POSIX_FADV_RANDOM as c::c_uint, 489 490 /// `POSIX_FADV_NOREUSE` 491 NoReuse = c::POSIX_FADV_NOREUSE as c::c_uint, 492 493 /// `POSIX_FADV_WILLNEED` 494 WillNeed = c::POSIX_FADV_WILLNEED as c::c_uint, 495 496 /// `POSIX_FADV_DONTNEED` 497 DontNeed = c::POSIX_FADV_DONTNEED as c::c_uint, 498 } 499 500 #[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))] 501 bitflags! { 502 /// `MFD_*` constants for use with [`memfd_create`]. 503 /// 504 /// [`memfd_create`]: crate::fs::memfd_create 505 pub struct MemfdFlags: c::c_uint { 506 /// `MFD_CLOEXEC` 507 const CLOEXEC = c::MFD_CLOEXEC; 508 509 /// `MFD_ALLOW_SEALING` 510 const ALLOW_SEALING = c::MFD_ALLOW_SEALING; 511 512 /// `MFD_HUGETLB` (since Linux 4.14) 513 const HUGETLB = c::MFD_HUGETLB; 514 515 /// `MFD_HUGE_64KB` 516 #[cfg(any(target_os = "android", target_os = "linux"))] 517 const HUGE_64KB = c::MFD_HUGE_64KB; 518 /// `MFD_HUGE_512JB` 519 #[cfg(any(target_os = "android", target_os = "linux"))] 520 const HUGE_512KB = c::MFD_HUGE_512KB; 521 /// `MFD_HUGE_1MB` 522 #[cfg(any(target_os = "android", target_os = "linux"))] 523 const HUGE_1MB = c::MFD_HUGE_1MB; 524 /// `MFD_HUGE_2MB` 525 #[cfg(any(target_os = "android", target_os = "linux"))] 526 const HUGE_2MB = c::MFD_HUGE_2MB; 527 /// `MFD_HUGE_8MB` 528 #[cfg(any(target_os = "android", target_os = "linux"))] 529 const HUGE_8MB = c::MFD_HUGE_8MB; 530 /// `MFD_HUGE_16MB` 531 #[cfg(any(target_os = "android", target_os = "linux"))] 532 const HUGE_16MB = c::MFD_HUGE_16MB; 533 /// `MFD_HUGE_32MB` 534 #[cfg(any(target_os = "android", target_os = "linux"))] 535 const HUGE_32MB = c::MFD_HUGE_32MB; 536 /// `MFD_HUGE_256MB` 537 #[cfg(any(target_os = "android", target_os = "linux"))] 538 const HUGE_256MB = c::MFD_HUGE_256MB; 539 /// `MFD_HUGE_512MB` 540 #[cfg(any(target_os = "android", target_os = "linux"))] 541 const HUGE_512MB = c::MFD_HUGE_512MB; 542 /// `MFD_HUGE_1GB` 543 #[cfg(any(target_os = "android", target_os = "linux"))] 544 const HUGE_1GB = c::MFD_HUGE_1GB; 545 /// `MFD_HUGE_2GB` 546 #[cfg(any(target_os = "android", target_os = "linux"))] 547 const HUGE_2GB = c::MFD_HUGE_2GB; 548 /// `MFD_HUGE_16GB` 549 #[cfg(any(target_os = "android", target_os = "linux"))] 550 const HUGE_16GB = c::MFD_HUGE_16GB; 551 } 552 } 553 554 #[cfg(any( 555 target_os = "android", 556 target_os = "freebsd", 557 target_os = "fuchsia", 558 target_os = "linux", 559 ))] 560 bitflags! { 561 /// `F_SEAL_*` constants for use with [`fcntl_add_seals`] and 562 /// [`fcntl_get_seals`]. 563 /// 564 /// [`fcntl_add_seals`]: crate::fs::fcntl_add_seals 565 /// [`fcntl_get_seals`]: crate::fs::fcntl_get_seals 566 pub struct SealFlags: i32 { 567 /// `F_SEAL_SEAL`. 568 const SEAL = c::F_SEAL_SEAL; 569 /// `F_SEAL_SHRINK`. 570 const SHRINK = c::F_SEAL_SHRINK; 571 /// `F_SEAL_GROW`. 572 const GROW = c::F_SEAL_GROW; 573 /// `F_SEAL_WRITE`. 574 const WRITE = c::F_SEAL_WRITE; 575 /// `F_SEAL_FUTURE_WRITE` (since Linux 5.1) 576 #[cfg(any(target_os = "android", target_os = "linux"))] 577 const FUTURE_WRITE = c::F_SEAL_FUTURE_WRITE; 578 } 579 } 580 581 #[cfg(all(target_os = "linux", target_env = "gnu"))] 582 bitflags! { 583 /// `STATX_*` constants for use with [`statx`]. 584 /// 585 /// [`statx`]: crate::fs::statx 586 pub struct StatxFlags: u32 { 587 /// `STATX_TYPE` 588 const TYPE = c::STATX_TYPE; 589 590 /// `STATX_MODE` 591 const MODE = c::STATX_MODE; 592 593 /// `STATX_NLINK` 594 const NLINK = c::STATX_NLINK; 595 596 /// `STATX_UID` 597 const UID = c::STATX_UID; 598 599 /// `STATX_GID` 600 const GID = c::STATX_GID; 601 602 /// `STATX_ATIME` 603 const ATIME = c::STATX_ATIME; 604 605 /// `STATX_MTIME` 606 const MTIME = c::STATX_MTIME; 607 608 /// `STATX_CTIME` 609 const CTIME = c::STATX_CTIME; 610 611 /// `STATX_INO` 612 const INO = c::STATX_INO; 613 614 /// `STATX_SIZE` 615 const SIZE = c::STATX_SIZE; 616 617 /// `STATX_BLOCKS` 618 const BLOCKS = c::STATX_BLOCKS; 619 620 /// `STATX_BASIC_STATS` 621 const BASIC_STATS = c::STATX_BASIC_STATS; 622 623 /// `STATX_BTIME` 624 const BTIME = c::STATX_BTIME; 625 626 /// `STATX_MNT_ID` (since Linux 5.8) 627 const MNT_ID = c::STATX_MNT_ID; 628 629 /// `STATX_ALL` 630 const ALL = c::STATX_ALL; 631 } 632 } 633 634 #[cfg(any( 635 target_os = "android", 636 all(target_os = "linux", not(target_env = "gnu")), 637 ))] 638 bitflags! { 639 /// `STATX_*` constants for use with [`statx`]. 640 /// 641 /// [`statx`]: crate::fs::statx 642 pub struct StatxFlags: u32 { 643 /// `STATX_TYPE` 644 const TYPE = 0x0001; 645 646 /// `STATX_MODE` 647 const MODE = 0x0002; 648 649 /// `STATX_NLINK` 650 const NLINK = 0x0004; 651 652 /// `STATX_UID` 653 const UID = 0x0008; 654 655 /// `STATX_GID` 656 const GID = 0x0010; 657 658 /// `STATX_ATIME` 659 const ATIME = 0x0020; 660 661 /// `STATX_MTIME` 662 const MTIME = 0x0040; 663 664 /// `STATX_CTIME` 665 const CTIME = 0x0080; 666 667 /// `STATX_INO` 668 const INO = 0x0100; 669 670 /// `STATX_SIZE` 671 const SIZE = 0x0200; 672 673 /// `STATX_BLOCKS` 674 const BLOCKS = 0x0400; 675 676 /// `STATX_BASIC_STATS` 677 const BASIC_STATS = 0x07ff; 678 679 /// `STATX_BTIME` 680 const BTIME = 0x800; 681 682 /// `STATX_MNT_ID` (since Linux 5.8) 683 const MNT_ID = 0x1000; 684 685 /// `STATX_ALL` 686 const ALL = 0xfff; 687 } 688 } 689 690 #[cfg(not(any( 691 target_os = "aix", 692 target_os = "illumos", 693 target_os = "netbsd", 694 target_os = "openbsd", 695 target_os = "redox", 696 target_os = "solaris", 697 )))] 698 bitflags! { 699 /// `FALLOC_FL_*` constants for use with [`fallocate`]. 700 /// 701 /// [`fallocate`]: crate::fs::fallocate 702 pub struct FallocateFlags: i32 { 703 /// `FALLOC_FL_KEEP_SIZE` 704 #[cfg(not(any( 705 target_os = "aix", 706 target_os = "dragonfly", 707 target_os = "freebsd", 708 target_os = "haiku", 709 target_os = "ios", 710 target_os = "macos", 711 target_os = "netbsd", 712 target_os = "openbsd", 713 target_os = "wasi", 714 )))] 715 const KEEP_SIZE = c::FALLOC_FL_KEEP_SIZE; 716 /// `FALLOC_FL_PUNCH_HOLE` 717 #[cfg(not(any( 718 target_os = "aix", 719 target_os = "dragonfly", 720 target_os = "freebsd", 721 target_os = "haiku", 722 target_os = "ios", 723 target_os = "macos", 724 target_os = "netbsd", 725 target_os = "openbsd", 726 target_os = "wasi", 727 )))] 728 const PUNCH_HOLE = c::FALLOC_FL_PUNCH_HOLE; 729 /// `FALLOC_FL_NO_HIDE_STALE` 730 #[cfg(not(any( 731 target_os = "aix", 732 target_os = "dragonfly", 733 target_os = "freebsd", 734 target_os = "haiku", 735 target_os = "ios", 736 target_os = "linux", 737 target_os = "macos", 738 target_os = "netbsd", 739 target_os = "openbsd", 740 target_os = "emscripten", 741 target_os = "fuchsia", 742 target_os = "wasi", 743 )))] 744 const NO_HIDE_STALE = c::FALLOC_FL_NO_HIDE_STALE; 745 /// `FALLOC_FL_COLLAPSE_RANGE` 746 #[cfg(not(any( 747 target_os = "aix", 748 target_os = "dragonfly", 749 target_os = "freebsd", 750 target_os = "haiku", 751 target_os = "ios", 752 target_os = "macos", 753 target_os = "netbsd", 754 target_os = "openbsd", 755 target_os = "emscripten", 756 target_os = "wasi", 757 )))] 758 const COLLAPSE_RANGE = c::FALLOC_FL_COLLAPSE_RANGE; 759 /// `FALLOC_FL_ZERO_RANGE` 760 #[cfg(not(any( 761 target_os = "aix", 762 target_os = "dragonfly", 763 target_os = "freebsd", 764 target_os = "haiku", 765 target_os = "ios", 766 target_os = "macos", 767 target_os = "netbsd", 768 target_os = "openbsd", 769 target_os = "emscripten", 770 target_os = "wasi", 771 )))] 772 const ZERO_RANGE = c::FALLOC_FL_ZERO_RANGE; 773 /// `FALLOC_FL_INSERT_RANGE` 774 #[cfg(not(any( 775 target_os = "aix", 776 target_os = "dragonfly", 777 target_os = "freebsd", 778 target_os = "haiku", 779 target_os = "ios", 780 target_os = "macos", 781 target_os = "netbsd", 782 target_os = "openbsd", 783 target_os = "emscripten", 784 target_os = "wasi", 785 )))] 786 const INSERT_RANGE = c::FALLOC_FL_INSERT_RANGE; 787 /// `FALLOC_FL_UNSHARE_RANGE` 788 #[cfg(not(any( 789 target_os = "aix", 790 target_os = "dragonfly", 791 target_os = "freebsd", 792 target_os = "haiku", 793 target_os = "ios", 794 target_os = "macos", 795 target_os = "netbsd", 796 target_os = "openbsd", 797 target_os = "emscripten", 798 target_os = "wasi", 799 )))] 800 const UNSHARE_RANGE = c::FALLOC_FL_UNSHARE_RANGE; 801 } 802 } 803 804 #[cfg(not(any( 805 target_os = "haiku", 806 target_os = "illumos", 807 target_os = "redox", 808 target_os = "solaris", 809 target_os = "wasi", 810 )))] 811 bitflags! { 812 /// `ST_*` constants for use with [`StatVfs`]. 813 pub struct StatVfsMountFlags: u64 { 814 /// `ST_MANDLOCK` 815 #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] 816 const MANDLOCK = libc::ST_MANDLOCK as u64; 817 818 /// `ST_NOATIME` 819 #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] 820 const NOATIME = libc::ST_NOATIME as u64; 821 822 /// `ST_NODEV` 823 #[cfg(any(target_os = "aix", target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] 824 const NODEV = libc::ST_NODEV as u64; 825 826 /// `ST_NODIRATIME` 827 #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] 828 const NODIRATIME = libc::ST_NODIRATIME as u64; 829 830 /// `ST_NOEXEC` 831 #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] 832 const NOEXEC = libc::ST_NOEXEC as u64; 833 834 /// `ST_NOSUID` 835 const NOSUID = libc::ST_NOSUID as u64; 836 837 /// `ST_RDONLY` 838 const RDONLY = libc::ST_RDONLY as u64; 839 840 /// `ST_RELATIME` 841 #[cfg(any(target_os = "android", all(target_os = "linux", target_env = "gnu")))] 842 const RELATIME = libc::ST_RELATIME as u64; 843 844 /// `ST_SYNCHRONOUS` 845 #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] 846 const SYNCHRONOUS = libc::ST_SYNCHRONOUS as u64; 847 } 848 } 849 850 /// `LOCK_*` constants for use with [`flock`] 851 /// 852 /// [`flock`]: crate::fs::flock 853 #[cfg(not(any(target_os = "solaris", target_os = "wasi")))] 854 #[derive(Clone, Copy, Debug, PartialEq, Eq)] 855 #[repr(i32)] 856 pub enum FlockOperation { 857 /// `LOCK_SH` 858 LockShared = c::LOCK_SH, 859 /// `LOCK_EX` 860 LockExclusive = c::LOCK_EX, 861 /// `LOCK_UN` 862 Unlock = c::LOCK_UN, 863 /// `LOCK_SH | LOCK_NB` 864 NonBlockingLockShared = c::LOCK_SH | c::LOCK_NB, 865 /// `LOCK_EX | LOCK_NB` 866 NonBlockingLockExclusive = c::LOCK_EX | c::LOCK_NB, 867 /// `LOCK_UN | LOCK_NB` 868 NonBlockingUnlock = c::LOCK_UN | c::LOCK_NB, 869 } 870 871 /// `struct stat` for use with [`statat`] and [`fstat`]. 872 /// 873 /// [`statat`]: crate::fs::statat 874 /// [`fstat`]: crate::fs::fstat 875 #[cfg(not(any( 876 target_os = "android", 877 target_os = "linux", 878 target_os = "emscripten", 879 target_os = "l4re", 880 )))] 881 pub type Stat = c::stat; 882 883 /// `struct stat` for use with [`statat`] and [`fstat`]. 884 /// 885 /// [`statat`]: crate::fs::statat 886 /// [`fstat`]: crate::fs::fstat 887 #[cfg(any( 888 all( 889 any(target_os = "android", target_os = "linux"), 890 target_pointer_width = "64", 891 ), 892 target_os = "emscripten", 893 target_os = "l4re", 894 ))] 895 pub type Stat = c::stat64; 896 897 /// `struct stat` for use with [`statat`] and [`fstat`]. 898 /// 899 /// [`statat`]: crate::fs::statat 900 /// [`fstat`]: crate::fs::fstat 901 // On 32-bit, Linux's `struct stat64` has a 32-bit `st_mtime` and friends, so 902 // we use our own struct, populated from `statx` where possible, to avoid the 903 // y2038 bug. 904 #[cfg(all( 905 any(target_os = "android", target_os = "linux"), 906 target_pointer_width = "32", 907 ))] 908 #[repr(C)] 909 #[derive(Debug, Copy, Clone)] 910 #[allow(missing_docs)] 911 pub struct Stat { 912 pub st_dev: u64, 913 pub st_mode: u32, 914 pub st_nlink: u32, 915 pub st_uid: u32, 916 pub st_gid: u32, 917 pub st_rdev: u64, 918 pub st_size: i64, 919 pub st_blksize: u32, 920 pub st_blocks: u64, 921 pub st_atime: u64, 922 pub st_atime_nsec: u32, 923 pub st_mtime: u64, 924 pub st_mtime_nsec: u32, 925 pub st_ctime: u64, 926 pub st_ctime_nsec: u32, 927 pub st_ino: u64, 928 } 929 930 /// `struct statfs` for use with [`statfs`] and [`fstatfs`]. 931 /// 932 /// [`statfs`]: crate::fs::statfs 933 /// [`fstatfs`]: crate::fs::fstatfs 934 #[cfg(not(any( 935 target_os = "android", 936 target_os = "emscripten", 937 target_os = "haiku", 938 target_os = "illumos", 939 target_os = "linux", 940 target_os = "l4re", 941 target_os = "netbsd", 942 target_os = "redox", 943 target_os = "solaris", 944 target_os = "wasi", 945 )))] 946 #[allow(clippy::module_name_repetitions)] 947 pub type StatFs = c::statfs; 948 949 /// `struct statfs` for use with [`statfs`] and [`fstatfs`]. 950 /// 951 /// [`statfs`]: crate::fs::statfs 952 /// [`fstatfs`]: crate::fs::fstatfs 953 #[cfg(any( 954 target_os = "android", 955 target_os = "linux", 956 target_os = "emscripten", 957 target_os = "l4re", 958 ))] 959 pub type StatFs = c::statfs64; 960 961 /// `struct statvfs` for use with [`statvfs`] and [`fstatvfs`]. 962 /// 963 /// [`statvfs`]: crate::fs::statvfs 964 /// [`fstatvfs`]: crate::fs::fstatvfs 965 #[cfg(not(any( 966 target_os = "haiku", 967 target_os = "illumos", 968 target_os = "redox", 969 target_os = "solaris", 970 target_os = "wasi", 971 )))] 972 #[allow(missing_docs)] 973 pub struct StatVfs { 974 pub f_bsize: u64, 975 pub f_frsize: u64, 976 pub f_blocks: u64, 977 pub f_bfree: u64, 978 pub f_bavail: u64, 979 pub f_files: u64, 980 pub f_ffree: u64, 981 pub f_favail: u64, 982 pub f_fsid: u64, 983 pub f_flag: StatVfsMountFlags, 984 pub f_namemax: u64, 985 } 986 987 /// `struct statx` for use with [`statx`]. 988 /// 989 /// [`statx`]: crate::fs::statx 990 #[cfg(all(target_os = "linux", target_env = "gnu"))] 991 // Use the glibc `struct statx`. 992 pub type Statx = c::statx; 993 994 /// `struct statx_timestamp` for use with [`Statx`]. 995 #[cfg(all(target_os = "linux", target_env = "gnu"))] 996 // Use the glibc `struct statx_timestamp`. 997 pub type StatxTimestamp = c::statx; 998 999 /// `struct statx` for use with [`statx`]. 1000 /// 1001 /// [`statx`]: crate::fs::statx 1002 // Non-glibc ABIs don't currently declare a `struct statx`, so we declare it 1003 // ourselves. 1004 #[cfg(any( 1005 target_os = "android", 1006 all(target_os = "linux", not(target_env = "gnu")), 1007 ))] 1008 #[repr(C)] 1009 #[allow(missing_docs)] 1010 pub struct Statx { 1011 pub stx_mask: u32, 1012 pub stx_blksize: u32, 1013 pub stx_attributes: u64, 1014 pub stx_nlink: u32, 1015 pub stx_uid: u32, 1016 pub stx_gid: u32, 1017 pub stx_mode: u16, 1018 __statx_pad1: [u16; 1], 1019 pub stx_ino: u64, 1020 pub stx_size: u64, 1021 pub stx_blocks: u64, 1022 pub stx_attributes_mask: u64, 1023 pub stx_atime: StatxTimestamp, 1024 pub stx_btime: StatxTimestamp, 1025 pub stx_ctime: StatxTimestamp, 1026 pub stx_mtime: StatxTimestamp, 1027 pub stx_rdev_major: u32, 1028 pub stx_rdev_minor: u32, 1029 pub stx_dev_major: u32, 1030 pub stx_dev_minor: u32, 1031 pub stx_mnt_id: u64, 1032 __statx_pad2: u64, 1033 __statx_pad3: [u64; 12], 1034 } 1035 1036 /// `struct statx_timestamp` for use with [`Statx`]. 1037 // Non-glibc ABIs don't currently declare a `struct statx_timestamp`, so we 1038 // declare it ourselves. 1039 #[cfg(any( 1040 target_os = "android", 1041 all(target_os = "linux", not(target_env = "gnu")), 1042 ))] 1043 #[repr(C)] 1044 #[allow(missing_docs)] 1045 pub struct StatxTimestamp { 1046 pub tv_sec: i64, 1047 pub tv_nsec: u32, 1048 pub __statx_timestamp_pad1: [i32; 1], 1049 } 1050 1051 /// `mode_t` 1052 #[cfg(not(all(target_os = "android", target_pointer_width = "32")))] 1053 pub type RawMode = c::mode_t; 1054 1055 /// `mode_t` 1056 #[cfg(all(target_os = "android", target_pointer_width = "32"))] 1057 pub type RawMode = c::c_uint; 1058 1059 /// `dev_t` 1060 #[cfg(not(all(target_os = "android", target_pointer_width = "32")))] 1061 pub type Dev = c::dev_t; 1062 1063 /// `dev_t` 1064 #[cfg(all(target_os = "android", target_pointer_width = "32"))] 1065 pub type Dev = c::c_ulonglong; 1066 1067 /// `__fsword_t` 1068 #[cfg(all( 1069 target_os = "linux", 1070 not(target_env = "musl"), 1071 not(target_arch = "s390x"), 1072 ))] 1073 pub type FsWord = c::__fsword_t; 1074 1075 /// `__fsword_t` 1076 #[cfg(all( 1077 any(target_os = "android", all(target_os = "linux", target_env = "musl")), 1078 target_pointer_width = "32", 1079 ))] 1080 pub type FsWord = u32; 1081 1082 /// `__fsword_t` 1083 #[cfg(all( 1084 any(target_os = "android", all(target_os = "linux", target_env = "musl")), 1085 not(target_arch = "s390x"), 1086 target_pointer_width = "64", 1087 ))] 1088 pub type FsWord = u64; 1089 1090 /// `__fsword_t` 1091 // s390x uses `u32` for `statfs` entries, even though `__fsword_t` is `u64`. 1092 #[cfg(all(target_os = "linux", target_arch = "s390x"))] 1093 pub type FsWord = u32; 1094 1095 #[cfg(not(target_os = "redox"))] 1096 pub use c::{UTIME_NOW, UTIME_OMIT}; 1097 1098 /// `PROC_SUPER_MAGIC`—The magic number for the procfs filesystem. 1099 #[cfg(all( 1100 any(target_os = "android", target_os = "linux"), 1101 not(target_env = "musl"), 1102 ))] 1103 pub const PROC_SUPER_MAGIC: FsWord = c::PROC_SUPER_MAGIC as FsWord; 1104 1105 /// `NFS_SUPER_MAGIC`—The magic number for the NFS filesystem. 1106 #[cfg(all( 1107 any(target_os = "android", target_os = "linux"), 1108 not(target_env = "musl"), 1109 ))] 1110 pub const NFS_SUPER_MAGIC: FsWord = c::NFS_SUPER_MAGIC as FsWord; 1111 1112 /// `PROC_SUPER_MAGIC`—The magic number for the procfs filesystem. 1113 #[cfg(all(any(target_os = "android", target_os = "linux"), target_env = "musl"))] 1114 pub const PROC_SUPER_MAGIC: FsWord = 0x0000_9fa0; 1115 1116 /// `NFS_SUPER_MAGIC`—The magic number for the NFS filesystem. 1117 #[cfg(all(any(target_os = "android", target_os = "linux"), target_env = "musl"))] 1118 pub const NFS_SUPER_MAGIC: FsWord = 0x0000_6969; 1119 1120 /// `copyfile_state_t`—State for use with [`fcopyfile`]. 1121 /// 1122 /// [`fcopyfile`]: crate::fs::fcopyfile 1123 #[cfg(any(target_os = "ios", target_os = "macos"))] 1124 #[allow(non_camel_case_types)] 1125 #[repr(transparent)] 1126 #[derive(Copy, Clone)] 1127 pub struct copyfile_state_t(pub(crate) *mut c::c_void); 1128 1129 #[cfg(any(target_os = "android", target_os = "linux"))] 1130 bitflags! { 1131 /// `MS_*` constants for use with [`mount`][crate::fs::mount]. 1132 pub struct MountFlags: c::c_ulong { 1133 /// `MS_BIND` 1134 const BIND = c::MS_BIND; 1135 1136 /// `MS_DIRSYNC` 1137 const DIRSYNC = c::MS_DIRSYNC; 1138 1139 /// `MS_LAZYTIME` 1140 const LAZYTIME = c::MS_LAZYTIME; 1141 1142 /// `MS_MANDLOCK` 1143 #[doc(alias = "MANDLOCK")] 1144 const PERMIT_MANDATORY_FILE_LOCKING = c::MS_MANDLOCK; 1145 1146 /// `MS_NOATIME` 1147 const NOATIME = c::MS_NOATIME; 1148 1149 /// `MS_NODEV` 1150 const NODEV = c::MS_NODEV; 1151 1152 /// `MS_NODIRATIME` 1153 const NODIRATIME = c::MS_NODIRATIME; 1154 1155 /// `MS_NOEXEC` 1156 const NOEXEC = c::MS_NOEXEC; 1157 1158 /// `MS_NOSUID` 1159 const NOSUID = c::MS_NOSUID; 1160 1161 /// `MS_RDONLY` 1162 const RDONLY = c::MS_RDONLY; 1163 1164 /// `MS_REC` 1165 const REC = c::MS_REC; 1166 1167 /// `MS_RELATIME` 1168 const RELATIME = c::MS_RELATIME; 1169 1170 /// `MS_SILENT` 1171 const SILENT = c::MS_SILENT; 1172 1173 /// `MS_STRICTATIME` 1174 const STRICTATIME = c::MS_STRICTATIME; 1175 1176 /// `MS_SYNCHRONOUS` 1177 const SYNCHRONOUS = c::MS_SYNCHRONOUS; 1178 } 1179 } 1180 1181 #[cfg(any(target_os = "android", target_os = "linux"))] 1182 bitflags! { 1183 /// `MS_*` constants for use with [`change_mount`][crate::fs::mount::change_mount]. 1184 pub struct MountPropagationFlags: c::c_ulong { 1185 /// `MS_SHARED` 1186 const SHARED = c::MS_SHARED; 1187 /// `MS_PRIVATE` 1188 const PRIVATE = c::MS_PRIVATE; 1189 /// `MS_SLAVE` 1190 const SLAVE = c::MS_SLAVE; 1191 /// `MS_UNBINDABLE` 1192 const UNBINDABLE = c::MS_UNBINDABLE; 1193 /// `MS_REC` 1194 const REC = c::MS_REC; 1195 } 1196 } 1197 1198 #[cfg(any(target_os = "android", target_os = "linux"))] 1199 bitflags! { 1200 pub(crate) struct InternalMountFlags: c::c_ulong { 1201 const REMOUNT = c::MS_REMOUNT; 1202 const MOVE = c::MS_MOVE; 1203 } 1204 } 1205 1206 #[cfg(any(target_os = "android", target_os = "linux"))] 1207 pub(crate) struct MountFlagsArg(pub(crate) c::c_ulong); 1208