xref: /linux/include/uapi/asm-generic/fcntl.h (revision c0329020da211b41afce4d1c8a1c2494c6d97883)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef _ASM_GENERIC_FCNTL_H
3 #define _ASM_GENERIC_FCNTL_H
4 
5 #include <linux/types.h>
6 
7 /*
8  * FMODE_EXEC is 0x20
9  * These cannot be used by userspace O_* until internal and external open
10  * flags are split.
11  * -Eric Paris
12  */
13 
14 /*
15  * When introducing new O_* bits, please check its uniqueness in fcntl_init().
16  */
17 
18 #define O_ACCMODE	00000003
19 #define O_RDONLY	00000000
20 #define O_WRONLY	00000001
21 #define O_RDWR		00000002
22 #ifndef O_CREAT
23 #define O_CREAT		00000100	/* not fcntl */
24 #endif
25 #ifndef O_EXCL
26 #define O_EXCL		00000200	/* not fcntl */
27 #endif
28 #ifndef O_NOCTTY
29 #define O_NOCTTY	00000400	/* not fcntl */
30 #endif
31 #ifndef O_TRUNC
32 #define O_TRUNC		00001000	/* not fcntl */
33 #endif
34 #ifndef O_APPEND
35 #define O_APPEND	00002000
36 #endif
37 #ifndef O_NONBLOCK
38 #define O_NONBLOCK	00004000
39 #endif
40 #ifndef O_DSYNC
41 #define O_DSYNC		00010000	/* used to be O_SYNC, see below */
42 #endif
43 #ifndef FASYNC
44 #define FASYNC		00020000	/* fcntl, for BSD compatibility */
45 #endif
46 #ifndef O_DIRECT
47 #define O_DIRECT	00040000	/* direct disk access hint */
48 #endif
49 #ifndef O_LARGEFILE
50 #define O_LARGEFILE	00100000
51 #endif
52 #ifndef O_DIRECTORY
53 #define O_DIRECTORY	00200000	/* must be a directory */
54 #endif
55 #ifndef O_NOFOLLOW
56 #define O_NOFOLLOW	00400000	/* don't follow links */
57 #endif
58 #ifndef O_NOATIME
59 #define O_NOATIME	01000000
60 #endif
61 #ifndef O_CLOEXEC
62 #define O_CLOEXEC	02000000	/* set close_on_exec */
63 #endif
64 
65 /*
66  * Before Linux 2.6.33 only O_DSYNC semantics were implemented, but using
67  * the O_SYNC flag.  We continue to use the existing numerical value
68  * for O_DSYNC semantics now, but using the correct symbolic name for it.
69  * This new value is used to request true Posix O_SYNC semantics.  It is
70  * defined in this strange way to make sure applications compiled against
71  * new headers get at least O_DSYNC semantics on older kernels.
72  *
73  * This has the nice side-effect that we can simply test for O_DSYNC
74  * wherever we do not care if O_DSYNC or O_SYNC is used.
75  *
76  * Note: __O_SYNC must never be used directly.
77  */
78 #ifndef O_SYNC
79 #define __O_SYNC	04000000
80 #define O_SYNC		(__O_SYNC|O_DSYNC)
81 #endif
82 
83 #ifndef O_PATH
84 #define O_PATH		010000000
85 #endif
86 
87 #ifndef __O_TMPFILE
88 #define __O_TMPFILE	020000000
89 #endif
90 
91 #ifndef O_EMPTYPATH
92 #define O_EMPTYPATH	(1 << 26)	/* allow empty path */
93 #endif
94 
95 /* a horrid kludge trying to make sure that this will fail on old kernels */
96 #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
97 
98 #ifndef O_NDELAY
99 #define O_NDELAY	O_NONBLOCK
100 #endif
101 
102 #define F_DUPFD		0	/* dup */
103 #define F_GETFD		1	/* get close_on_exec */
104 #define F_SETFD		2	/* set/clear close_on_exec */
105 #define F_GETFL		3	/* get file->f_flags */
106 #define F_SETFL		4	/* set file->f_flags */
107 #ifndef F_GETLK
108 #define F_GETLK		5
109 #define F_SETLK		6
110 #define F_SETLKW	7
111 #endif
112 #ifndef F_SETOWN
113 #define F_SETOWN	8	/* for sockets. */
114 #define F_GETOWN	9	/* for sockets. */
115 #endif
116 #ifndef F_SETSIG
117 #define F_SETSIG	10	/* for sockets. */
118 #define F_GETSIG	11	/* for sockets. */
119 #endif
120 
121 #if __BITS_PER_LONG == 32 || defined(__KERNEL__)
122 #ifndef F_GETLK64
123 #define F_GETLK64	12	/*  using 'struct flock64' */
124 #define F_SETLK64	13
125 #define F_SETLKW64	14
126 #endif
127 #endif /* __BITS_PER_LONG == 32 || defined(__KERNEL__) */
128 
129 #ifndef F_SETOWN_EX
130 #define F_SETOWN_EX	15
131 #define F_GETOWN_EX	16
132 #endif
133 
134 #ifndef F_GETOWNER_UIDS
135 #define F_GETOWNER_UIDS	17
136 #endif
137 
138 /*
139  * Open File Description Locks
140  *
141  * Usually record locks held by a process are released on *any* close and are
142  * not inherited across a fork().
143  *
144  * These cmd values will set locks that conflict with process-associated
145  * record  locks, but are "owned" by the open file description, not the
146  * process. This means that they are inherited across fork() like BSD (flock)
147  * locks, and they are only released automatically when the last reference to
148  * the the open file against which they were acquired is put.
149  */
150 #define F_OFD_GETLK	36
151 #define F_OFD_SETLK	37
152 #define F_OFD_SETLKW	38
153 
154 #define F_OWNER_TID	0
155 #define F_OWNER_PID	1
156 #define F_OWNER_PGRP	2
157 
158 struct f_owner_ex {
159 	int	type;
160 	__kernel_pid_t	pid;
161 };
162 
163 /* for F_[GET|SET]FL */
164 #define FD_CLOEXEC	1	/* actually anything with low bit set goes */
165 
166 /* for posix fcntl() and lockf() */
167 #ifndef F_RDLCK
168 #define F_RDLCK		0
169 #define F_WRLCK		1
170 #define F_UNLCK		2
171 #endif
172 
173 /* for old implementation of bsd flock () */
174 #ifndef F_EXLCK
175 #define F_EXLCK		4	/* or 3 */
176 #define F_SHLCK		8	/* or 4 */
177 #endif
178 
179 /* operations for bsd flock(), also used by the kernel implementation */
180 #define LOCK_SH		1	/* shared lock */
181 #define LOCK_EX		2	/* exclusive lock */
182 #define LOCK_NB		4	/* or'd with one of the above to prevent
183 				   blocking */
184 #define LOCK_UN		8	/* remove lock */
185 
186 /*
187  * LOCK_MAND support has been removed from the kernel. We leave the symbols
188  * here to not break legacy builds, but these should not be used in new code.
189  */
190 #define LOCK_MAND	32	/* This is a mandatory flock ... */
191 #define LOCK_READ	64	/* which allows concurrent read operations */
192 #define LOCK_WRITE	128	/* which allows concurrent write operations */
193 #define LOCK_RW		192	/* which allows concurrent read & write ops */
194 
195 #define F_LINUX_SPECIFIC_BASE	1024
196 
197 #ifndef HAVE_ARCH_STRUCT_FLOCK
198 struct flock {
199 	short	l_type;
200 	short	l_whence;
201 	__kernel_off_t	l_start;
202 	__kernel_off_t	l_len;
203 	__kernel_pid_t	l_pid;
204 #ifdef	__ARCH_FLOCK_EXTRA_SYSID
205 	__ARCH_FLOCK_EXTRA_SYSID
206 #endif
207 #ifdef	__ARCH_FLOCK_PAD
208 	__ARCH_FLOCK_PAD
209 #endif
210 };
211 
212 struct flock64 {
213 	short  l_type;
214 	short  l_whence;
215 	__kernel_loff_t l_start;
216 	__kernel_loff_t l_len;
217 	__kernel_pid_t  l_pid;
218 #ifdef	__ARCH_FLOCK64_PAD
219 	__ARCH_FLOCK64_PAD
220 #endif
221 };
222 #endif /* HAVE_ARCH_STRUCT_FLOCK */
223 
224 #endif /* _ASM_GENERIC_FCNTL_H */
225