fcntl.rs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. const F_LINUX_SPECIFIC_BASE: u32 = 1024;
  2. /// fcntl syscall command
  3. ///
  4. /// for linux-specific fcntl commands, see:
  5. /// https://opengrok.ringotek.cn/xref/linux-5.19.10/tools/include/uapi/linux/fcntl.h#8
  6. #[derive(Debug, Copy, Clone, Eq, PartialEq, FromPrimitive, ToPrimitive)]
  7. #[repr(u32)]
  8. pub enum FcntlCommand {
  9. /// dup
  10. DupFd = 0,
  11. /// get close-on-exec
  12. GetFd = 1,
  13. /// set/clear close-on-exec
  14. SetFd = 2,
  15. /// get file flags
  16. GetFlags = 3,
  17. /// set file flags
  18. SetFlags = 4,
  19. /// get record locking info
  20. GetLock = 5,
  21. /// set record locking info (non-blocking)
  22. SetLock = 6,
  23. /// set record locking info (blocking)
  24. SetLockWait = 7,
  25. SetLease = F_LINUX_SPECIFIC_BASE + 0,
  26. GetLease = F_LINUX_SPECIFIC_BASE + 1,
  27. /// Request nofications on a directory.
  28. /// See below for events that may be notified.
  29. Notify = F_LINUX_SPECIFIC_BASE + 2,
  30. /// Cancel a blocking posix lock; internal use only until we expose an
  31. /// asynchronous lock api to userspace
  32. CancelLock = F_LINUX_SPECIFIC_BASE + 5,
  33. /// Create a file descriptor with FD_CLOEXEC set.
  34. DupFdCloexec = F_LINUX_SPECIFIC_BASE + 6,
  35. /// Set pipe page size array
  36. SetPipeSize = F_LINUX_SPECIFIC_BASE + 7,
  37. /// Get pipe page size array
  38. GetPipeSize = F_LINUX_SPECIFIC_BASE + 8,
  39. /// Set seals
  40. AddSeals = F_LINUX_SPECIFIC_BASE + 9,
  41. /// Get seals
  42. GetSeals = F_LINUX_SPECIFIC_BASE + 10,
  43. /**
  44. * Set/Get write life time hints. {GET,SET}_RW_HINT operate on the
  45. * underlying inode, while {GET,SET}_FILE_RW_HINT operate only on
  46. * the specific file.
  47. */
  48. GetRwHint = F_LINUX_SPECIFIC_BASE + 11,
  49. SetRwHint = F_LINUX_SPECIFIC_BASE + 12,
  50. GetFileRwHint = F_LINUX_SPECIFIC_BASE + 13,
  51. SetFileRwHint = F_LINUX_SPECIFIC_BASE + 14,
  52. }
  53. /// The constants AT_REMOVEDIR and AT_EACCESS have the same value. AT_EACCESS is
  54. /// meaningful only to faccessat, while AT_REMOVEDIR is meaningful only to
  55. /// unlinkat. The two functions do completely different things and therefore,
  56. /// the flags can be allowed to overlap. For example, passing AT_REMOVEDIR to
  57. /// faccessat would be undefined behavior and thus treating it equivalent to
  58. /// AT_EACCESS is valid undefined behavior.
  59. #[derive(Debug, Copy, Clone, Eq, PartialEq, FromPrimitive, ToPrimitive)]
  60. #[allow(non_camel_case_types)]
  61. pub enum AtFlags {
  62. /// 特殊值,用于指示openat应使用当前工作目录。
  63. AtFdCwd = -100,
  64. /// 不要跟随符号链接。
  65. /// AT_SYMLINK_NOFOLLOW: 0x100
  66. AtSymlinkNoFollow = 0x100,
  67. /// AtEAccess: 使用有效ID进行访问测试,而不是实际ID。
  68. /// AtRemoveDir: 删除目录而不是取消链接文件。
  69. /// AT_EACCESS: 0x200
  70. /// AT_REMOVEDIR: 0x200
  71. AtEAccess_OR_AtRemoveDir = 0x200,
  72. /// 跟随符号链接。
  73. /// AT_SYMLINK_FOLLOW: 0x400
  74. AtSymlinkFollow = 0x400,
  75. /// 禁止终端自动挂载遍历。
  76. /// AT_NO_AUTOMOUNT: 0x800
  77. AtNoAutomount = 0x800,
  78. /// 允许空的相对路径名。
  79. /// AT_EMPTY_PATH: 0x1000
  80. AtEmptyPath = 0x1000,
  81. /// statx()所需的同步类型。
  82. /// AT_STATX_SYNC_TYPE: 0x6000
  83. AtStatxSyncType = 0x6000,
  84. /// 执行与stat()相同的操作。
  85. /// AT_STATX_SYNC_AS_STAT: 0x0000
  86. AtStatxSyncAsStat = 0x0000,
  87. /// 强制将属性与服务器同步。
  88. /// AT_STATX_FORCE_SYNC: 0x2000
  89. AtStatxForceSync = 0x2000,
  90. /// 不要将属性与服务器同步。
  91. /// AT_STATX_DONT_SYNC: 0x4000
  92. AtStatxDontSync = 0x4000,
  93. /// 应用于整个子树。
  94. /// AT_RECURSIVE: 0x8000
  95. AtRecursive = 0x8000,
  96. }
  97. impl Into<i32> for AtFlags {
  98. fn into(self) -> i32 {
  99. self as i32
  100. }
  101. }
  102. /// for F_[GET|SET]FL
  103. pub const FD_CLOEXEC: u32 = 1;