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