]>
Commit | Line | Data |
---|---|---|
28f540f4 | 1 | /* O_*, F_*, FD_* bit values for GNU. |
d4697bc9 | 2 | Copyright (C) 1993-2014 Free Software Foundation, Inc. |
ceb2d9aa UD |
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 | |
41bdb6e2 AJ |
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. | |
ceb2d9aa UD |
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 | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
ceb2d9aa | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
28f540f4 | 18 | |
5107cf1d | 19 | #ifndef _FCNTL_H |
dfd2257a | 20 | # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead." |
5107cf1d | 21 | #endif |
28f540f4 | 22 | |
9844ff30 RM |
23 | #include <sys/types.h> |
24 | ||
28f540f4 RM |
25 | /* File access modes. These are understood by io servers; they can be |
26 | passed in `dir_lookup', and are returned by `io_get_openmodes'. | |
27 | Consequently they can be passed to `open', `hurd_file_name_lookup', and | |
28 | `file_name_lookup'; and are returned by `fcntl' with the F_GETFL | |
29 | command. */ | |
30 | ||
31 | /* In GNU, read and write are bits (unlike BSD). */ | |
32 | #ifdef __USE_GNU | |
dfd2257a UD |
33 | # define O_READ O_RDONLY /* Open for reading. */ |
34 | # define O_WRITE O_WRONLY /* Open for writing. */ | |
35 | # define O_EXEC 0x0004 /* Open for execution. */ | |
36 | # define O_NORW 0 /* Open without R/W access. */ | |
28f540f4 RM |
37 | #endif |
38 | /* POSIX.1 standard names. */ | |
39 | #define O_RDONLY 0x0001 /* Open read-only. */ | |
40 | #define O_WRONLY 0x0002 /* Open write-only. */ | |
41 | #define O_RDWR (O_RDONLY|O_WRONLY) /* Open for reading and writing. */ | |
42 | #define O_ACCMODE O_RDWR /* Mask for file access modes. */ | |
43 | ||
3331899a | 44 | #define O_LARGEFILE 0 |
28f540f4 RM |
45 | |
46 | ||
47 | /* File name translation flags. These are understood by io servers; | |
48 | they can be passed in `dir_lookup', and consequently to `open', | |
49 | `hurd_file_name_lookup', and `file_name_lookup'. */ | |
50 | ||
51 | #define O_CREAT 0x0010 /* Create file if it doesn't exist. */ | |
52 | #define O_EXCL 0x0020 /* Fail if file already exists. */ | |
53 | #ifdef __USE_GNU | |
dfd2257a UD |
54 | # define O_NOLINK 0x0040 /* No name mappings on final component. */ |
55 | # define O_NOTRANS 0x0080 /* No translator on final component. */ | |
ee16e894 | 56 | #endif |
791cfdb7 | 57 | |
ee16e894 | 58 | #ifdef __USE_XOPEN2K8 |
791cfdb7 RM |
59 | # define O_NOFOLLOW 0x00100000 /* Produce ENOENT if file is a symlink. */ |
60 | # define O_DIRECTORY 0x00200000 /* Produce ENOTDIR if not a directory. */ | |
28f540f4 RM |
61 | #endif |
62 | ||
63 | ||
64 | /* I/O operating modes. These are understood by io servers; they can be | |
65 | passed in `dir_lookup' and set or fetched with `io_*_openmodes'. | |
66 | Consequently they can be passed to `open', `hurd_file_name_lookup', | |
67 | `file_name_lookup', and `fcntl' with the F_SETFL command; and are | |
68 | returned by `fcntl' with the F_GETFL command. */ | |
69 | ||
70 | #define O_APPEND 0x0100 /* Writes always append to the file. */ | |
8179dcc1 RM |
71 | #define O_ASYNC 0x0200 /* Send SIGIO to owner when data is ready. */ |
72 | #define O_FSYNC 0x0400 /* Synchronous writes. */ | |
73 | #define O_SYNC O_FSYNC | |
28f540f4 | 74 | #ifdef __USE_GNU |
dfd2257a | 75 | # define O_NOATIME 0x0800 /* Don't set access time on read (owner). */ |
28f540f4 | 76 | #endif |
b207ff4b | 77 | #ifdef __USE_MISC |
dfd2257a UD |
78 | # define O_SHLOCK 0x00020000 /* Open with shared file lock. */ |
79 | # define O_EXLOCK 0x00040000 /* Open with exclusive file lock. */ | |
b207ff4b | 80 | #endif |
28f540f4 | 81 | |
eeeeed6a RM |
82 | /* These are lesser flavors of partial synchronization that are |
83 | implied by our one flag (O_FSYNC). */ | |
84 | #if defined __USE_POSIX199309 || defined __USE_UNIX98 | |
85 | # define O_DSYNC O_SYNC /* Synchronize data. */ | |
86 | # define O_RSYNC O_SYNC /* Synchronize read operations. */ | |
87 | #endif | |
88 | ||
28f540f4 RM |
89 | |
90 | /* The name O_NONBLOCK is unfortunately overloaded; it is both a file name | |
91 | translation flag and an I/O operating mode. O_NDELAY is the deprecated | |
92 | BSD name for the same flag, overloaded in the same way. | |
93 | ||
94 | When used in `dir_lookup' (and consequently `open', `hurd_file_name_lookup', | |
95 | or `file_name_lookup'), O_NONBLOCK says the open should return immediately | |
96 | instead of blocking for any significant length of time (e.g., to wait | |
97 | for carrier detect on a serial line). It is also saved as an I/O | |
98 | operating mode, and after open has the following meaning. | |
99 | ||
100 | When used in `io_*_openmodes' (and consequently `fcntl' with the F_SETFL | |
101 | command), the O_NONBLOCK flag means to do nonblocking i/o: any i/o | |
102 | operation that would block for any significant length of time will instead | |
103 | fail with EAGAIN. */ | |
104 | ||
105 | #define O_NONBLOCK 0x0008 /* Non-blocking open or non-blocking I/O. */ | |
106 | #ifdef __USE_BSD | |
dfd2257a | 107 | # define O_NDELAY O_NONBLOCK /* Deprecated. */ |
28f540f4 RM |
108 | #endif |
109 | ||
110 | ||
111 | #ifdef __USE_GNU | |
112 | /* Mask of bits which are understood by io servers. */ | |
dfd2257a | 113 | # define O_HURD (0xffff | O_EXLOCK | O_SHLOCK) |
28f540f4 RM |
114 | #endif |
115 | ||
116 | ||
117 | /* Open-time action flags. These are understood by `hurd_file_name_lookup' | |
118 | and consequently by `open' and `file_name_lookup'. They are not preserved | |
119 | once the file has been opened. */ | |
120 | ||
121 | #define O_TRUNC 0x00010000 /* Truncate file to zero length. */ | |
ee16e894 | 122 | #ifdef __USE_XOPEN2K8 |
9ef78a12 RM |
123 | # define O_CLOEXEC 0x00400000 /* Set FD_CLOEXEC. */ |
124 | #endif | |
28f540f4 RM |
125 | |
126 | ||
127 | /* Controlling terminal flags. These are understood only by `open', | |
128 | and are not preserved once the file has been opened. */ | |
129 | ||
130 | #ifdef __USE_GNU | |
dfd2257a | 131 | # define O_IGNORE_CTTY 0x00080000 /* Don't do any ctty magic at all. */ |
28f540f4 RM |
132 | #endif |
133 | /* `open' never assigns a controlling terminal in GNU. */ | |
134 | #define O_NOCTTY 0 /* Don't assign a controlling terminal. */ | |
135 | ||
136 | ||
137 | #ifdef __USE_BSD | |
138 | /* Bits in the file status flags returned by F_GETFL. */ | |
dfd2257a UD |
139 | # define FREAD O_RDONLY |
140 | # define FWRITE O_WRONLY | |
28f540f4 RM |
141 | |
142 | /* Traditional BSD names the O_* bits. */ | |
dfd2257a UD |
143 | # define FASYNC O_ASYNC |
144 | # define FCREAT O_CREAT | |
145 | # define FEXCL O_EXCL | |
146 | # define FTRUNC O_TRUNC | |
147 | # define FNOCTTY O_NOCTTY | |
148 | # define FFSYNC O_FSYNC | |
149 | # define FSYNC O_SYNC | |
150 | # define FAPPEND O_APPEND | |
151 | # define FNONBLOCK O_NONBLOCK | |
152 | # define FNDELAY O_NDELAY | |
28f540f4 RM |
153 | #endif |
154 | ||
155 | ||
156 | /* Values for the second argument to `fcntl'. */ | |
157 | #define F_DUPFD 0 /* Duplicate file descriptor. */ | |
158 | #define F_GETFD 1 /* Get file descriptor flags. */ | |
159 | #define F_SETFD 2 /* Set file descriptor flags. */ | |
160 | #define F_GETFL 3 /* Get file status flags. */ | |
161 | #define F_SETFL 4 /* Set file status flags. */ | |
ee16e894 | 162 | #if defined __USE_BSD || defined __USE_UNIX98 || defined __USE_XOPEN2K8 |
dfd2257a UD |
163 | # define F_GETOWN 5 /* Get owner (receiver of SIGIO). */ |
164 | # define F_SETOWN 6 /* Set owner (receiver of SIGIO). */ | |
28f540f4 RM |
165 | #endif |
166 | #define F_GETLK 7 /* Get record locking info. */ | |
167 | #define F_SETLK 8 /* Set record locking info (non-blocking). */ | |
168 | #define F_SETLKW 9 /* Set record locking info (blocking). */ | |
169 | ||
ee16e894 | 170 | #ifdef __USE_XOPEN2K8 |
bd92328d RM |
171 | # define F_DUPFD_CLOEXEC 1030 /* Duplicate, set FD_CLOEXEC on new one. */ |
172 | #endif | |
173 | ||
174 | ||
28f540f4 RM |
175 | /* File descriptor flags used with F_GETFD and F_SETFD. */ |
176 | #define FD_CLOEXEC 1 /* Close on exec. */ | |
177 | ||
178 | ||
cdd225ad | 179 | #include <bits/types.h> |
28f540f4 RM |
180 | |
181 | /* The structure describing an advisory lock. This is the type of the third | |
182 | argument to `fcntl' for the F_GETLK, F_SETLK, and F_SETLKW requests. */ | |
183 | struct flock | |
184 | { | |
185 | int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */ | |
186 | int l_whence; /* Where `l_start' is relative to (like `lseek'). */ | |
dfd2257a | 187 | #ifndef __USE_FILE_OFFSET64 |
28f540f4 RM |
188 | __off_t l_start; /* Offset where the lock begins. */ |
189 | __off_t l_len; /* Size of the locked area; zero means until EOF. */ | |
dfd2257a UD |
190 | #else |
191 | __off64_t l_start; /* Offset where the lock begins. */ | |
192 | __off64_t l_len; /* Size of the locked area; zero means until EOF. */ | |
193 | #endif | |
194 | __pid_t l_pid; /* Process holding the lock. */ | |
195 | }; | |
196 | ||
197 | #ifdef __USE_LARGEFILE64 | |
198 | struct flock64 | |
199 | { | |
200 | int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */ | |
201 | int l_whence; /* Where `l_start' is relative to (like `lseek'). */ | |
202 | __off64_t l_start; /* Offset where the lock begins. */ | |
203 | __off64_t l_len; /* Size of the locked area; zero means until EOF. */ | |
28f540f4 RM |
204 | __pid_t l_pid; /* Process holding the lock. */ |
205 | }; | |
dfd2257a | 206 | #endif |
28f540f4 RM |
207 | |
208 | /* Values for the `l_type' field of a `struct flock'. */ | |
209 | #define F_RDLCK 1 /* Read lock. */ | |
210 | #define F_WRLCK 2 /* Write lock. */ | |
211 | #define F_UNLCK 3 /* Remove lock. */ | |
bb8e0116 UD |
212 | |
213 | /* Advise to `posix_fadvise'. */ | |
214 | #ifdef __USE_XOPEN2K | |
215 | # define POSIX_FADV_NORMAL 0 /* No further special treatment. */ | |
216 | # define POSIX_FADV_RANDOM 1 /* Expect random page references. */ | |
217 | # define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */ | |
218 | # define POSIX_FADV_WILLNEED 3 /* Will need these pages. */ | |
219 | # define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */ | |
220 | # define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */ | |
221 | #endif |