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