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