cd4722b836ea048094a6c62ef7fdb721a133a0e3
[jlayton/glibc.git] / sysdeps / unix / sysv / linux / bits / fcntl-linux.h
1 /* O_*, F_*, FD_* bit values for Linux.
2    Copyright (C) 2001-2014 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   020200000
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 #ifdef __USE_LARGEFILE64
121 # define O_LARGEFILE __O_LARGEFILE
122 #endif
123
124 #ifdef __USE_XOPEN2K8
125 # define O_DIRECTORY    __O_DIRECTORY   /* Must be a directory.  */
126 # define O_NOFOLLOW     __O_NOFOLLOW    /* Do not follow links.  */
127 # define O_CLOEXEC      __O_CLOEXEC     /* Set close_on_exec.  */
128 #endif
129
130 #ifdef __USE_GNU
131 # define O_DIRECT       __O_DIRECT      /* Direct disk access.  */
132 # define O_NOATIME      __O_NOATIME     /* Do not set atime.  */
133 # define O_PATH         __O_PATH        /* Resolve pathname but do not open file.  */
134 # define O_TMPFILE      __O_TMPFILE     /* Atomically create nameless file.  */
135 #endif
136
137 /* For now, Linux has no separate synchronicitiy options for read
138    operations.  We define O_RSYNC therefore as the same as O_SYNC
139    since this is a superset.  */
140 #if defined __USE_POSIX199309 || defined __USE_UNIX98
141 # define O_DSYNC        __O_DSYNC       /* Synchronize data.  */
142 # if defined __O_RSYNC
143 #  define O_RSYNC       __O_RSYNC       /* Synchronize read operations.  */
144 # else
145 #  define O_RSYNC       O_SYNC          /* Synchronize read operations.  */
146 # endif
147 #endif
148
149 /* Values for the second argument to `fcntl'.  */
150 #define F_DUPFD         0       /* Duplicate file descriptor.  */
151 #define F_GETFD         1       /* Get file descriptor flags.  */
152 #define F_SETFD         2       /* Set file descriptor flags.  */
153 #define F_GETFL         3       /* Get file status flags.  */
154 #define F_SETFL         4       /* Set file status flags.  */
155
156 #ifndef __F_SETOWN
157 # define __F_SETOWN     8
158 # define __F_GETOWN     9
159 #endif
160
161 #if defined __USE_BSD || defined __USE_UNIX98 || defined __USE_XOPEN2K8
162 # define F_SETOWN       __F_SETOWN /* Get owner (process receiving SIGIO).  */
163 # define F_GETOWN       __F_GETOWN /* Set owner (process receiving SIGIO).  */
164 #endif
165
166 #ifndef __F_SETSIG
167 # define __F_SETSIG     10      /* Set number of signal to be sent.  */
168 # define __F_GETSIG     11      /* Get number of signal to be sent.  */
169 #endif
170 #ifndef __F_SETOWN_EX
171 # define __F_SETOWN_EX  15      /* Get owner (thread receiving SIGIO).  */
172 # define __F_GETOWN_EX  16      /* Set owner (thread receiving SIGIO).  */
173 #endif
174
175 #ifdef __USE_GNU
176 # define F_SETSIG       __F_SETSIG      /* Set number of signal to be sent.  */
177 # define F_GETSIG       __F_GETSIG      /* Get number of signal to be sent.  */
178 # define F_SETOWN_EX    __F_SETOWN_EX   /* Get owner (thread receiving SIGIO).  */
179 # define F_GETOWN_EX    __F_GETOWN_EX   /* Set owner (thread receiving SIGIO).  */
180 #endif
181
182 #ifdef __USE_GNU
183 # define F_SETLEASE     1024    /* Set a lease.  */
184 # define F_GETLEASE     1025    /* Enquire what lease is active.  */
185 # define F_NOTIFY       1026    /* Request notifications on a directory.  */
186 # define F_SETPIPE_SZ   1031    /* Set pipe page size array.  */
187 # define F_GETPIPE_SZ   1032    /* Set pipe page size array.  */
188 #endif
189 #ifdef __USE_XOPEN2K8
190 # define F_DUPFD_CLOEXEC 1030   /* Duplicate file descriptor with
191                                    close-on-exit set.  */
192 #endif
193
194 /* For F_[GET|SET]FD.  */
195 #define FD_CLOEXEC      1       /* Actually anything with low bit set goes */
196
197 #ifndef F_RDLCK
198 /* For posix fcntl() and `l_type' field of a `struct flock' for lockf().  */
199 # define F_RDLCK                0       /* Read lock.  */
200 # define F_WRLCK                1       /* Write lock.  */
201 # define F_UNLCK                2       /* Remove lock.  */
202 #endif
203
204
205 /* For old implementation of BSD flock.  */
206 #ifndef F_EXLCK
207 # define F_EXLCK                4       /* or 3 */
208 # define F_SHLCK                8       /* or 4 */
209 #endif
210
211 #ifdef __USE_BSD
212 /* Operations for BSD flock, also used by the kernel implementation.  */
213 # define LOCK_SH        1       /* Shared lock.  */
214 # define LOCK_EX        2       /* Exclusive lock.  */
215 # define LOCK_NB        4       /* Or'd with one of the above to prevent
216                                    blocking.  */
217 # define LOCK_UN        8       /* Remove lock.  */
218 #endif
219
220 #ifdef __USE_GNU
221 # define LOCK_MAND      32      /* This is a mandatory flock:   */
222 # define LOCK_READ      64      /* ... which allows concurrent read operations.  */
223 # define LOCK_WRITE     128     /* ... which allows concurrent write operations.  */
224 # define LOCK_RW        192     /* ... Which allows concurrent read & write operations.  */
225 #endif
226
227 #ifdef __USE_GNU
228 /* Types of directory notifications that may be requested with F_NOTIFY.  */
229 # define DN_ACCESS      0x00000001      /* File accessed.  */
230 # define DN_MODIFY      0x00000002      /* File modified.  */
231 # define DN_CREATE      0x00000004      /* File created.  */
232 # define DN_DELETE      0x00000008      /* File removed.  */
233 # define DN_RENAME      0x00000010      /* File renamed.  */
234 # define DN_ATTRIB      0x00000020      /* File changed attributes.  */
235 # define DN_MULTISHOT   0x80000000      /* Don't remove notifier.  */
236 #endif
237
238
239 #ifdef __USE_GNU
240 /* Owner types.  */
241 enum __pid_type
242   {
243     F_OWNER_TID = 0,            /* Kernel thread.  */
244     F_OWNER_PID,                /* Process.  */
245     F_OWNER_PGRP,               /* Process group.  */
246     F_OWNER_GID = F_OWNER_PGRP  /* Alternative, obsolete name.  */
247   };
248
249 /* Structure to use with F_GETOWN_EX and F_SETOWN_EX.  */
250 struct f_owner_ex
251   {
252     enum __pid_type type;       /* Owner type of ID.  */
253     __pid_t pid;                /* ID of owner.  */
254   };
255 #endif
256
257 /* Define some more compatibility macros to be backward compatible with
258    BSD systems which did not managed to hide these kernel macros.  */
259 #ifdef  __USE_BSD
260 # define FAPPEND        O_APPEND
261 # define FFSYNC         O_FSYNC
262 # define FASYNC         O_ASYNC
263 # define FNONBLOCK      O_NONBLOCK
264 # define FNDELAY        O_NDELAY
265 #endif /* Use BSD.  */
266
267 #ifndef __POSIX_FADV_DONTNEED
268 #  define __POSIX_FADV_DONTNEED 4
269 #  define __POSIX_FADV_NOREUSE  5
270 #endif
271 /* Advise to `posix_fadvise'.  */
272 #ifdef __USE_XOPEN2K
273 # define POSIX_FADV_NORMAL      0 /* No further special treatment.  */
274 # define POSIX_FADV_RANDOM      1 /* Expect random page references.  */
275 # define POSIX_FADV_SEQUENTIAL  2 /* Expect sequential page references.  */
276 # define POSIX_FADV_WILLNEED    3 /* Will need these pages.  */
277 # define POSIX_FADV_DONTNEED    __POSIX_FADV_DONTNEED /* Don't need these pages.  */
278 # define POSIX_FADV_NOREUSE     __POSIX_FADV_NOREUSE /* Data will be accessed once.  */
279 #endif
280
281
282 #ifdef __USE_GNU
283 /* Flags for SYNC_FILE_RANGE.  */
284 # define SYNC_FILE_RANGE_WAIT_BEFORE    1 /* Wait upon writeout of all pages
285                                              in the range before performing the
286                                              write.  */
287 # define SYNC_FILE_RANGE_WRITE          2 /* Initiate writeout of all those
288                                              dirty pages in the range which are
289                                              not presently under writeback.  */
290 # define SYNC_FILE_RANGE_WAIT_AFTER     4 /* Wait upon writeout of all pages in
291                                              the range after performing the
292                                              write.  */
293
294 /* Flags for SPLICE and VMSPLICE.  */
295 # define SPLICE_F_MOVE          1       /* Move pages instead of copying.  */
296 # define SPLICE_F_NONBLOCK      2       /* Don't block on the pipe splicing
297                                            (but we may still block on the fd
298                                            we splice from/to).  */
299 # define SPLICE_F_MORE          4       /* Expect more data.  */
300 # define SPLICE_F_GIFT          8       /* Pages passed in are a gift.  */
301
302
303 /* Flags for fallocate.  */
304 # define FALLOC_FL_KEEP_SIZE            1 /* Don't extend size of file
305                                              even if offset + len is
306                                              greater than file size.  */
307 # define FALLOC_FL_PUNCH_HOLE           2 /* Create a hole in the file.  */
308
309
310 /* File handle structure.  */
311 struct file_handle
312 {
313   unsigned int handle_bytes;
314   int handle_type;
315   /* File identifier.  */
316   unsigned char f_handle[0];
317 };
318
319 /* Maximum handle size (for now).  */
320 # define MAX_HANDLE_SZ  128
321 #endif
322
323 __BEGIN_DECLS
324
325 #ifdef __USE_GNU
326
327 /* Provide kernel hint to read ahead.  */
328 extern ssize_t readahead (int __fd, __off64_t __offset, size_t __count)
329     __THROW;
330
331
332 /* Selective file content synch'ing.
333
334    This function is a possible cancellation point and therefore not
335    marked with __THROW.  */
336 extern int sync_file_range (int __fd, __off64_t __offset, __off64_t __count,
337                             unsigned int __flags);
338
339
340 /* Splice address range into a pipe.
341
342    This function is a possible cancellation point and therefore not
343    marked with __THROW.  */
344 extern ssize_t vmsplice (int __fdout, const struct iovec *__iov,
345                          size_t __count, unsigned int __flags);
346
347 /* Splice two files together.
348
349    This function is a possible cancellation point and therefore not
350    marked with __THROW.  */
351 extern ssize_t splice (int __fdin, __off64_t *__offin, int __fdout,
352                        __off64_t *__offout, size_t __len,
353                        unsigned int __flags);
354
355 /* In-kernel implementation of tee for pipe buffers.
356
357    This function is a possible cancellation point and therefore not
358    marked with __THROW.  */
359 extern ssize_t tee (int __fdin, int __fdout, size_t __len,
360                     unsigned int __flags);
361
362 /* Reserve storage for the data of the file associated with FD.
363
364    This function is a possible cancellation point and therefore not
365    marked with __THROW.  */
366 # ifndef __USE_FILE_OFFSET64
367 extern int fallocate (int __fd, int __mode, __off_t __offset, __off_t __len);
368 # else
369 #  ifdef __REDIRECT
370 extern int __REDIRECT (fallocate, (int __fd, int __mode, __off64_t __offset,
371                                    __off64_t __len),
372                        fallocate64);
373 #  else
374 #   define fallocate fallocate64
375 #  endif
376 # endif
377 # ifdef __USE_LARGEFILE64
378 extern int fallocate64 (int __fd, int __mode, __off64_t __offset,
379                         __off64_t __len);
380 # endif
381
382
383 /* Map file name to file handle.  */
384 extern int name_to_handle_at (int __dfd, const char *__name,
385                               struct file_handle *__handle, int *__mnt_id,
386                               int __flags) __THROW;
387
388 /* Open file using the file handle.
389
390    This function is a possible cancellation point and therefore not
391    marked with __THROW.  */
392 extern int open_by_handle_at (int __mountdirfd, struct file_handle *__handle,
393                               int __flags);
394
395 #endif  /* use GNU */
396
397 __END_DECLS