xref: /DragonOS/kernel/src/filesystem/vfs/fcntl.rs (revision dfe53cf087ef4c7b6db63d992906b062dc63e93f)
1 const F_LINUX_SPECIFIC_BASE: u32 = 1024;
2 
3 /// fcntl syscall command
4 ///
5 /// for linux-specific fcntl commands, see:
6 /// https://code.dragonos.org.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,
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 bitflags! {
62 
63     ///  The constants AT_REMOVEDIR and AT_EACCESS have the same value.  AT_EACCESS is
64     ///  meaningful only to faccessat, while AT_REMOVEDIR is meaningful only to
65     ///  unlinkat.  The two functions do completely different things and therefore,
66     ///  the flags can be allowed to overlap.  For example, passing AT_REMOVEDIR to
67     ///  faccessat would be undefined behavior and thus treating it equivalent to
68     ///  AT_EACCESS is valid undefined behavior.
69     #[allow(clippy::bad_bit_mask)]
70     pub struct AtFlags: i32 {
71         /// 特殊值,用于指示openat应使用当前工作目录。
72         const AT_FDCWD = -100;
73         /// 不要跟随符号链接。
74         const AT_SYMLINK_NOFOLLOW = 0x100;
75         /// AtEAccess: 使用有效ID进行访问测试,而不是实际ID。
76         const AT_EACCESS = 0x200;
77         /// AtRemoveDir: 删除目录而不是取消链接文件。
78         const AT_REMOVEDIR = 0x200;
79 
80         /// 跟随符号链接。
81         /// AT_SYMLINK_FOLLOW: 0x400
82         const AT_SYMLINK_FOLLOW = 0x400;
83         /// 禁止终端自动挂载遍历。
84         /// AT_NO_AUTOMOUNT: 0x800
85         const AT_NO_AUTOMOUNT = 0x800;
86         /// 允许空的相对路径名。
87         /// AT_EMPTY_PATH: 0x1000
88         const AT_EMPTY_PATH = 0x1000;
89         /// statx()所需的同步类型。
90         /// AT_STATX_SYNC_TYPE: 0x6000
91         const AT_STATX_SYNC_TYPE = 0x6000;
92         /// 执行与stat()相同的操作。
93         /// AT_STATX_SYNC_AS_STAT: 0x0000
94         const AT_STATX_SYNC_AS_STAT = 0x0000;
95         /// 强制将属性与服务器同步。
96         /// AT_STATX_FORCE_SYNC: 0x2000
97         const AT_STATX_FORCE_SYNC = 0x2000;
98         /// 不要将属性与服务器同步。
99         /// AT_STATX_DONT_SYNC: 0x4000
100         const AT_STATX_DONT_SYNC = 0x4000;
101         /// 应用于整个子树。
102         /// AT_RECURSIVE: 0x8000
103         const AT_RECURSIVE = 0x8000;
104     }
105 }
106 
107 /// for F_[GET|SET]FL
108 pub const FD_CLOEXEC: u32 = 1;
109