xref: /DragonOS/kernel/src/filesystem/vfs/fcntl.rs (revision 709498cac1f2134b2a5e089366ee7136ee029369)
16d81180bSLoGin const F_LINUX_SPECIFIC_BASE: u32 = 1024;
26d81180bSLoGin 
36d81180bSLoGin /// fcntl syscall command
46d81180bSLoGin ///
56d81180bSLoGin /// for linux-specific fcntl commands, see:
66d81180bSLoGin /// https://opengrok.ringotek.cn/xref/linux-5.19.10/tools/include/uapi/linux/fcntl.h#8
76d81180bSLoGin #[derive(Debug, Copy, Clone, Eq, PartialEq, FromPrimitive, ToPrimitive)]
86d81180bSLoGin #[repr(u32)]
96d81180bSLoGin pub enum FcntlCommand {
106d81180bSLoGin     /// dup
116d81180bSLoGin     DupFd = 0,
126d81180bSLoGin     /// get close-on-exec
136d81180bSLoGin     GetFd = 1,
146d81180bSLoGin     /// set/clear close-on-exec
156d81180bSLoGin     SetFd = 2,
166d81180bSLoGin     /// get file flags
176d81180bSLoGin     GetFlags = 3,
186d81180bSLoGin     /// set file flags
196d81180bSLoGin     SetFlags = 4,
206d81180bSLoGin     /// get record locking info
216d81180bSLoGin     GetLock = 5,
226d81180bSLoGin     /// set record locking info (non-blocking)
236d81180bSLoGin     SetLock = 6,
246d81180bSLoGin     /// set record locking info (blocking)
256d81180bSLoGin     SetLockWait = 7,
266d81180bSLoGin 
276d81180bSLoGin     SetLease = F_LINUX_SPECIFIC_BASE + 0,
286d81180bSLoGin     GetLease = F_LINUX_SPECIFIC_BASE + 1,
296d81180bSLoGin 
306d81180bSLoGin     /// Request nofications on a directory.
316d81180bSLoGin     /// See below for events that may be notified.
326d81180bSLoGin     Notify = F_LINUX_SPECIFIC_BASE + 2,
336d81180bSLoGin 
346d81180bSLoGin     /// Cancel a blocking posix lock; internal use only until we expose an
356d81180bSLoGin     /// asynchronous lock api to userspace
366d81180bSLoGin     CancelLock = F_LINUX_SPECIFIC_BASE + 5,
376d81180bSLoGin     /// Create a file descriptor with FD_CLOEXEC set.
386d81180bSLoGin     DupFdCloexec = F_LINUX_SPECIFIC_BASE + 6,
396d81180bSLoGin 
406d81180bSLoGin     /// Set pipe page size array
416d81180bSLoGin     SetPipeSize = F_LINUX_SPECIFIC_BASE + 7,
426d81180bSLoGin     /// Get pipe page size array
436d81180bSLoGin     GetPipeSize = F_LINUX_SPECIFIC_BASE + 8,
446d81180bSLoGin 
456d81180bSLoGin     /// Set seals
466d81180bSLoGin     AddSeals = F_LINUX_SPECIFIC_BASE + 9,
476d81180bSLoGin     /// Get seals
486d81180bSLoGin     GetSeals = F_LINUX_SPECIFIC_BASE + 10,
496d81180bSLoGin 
506d81180bSLoGin     /**
516d81180bSLoGin      * Set/Get write life time hints. {GET,SET}_RW_HINT operate on the
526d81180bSLoGin      * underlying inode, while {GET,SET}_FILE_RW_HINT operate only on
536d81180bSLoGin      * the specific file.
546d81180bSLoGin      */
556d81180bSLoGin     GetRwHint = F_LINUX_SPECIFIC_BASE + 11,
566d81180bSLoGin     SetRwHint = F_LINUX_SPECIFIC_BASE + 12,
576d81180bSLoGin     GetFileRwHint = F_LINUX_SPECIFIC_BASE + 13,
586d81180bSLoGin     SetFileRwHint = F_LINUX_SPECIFIC_BASE + 14,
596d81180bSLoGin }
606d81180bSLoGin 
61*709498caSLoGin ///  The constants AT_REMOVEDIR and AT_EACCESS have the same value.  AT_EACCESS is
62*709498caSLoGin ///  meaningful only to faccessat, while AT_REMOVEDIR is meaningful only to
63*709498caSLoGin ///  unlinkat.  The two functions do completely different things and therefore,
64*709498caSLoGin ///  the flags can be allowed to overlap.  For example, passing AT_REMOVEDIR to
65*709498caSLoGin ///  faccessat would be undefined behavior and thus treating it equivalent to
66*709498caSLoGin ///  AT_EACCESS is valid undefined behavior.
67*709498caSLoGin #[derive(Debug, Copy, Clone, Eq, PartialEq, FromPrimitive, ToPrimitive)]
68*709498caSLoGin #[allow(non_camel_case_types)]
69*709498caSLoGin pub enum AtFlags {
70*709498caSLoGin     /// 特殊值,用于指示openat应使用当前工作目录。
71*709498caSLoGin     AtFdCwd = -100,
72*709498caSLoGin     /// 不要跟随符号链接。
73*709498caSLoGin     /// AT_SYMLINK_NOFOLLOW: 0x100
74*709498caSLoGin     AtSymlinkNoFollow = 0x100,
75*709498caSLoGin     /// AtEAccess: 使用有效ID进行访问测试,而不是实际ID。
76*709498caSLoGin     /// AtRemoveDir: 删除目录而不是取消链接文件。
77*709498caSLoGin     /// AT_EACCESS: 0x200
78*709498caSLoGin     /// AT_REMOVEDIR: 0x200
79*709498caSLoGin     AtEAccess_OR_AtRemoveDir = 0x200,
80*709498caSLoGin 
81*709498caSLoGin     /// 跟随符号链接。
82*709498caSLoGin     /// AT_SYMLINK_FOLLOW: 0x400
83*709498caSLoGin     AtSymlinkFollow = 0x400,
84*709498caSLoGin     /// 禁止终端自动挂载遍历。
85*709498caSLoGin     /// AT_NO_AUTOMOUNT: 0x800
86*709498caSLoGin     AtNoAutomount = 0x800,
87*709498caSLoGin     /// 允许空的相对路径名。
88*709498caSLoGin     /// AT_EMPTY_PATH: 0x1000
89*709498caSLoGin     AtEmptyPath = 0x1000,
90*709498caSLoGin     /// statx()所需的同步类型。
91*709498caSLoGin     /// AT_STATX_SYNC_TYPE: 0x6000
92*709498caSLoGin     AtStatxSyncType = 0x6000,
93*709498caSLoGin     /// 执行与stat()相同的操作。
94*709498caSLoGin     /// AT_STATX_SYNC_AS_STAT: 0x0000
95*709498caSLoGin     AtStatxSyncAsStat = 0x0000,
96*709498caSLoGin     /// 强制将属性与服务器同步。
97*709498caSLoGin     /// AT_STATX_FORCE_SYNC: 0x2000
98*709498caSLoGin     AtStatxForceSync = 0x2000,
99*709498caSLoGin     /// 不要将属性与服务器同步。
100*709498caSLoGin     /// AT_STATX_DONT_SYNC: 0x4000
101*709498caSLoGin     AtStatxDontSync = 0x4000,
102*709498caSLoGin     /// 应用于整个子树。
103*709498caSLoGin     /// AT_RECURSIVE: 0x8000
104*709498caSLoGin     AtRecursive = 0x8000,
105*709498caSLoGin }
106*709498caSLoGin 
107*709498caSLoGin impl Into<i32> for AtFlags {
108*709498caSLoGin     fn into(self) -> i32 {
109*709498caSLoGin         self as i32
110*709498caSLoGin     }
111*709498caSLoGin }
112*709498caSLoGin 
1136d81180bSLoGin /// for F_[GET|SET]FL
1146d81180bSLoGin pub const FD_CLOEXEC: u32 = 1;
115