xref: /linux/include/uapi/linux/fcntl.h (revision 7fc2cd2e4b398c57c9cf961cfea05eadbf34c05c)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef _UAPI_LINUX_FCNTL_H
3 #define _UAPI_LINUX_FCNTL_H
4 
5 #include <asm/fcntl.h>
6 #include <linux/openat2.h>
7 #ifdef __KERNEL__
8 #include <linux/types.h>
9 #else
10 #include <stdint.h>
11 #endif
12 
13 #define F_SETLEASE	(F_LINUX_SPECIFIC_BASE + 0)
14 #define F_GETLEASE	(F_LINUX_SPECIFIC_BASE + 1)
15 
16 /*
17  * Request nofications on a directory.
18  * See below for events that may be notified.
19  */
20 #define F_NOTIFY	(F_LINUX_SPECIFIC_BASE + 2)
21 
22 #define F_DUPFD_QUERY	(F_LINUX_SPECIFIC_BASE + 3)
23 
24 /* Was the file just created? */
25 #define F_CREATED_QUERY	(F_LINUX_SPECIFIC_BASE + 4)
26 
27 /*
28  * Cancel a blocking posix lock; internal use only until we expose an
29  * asynchronous lock api to userspace:
30  */
31 #define F_CANCELLK	(F_LINUX_SPECIFIC_BASE + 5)
32 
33 /* Create a file descriptor with FD_CLOEXEC set. */
34 #define F_DUPFD_CLOEXEC	(F_LINUX_SPECIFIC_BASE + 6)
35 
36 /*
37  * Set and get of pipe page size array
38  */
39 #define F_SETPIPE_SZ	(F_LINUX_SPECIFIC_BASE + 7)
40 #define F_GETPIPE_SZ	(F_LINUX_SPECIFIC_BASE + 8)
41 
42 /*
43  * Set/Get seals
44  */
45 #define F_ADD_SEALS	(F_LINUX_SPECIFIC_BASE + 9)
46 #define F_GET_SEALS	(F_LINUX_SPECIFIC_BASE + 10)
47 
48 /*
49  * Types of seals
50  */
51 #define F_SEAL_SEAL	0x0001	/* prevent further seals from being set */
52 #define F_SEAL_SHRINK	0x0002	/* prevent file from shrinking */
53 #define F_SEAL_GROW	0x0004	/* prevent file from growing */
54 #define F_SEAL_WRITE	0x0008	/* prevent writes */
55 #define F_SEAL_FUTURE_WRITE	0x0010  /* prevent future writes while mapped */
56 #define F_SEAL_EXEC	0x0020  /* prevent chmod modifying exec bits */
57 /* (1U << 31) is reserved for signed error codes */
58 
59 /*
60  * Set/Get write life time hints. {GET,SET}_RW_HINT operate on the
61  * underlying inode, while {GET,SET}_FILE_RW_HINT operate only on
62  * the specific file.
63  */
64 #define F_GET_RW_HINT		(F_LINUX_SPECIFIC_BASE + 11)
65 #define F_SET_RW_HINT		(F_LINUX_SPECIFIC_BASE + 12)
66 #define F_GET_FILE_RW_HINT	(F_LINUX_SPECIFIC_BASE + 13)
67 #define F_SET_FILE_RW_HINT	(F_LINUX_SPECIFIC_BASE + 14)
68 
69 /*
70  * Valid hint values for F_{GET,SET}_RW_HINT. 0 is "not set", or can be
71  * used to clear any hints previously set.
72  */
73 #define RWH_WRITE_LIFE_NOT_SET	0
74 #define RWH_WRITE_LIFE_NONE	1
75 #define RWH_WRITE_LIFE_SHORT	2
76 #define RWH_WRITE_LIFE_MEDIUM	3
77 #define RWH_WRITE_LIFE_LONG	4
78 #define RWH_WRITE_LIFE_EXTREME	5
79 
80 /*
81  * The originally introduced spelling is remained from the first
82  * versions of the patch set that introduced the feature, see commit
83  * v4.13-rc1~212^2~51.
84  */
85 #define RWF_WRITE_LIFE_NOT_SET	RWH_WRITE_LIFE_NOT_SET
86 
87 /* Set/Get delegations */
88 #define F_GETDELEG		(F_LINUX_SPECIFIC_BASE + 15)
89 #define F_SETDELEG		(F_LINUX_SPECIFIC_BASE + 16)
90 
91 /* Argument structure for F_GETDELEG and F_SETDELEG */
92 struct delegation {
93 	uint32_t	d_flags;	/* Must be 0 */
94 	uint16_t	d_type;		/* F_RDLCK, F_WRLCK, F_UNLCK */
95 	uint16_t	__pad;		/* Must be 0 */
96 };
97 
98 /*
99  * Types of directory notifications that may be requested.
100  */
101 #define DN_ACCESS	0x00000001	/* File accessed */
102 #define DN_MODIFY	0x00000002	/* File modified */
103 #define DN_CREATE	0x00000004	/* File created */
104 #define DN_DELETE	0x00000008	/* File removed */
105 #define DN_RENAME	0x00000010	/* File renamed */
106 #define DN_ATTRIB	0x00000020	/* File changed attibutes */
107 #define DN_MULTISHOT	0x80000000	/* Don't remove notifier */
108 
109 /* Reserved kernel ranges [-100], [-10000, -40000]. */
110 #define AT_FDCWD		-100    /* Special value for dirfd used to
111 					   indicate openat should use the
112 					   current working directory. */
113 
114 /*
115  * The concept of process and threads in userland and the kernel is a confusing
116  * one - within the kernel every thread is a 'task' with its own individual PID,
117  * however from userland's point of view threads are grouped by a single PID,
118  * which is that of the 'thread group leader', typically the first thread
119  * spawned.
120  *
121  * To cut the Gideon knot, for internal kernel usage, we refer to
122  * PIDFD_SELF_THREAD to refer to the current thread (or task from a kernel
123  * perspective), and PIDFD_SELF_THREAD_GROUP to refer to the current thread
124  * group leader...
125  */
126 #define PIDFD_SELF_THREAD		-10000 /* Current thread. */
127 #define PIDFD_SELF_THREAD_GROUP		-10001 /* Current thread group leader. */
128 
129 #define FD_PIDFS_ROOT			-10002 /* Root of the pidfs filesystem */
130 #define FD_NSFS_ROOT			-10003 /* Root of the nsfs filesystem */
131 #define FD_INVALID			-10009 /* Invalid file descriptor: -10000 - EBADF = -10009 */
132 
133 /* Generic flags for the *at(2) family of syscalls. */
134 
135 /* Reserved for per-syscall flags	0xff. */
136 #define AT_SYMLINK_NOFOLLOW		0x100   /* Do not follow symbolic
137 						   links. */
138 /* Reserved for per-syscall flags	0x200 */
139 #define AT_SYMLINK_FOLLOW		0x400   /* Follow symbolic links. */
140 #define AT_NO_AUTOMOUNT			0x800	/* Suppress terminal automount
141 						   traversal. */
142 #define AT_EMPTY_PATH			0x1000	/* Allow empty relative
143 						   pathname to operate on dirfd
144 						   directly. */
145 /*
146  * These flags are currently statx(2)-specific, but they could be made generic
147  * in the future and so they should not be used for other per-syscall flags.
148  */
149 #define AT_STATX_SYNC_TYPE		0x6000	/* Type of synchronisation required from statx() */
150 #define AT_STATX_SYNC_AS_STAT		0x0000	/* - Do whatever stat() does */
151 #define AT_STATX_FORCE_SYNC		0x2000	/* - Force the attributes to be sync'd with the server */
152 #define AT_STATX_DONT_SYNC		0x4000	/* - Don't sync attributes with the server */
153 
154 #define AT_RECURSIVE			0x8000	/* Apply to the entire subtree */
155 
156 /*
157  * Per-syscall flags for the *at(2) family of syscalls.
158  *
159  * These are flags that are so syscall-specific that a user passing these flags
160  * to the wrong syscall is so "clearly wrong" that we can safely call such
161  * usage "undefined behaviour".
162  *
163  * For example, the constants AT_REMOVEDIR and AT_EACCESS have the same value.
164  * AT_EACCESS is meaningful only to faccessat, while AT_REMOVEDIR is meaningful
165  * only to unlinkat. The two functions do completely different things and
166  * therefore, the flags can be allowed to overlap. For example, passing
167  * AT_REMOVEDIR to faccessat would be undefined behavior and thus treating it
168  * equivalent to AT_EACCESS is valid undefined behavior.
169  *
170  * Note for implementers: When picking a new per-syscall AT_* flag, try to
171  * reuse already existing flags first. This leaves us with as many unused bits
172  * as possible, so we can use them for generic bits in the future if necessary.
173  */
174 
175 /* Flags for renameat2(2) (must match legacy RENAME_* flags). */
176 #define AT_RENAME_NOREPLACE	0x0001
177 #define AT_RENAME_EXCHANGE	0x0002
178 #define AT_RENAME_WHITEOUT	0x0004
179 
180 /* Flag for faccessat(2). */
181 #define AT_EACCESS		0x200	/* Test access permitted for
182                                            effective IDs, not real IDs.  */
183 /* Flag for unlinkat(2). */
184 #define AT_REMOVEDIR		0x200   /* Remove directory instead of
185                                            unlinking file.  */
186 /* Flags for name_to_handle_at(2). */
187 #define AT_HANDLE_FID		0x200	/* File handle is needed to compare
188 					   object identity and may not be
189 					   usable with open_by_handle_at(2). */
190 #define AT_HANDLE_MNT_ID_UNIQUE	0x001	/* Return the u64 unique mount ID. */
191 #define AT_HANDLE_CONNECTABLE	0x002	/* Request a connectable file handle */
192 
193 /* Flags for execveat2(2). */
194 #define AT_EXECVE_CHECK		0x10000	/* Only perform a check if execution
195 					   would be allowed. */
196 
197 #endif /* _UAPI_LINUX_FCNTL_H */
198