xref: /DragonOS/kernel/src/filesystem/vfs/fcntl.rs (revision 83ed0ebc293d5a10245089f627f52770fd5b9dd4)
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 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     pub struct AtFlags: i32 {
70         /// 特殊值,用于指示openat应使用当前工作目录。
71         const AT_FDCWD = -100;
72         /// 不要跟随符号链接。
73         const AT_SYMLINK_NOFOLLOW = 0x100;
74         /// AtEAccess: 使用有效ID进行访问测试,而不是实际ID。
75         const AT_EACCESS = 0x200;
76         /// AtRemoveDir: 删除目录而不是取消链接文件。
77         const AT_REMOVEDIR = 0x200;
78 
79         /// 跟随符号链接。
80         /// AT_SYMLINK_FOLLOW: 0x400
81         const AT_SYMLINK_FOLLOW = 0x400;
82         /// 禁止终端自动挂载遍历。
83         /// AT_NO_AUTOMOUNT: 0x800
84         const AT_NO_AUTOMOUNT = 0x800;
85         /// 允许空的相对路径名。
86         /// AT_EMPTY_PATH: 0x1000
87         const AT_EMPTY_PATH = 0x1000;
88         /// statx()所需的同步类型。
89         /// AT_STATX_SYNC_TYPE: 0x6000
90         const AT_STATX_SYNC_TYPE = 0x6000;
91         /// 执行与stat()相同的操作。
92         /// AT_STATX_SYNC_AS_STAT: 0x0000
93         const AT_STATX_SYNC_AS_STAT = 0x0000;
94         /// 强制将属性与服务器同步。
95         /// AT_STATX_FORCE_SYNC: 0x2000
96         const AT_STATX_FORCE_SYNC = 0x2000;
97         /// 不要将属性与服务器同步。
98         /// AT_STATX_DONT_SYNC: 0x4000
99         const AT_STATX_DONT_SYNC = 0x4000;
100         /// 应用于整个子树。
101         /// AT_RECURSIVE: 0x8000
102         const AT_RECURSIVE = 0x8000;
103     }
104 }
105 
106 /// for F_[GET|SET]FL
107 pub const FD_CLOEXEC: u32 = 1;
108