1    	/* O_*, F_*, FD_* bit values for Linux.
2    	   Copyright (C) 2001-2015 Free Software Foundation, Inc.
3    	   This file is part of the GNU C Library.
4    	
5    	   The GNU C Library is free software; you can redistribute it and/or
6    	   modify it under the terms of the GNU Lesser General Public
7    	   License as published by the Free Software Foundation; either
8    	   version 2.1 of the License, or (at your option) any later version.
9    	
10   	   The GNU C Library is distributed in the hope that it will be useful,
11   	   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   	   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   	   Lesser General Public License for more details.
14   	
15   	   You should have received a copy of the GNU Lesser General Public
16   	   License along with the GNU C Library; if not, see
17   	   <http://www.gnu.org/licenses/>.  */
18   	
19   	#ifndef	_FCNTL_H
20   	# error "Never use <bits/fcntl-linux.h> directly; include <fcntl.h> instead."
21   	#endif
22   	
23   	/* This file contains shared definitions between Linux architectures
24   	   and is included by <bits/fcntl.h> to declare them.  The various
25   	   #ifndef cases allow the architecture specific file to define those
26   	   values with different values.
27   	
28   	   A minimal <bits/fcntl.h> contains just:
29   	
30   	   struct flock {...}
31   	   #ifdef __USE_LARGEFILE64
32   	   struct flock64 {...}
33   	   #endif
34   	   #include <bits/fcntl-linux.h>
35   	*/
36   	
37   	#ifdef __USE_GNU
38   	# include <bits/uio.h>
39   	#endif
40   	
41   	/* open/fcntl.  */
42   	#define O_ACCMODE	   0003
43   	#define O_RDONLY	     00
44   	#define O_WRONLY	     01
45   	#define O_RDWR		     02
46   	#ifndef O_CREAT
47   	# define O_CREAT	   0100	/* Not fcntl.  */
48   	#endif
49   	#ifndef O_EXCL
50   	# define O_EXCL		   0200	/* Not fcntl.  */
51   	#endif
52   	#ifndef O_NOCTTY
53   	# define O_NOCTTY	   0400	/* Not fcntl.  */
54   	#endif
55   	#ifndef O_TRUNC
56   	# define O_TRUNC	  01000	/* Not fcntl.  */
57   	#endif
58   	#ifndef O_APPEND
59   	# define O_APPEND	  02000
60   	#endif
61   	#ifndef O_NONBLOCK
62   	# define O_NONBLOCK	  04000
63   	#endif
64   	#ifndef O_NDELAY
65   	# define O_NDELAY	O_NONBLOCK
66   	#endif
67   	#ifndef O_SYNC
68   	# define O_SYNC	       04010000
69   	#endif
70   	#define O_FSYNC		O_SYNC
71   	#ifndef O_ASYNC
72   	# define O_ASYNC	 020000
73   	#endif
74   	#ifndef __O_LARGEFILE
75   	# define __O_LARGEFILE	0100000
76   	#endif
77   	
78   	#ifndef __O_DIRECTORY
79   	# define __O_DIRECTORY  0200000
80   	#endif
81   	#ifndef __O_NOFOLLOW
82   	# define __O_NOFOLLOW	0400000
83   	#endif
84   	#ifndef __O_CLOEXEC
85   	# define __O_CLOEXEC   02000000
86   	#endif
87   	#ifndef __O_DIRECT
88   	# define __O_DIRECT	 040000
89   	#endif
90   	#ifndef __O_NOATIME
91   	# define __O_NOATIME   01000000
92   	#endif
93   	#ifndef __O_PATH
94   	# define __O_PATH     010000000
95   	#endif
96   	#ifndef __O_DSYNC
97   	# define __O_DSYNC	 010000
98   	#endif
99   	#ifndef __O_TMPFILE
100  	# define __O_TMPFILE   (020000000 | __O_DIRECTORY)
101  	#endif
102  	
103  	#ifndef F_GETLK
104  	# ifndef __USE_FILE_OFFSET64
105  	#  define F_GETLK	5	/* Get record locking info.  */
106  	#  define F_SETLK	6	/* Set record locking info (non-blocking).  */
107  	#  define F_SETLKW	7	/* Set record locking info (blocking).	*/
108  	# else
109  	#  define F_GETLK	F_GETLK64  /* Get record locking info.	*/
110  	#  define F_SETLK	F_SETLK64  /* Set record locking info (non-blocking).*/
111  	#  define F_SETLKW	F_SETLKW64 /* Set record locking info (blocking).  */
112  	# endif
113  	#endif
114  	#ifndef F_GETLK64
115  	# define F_GETLK64	12	/* Get record locking info.  */
116  	# define F_SETLK64	13	/* Set record locking info (non-blocking).  */
117  	# define F_SETLKW64	14	/* Set record locking info (blocking).	*/
118  	#endif
119  	
120  	/* open file description locks.
121  	
122  	   Usually record locks held by a process are released on *any* close and are
123  	   not inherited across a fork.
124  	
125  	   These cmd values will set locks that conflict with process-associated record
126  	   locks, but are "owned" by the opened file description, not the process.
127  	   This means that they are inherited across fork or clone with CLONE_FILES
128  	   like BSD (flock) locks, and they are only released automatically when the
129  	   last reference to the the file description against which they were acquired
130  	   is put. */
131  	#ifdef __USE_GNU
132  	# define F_OFD_GETLK	36
133  	# define F_OFD_SETLK	37
134  	# define F_OFD_SETLKW	38
135  	#endif
136  	
137  	#ifdef __USE_LARGEFILE64
138  	# define O_LARGEFILE __O_LARGEFILE
139  	#endif
140  	
141  	#ifdef __USE_XOPEN2K8
142  	# define O_DIRECTORY	__O_DIRECTORY	/* Must be a directory.	 */
143  	# define O_NOFOLLOW	__O_NOFOLLOW	/* Do not follow links.	 */
144  	# define O_CLOEXEC	__O_CLOEXEC	/* Set close_on_exec.  */
145  	#endif
146  	
147  	#ifdef __USE_GNU
148  	# define O_DIRECT	__O_DIRECT	/* Direct disk access.	*/
149  	# define O_NOATIME	__O_NOATIME	/* Do not set atime.  */
150  	# define O_PATH		__O_PATH	/* Resolve pathname but do not open file.  */
151  	# define O_TMPFILE	__O_TMPFILE	/* Atomically create nameless file.  */
152  	#endif
153  	
154  	/* For now, Linux has no separate synchronicitiy options for read
155  	   operations.  We define O_RSYNC therefore as the same as O_SYNC
156  	   since this is a superset.  */
157  	#if defined __USE_POSIX199309 || defined __USE_UNIX98
158  	# define O_DSYNC	__O_DSYNC	/* Synchronize data.  */
159  	# if defined __O_RSYNC
160  	#  define O_RSYNC	__O_RSYNC	/* Synchronize read operations.	 */
161  	# else
162  	#  define O_RSYNC	O_SYNC		/* Synchronize read operations.	 */
163  	# endif
164  	#endif
165  	
166  	/* Values for the second argument to `fcntl'.  */
167  	#define F_DUPFD		0	/* Duplicate file descriptor.  */
168  	#define F_GETFD		1	/* Get file descriptor flags.  */
169  	#define F_SETFD		2	/* Set file descriptor flags.  */
170  	#define F_GETFL		3	/* Get file status flags.  */
171  	#define F_SETFL		4	/* Set file status flags.  */
172  	
173  	#ifndef __F_SETOWN
174  	# define __F_SETOWN	8
175  	# define __F_GETOWN	9
176  	#endif
177  	
178  	#if defined __USE_UNIX98 || defined __USE_XOPEN2K8
179  	# define F_SETOWN	__F_SETOWN /* Get owner (process receiving SIGIO).  */
180  	# define F_GETOWN	__F_GETOWN /* Set owner (process receiving SIGIO).  */
181  	#endif
182  	
183  	#ifndef __F_SETSIG
184  	# define __F_SETSIG	10	/* Set number of signal to be sent.  */
185  	# define __F_GETSIG	11	/* Get number of signal to be sent.  */
186  	#endif
187  	#ifndef __F_SETOWN_EX
188  	# define __F_SETOWN_EX	15	/* Get owner (thread receiving SIGIO).  */
189  	# define __F_GETOWN_EX	16	/* Set owner (thread receiving SIGIO).  */
190  	#endif
191  	
192  	#ifdef __USE_GNU
193  	# define F_SETSIG	__F_SETSIG	/* Set number of signal to be sent.  */
194  	# define F_GETSIG	__F_GETSIG	/* Get number of signal to be sent.  */
195  	# define F_SETOWN_EX	__F_SETOWN_EX	/* Get owner (thread receiving SIGIO).  */
196  	# define F_GETOWN_EX	__F_GETOWN_EX	/* Set owner (thread receiving SIGIO).  */
197  	#endif
198  	
199  	#ifdef __USE_GNU
200  	# define F_SETLEASE	1024	/* Set a lease.	 */
201  	# define F_GETLEASE	1025	/* Enquire what lease is active.  */
202  	# define F_NOTIFY	1026	/* Request notifications on a directory.  */
203  	# define F_SETPIPE_SZ	1031	/* Set pipe page size array.  */
204  	# define F_GETPIPE_SZ	1032	/* Set pipe page size array.  */
205  	#endif
206  	#ifdef __USE_XOPEN2K8
207  	# define F_DUPFD_CLOEXEC 1030	/* Duplicate file descriptor with
208  					   close-on-exit set.  */
209  	#endif
210  	
211  	/* For F_[GET|SET]FD.  */
212  	#define FD_CLOEXEC	1	/* Actually anything with low bit set goes */
213  	
214  	#ifndef F_RDLCK
215  	/* For posix fcntl() and `l_type' field of a `struct flock' for lockf().  */
216  	# define F_RDLCK		0	/* Read lock.  */
217  	# define F_WRLCK		1	/* Write lock.	*/
218  	# define F_UNLCK		2	/* Remove lock.	 */
219  	#endif
220  	
221  	
222  	/* For old implementation of BSD flock.  */
223  	#ifndef F_EXLCK
224  	# define F_EXLCK		4	/* or 3 */
225  	# define F_SHLCK		8	/* or 4 */
226  	#endif
227  	
228  	#ifdef __USE_MISC
229  	/* Operations for BSD flock, also used by the kernel implementation.  */
230  	# define LOCK_SH	1	/* Shared lock.  */
231  	# define LOCK_EX	2	/* Exclusive lock.  */
232  	# define LOCK_NB	4	/* Or'd with one of the above to prevent
233  					   blocking.  */
234  	# define LOCK_UN	8	/* Remove lock.  */
235  	#endif
236  	
237  	#ifdef __USE_GNU
238  	# define LOCK_MAND	32	/* This is a mandatory flock:	*/
239  	# define LOCK_READ	64	/* ... which allows concurrent read operations.	 */
240  	# define LOCK_WRITE	128	/* ... which allows concurrent write operations.  */
241  	# define LOCK_RW	192	/* ... Which allows concurrent read & write operations.	 */
242  	#endif
243  	
244  	#ifdef __USE_GNU
245  	/* Types of directory notifications that may be requested with F_NOTIFY.  */
246  	# define DN_ACCESS	0x00000001	/* File accessed.  */
247  	# define DN_MODIFY	0x00000002	/* File modified.  */
248  	# define DN_CREATE	0x00000004	/* File created.  */
249  	# define DN_DELETE	0x00000008	/* File removed.  */
250  	# define DN_RENAME	0x00000010	/* File renamed.  */
251  	# define DN_ATTRIB	0x00000020	/* File changed attributes.  */
252  	# define DN_MULTISHOT	0x80000000	/* Don't remove notifier.  */
253  	#endif
254  	
255  	
256  	#ifdef __USE_GNU
257  	/* Owner types.  */
258  	enum __pid_type
259  	  {
260  	    F_OWNER_TID = 0,		/* Kernel thread.  */
261  	    F_OWNER_PID,		/* Process.  */
262  	    F_OWNER_PGRP,		/* Process group.  */
263  	    F_OWNER_GID = F_OWNER_PGRP	/* Alternative, obsolete name.  */
264  	  };
265  	
266  	/* Structure to use with F_GETOWN_EX and F_SETOWN_EX.  */
267  	struct f_owner_ex
268  	  {
269  	    enum __pid_type type;	/* Owner type of ID.  */
270  	    __pid_t pid;		/* ID of owner.  */
271  	  };
272  	#endif
273  	
274  	/* Define some more compatibility macros to be backward compatible with
275  	   BSD systems which did not managed to hide these kernel macros.  */
276  	#ifdef	__USE_MISC
277  	# define FAPPEND	O_APPEND
278  	# define FFSYNC		O_FSYNC
279  	# define FASYNC		O_ASYNC
280  	# define FNONBLOCK	O_NONBLOCK
281  	# define FNDELAY	O_NDELAY
282  	#endif /* Use misc.  */
283  	
284  	#ifndef __POSIX_FADV_DONTNEED
285  	#  define __POSIX_FADV_DONTNEED	4
286  	#  define __POSIX_FADV_NOREUSE	5
287  	#endif
288  	/* Advise to `posix_fadvise'.  */
289  	#ifdef __USE_XOPEN2K
290  	# define POSIX_FADV_NORMAL	0 /* No further special treatment.  */
291  	# define POSIX_FADV_RANDOM	1 /* Expect random page references.  */
292  	# define POSIX_FADV_SEQUENTIAL	2 /* Expect sequential page references.	 */
293  	# define POSIX_FADV_WILLNEED	3 /* Will need these pages.  */
294  	# define POSIX_FADV_DONTNEED	__POSIX_FADV_DONTNEED /* Don't need these pages.  */
295  	# define POSIX_FADV_NOREUSE	__POSIX_FADV_NOREUSE /* Data will be accessed once.  */
296  	#endif
297  	
298  	
299  	#ifdef __USE_GNU
300  	/* Flags for SYNC_FILE_RANGE.  */
301  	# define SYNC_FILE_RANGE_WAIT_BEFORE	1 /* Wait upon writeout of all pages
302  						     in the range before performing the
303  						     write.  */
304  	# define SYNC_FILE_RANGE_WRITE		2 /* Initiate writeout of all those
305  						     dirty pages in the range which are
306  						     not presently under writeback.  */
307  	# define SYNC_FILE_RANGE_WAIT_AFTER	4 /* Wait upon writeout of all pages in
308  						     the range after performing the
309  						     write.  */
310  	
311  	/* Flags for SPLICE and VMSPLICE.  */
312  	# define SPLICE_F_MOVE		1	/* Move pages instead of copying.  */
313  	# define SPLICE_F_NONBLOCK	2	/* Don't block on the pipe splicing
314  						   (but we may still block on the fd
315  						   we splice from/to).  */
316  	# define SPLICE_F_MORE		4	/* Expect more data.  */
317  	# define SPLICE_F_GIFT		8	/* Pages passed in are a gift.  */
318  	
319  	
320  	/* Flags for fallocate.  */
321  	# define FALLOC_FL_KEEP_SIZE		1 /* Don't extend size of file
322  						     even if offset + len is
323  						     greater than file size.  */
324  	# define FALLOC_FL_PUNCH_HOLE		2 /* Create a hole in the file.  */
325  	# define FALLOC_FL_COLLAPSE_RANGE	8 /* Remove a range of a file
326  						     without leaving a
327  						     hole.  */
328  	# define FALLOC_FL_ZERO_RANGE		16 /* Convert a range of a
329  						      file to zeros.  */
330  	
331  	
332  	/* File handle structure.  */
333  	struct file_handle
334  	{
335  	  unsigned int handle_bytes;
336  	  int handle_type;
337  	  /* File identifier.  */
338  	  unsigned char f_handle[0];
339  	};
340  	
341  	/* Maximum handle size (for now).  */
342  	# define MAX_HANDLE_SZ	128
343  	#endif
344  	
345  	__BEGIN_DECLS
346  	
347  	#ifdef __USE_GNU
348  	
349  	/* Provide kernel hint to read ahead.  */
350  	extern ssize_t readahead (int __fd, __off64_t __offset, size_t __count)
351  	    __THROW;
352  	
353  	
354  	/* Selective file content synch'ing.
355  	
356  	   This function is a possible cancellation point and therefore not
357  	   marked with __THROW.  */
358  	extern int sync_file_range (int __fd, __off64_t __offset, __off64_t __count,
359  				    unsigned int __flags);
360  	
361  	
362  	/* Splice address range into a pipe.
363  	
364  	   This function is a possible cancellation point and therefore not
365  	   marked with __THROW.  */
366  	extern ssize_t vmsplice (int __fdout, const struct iovec *__iov,
367  				 size_t __count, unsigned int __flags);
368  	
369  	/* Splice two files together.
370  	
371  	   This function is a possible cancellation point and therefore not
372  	   marked with __THROW.  */
373  	extern ssize_t splice (int __fdin, __off64_t *__offin, int __fdout,
374  			       __off64_t *__offout, size_t __len,
375  			       unsigned int __flags);
376  	
377  	/* In-kernel implementation of tee for pipe buffers.
378  	
379  	   This function is a possible cancellation point and therefore not
380  	   marked with __THROW.  */
381  	extern ssize_t tee (int __fdin, int __fdout, size_t __len,
382  			    unsigned int __flags);
383  	
384  	/* Reserve storage for the data of the file associated with FD.
385  	
386  	   This function is a possible cancellation point and therefore not
387  	   marked with __THROW.  */
388  	# ifndef __USE_FILE_OFFSET64
389  	extern int fallocate (int __fd, int __mode, __off_t __offset, __off_t __len);
390  	# else
391  	#  ifdef __REDIRECT
392  	extern int __REDIRECT (fallocate, (int __fd, int __mode, __off64_t __offset,
393  					   __off64_t __len),
394  			       fallocate64);
395  	#  else
396  	#   define fallocate fallocate64
397  	#  endif
398  	# endif
399  	# ifdef __USE_LARGEFILE64
400  	extern int fallocate64 (int __fd, int __mode, __off64_t __offset,
401  				__off64_t __len);
402  	# endif
403  	
404  	
405  	/* Map file name to file handle.  */
406  	extern int name_to_handle_at (int __dfd, const char *__name,
407  				      struct file_handle *__handle, int *__mnt_id,
408  				      int __flags) __THROW;
409  	
410  	/* Open file using the file handle.
411  	
412  	   This function is a possible cancellation point and therefore not
413  	   marked with __THROW.  */
414  	extern int open_by_handle_at (int __mountdirfd, struct file_handle *__handle,
415  				      int __flags);
416  	
417  	#endif	/* use GNU */
418  	
419  	__END_DECLS
420