]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Hey Emacs! This file is -*- nroff -*- source. |
2 | .\" | |
3 | .\" This manpage is Copyright (C) 1992 Drew Eckhardt; | |
4 | .\" 1993 Michael Haardt, Ian Jackson. | |
5 | .\" | |
6 | .\" Permission is granted to make and distribute verbatim copies of this | |
7 | .\" manual provided the copyright notice and this permission notice are | |
8 | .\" preserved on all copies. | |
9 | .\" | |
10 | .\" Permission is granted to copy and distribute modified versions of this | |
11 | .\" manual under the conditions for verbatim copying, provided that the | |
12 | .\" entire resulting derived work is distributed under the terms of a | |
13 | .\" permission notice identical to this one. | |
c13182ef | 14 | .\" |
fea681da MK |
15 | .\" Since the Linux kernel and libraries are constantly changing, this |
16 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
17 | .\" responsibility for errors or omissions, or for damages resulting from | |
18 | .\" the use of the information contained herein. The author(s) may not | |
19 | .\" have taken the same level of care in the production of this manual, | |
20 | .\" which is licensed free of charge, as they might when working | |
21 | .\" professionally. | |
c13182ef | 22 | .\" |
fea681da MK |
23 | .\" Formatted or processed versions of this manual, if unaccompanied by |
24 | .\" the source, must acknowledge the copyright and authors of this work. | |
25 | .\" | |
26 | .\" Modified 1993-07-21 by Rik Faith <faith@cs.unc.edu> | |
27 | .\" Modified 1994-08-21 by Michael Haardt | |
28 | .\" Modified 1996-04-13 by Andries Brouwer <aeb@cwi.nl> | |
29 | .\" Modified 1996-05-13 by Thomas Koenig | |
30 | .\" Modified 1996-12-20 by Michael Haardt | |
31 | .\" Modified 1999-02-19 by Andries Brouwer <aeb@cwi.nl> | |
32 | .\" Modified 1998-11-28 by Joseph S. Myers <jsm28@hermes.cam.ac.uk> | |
33 | .\" Modified 1999-06-03 by Michael Haardt | |
305a0578 MK |
34 | .\" Modified 2002-05-07 by Michael Kerrisk <mtk-manpages@gmx.net> |
35 | .\" Modified 2004-06-23 by Michael Kerrisk <mtk-manpages@gmx.net> | |
1c1e15ed MK |
36 | .\" 2004-12-08, mtk, reordered flags list alphabetically |
37 | .\" 2004-12-08, Martin Pool <mbp@sourcefrog.net> (& mtk), added O_NOATIME | |
fea681da | 38 | .\" |
e366dbc4 | 39 | .TH OPEN 2 2005-06-22 "Linux 2.6.12" "Linux Programmer's Manual" |
fea681da MK |
40 | .SH NAME |
41 | open, creat \- open and possibly create a file or device | |
42 | .SH SYNOPSIS | |
43 | .nf | |
44 | .B #include <sys/types.h> | |
45 | .B #include <sys/stat.h> | |
46 | .B #include <fcntl.h> | |
47 | .sp | |
48 | .BI "int open(const char *" pathname ", int " flags ); | |
49 | .BI "int open(const char *" pathname ", int " flags ", mode_t " mode ); | |
50 | .BI "int creat(const char *" pathname ", mode_t " mode ); | |
51 | .fi | |
52 | .SH DESCRIPTION | |
e366dbc4 | 53 | Given a |
c13182ef | 54 | .IR pathname |
e366dbc4 | 55 | for a file, |
1f6ceb40 | 56 | .BR open () |
c13182ef | 57 | returns a file descriptor, a small, non-negative integer |
e366dbc4 MK |
58 | for use in subsequent system calls |
59 | .RB ( read "(2), " write "(2), " lseek "(2), " fcntl "(2), etc.)." | |
60 | The file descriptor returned by a successful call will be | |
2c4bff36 | 61 | the lowest-numbered file descriptor not currently open for the process. |
e366dbc4 | 62 | .PP |
c13182ef | 63 | The new file descriptor is set to remain open across an |
e366dbc4 | 64 | .BR execve (2) |
1f6ceb40 MK |
65 | (i.e., the |
66 | .B FD_CLOEXEC | |
67 | file descriptor flag described in | |
68 | .BR fcntl (2) | |
69 | is initially disabled). | |
70 | The file offset is set to the beginning of the file (see | |
c13182ef | 71 | .BR lseek (2)). |
e366dbc4 MK |
72 | .PP |
73 | A call to | |
74 | .BR open () | |
75 | creates a new | |
76 | .IR "open file description" , | |
77 | an entry in the system-wide table of open files. | |
e366dbc4 MK |
78 | This entry records the file offset and the file status flags |
79 | (modifiable via the | |
0bfa087b | 80 | .BR fcntl (2) |
e366dbc4 MK |
81 | .B F_SETFL |
82 | operation). | |
2c4bff36 MK |
83 | A file descriptor is a reference to one of these entries; |
84 | this reference is unaffected if | |
85 | .I pathname | |
86 | is subsequently removed or modified to refer to a different file. | |
e366dbc4 | 87 | The new open file description is initially not shared |
2c4bff36 MK |
88 | with any other process, |
89 | but sharing may arise via | |
90 | .BR fork (2). | |
e366dbc4 | 91 | .PP |
fea681da MK |
92 | The parameter |
93 | .I flags | |
e366dbc4 MK |
94 | must include one of the following |
95 | .IR "access modes" : | |
96 | .BR O_RDONLY ", " O_WRONLY ", or " O_RDWR. | |
97 | These request opening the file read-only, write-only, or read/write, | |
98 | respectively. | |
bfe9ba67 MK |
99 | |
100 | In addition, zero or more file creation flags and file status flags | |
c13182ef | 101 | can be |
fea681da | 102 | .RI bitwise- or 'd |
e366dbc4 | 103 | in |
bfe9ba67 | 104 | .IR flags . |
c13182ef MK |
105 | The |
106 | .I file creation flags | |
107 | are | |
bfe9ba67 | 108 | .BR O_CREAT ", " O_EXCL ", " O_NOCTTY ", and " O_TRUNC . |
c13182ef MK |
109 | The |
110 | .I file status flags | |
bfe9ba67 MK |
111 | are all of the remaining flags listed below. |
112 | The distinction between these two groups of flags is that | |
113 | the file status flags can be retrieved and (in some cases) | |
114 | modified using | |
115 | .BR fcntl (2). | |
116 | The full list of file creation flags and file status flags is as follows: | |
fea681da | 117 | .TP |
1c1e15ed | 118 | .B O_APPEND |
c13182ef MK |
119 | The file is opened in append mode. |
120 | Before each | |
0bfa087b | 121 | .BR write (2), |
1e568304 | 122 | the file offset is positioned at the end of the file, |
1c1e15ed | 123 | as if with |
0bfa087b | 124 | .BR lseek (2). |
1c1e15ed MK |
125 | .B O_APPEND |
126 | may lead to corrupted files on NFS file systems if more than one process | |
c13182ef MK |
127 | appends data to a file at once. |
128 | This is because NFS does not support | |
1c1e15ed MK |
129 | appending to a file, so the client kernel has to simulate it, which |
130 | can't be done without a race condition. | |
131 | .TP | |
132 | .B O_ASYNC | |
b50582eb MK |
133 | Enable signal-driven I/O: |
134 | generate a signal (SIGIO by default, but this can be changed via | |
1c1e15ed MK |
135 | .BR fcntl (2)) |
136 | when input or output becomes possible on this file descriptor. | |
c13182ef | 137 | This feature is only available for terminals, pseudo-terminals, |
1f6ceb40 MK |
138 | sockets, and (since Linux 2.6) pipes and FIFOs. |
139 | See | |
1c1e15ed MK |
140 | .BR fcntl (2) |
141 | for further details. | |
142 | .TP | |
fea681da MK |
143 | .B O_CREAT |
144 | If the file does not exist it will be created. | |
145 | The owner (user ID) of the file is set to the effective user ID | |
c13182ef MK |
146 | of the process. |
147 | The group ownership (group ID) is set either to | |
fea681da MK |
148 | the effective group ID of the process or to the group ID of the |
149 | parent directory (depending on filesystem type and mount options, | |
150 | and the mode of the parent directory, see, e.g., the mount options | |
151 | .I bsdgroups | |
152 | and | |
153 | .I sysvgroups | |
154 | of the ext2 filesystem, as described in | |
155 | .BR mount (8)). | |
156 | .TP | |
1c1e15ed MK |
157 | .B O_DIRECT |
158 | Try to minimize cache effects of the I/O to and from this file. | |
159 | In general this will degrade performance, but it is useful in | |
160 | special situations, such as when applications do their own caching. | |
161 | File I/O is done directly to/from user space buffers. | |
e366dbc4 | 162 | The I/O is synchronous, i.e., at the completion of a |
1c1e15ed MK |
163 | .BR read (2) |
164 | or | |
e366dbc4 MK |
165 | .BR write (2), |
166 | data is guaranteed to have been transferred. | |
1c1e15ed MK |
167 | Under Linux 2.4 transfer sizes, and the alignment of user buffer |
168 | and file offset must all be multiples of the logical block size | |
c13182ef MK |
169 | of the file system. |
170 | Under Linux 2.6 alignment to 512-byte boundaries | |
1c1e15ed MK |
171 | suffices. |
172 | .\" Alignment should satisfy requirements for the underlying device | |
173 | .\" There may be coherency problems. | |
9b54d4fa | 174 | .sp |
c13182ef | 175 | A semantically similar (but deprecated) interface for block devices |
9b54d4fa | 176 | is described in |
1c1e15ed MK |
177 | .BR raw (8). |
178 | .TP | |
179 | .B O_DIRECTORY | |
c13182ef | 180 | If \fIpathname\fR is not a directory, cause the open to fail. |
9f8d688a MK |
181 | .\" But see the following and its replies: |
182 | .\" http://marc.theaimsgroup.com/?t=112748702800001&r=1&w=2 | |
183 | .\" [PATCH] open: O_DIRECTORY and O_CREAT together should fail | |
184 | .\" O_DIRECTORY | O_CREAT causes O_DIRECTORY to be ignored. | |
185 | This flag is Linux-specific, and was added in kernel version 2.1.126, to | |
60a90ecd MK |
186 | avoid denial-of-service problems if |
187 | .BR opendir (3) | |
188 | is called on a | |
1c1e15ed | 189 | FIFO or tape device, but should not be used outside of the |
9e370fba MK |
190 | implementation of |
191 | .BR opendir (3). | |
1c1e15ed | 192 | .TP |
fea681da MK |
193 | .B O_EXCL |
194 | When used with | |
195 | .BR O_CREAT , | |
196 | if the file already exists it is an error and the | |
1c1e15ed | 197 | .BR open () |
c13182ef MK |
198 | will fail. |
199 | In this context, a symbolic link exists, regardless | |
1f6ceb40 | 200 | of where it points to. |
fea681da | 201 | .B O_EXCL |
1f6ceb40 | 202 | is broken on NFS file systems; programs which rely on it for performing |
c13182ef MK |
203 | locking tasks will contain a race condition. |
204 | The solution for performing | |
1c1e15ed MK |
205 | atomic file locking using a lockfile is to create a unique file on |
206 | the same file system (e.g., incorporating hostname and pid), use | |
fea681da | 207 | .BR link (2) |
c13182ef | 208 | to make a link to the lockfile. |
60a90ecd MK |
209 | If |
210 | .BR link (2) | |
211 | returns 0, the lock is | |
c13182ef MK |
212 | successful. |
213 | Otherwise, use | |
fea681da MK |
214 | .BR stat (2) |
215 | on the unique file to check if its link count has increased to 2, | |
216 | in which case the lock is also successful. | |
217 | .TP | |
1c1e15ed MK |
218 | .B O_LARGEFILE |
219 | (LFS) | |
220 | Allow files whose sizes cannot be represented in an | |
8478ee02 | 221 | .I off_t |
1c1e15ed | 222 | (but can be represented in an |
8478ee02 | 223 | .IR off64_t ) |
1c1e15ed | 224 | to be opened. |
c13182ef | 225 | The |
bcdd964e MK |
226 | .B _LARGEFILE64_SOURCE |
227 | macro must be defined in order to obtain this definition. | |
c13182ef | 228 | Setting the |
bcdd964e | 229 | .B _FILE_OFFSET_BITS |
9f3d8b28 MK |
230 | feature test macro to 64 (rather than using |
231 | .BR O_LARGEFILE ) | |
232 | is the preferred method of obtaining | |
233 | method of accessing large files on 32-bit systems (see | |
2dcbf4f7 | 234 | .BR feature_test_macros (7)). |
1c1e15ed MK |
235 | .TP |
236 | .B O_NOATIME | |
237 | (Since Linux 2.6.8) | |
310b7919 MK |
238 | Do not update the file last access time (st_atime in the inode) |
239 | when the file is | |
1c1e15ed MK |
240 | .BR read (2). |
241 | This flag is intended for use by indexing or backup programs, | |
242 | where its use can significantly reduce the amount of disk activity. | |
243 | This flag may not be effective on all filesystems. | |
244 | One example is NFS, where the server maintains the access time. | |
c13182ef | 245 | .\" FIXME? The O_NOATIME flag also affects the treatment of st_atime |
92057f4d | 246 | .\" by mmap() and readdir(2), MTK, Dec 04. |
1c1e15ed | 247 | .TP |
fea681da MK |
248 | .B O_NOCTTY |
249 | If | |
250 | .I pathname | |
251 | refers to a terminal device \(em see | |
252 | .BR tty (4) | |
253 | \(em it will not become the process's controlling terminal even if the | |
254 | process does not have one. | |
255 | .TP | |
1c1e15ed | 256 | .B O_NOFOLLOW |
c13182ef MK |
257 | If \fIpathname\fR is a symbolic link, then the open fails. |
258 | This is a FreeBSD extension, which was added to Linux in version 2.1.126. | |
1c1e15ed | 259 | Symbolic links in earlier components of the pathname will still be |
e366dbc4 MK |
260 | followed. |
261 | .\" The headers from glibc 2.0.100 and later include a | |
262 | .\" definition of this flag; \fIkernels before 2.1.126 will ignore it if | |
263 | .\" used\fR. | |
fea681da MK |
264 | .TP |
265 | .BR O_NONBLOCK " or " O_NDELAY | |
c13182ef MK |
266 | When possible, the file is opened in non-blocking mode. |
267 | Neither the | |
1c1e15ed | 268 | .BR open () |
fea681da MK |
269 | nor any subsequent operations on the file descriptor which is |
270 | returned will cause the calling process to wait. | |
271 | For the handling of FIFOs (named pipes), see also | |
af5b2ef2 | 272 | .BR fifo (7). |
db28bfac MK |
273 | For a discussion of the effect of |
274 | .BR O_NONBLOCK | |
275 | in conjunction with mandatory file locks and with file leases, see | |
276 | .BR fcntl (2). | |
fea681da MK |
277 | .TP |
278 | .B O_SYNC | |
c13182ef MK |
279 | The file is opened for synchronous I/O. |
280 | Any | |
0bfa087b | 281 | .BR write (2)s |
fea681da MK |
282 | on the resulting file descriptor will block the calling process until |
283 | the data has been physically written to the underlying hardware. | |
b07cd0a9 | 284 | .IR "But see NOTES below" . |
fea681da | 285 | .TP |
1c1e15ed MK |
286 | .B O_TRUNC |
287 | If the file already exists and is a regular file and the open mode allows | |
288 | writing (i.e., is O_RDWR or O_WRONLY) it will be truncated to length 0. | |
289 | If the file is a FIFO or terminal device file, the O_TRUNC | |
c13182ef MK |
290 | flag is ignored. |
291 | Otherwise the effect of O_TRUNC is unspecified. | |
fea681da MK |
292 | .PP |
293 | Some of these optional flags can be altered using | |
0bfa087b | 294 | .BR fcntl (2) |
fea681da MK |
295 | after the file has been opened. |
296 | ||
297 | The argument | |
298 | .I mode | |
c13182ef MK |
299 | specifies the permissions to use in case a new file is created. |
300 | It is | |
fea681da MK |
301 | modified by the process's |
302 | .BR umask | |
303 | in the usual way: the permissions of the created file are | |
304 | .BR "(mode & ~umask)" . | |
305 | Note that this mode only applies to future accesses of the | |
306 | newly created file; the | |
1c1e15ed | 307 | .BR open () |
fea681da MK |
308 | call that creates a read-only file may well return a read/write |
309 | file descriptor. | |
310 | .PP | |
311 | The following symbolic constants are provided for | |
312 | .IR mode : | |
313 | .TP | |
314 | .B S_IRWXU | |
315 | 00700 user (file owner) has read, write and execute permission | |
316 | .TP | |
cc513f7f | 317 | .B S_IRUSR |
fea681da MK |
318 | 00400 user has read permission |
319 | .TP | |
cc513f7f | 320 | .B S_IWUSR |
fea681da MK |
321 | 00200 user has write permission |
322 | .TP | |
cc513f7f | 323 | .B S_IXUSR |
fea681da MK |
324 | 00100 user has execute permission |
325 | .TP | |
326 | .B S_IRWXG | |
327 | 00070 group has read, write and execute permission | |
328 | .TP | |
329 | .B S_IRGRP | |
330 | 00040 group has read permission | |
331 | .TP | |
332 | .B S_IWGRP | |
333 | 00020 group has write permission | |
334 | .TP | |
335 | .B S_IXGRP | |
336 | 00010 group has execute permission | |
337 | .TP | |
338 | .B S_IRWXO | |
339 | 00007 others have read, write and execute permission | |
340 | .TP | |
341 | .B S_IROTH | |
342 | 00004 others have read permission | |
343 | .TP | |
344 | .B S_IWOTH | |
d301ee6c | 345 | 00002 others have write permission |
fea681da MK |
346 | .TP |
347 | .B S_IXOTH | |
348 | 00001 others have execute permission | |
349 | .PP | |
350 | .I mode | |
351 | must be specified when | |
352 | .B O_CREAT | |
353 | is in the | |
354 | .IR flags , | |
355 | and is ignored otherwise. | |
356 | ||
1c1e15ed | 357 | .BR creat () |
fea681da | 358 | is equivalent to |
1c1e15ed | 359 | .BR open () |
fea681da MK |
360 | with |
361 | .I flags | |
362 | equal to | |
363 | .BR O_CREAT|O_WRONLY|O_TRUNC . | |
364 | .SH "RETURN VALUE" | |
c13182ef MK |
365 | .BR open () |
366 | and | |
e1d6264d | 367 | .BR creat () |
1c1e15ed MK |
368 | return the new file descriptor, or \-1 if an error occurred |
369 | (in which case, | |
fea681da MK |
370 | .I errno |
371 | is set appropriately). | |
28c54d45 | 372 | .SH NOTES |
b07cd0a9 MK |
373 | There are many infelicities in the protocol underlying NFS, affecting |
374 | amongst others | |
375 | .BR O_SYNC " and " O_NDELAY . | |
376 | ||
377 | POSIX provides for three different variants of synchronised I/O, | |
378 | corresponding to the flags \fBO_SYNC\fR, \fBO_DSYNC\fR and | |
379 | \fBO_RSYNC\fR. | |
380 | Currently (2.1.130) these are all synonymous under Linux. | |
381 | ||
fea681da | 382 | Note that |
1c1e15ed | 383 | .BR open () |
fea681da | 384 | can open device special files, but |
1c1e15ed | 385 | .BR creat () |
e9496f74 | 386 | cannot create them; use |
fea681da MK |
387 | .BR mknod (2) |
388 | instead. | |
389 | .LP | |
60a90ecd MK |
390 | On NFS file systems with UID mapping enabled, |
391 | .BR open () | |
392 | may | |
393 | return a file descriptor but e.g. | |
394 | .BR read (2) | |
395 | requests are denied | |
1c1e15ed | 396 | with \fBEACCES\fP. |
60a90ecd MK |
397 | This is because the client performs |
398 | .BR open () | |
399 | by checking the | |
1c1e15ed MK |
400 | permissions, but UID mapping is performed by the server upon |
401 | read and write requests. | |
fea681da | 402 | |
310b7919 MK |
403 | If the file is newly created, its st_atime, st_ctime, st_mtime fields |
404 | (respectively, time of last access, time of last status change, and | |
405 | time of last modification; see | |
406 | .BR stat (2)) | |
407 | are set | |
408 | to the current time, and so are the st_ctime and st_mtime fields of the | |
fea681da MK |
409 | parent directory. |
410 | Otherwise, if the file is modified because of the O_TRUNC flag, | |
310b7919 | 411 | its st_ctime and st_mtime fields are set to the current time. |
fea681da MK |
412 | .SH ERRORS |
413 | .TP | |
414 | .B EACCES | |
415 | The requested access to the file is not allowed, or search permission | |
416 | is denied for one of the directories in the path prefix of | |
417 | .IR pathname , | |
418 | or the file did not exist yet and write access to the parent directory | |
419 | is not allowed. | |
420 | (See also | |
421 | .BR path_resolution (2).) | |
422 | .TP | |
423 | .B EEXIST | |
424 | .I pathname | |
425 | already exists and | |
426 | .BR O_CREAT " and " O_EXCL | |
427 | were used. | |
428 | .TP | |
429 | .B EFAULT | |
c13182ef | 430 | .IR pathname |
e1d6264d | 431 | points outside your accessible address space. |
fea681da | 432 | .TP |
9f5773f7 MK |
433 | .B EFBIG |
434 | .I pathname | |
435 | refers to a regular file, too large to be opened; see O_LARGEFILE above. | |
c13182ef | 436 | (POSIX.1-2001 specifies the error |
9f5773f7 MK |
437 | .B EOVERFLOW |
438 | for this case.) | |
439 | .\" FIXME Maybe this deviation from the standard will get repaired. | |
440 | .\" See http://bugzilla.kernel.org/show_bug.cgi?id=7253 | |
441 | .\" "Open of a large file on 32-bit fails with EFBIG, should be EOVERFLOW" | |
442 | .\" Reported 2006-10-03 | |
443 | .TP | |
fea681da MK |
444 | .B EISDIR |
445 | .I pathname | |
446 | refers to a directory and the access requested involved writing | |
447 | (that is, | |
448 | .B O_WRONLY | |
449 | or | |
450 | .B O_RDWR | |
451 | is set). | |
452 | .TP | |
453 | .B ELOOP | |
454 | Too many symbolic links were encountered in resolving | |
455 | .IR pathname , | |
456 | or \fBO_NOFOLLOW\fR was specified but | |
457 | .I pathname | |
458 | was a symbolic link. | |
459 | .TP | |
460 | .B EMFILE | |
461 | The process already has the maximum number of files open. | |
462 | .TP | |
463 | .B ENAMETOOLONG | |
e1d6264d MK |
464 | .IR pathname |
465 | was too long. | |
fea681da MK |
466 | .TP |
467 | .B ENFILE | |
468 | The system limit on the total number of open files has been reached. | |
469 | .TP | |
470 | .B ENODEV | |
471 | .I pathname | |
472 | refers to a device special file and no corresponding device exists. | |
e9496f74 | 473 | (This is a Linux kernel bug; in this situation ENXIO must be returned.) |
fea681da MK |
474 | .TP |
475 | .B ENOENT | |
476 | O_CREAT is not set and the named file does not exist. | |
477 | Or, a directory component in | |
478 | .I pathname | |
479 | does not exist or is a dangling symbolic link. | |
480 | .TP | |
481 | .B ENOMEM | |
482 | Insufficient kernel memory was available. | |
483 | .TP | |
484 | .B ENOSPC | |
485 | .I pathname | |
486 | was to be created but the device containing | |
487 | .I pathname | |
488 | has no room for the new file. | |
489 | .TP | |
490 | .B ENOTDIR | |
491 | A component used as a directory in | |
492 | .I pathname | |
493 | is not, in fact, a directory, or \fBO_DIRECTORY\fR was specified and | |
494 | .I pathname | |
495 | was not a directory. | |
496 | .TP | |
497 | .B ENXIO | |
498 | O_NONBLOCK | O_WRONLY is set, the named file is a FIFO and | |
499 | no process has the file open for reading. | |
500 | Or, the file is a device special file and no corresponding device exists. | |
501 | .TP | |
1c1e15ed MK |
502 | .B EPERM |
503 | The | |
504 | .B O_NOATIME | |
505 | flag was specified, but the effective user ID of the caller | |
506 | .\" Strictly speaking, it's the file system UID... (MTK) | |
507 | did not match the owner of the file and the caller was not privileged | |
508 | .RB ( CAP_FOWNER ). | |
509 | .TP | |
fea681da MK |
510 | .B EROFS |
511 | .I pathname | |
512 | refers to a file on a read-only filesystem and write access was | |
513 | requested. | |
514 | .TP | |
515 | .B ETXTBSY | |
516 | .I pathname | |
517 | refers to an executable image which is currently being executed and | |
518 | write access was requested. | |
d3952311 MK |
519 | .TP |
520 | .B EWOULDBLOCK | |
521 | The | |
522 | .B O_NONBLOCK | |
523 | flag was specified, and an incompatible lease was held on the file | |
524 | (see | |
525 | .BR fcntl (2)). | |
19c98696 | 526 | .SH NOTES |
fea681da MK |
527 | Under Linux, the O_NONBLOCK flag indicates that one wants to open |
528 | but does not necessarily have the intention to read or write. | |
529 | This is typically used to open devices in order to get a file descriptor | |
530 | for use with | |
531 | .BR ioctl (2). | |
532 | .SH "CONFORMING TO" | |
97c1eac8 | 533 | SVr4, 4.3BSD, POSIX.1-2001. |
fea681da | 534 | The |
1c1e15ed MK |
535 | .BR O_NOATIME , |
536 | .BR O_NOFOLLOW , | |
fea681da MK |
537 | and |
538 | .B O_DIRECTORY | |
75b48e9d | 539 | flags are Linux specific. |
fea681da MK |
540 | One may have to define the |
541 | .B _GNU_SOURCE | |
542 | macro to get their definitions. | |
543 | .LP | |
544 | The (undefined) effect of | |
545 | .B O_RDONLY | O_TRUNC | |
c13182ef | 546 | varies among implementations. |
bcdd964e | 547 | On many systems the file is actually truncated. |
fea681da MK |
548 | .\" Linux 2.0, 2.5: truncate |
549 | .\" Solaris 5.7, 5.8: truncate | |
550 | .\" Irix 6.5: truncate | |
551 | .\" Tru64 5.1B: truncate | |
552 | .\" HP-UX 11.22: truncate | |
553 | .\" FreeBSD 4.7: truncate | |
554 | .LP | |
555 | The | |
556 | .B O_DIRECT | |
557 | flag was introduced in SGI IRIX, where it has alignment restrictions | |
c13182ef MK |
558 | similar to those of Linux 2.4. |
559 | IRIX has also a fcntl(2) call to | |
560 | query appropriate alignments, and sizes. | |
561 | FreeBSD 4.x introduced | |
fea681da MK |
562 | a flag of same name, but without alignment restrictions. |
563 | Support was added under Linux in kernel version 2.4.10. | |
564 | Older Linux kernels simply ignore this flag. | |
1f6ceb40 MK |
565 | One may have to define the |
566 | .B _GNU_SOURCE | |
567 | macro to get its definition. | |
fea681da MK |
568 | .SH BUGS |
569 | "The thing that has always disturbed me about O_DIRECT is that the whole | |
570 | interface is just stupid, and was probably designed by a deranged monkey | |
e9496f74 | 571 | on some serious mind-controlling substances." \(em Linus |
b50582eb MK |
572 | |
573 | Currently, it is not possible to enable signal-driven | |
574 | I/O by specifying | |
575 | .B O_ASYNC | |
c13182ef | 576 | when calling |
b50582eb MK |
577 | .BR open (); |
578 | use | |
579 | .BR fcntl (2) | |
580 | to enable this flag. | |
92057f4d MK |
581 | .\" FIXME Check bugzilla report on open(O_ASYNC) |
582 | .\" See http://bugzilla.kernel.org/show_bug.cgi?id=5993 | |
fea681da MK |
583 | .SH "SEE ALSO" |
584 | .BR close (2), | |
e366dbc4 | 585 | .BR dup (2), |
fea681da MK |
586 | .BR fcntl (2), |
587 | .BR link (2), | |
1f6ceb40 | 588 | .BR lseek (2), |
fea681da MK |
589 | .BR mknod (2), |
590 | .BR mount (2), | |
e366dbc4 | 591 | .BR mmap (2), |
28c54d45 | 592 | .BR openat (2), |
fea681da MK |
593 | .BR path_resolution (2), |
594 | .BR read (2), | |
595 | .BR socket (2), | |
596 | .BR stat (2), | |
597 | .BR umask (2), | |
598 | .BR unlink (2), | |
599 | .BR write (2), | |
600 | .BR fopen (3), | |
50e5322c | 601 | .BR fifo (7), |
a8e7c990 | 602 | .BR feature_test_macros (7) |