]>
Commit | Line | Data |
---|---|---|
fea681da | 1 | .\" This manpage is Copyright (C) 1992 Drew Eckhardt; |
fd185f58 MK |
2 | .\" and Copyright (C) 1993 Michael Haardt, Ian Jackson. |
3 | .\" and Copyright (C) 2008 Greg Banks | |
7b8ba76c | 4 | .\" and Copyright (C) 2006, 2008, 2013, 2014 Michael Kerrisk <mtk.manpages@gmail.com> |
fea681da | 5 | .\" |
93015253 | 6 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
7 | .\" Permission is granted to make and distribute verbatim copies of this |
8 | .\" manual provided the copyright notice and this permission notice are | |
9 | .\" preserved on all copies. | |
10 | .\" | |
11 | .\" Permission is granted to copy and distribute modified versions of this | |
12 | .\" manual under the conditions for verbatim copying, provided that the | |
13 | .\" entire resulting derived work is distributed under the terms of a | |
14 | .\" permission notice identical to this one. | |
c13182ef | 15 | .\" |
fea681da MK |
16 | .\" Since the Linux kernel and libraries are constantly changing, this |
17 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
18 | .\" responsibility for errors or omissions, or for damages resulting from | |
19 | .\" the use of the information contained herein. The author(s) may not | |
20 | .\" have taken the same level of care in the production of this manual, | |
21 | .\" which is licensed free of charge, as they might when working | |
22 | .\" professionally. | |
c13182ef | 23 | .\" |
fea681da MK |
24 | .\" Formatted or processed versions of this manual, if unaccompanied by |
25 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 26 | .\" %%%LICENSE_END |
fea681da MK |
27 | .\" |
28 | .\" Modified 1993-07-21 by Rik Faith <faith@cs.unc.edu> | |
29 | .\" Modified 1994-08-21 by Michael Haardt | |
30 | .\" Modified 1996-04-13 by Andries Brouwer <aeb@cwi.nl> | |
31 | .\" Modified 1996-05-13 by Thomas Koenig | |
32 | .\" Modified 1996-12-20 by Michael Haardt | |
33 | .\" Modified 1999-02-19 by Andries Brouwer <aeb@cwi.nl> | |
34 | .\" Modified 1998-11-28 by Joseph S. Myers <jsm28@hermes.cam.ac.uk> | |
35 | .\" Modified 1999-06-03 by Michael Haardt | |
c11b1abf MK |
36 | .\" Modified 2002-05-07 by Michael Kerrisk <mtk.manpages@gmail.com> |
37 | .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com> | |
1c1e15ed MK |
38 | .\" 2004-12-08, mtk, reordered flags list alphabetically |
39 | .\" 2004-12-08, Martin Pool <mbp@sourcefrog.net> (& mtk), added O_NOATIME | |
fe75ec04 | 40 | .\" 2007-09-18, mtk, Added description of O_CLOEXEC + other minor edits |
447bb15e | 41 | .\" 2008-01-03, mtk, with input from Trond Myklebust |
f4b9d6a5 MK |
42 | .\" <trond.myklebust@fys.uio.no> and Timo Sirainen <tss@iki.fi> |
43 | .\" Rewrite description of O_EXCL. | |
ddc4d339 MK |
44 | .\" 2008-01-11, Greg Banks <gnb@melbourne.sgi.com>: add more detail |
45 | .\" on O_DIRECT. | |
d77eb764 | 46 | .\" 2008-02-26, Michael Haardt: Reorganized text for O_CREAT and mode |
fea681da | 47 | .\" |
61b7c1e1 | 48 | .\" FIXME . Apr 08: The next POSIX revision has O_EXEC, O_SEARCH, and |
9f91e36c MK |
49 | .\" O_TTYINIT. Eventually these may need to be documented. --mtk |
50 | .\" | |
35deeb87 | 51 | .TH OPEN 2 2016-12-12 "Linux" "Linux Programmer's Manual" |
fea681da | 52 | .SH NAME |
7b8ba76c | 53 | open, openat, creat \- open and possibly create a file |
fea681da MK |
54 | .SH SYNOPSIS |
55 | .nf | |
56 | .B #include <sys/types.h> | |
57 | .B #include <sys/stat.h> | |
58 | .B #include <fcntl.h> | |
59 | .sp | |
60 | .BI "int open(const char *" pathname ", int " flags ); | |
61 | .BI "int open(const char *" pathname ", int " flags ", mode_t " mode ); | |
5895e7eb | 62 | |
fea681da | 63 | .BI "int creat(const char *" pathname ", mode_t " mode ); |
7b8ba76c MK |
64 | .sp |
65 | .BI "int openat(int " dirfd ", const char *" pathname ", int " flags ); | |
66 | .BI "int openat(int " dirfd ", const char *" pathname ", int " flags \ | |
67 | ", mode_t " mode ); | |
fea681da | 68 | .fi |
7b8ba76c MK |
69 | .sp |
70 | .in -4n | |
71 | Feature Test Macro Requirements for glibc (see | |
72 | .BR feature_test_macros (7)): | |
73 | .in | |
74 | .sp | |
75 | .BR openat (): | |
76 | .PD 0 | |
77 | .ad l | |
78 | .RS 4 | |
79 | .TP 4 | |
80 | Since glibc 2.10: | |
b0da7b8b | 81 | _POSIX_C_SOURCE\ >=\ 200809L |
7b8ba76c MK |
82 | .TP |
83 | Before glibc 2.10: | |
84 | _ATFILE_SOURCE | |
85 | .RE | |
86 | .ad | |
87 | .PD | |
fea681da | 88 | .SH DESCRIPTION |
e366dbc4 | 89 | Given a |
0daa9e92 | 90 | .I pathname |
e366dbc4 | 91 | for a file, |
1f6ceb40 | 92 | .BR open () |
2fda57bd | 93 | returns a file descriptor, a small, nonnegative integer |
e366dbc4 MK |
94 | for use in subsequent system calls |
95 | .RB ( read "(2), " write "(2), " lseek "(2), " fcntl "(2), etc.)." | |
96 | The file descriptor returned by a successful call will be | |
2c4bff36 | 97 | the lowest-numbered file descriptor not currently open for the process. |
e366dbc4 | 98 | .PP |
fe75ec04 | 99 | By default, the new file descriptor is set to remain open across an |
e366dbc4 | 100 | .BR execve (2) |
1f6ceb40 MK |
101 | (i.e., the |
102 | .B FD_CLOEXEC | |
103 | file descriptor flag described in | |
31d79098 SP |
104 | .BR fcntl (2) |
105 | is initially disabled); the | |
fe75ec04 | 106 | .B O_CLOEXEC |
d6a74b95 | 107 | flag, described below, can be used to change this default. |
1f6ceb40 | 108 | The file offset is set to the beginning of the file (see |
c13182ef | 109 | .BR lseek (2)). |
e366dbc4 MK |
110 | .PP |
111 | A call to | |
112 | .BR open () | |
113 | creates a new | |
114 | .IR "open file description" , | |
115 | an entry in the system-wide table of open files. | |
61b12e2b | 116 | The open file description records the file offset and the file status flags |
20ee63c1 | 117 | (see below). |
61b12e2b | 118 | A file descriptor is a reference to an open file description; |
2c4bff36 MK |
119 | this reference is unaffected if |
120 | .I pathname | |
121 | is subsequently removed or modified to refer to a different file. | |
d20d9d33 | 122 | For further details on open file descriptions, see NOTES. |
e366dbc4 | 123 | .PP |
c4bb193f | 124 | The argument |
fea681da | 125 | .I flags |
e366dbc4 MK |
126 | must include one of the following |
127 | .IR "access modes" : | |
c7992edc | 128 | .BR O_RDONLY ", " O_WRONLY ", or " O_RDWR . |
e366dbc4 MK |
129 | These request opening the file read-only, write-only, or read/write, |
130 | respectively. | |
bfe9ba67 MK |
131 | |
132 | In addition, zero or more file creation flags and file status flags | |
c13182ef | 133 | can be |
fea681da | 134 | .RI bitwise- or 'd |
e366dbc4 | 135 | in |
bfe9ba67 | 136 | .IR flags . |
c13182ef MK |
137 | The |
138 | .I file creation flags | |
139 | are | |
0e40804c | 140 | .BR O_CLOEXEC , |
b072a788 | 141 | .BR O_CREAT , |
0e40804c MK |
142 | .BR O_DIRECTORY , |
143 | .BR O_EXCL , | |
144 | .BR O_NOCTTY , | |
145 | .BR O_NOFOLLOW , | |
f2698a42 | 146 | .BR O_TMPFILE , |
0e40804c | 147 | and |
15fb5d03 | 148 | .BR O_TRUNC . |
c13182ef MK |
149 | The |
150 | .I file status flags | |
bfe9ba67 | 151 | are all of the remaining flags listed below. |
0e40804c | 152 | .\" SUSv4 divides the flags into: |
93ee8f96 MK |
153 | .\" * Access mode |
154 | .\" * File creation | |
155 | .\" * File status | |
156 | .\" * Other (O_CLOEXEC, O_DIRECTORY, O_NOFOLLOW) | |
157 | .\" though it's not clear what the difference between "other" and | |
0e40804c MK |
158 | .\" "File creation" flags is. I raised an Aardvark to see if this |
159 | .\" can be clarified in SUSv4; 10 Oct 2008. | |
160 | .\" http://thread.gmane.org/gmane.comp.standards.posix.austin.general/64/focus=67 | |
161 | .\" TC1 (balloted in 2013), resolved this, so that those three constants | |
162 | .\" are also categorized" as file status flags. | |
163 | .\" | |
bfe9ba67 MK |
164 | The distinction between these two groups of flags is that |
165 | the file status flags can be retrieved and (in some cases) | |
566b427d MK |
166 | modified; see |
167 | .BR fcntl (2) | |
168 | for details. | |
169 | ||
bfe9ba67 | 170 | The full list of file creation flags and file status flags is as follows: |
fea681da | 171 | .TP |
1c1e15ed | 172 | .B O_APPEND |
c13182ef MK |
173 | The file is opened in append mode. |
174 | Before each | |
0bfa087b | 175 | .BR write (2), |
1e568304 | 176 | the file offset is positioned at the end of the file, |
1c1e15ed | 177 | as if with |
0bfa087b | 178 | .BR lseek (2). |
1c1e15ed | 179 | .B O_APPEND |
9ee4a2b6 | 180 | may lead to corrupted files on NFS filesystems if more than one process |
c13182ef | 181 | appends data to a file at once. |
a4391429 MK |
182 | .\" For more background, see |
183 | .\" http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=453946 | |
184 | .\" http://nfs.sourceforge.net/ | |
c13182ef | 185 | This is because NFS does not support |
1c1e15ed MK |
186 | appending to a file, so the client kernel has to simulate it, which |
187 | can't be done without a race condition. | |
188 | .TP | |
189 | .B O_ASYNC | |
b50582eb | 190 | Enable signal-driven I/O: |
8bd58774 MK |
191 | generate a signal |
192 | .RB ( SIGIO | |
193 | by default, but this can be changed via | |
1c1e15ed MK |
194 | .BR fcntl (2)) |
195 | when input or output becomes possible on this file descriptor. | |
33a0ccb2 | 196 | This feature is available only for terminals, pseudoterminals, |
1f6ceb40 MK |
197 | sockets, and (since Linux 2.6) pipes and FIFOs. |
198 | See | |
1c1e15ed MK |
199 | .BR fcntl (2) |
200 | for further details. | |
9bde4908 | 201 | See also BUGS, below. |
fe75ec04 | 202 | .TP |
31c1f2b0 | 203 | .BR O_CLOEXEC " (since Linux 2.6.23)" |
7fdec065 | 204 | .\" NOTE! several other man pages refer to this text |
fe75ec04 | 205 | Enable the close-on-exec flag for the new file descriptor. |
00d82ce8 MK |
206 | .\" FIXME . for later review when Issue 8 is one day released... |
207 | .\" POSIX proposes to fix many APIs that provide hidden FDs | |
208 | .\" http://austingroupbugs.net/tag_view_page.php?tag_id=8 | |
209 | .\" http://austingroupbugs.net/view.php?id=368 | |
24ec631f | 210 | Specifying this flag permits a program to avoid additional |
fe75ec04 MK |
211 | .BR fcntl (2) |
212 | .B F_SETFD | |
24ec631f | 213 | operations to set the |
0daa9e92 | 214 | .B FD_CLOEXEC |
fe75ec04 | 215 | flag. |
7756d157 MK |
216 | |
217 | Note that the use of this flag is essential in some multithreaded programs, | |
218 | because using a separate | |
fe75ec04 MK |
219 | .BR fcntl (2) |
220 | .B F_SETFD | |
221 | operation to set the | |
0daa9e92 | 222 | .B FD_CLOEXEC |
fe75ec04 | 223 | flag does not suffice to avoid race conditions |
7756d157 MK |
224 | where one thread opens a file descriptor and |
225 | attempts to set its close-on-exec flag using | |
226 | .BR fcntl (2) | |
227 | at the same time as another thread does a | |
fe75ec04 MK |
228 | .BR fork (2) |
229 | plus | |
230 | .BR execve (2). | |
7756d157 | 231 | Depending on the order of execution, |
30821db8 | 232 | the race may lead to the file descriptor returned by |
7756d157 MK |
233 | .BR open () |
234 | being unintentionally leaked to the program executed by the child process | |
235 | created by | |
236 | .BR fork (2). | |
237 | (This kind of race is in principle possible for any system call | |
238 | that creates a file descriptor whose close-on-exec flag should be set, | |
239 | and various other Linux system calls provide an equivalent of the | |
240 | .BR O_CLOEXEC | |
241 | flag to deal with this problem.) | |
fe75ec04 | 242 | .\" This flag fixes only one form of the race condition; |
d9cb0d7d | 243 | .\" The race can also occur with, for example, file descriptors |
fe75ec04 | 244 | .\" returned by accept(), pipe(), etc. |
1c1e15ed | 245 | .TP |
fea681da | 246 | .B O_CREAT |
f1ad56a6 | 247 | If the file does not exist, it will be created. |
7351ae87 | 248 | |
40169a93 | 249 | The owner (user ID) of the new file is set to the effective user ID |
c13182ef | 250 | of the process. |
ddf5e4ab MK |
251 | |
252 | The group ownership (group ID) of the new file is set either to | |
253 | the effective group ID of the process (System V semantics) | |
254 | or to the group ID of the parent directory (BSD semantics). | |
255 | On Linux, the behavior depends on whether the | |
256 | set-group-ID mode bit is set on the parent directory: | |
257 | if that bit is set, then BSD semantics apply; | |
258 | otherwise, System V semantics apply. | |
259 | For some filesystems, the behavior also depends on the | |
fea681da MK |
260 | .I bsdgroups |
261 | and | |
262 | .I sysvgroups | |
ddf5e4ab | 263 | mount options described in |
fea681da | 264 | .BR mount (8)). |
8b39ad66 MK |
265 | .\" As at 2.6.25, bsdgroups is supported by ext2, ext3, ext4, and |
266 | .\" XFS (since 2.6.14). | |
4e698277 MK |
267 | .RS |
268 | .PP | |
1bab84a8 | 269 | The |
4e698277 | 270 | .I mode |
1bab84a8 | 271 | argument specifies the file mode bits be applied when a new file is created. |
4e698277 MK |
272 | This argument must be supplied when |
273 | .B O_CREAT | |
f2698a42 AL |
274 | or |
275 | .B O_TMPFILE | |
4e698277 MK |
276 | is specified in |
277 | .IR flags ; | |
f2698a42 | 278 | if neither |
4e698277 | 279 | .B O_CREAT |
f2698a42 AL |
280 | nor |
281 | .B O_TMPFILE | |
282 | is specified, then | |
4e698277 MK |
283 | .I mode |
284 | is ignored. | |
58222012 | 285 | The effective mode is modified by the process's |
4e698277 | 286 | .I umask |
58222012 MK |
287 | in the usual way: in the absence of a default ACL, the mode of the |
288 | created file is | |
84a275c4 | 289 | .IR "(mode\ &\ ~umask)" . |
33a0ccb2 | 290 | Note that this mode applies only to future accesses of the |
4e698277 MK |
291 | newly created file; the |
292 | .BR open () | |
293 | call that creates a read-only file may well return a read/write | |
294 | file descriptor. | |
295 | .PP | |
296 | The following symbolic constants are provided for | |
297 | .IR mode : | |
298 | .TP 9 | |
299 | .B S_IRWXU | |
97d5b762 | 300 | 00700 user (file owner) has read, write, and execute permission |
4e698277 MK |
301 | .TP |
302 | .B S_IRUSR | |
303 | 00400 user has read permission | |
304 | .TP | |
305 | .B S_IWUSR | |
306 | 00200 user has write permission | |
307 | .TP | |
308 | .B S_IXUSR | |
309 | 00100 user has execute permission | |
310 | .TP | |
311 | .B S_IRWXG | |
97d5b762 | 312 | 00070 group has read, write, and execute permission |
4e698277 MK |
313 | .TP |
314 | .B S_IRGRP | |
315 | 00040 group has read permission | |
316 | .TP | |
317 | .B S_IWGRP | |
318 | 00020 group has write permission | |
319 | .TP | |
320 | .B S_IXGRP | |
321 | 00010 group has execute permission | |
322 | .TP | |
323 | .B S_IRWXO | |
97d5b762 | 324 | 00007 others have read, write, and execute permission |
4e698277 MK |
325 | .TP |
326 | .B S_IROTH | |
327 | 00004 others have read permission | |
328 | .TP | |
329 | .B S_IWOTH | |
330 | 00002 others have write permission | |
331 | .TP | |
332 | .B S_IXOTH | |
333 | 00001 others have execute permission | |
334 | .RE | |
9e1d8950 MK |
335 | .IP |
336 | According to POSIX, the effect when other bits are set in | |
337 | .I mode | |
338 | is unspecified. | |
339 | On Linux, the following bits are also honored in | |
340 | .IR mode : | |
341 | .RS | |
342 | .TP 9 | |
343 | .B S_ISUID | |
344 | 0004000 set-user-ID bit | |
345 | .TP | |
346 | .B S_ISGID | |
347 | 0002000 set-group-ID bit (see | |
348 | .BR stat (2)) | |
349 | .TP | |
350 | .B S_ISVTX | |
351 | 0001000 sticky bit (see | |
352 | .BR stat (2)) | |
353 | .RE | |
fea681da | 354 | .TP |
31c1f2b0 | 355 | .BR O_DIRECT " (since Linux 2.4.10)" |
1c1e15ed MK |
356 | Try to minimize cache effects of the I/O to and from this file. |
357 | In general this will degrade performance, but it is useful in | |
358 | special situations, such as when applications do their own caching. | |
bce0482f | 359 | File I/O is done directly to/from user-space buffers. |
015221ef CH |
360 | The |
361 | .B O_DIRECT | |
0deb3ce9 | 362 | flag on its own makes an effort to transfer data synchronously, |
015221ef CH |
363 | but does not give the guarantees of the |
364 | .B O_SYNC | |
0deb3ce9 JM |
365 | flag that data and necessary metadata are transferred. |
366 | To guarantee synchronous I/O, | |
015221ef CH |
367 | .B O_SYNC |
368 | must be used in addition to | |
369 | .BR O_DIRECT . | |
be02e49f | 370 | See NOTES below for further discussion. |
9b54d4fa | 371 | .sp |
c13182ef | 372 | A semantically similar (but deprecated) interface for block devices |
9b54d4fa | 373 | is described in |
1c1e15ed MK |
374 | .BR raw (8). |
375 | .TP | |
376 | .B O_DIRECTORY | |
a8d55537 | 377 | If \fIpathname\fP is not a directory, cause the open to fail. |
9f8d688a MK |
378 | .\" But see the following and its replies: |
379 | .\" http://marc.theaimsgroup.com/?t=112748702800001&r=1&w=2 | |
380 | .\" [PATCH] open: O_DIRECTORY and O_CREAT together should fail | |
381 | .\" O_DIRECTORY | O_CREAT causes O_DIRECTORY to be ignored. | |
65496644 | 382 | This flag was added in kernel version 2.1.126, to |
60a90ecd MK |
383 | avoid denial-of-service problems if |
384 | .BR opendir (3) | |
385 | is called on a | |
a3041a58 | 386 | FIFO or tape device. |
1c1e15ed | 387 | .TP |
6cf19e62 MK |
388 | .B O_DSYNC |
389 | Write operations on the file will complete according to the requirements of | |
390 | synchronized I/O | |
391 | .I data | |
392 | integrity completion. | |
393 | ||
394 | By the time | |
395 | .BR write (2) | |
396 | (and similar) | |
397 | return, the output data | |
398 | has been transferred to the underlying hardware, | |
399 | along with any file metadata that would be required to retrieve that data | |
400 | (i.e., as though each | |
401 | .BR write (2) | |
402 | was followed by a call to | |
403 | .BR fdatasync (2)). | |
404 | .IR "See NOTES below" . | |
405 | .TP | |
fea681da | 406 | .B O_EXCL |
f4b9d6a5 MK |
407 | Ensure that this call creates the file: |
408 | if this flag is specified in conjunction with | |
fea681da | 409 | .BR O_CREAT , |
f4b9d6a5 MK |
410 | and |
411 | .I pathname | |
412 | already exists, then | |
1c1e15ed | 413 | .BR open () |
c13182ef | 414 | will fail. |
f4b9d6a5 MK |
415 | |
416 | When these two flags are specified, symbolic links are not followed: | |
417 | .\" POSIX.1-2001 explicitly requires this behavior. | |
418 | if | |
419 | .I pathname | |
420 | is a symbolic link, then | |
421 | .BR open () | |
422 | fails regardless of where the symbolic link points to. | |
423 | ||
10b7a945 IHV |
424 | In general, the behavior of |
425 | .B O_EXCL | |
426 | is undefined if it is used without | |
427 | .BR O_CREAT . | |
428 | There is one exception: on Linux 2.6 and later, | |
429 | .B O_EXCL | |
430 | can be used without | |
431 | .B O_CREAT | |
432 | if | |
433 | .I pathname | |
434 | refers to a block device. | |
6303d401 DB |
435 | If the block device is in use by the system (e.g., mounted), |
436 | .BR open () | |
10b7a945 IHV |
437 | fails with the error |
438 | .BR EBUSY . | |
439 | ||
efe08656 | 440 | On NFS, |
f4b9d6a5 | 441 | .B O_EXCL |
33a0ccb2 | 442 | is supported only when using NFSv3 or later on kernel 2.6 or later. |
efe08656 | 443 | In NFS environments where |
fea681da | 444 | .B O_EXCL |
f4b9d6a5 MK |
445 | support is not provided, programs that rely on it |
446 | for performing locking tasks will contain a race condition. | |
447 | Portable programs that want to perform atomic file locking using a lockfile, | |
448 | and need to avoid reliance on NFS support for | |
449 | .BR O_EXCL , | |
450 | can create a unique file on | |
9ee4a2b6 | 451 | the same filesystem (e.g., incorporating hostname and PID), and use |
fea681da | 452 | .BR link (2) |
c13182ef | 453 | to make a link to the lockfile. |
60a90ecd MK |
454 | If |
455 | .BR link (2) | |
f4b9d6a5 | 456 | returns 0, the lock is successful. |
c13182ef | 457 | Otherwise, use |
fea681da MK |
458 | .BR stat (2) |
459 | on the unique file to check if its link count has increased to 2, | |
460 | in which case the lock is also successful. | |
461 | .TP | |
1c1e15ed MK |
462 | .B O_LARGEFILE |
463 | (LFS) | |
464 | Allow files whose sizes cannot be represented in an | |
8478ee02 | 465 | .I off_t |
1c1e15ed | 466 | (but can be represented in an |
8478ee02 | 467 | .IR off64_t ) |
1c1e15ed | 468 | to be opened. |
c13182ef | 469 | The |
bcdd964e | 470 | .B _LARGEFILE64_SOURCE |
e417acb0 MK |
471 | macro must be defined |
472 | (before including | |
473 | .I any | |
474 | header files) | |
475 | in order to obtain this definition. | |
c13182ef | 476 | Setting the |
bcdd964e | 477 | .B _FILE_OFFSET_BITS |
9f3d8b28 MK |
478 | feature test macro to 64 (rather than using |
479 | .BR O_LARGEFILE ) | |
12e263f1 | 480 | is the preferred |
9f3d8b28 | 481 | method of accessing large files on 32-bit systems (see |
2dcbf4f7 | 482 | .BR feature_test_macros (7)). |
1c1e15ed | 483 | .TP |
31c1f2b0 | 484 | .BR O_NOATIME " (since Linux 2.6.8)" |
1bb72c96 MK |
485 | Do not update the file last access time |
486 | .RI ( st_atime | |
487 | in the inode) | |
310b7919 | 488 | when the file is |
1c1e15ed | 489 | .BR read (2). |
47c906e5 MK |
490 | |
491 | This flag can be employed only if one of the following conditions is true: | |
492 | .RS | |
493 | .IP * 3 | |
494 | The effective UID of the process | |
495 | .\" Strictly speaking: the filesystem UID | |
496 | matches the owner UID of the file. | |
497 | .IP * | |
498 | The calling process has the | |
499 | .BR CAP_FOWNER | |
500 | capability in its user namespace and | |
501 | the owner UID of the file has a mapping in the namespace. | |
502 | .RE | |
503 | .IP | |
1c1e15ed MK |
504 | This flag is intended for use by indexing or backup programs, |
505 | where its use can significantly reduce the amount of disk activity. | |
9ee4a2b6 | 506 | This flag may not be effective on all filesystems. |
1c1e15ed | 507 | One example is NFS, where the server maintains the access time. |
0e1ad98c | 508 | .\" The O_NOATIME flag also affects the treatment of st_atime |
92057f4d | 509 | .\" by mmap() and readdir(2), MTK, Dec 04. |
1c1e15ed | 510 | .TP |
fea681da MK |
511 | .B O_NOCTTY |
512 | If | |
513 | .I pathname | |
5503c85e | 514 | refers to a terminal device\(emsee |
1bb72c96 MK |
515 | .BR tty (4)\(emit |
516 | will not become the process's controlling terminal even if the | |
fea681da MK |
517 | process does not have one. |
518 | .TP | |
1c1e15ed | 519 | .B O_NOFOLLOW |
6ccb7137 MK |
520 | If \fIpathname\fP is a symbolic link, then the open fails, with the error |
521 | .BR ELOOP . | |
522 | (Note that this is indistinguishable from the case where | |
523 | an open fails because there are too many symbolic links found | |
524 | while resolving components in the prefix part of the pathname.) | |
8db11e23 MK |
525 | This flag is a FreeBSD extension, which was added to Linux in version 2.1.126, |
526 | and has subsequently been standardized in POSIX.1-2008. | |
1c1e15ed | 527 | Symbolic links in earlier components of the pathname will still be |
e366dbc4 | 528 | followed. |
1135dbe1 | 529 | See also |
843068bd | 530 | .BR O_PATH |
1135dbe1 | 531 | below. |
e366dbc4 MK |
532 | .\" The headers from glibc 2.0.100 and later include a |
533 | .\" definition of this flag; \fIkernels before 2.1.126 will ignore it if | |
a8d55537 | 534 | .\" used\fP. |
fea681da MK |
535 | .TP |
536 | .BR O_NONBLOCK " or " O_NDELAY | |
ff40dbb3 | 537 | When possible, the file is opened in nonblocking mode. |
c13182ef | 538 | Neither the |
1c1e15ed | 539 | .BR open () |
fea681da MK |
540 | nor any subsequent operations on the file descriptor which is |
541 | returned will cause the calling process to wait. | |
403b78f8 | 542 | |
9f629381 MK |
543 | Note that this flag has no effect for regular files and block devices; |
544 | that is, I/O operations will (briefly) block when device activity | |
545 | is required, regardless of whether | |
546 | .B O_NONBLOCK | |
547 | is set. | |
548 | Since | |
549 | .B O_NONBLOCK | |
550 | semantics might eventually be implemented, | |
551 | applications should not depend upon blocking behavior | |
552 | when specifying this flag for regular files and block devices. | |
553 | ||
fea681da | 554 | For the handling of FIFOs (named pipes), see also |
af5b2ef2 | 555 | .BR fifo (7). |
db28bfac | 556 | For a discussion of the effect of |
0daa9e92 | 557 | .B O_NONBLOCK |
db28bfac MK |
558 | in conjunction with mandatory file locks and with file leases, see |
559 | .BR fcntl (2). | |
fea681da | 560 | .TP |
1135dbe1 MK |
561 | .BR O_PATH " (since Linux 2.6.39)" |
562 | .\" commit 1abf0c718f15a56a0a435588d1b104c7a37dc9bd | |
563 | .\" commit 326be7b484843988afe57566b627fb7a70beac56 | |
564 | .\" commit 65cfc6722361570bfe255698d9cd4dccaf47570d | |
565 | .\" | |
566 | .\" http://thread.gmane.org/gmane.linux.man/2790/focus=3496 | |
567 | .\" Subject: Re: [PATCH] open(2): document O_PATH | |
568 | .\" Newsgroups: gmane.linux.man, gmane.linux.kernel | |
569 | .\" | |
1135dbe1 | 570 | Obtain a file descriptor that can be used for two purposes: |
9ee4a2b6 | 571 | to indicate a location in the filesystem tree and |
1135dbe1 MK |
572 | to perform operations that act purely at the file descriptor level. |
573 | The file itself is not opened, and other file operations (e.g., | |
574 | .BR read (2), | |
575 | .BR write (2), | |
576 | .BR fchmod (2), | |
577 | .BR fchown (2), | |
2510e4e5 RH |
578 | .BR fgetxattr (2), |
579 | .BR mmap (2)) | |
1135dbe1 MK |
580 | fail with the error |
581 | .BR EBADF . | |
582 | ||
583 | The following operations | |
584 | .I can | |
585 | be performed on the resulting file descriptor: | |
586 | .RS | |
587 | .IP * 3 | |
588 | .BR close (2); | |
589 | .BR fchdir (2) | |
590 | (since Linux 3.5); | |
591 | .\" commit 332a2e1244bd08b9e3ecd378028513396a004a24 | |
592 | .BR fstat (2) | |
593 | (since Linux 3.6). | |
594 | .\" fstat(): commit 55815f70147dcfa3ead5738fd56d3574e2e3c1c2 | |
595 | .IP * | |
596 | Duplicating the file descriptor | |
597 | .RB ( dup (2), | |
598 | .BR fcntl (2) | |
599 | .BR F_DUPFD , | |
600 | etc.). | |
601 | .IP * | |
602 | Getting and setting file descriptor flags | |
603 | .RB ( fcntl (2) | |
604 | .BR F_GETFD | |
605 | and | |
606 | .BR F_SETFD ). | |
09f677a3 MK |
607 | .IP * |
608 | Retrieving open file status flags using the | |
609 | .BR fcntl (2) | |
13a082cb | 610 | .BR F_GETFL |
09f677a3 MK |
611 | operation: the returned flags will include the bit |
612 | .BR O_PATH . | |
1135dbe1 MK |
613 | .IP * |
614 | Passing the file descriptor as the | |
615 | .IR dirfd | |
616 | argument of | |
490f876a | 617 | .BR openat () |
1135dbe1 | 618 | and the other "*at()" system calls. |
7dee406b AL |
619 | This includes |
620 | .BR linkat (2) | |
621 | with | |
0da5e58a | 622 | .BR AT_EMPTY_PATH |
7dee406b AL |
623 | (or via procfs using |
624 | .BR AT_SYMLINK_FOLLOW ) | |
625 | even if the file is not a directory. | |
1135dbe1 MK |
626 | .IP * |
627 | Passing the file descriptor to another process via a UNIX domain socket | |
628 | (see | |
629 | .BR SCM_RIGHTS | |
630 | in | |
631 | .BR unix (7)). | |
632 | .RE | |
633 | .IP | |
634 | When | |
635 | .B O_PATH | |
636 | is specified in | |
637 | .IR flags , | |
638 | flag bits other than | |
6807fc6f MK |
639 | .BR O_CLOEXEC , |
640 | .BR O_DIRECTORY , | |
1135dbe1 MK |
641 | and |
642 | .BR O_NOFOLLOW | |
643 | are ignored. | |
644 | ||
d30344ab MK |
645 | If |
646 | .I pathname | |
647 | is a symbolic link and the | |
1135dbe1 MK |
648 | .BR O_NOFOLLOW |
649 | flag is also specified, | |
650 | then the call returns a file descriptor referring to the symbolic link. | |
651 | This file descriptor can be used as the | |
652 | .I dirfd | |
653 | argument in calls to | |
654 | .BR fchownat (2), | |
655 | .BR fstatat (2), | |
656 | .BR linkat (2), | |
657 | and | |
658 | .BR readlinkat (2) | |
659 | with an empty pathname to have the calls operate on the symbolic link. | |
660 | .TP | |
fea681da | 661 | .B O_SYNC |
6cf19e62 MK |
662 | Write operations on the file will complete according to the requirements of |
663 | synchronized I/O | |
664 | .I file | |
665 | integrity completion | |
f36a1468 | 666 | (by contrast with the |
6cf19e62 MK |
667 | synchronized I/O |
668 | .I data | |
669 | integrity completion | |
670 | provided by | |
671 | .BR O_DSYNC .) | |
672 | ||
673 | By the time | |
674 | .BR write (2) | |
675 | (and similar) | |
676 | return, the output data and associated file metadata | |
677 | have been transferred to the underlying hardware | |
678 | (i.e., as though each | |
679 | .BR write (2) | |
680 | was followed by a call to | |
681 | .BR fsync (2)). | |
682 | .IR "See NOTES below" . | |
fea681da | 683 | .TP |
40398c1a MK |
684 | .BR O_TMPFILE " (since Linux 3.11)" |
685 | .\" commit 60545d0d4610b02e55f65d141c95b18ccf855b6e | |
686 | .\" commit f4e0c30c191f87851c4a53454abb55ee276f4a7e | |
687 | .\" commit bb458c644a59dbba3a1fe59b27106c5e68e1c4bd | |
688 | Create an unnamed temporary file. | |
689 | The | |
690 | .I pathname | |
691 | argument specifies a directory; | |
692 | an unnamed inode will be created in that directory's filesystem. | |
693 | Anything written to the resulting file will be lost when | |
694 | the last file descriptor is closed, unless the file is given a name. | |
695 | ||
696 | .B O_TMPFILE | |
697 | must be specified with one of | |
698 | .B O_RDWR | |
699 | or | |
700 | .B O_WRONLY | |
701 | and, optionally, | |
702 | .BR O_EXCL . | |
703 | If | |
704 | .B O_EXCL | |
705 | is not specified, then | |
706 | .BR linkat (2) | |
707 | can be used to link the temporary file into the filesystem, making it | |
708 | permanent, using code like the following: | |
709 | ||
710 | .in +4n | |
711 | .nf | |
712 | char path[PATH_MAX]; | |
713 | fd = open("/path/to/dir", O_TMPFILE | O_RDWR, | |
0fb83d00 MK |
714 | S_IRUSR | S_IWUSR); |
715 | ||
40398c1a | 716 | /* File I/O on 'fd'... */ |
0fb83d00 | 717 | |
40398c1a | 718 | snprintf(path, PATH_MAX, "/proc/self/fd/%d", fd); |
e1252130 | 719 | linkat(AT_FDCWD, path, AT_FDCWD, "/path/for/file", |
0fb83d00 | 720 | AT_SYMLINK_FOLLOW); |
40398c1a MK |
721 | .fi |
722 | .in | |
723 | ||
724 | In this case, | |
725 | the | |
726 | .BR open () | |
727 | .I mode | |
728 | argument determines the file permission mode, as with | |
729 | .BR O_CREAT . | |
730 | ||
0115aaed MK |
731 | Specifying |
732 | .B O_EXCL | |
733 | in conjunction with | |
734 | .B O_TMPFILE | |
735 | prevents a temporary file from being linked into the filesystem | |
736 | in the above manner. | |
737 | (Note that the meaning of | |
738 | .B O_EXCL | |
739 | in this case is different from the meaning of | |
740 | .B O_EXCL | |
741 | otherwise.) | |
742 | ||
40398c1a MK |
743 | There are two main use cases for |
744 | .\" Inspired by http://lwn.net/Articles/559147/ | |
745 | .BR O_TMPFILE : | |
746 | .RS | |
747 | .IP * 3 | |
748 | Improved | |
749 | .BR tmpfile (3) | |
750 | functionality: race-free creation of temporary files that | |
751 | (1) are automatically deleted when closed; | |
752 | (2) can never be reached via any pathname; | |
753 | (3) are not subject to symlink attacks; and | |
754 | (4) do not require the caller to devise unique names. | |
755 | .IP * | |
756 | Creating a file that is initially invisible, which is then populated | |
8b04592d | 757 | with data and adjusted to have appropriate filesystem attributes |
c89a9937 EB |
758 | .RB ( fchown (2), |
759 | .BR fchmod (2), | |
40398c1a MK |
760 | .BR fsetxattr (2), |
761 | etc.) | |
762 | before being atomically linked into the filesystem | |
763 | in a fully formed state (using | |
764 | .BR linkat (2) | |
765 | as described above). | |
766 | .RE | |
767 | .IP | |
768 | .B O_TMPFILE | |
769 | requires support by the underlying filesystem; | |
40398c1a | 770 | only a subset of Linux filesystems provide that support. |
cde2074a | 771 | In the initial implementation, support was provided in |
9af6b115 | 772 | the ext2, ext3, ext4, UDF, Minix, and shmem filesystems. |
bd79a35a | 773 | .\" To check for support, grep for "tmpfile" in kernel sources |
6065b906 MK |
774 | Support for other filesystems has subsequently been added as follows: |
775 | XFS (Linux 3.15); | |
cde2074a MK |
776 | .\" commit 99b6436bc29e4f10e4388c27a3e4810191cc4788 |
777 | .\" commit ab29743117f9f4c22ac44c13c1647fb24fb2bafe | |
1b9d5819 | 778 | Btrfs (Linux 3.16); |
e746db2e | 779 | .\" commit ef3b9af50bfa6a1f02cd7b3f5124b712b1ba3e3c |
6065b906 | 780 | F2FS (Linux 3.16); |
bd79a35a | 781 | .\" commit 50732df02eefb39ab414ef655979c2c9b64ad21c |
6065b906 | 782 | and ubifs (Linux 4.9) |
40398c1a | 783 | .TP |
1c1e15ed | 784 | .B O_TRUNC |
4d61d36a | 785 | If the file already exists and is a regular file and the access mode allows |
682edefb MK |
786 | writing (i.e., is |
787 | .B O_RDWR | |
788 | or | |
789 | .BR O_WRONLY ) | |
790 | it will be truncated to length 0. | |
791 | If the file is a FIFO or terminal device file, the | |
792 | .B O_TRUNC | |
c13182ef | 793 | flag is ignored. |
2b9b829d | 794 | Otherwise, the effect of |
682edefb MK |
795 | .B O_TRUNC |
796 | is unspecified. | |
7b8ba76c | 797 | .SS creat() |
1f7191bb | 798 | A call to |
1c1e15ed | 799 | .BR creat () |
1f7191bb | 800 | is equivalent to calling |
1c1e15ed | 801 | .BR open () |
fea681da MK |
802 | with |
803 | .I flags | |
804 | equal to | |
805 | .BR O_CREAT|O_WRONLY|O_TRUNC . | |
7b8ba76c MK |
806 | .SS openat() |
807 | The | |
808 | .BR openat () | |
809 | system call operates in exactly the same way as | |
cadd38ba | 810 | .BR open (), |
7b8ba76c MK |
811 | except for the differences described here. |
812 | ||
813 | If the pathname given in | |
814 | .I pathname | |
815 | is relative, then it is interpreted relative to the directory | |
3ad65ff0 | 816 | referred to by the file descriptor |
7b8ba76c MK |
817 | .I dirfd |
818 | (rather than relative to the current working directory of | |
819 | the calling process, as is done by | |
cadd38ba | 820 | .BR open () |
7b8ba76c MK |
821 | for a relative pathname). |
822 | ||
823 | If | |
824 | .I pathname | |
825 | is relative and | |
826 | .I dirfd | |
827 | is the special value | |
828 | .BR AT_FDCWD , | |
829 | then | |
830 | .I pathname | |
831 | is interpreted relative to the current working | |
832 | directory of the calling process (like | |
cadd38ba | 833 | .BR open ()). |
7b8ba76c MK |
834 | |
835 | If | |
836 | .I pathname | |
837 | is absolute, then | |
838 | .I dirfd | |
839 | is ignored. | |
47297adb | 840 | .SH RETURN VALUE |
7b8ba76c MK |
841 | .BR open (), |
842 | .BR openat (), | |
c13182ef | 843 | and |
e1d6264d | 844 | .BR creat () |
1c1e15ed MK |
845 | return the new file descriptor, or \-1 if an error occurred |
846 | (in which case, | |
fea681da MK |
847 | .I errno |
848 | is set appropriately). | |
fea681da | 849 | .SH ERRORS |
7b8ba76c MK |
850 | .BR open (), |
851 | .BR openat (), | |
852 | and | |
853 | .BR creat () | |
854 | can fail with the following errors: | |
fea681da MK |
855 | .TP |
856 | .B EACCES | |
857 | The requested access to the file is not allowed, or search permission | |
858 | is denied for one of the directories in the path prefix of | |
859 | .IR pathname , | |
860 | or the file did not exist yet and write access to the parent directory | |
861 | is not allowed. | |
862 | (See also | |
ad7cc990 | 863 | .BR path_resolution (7).) |
fea681da | 864 | .TP |
a1f01685 MH |
865 | .B EDQUOT |
866 | Where | |
867 | .B O_CREAT | |
868 | is specified, the file does not exist, and the user's quota of disk | |
9ee4a2b6 | 869 | blocks or inodes on the filesystem has been exhausted. |
a1f01685 | 870 | .TP |
fea681da MK |
871 | .B EEXIST |
872 | .I pathname | |
873 | already exists and | |
874 | .BR O_CREAT " and " O_EXCL | |
875 | were used. | |
876 | .TP | |
877 | .B EFAULT | |
0daa9e92 | 878 | .I pathname |
e1d6264d | 879 | points outside your accessible address space. |
fea681da | 880 | .TP |
9f5773f7 | 881 | .B EFBIG |
7c7fb552 MK |
882 | See |
883 | .BR EOVERFLOW . | |
9f5773f7 | 884 | .TP |
e51412ea MK |
885 | .B EINTR |
886 | While blocked waiting to complete an open of a slow device | |
887 | (e.g., a FIFO; see | |
888 | .BR fifo (7)), | |
889 | the call was interrupted by a signal handler; see | |
890 | .BR signal (7). | |
891 | .TP | |
ef490193 DG |
892 | .B EINVAL |
893 | The filesystem does not support the | |
894 | .BR O_DIRECT | |
e6f89ed2 MK |
895 | flag. |
896 | See | |
ef490193 DG |
897 | .BR NOTES |
898 | for more information. | |
899 | .TP | |
8e335391 MK |
900 | .B EINVAL |
901 | Invalid value in | |
902 | .\" In particular, __O_TMPFILE instead of O_TMPFILE | |
903 | .IR flags . | |
904 | .TP | |
905 | .B EINVAL | |
906 | .B O_TMPFILE | |
907 | was specified in | |
908 | .IR flags , | |
909 | but neither | |
910 | .B O_WRONLY | |
911 | nor | |
912 | .B O_RDWR | |
913 | was specified. | |
914 | .TP | |
fea681da MK |
915 | .B EISDIR |
916 | .I pathname | |
917 | refers to a directory and the access requested involved writing | |
918 | (that is, | |
919 | .B O_WRONLY | |
920 | or | |
921 | .B O_RDWR | |
922 | is set). | |
923 | .TP | |
8e335391 | 924 | .B EISDIR |
843068bd MK |
925 | .I pathname |
926 | refers to an existing directory, | |
8e335391 MK |
927 | .B O_TMPFILE |
928 | and one of | |
929 | .B O_WRONLY | |
930 | or | |
931 | .B O_RDWR | |
932 | were specified in | |
933 | .IR flags , | |
934 | but this kernel version does not provide the | |
935 | .B O_TMPFILE | |
936 | functionality. | |
937 | .TP | |
fea681da MK |
938 | .B ELOOP |
939 | Too many symbolic links were encountered in resolving | |
289f7907 MK |
940 | .IR pathname . |
941 | .TP | |
942 | .B ELOOP | |
fea681da | 943 | .I pathname |
289f7907 MK |
944 | was a symbolic link, and |
945 | .I flags | |
946 | specified | |
947 | .BR O_NOFOLLOW | |
948 | but not | |
949 | .BR O_PATH . | |
fea681da MK |
950 | .TP |
951 | .B EMFILE | |
26c32fab | 952 | The per-process limit on the number of open file descriptors has been reached |
12c21590 MK |
953 | (see the description of |
954 | .BR RLIMIT_NOFILE | |
955 | in | |
956 | .BR getrlimit (2)). | |
fea681da MK |
957 | .TP |
958 | .B ENAMETOOLONG | |
0daa9e92 | 959 | .I pathname |
e1d6264d | 960 | was too long. |
fea681da MK |
961 | .TP |
962 | .B ENFILE | |
e258766b | 963 | The system-wide limit on the total number of open files has been reached. |
fea681da MK |
964 | .TP |
965 | .B ENODEV | |
966 | .I pathname | |
967 | refers to a device special file and no corresponding device exists. | |
682edefb MK |
968 | (This is a Linux kernel bug; in this situation |
969 | .B ENXIO | |
970 | must be returned.) | |
fea681da MK |
971 | .TP |
972 | .B ENOENT | |
682edefb MK |
973 | .B O_CREAT |
974 | is not set and the named file does not exist. | |
fea681da MK |
975 | Or, a directory component in |
976 | .I pathname | |
977 | does not exist or is a dangling symbolic link. | |
978 | .TP | |
ba03011f MK |
979 | .B ENOENT |
980 | .I pathname | |
981 | refers to a nonexistent directory, | |
982 | .B O_TMPFILE | |
983 | and one of | |
984 | .B O_WRONLY | |
985 | or | |
986 | .B O_RDWR | |
987 | were specified in | |
988 | .IR flags , | |
989 | but this kernel version does not provide the | |
990 | .B O_TMPFILE | |
991 | functionality. | |
992 | .TP | |
fea681da | 993 | .B ENOMEM |
8ef529f9 MK |
994 | The named file is a FIFO, |
995 | but memory for the FIFO buffer can't be allocated because | |
996 | the per-user hard limit on memory allocation for pipes has been reached | |
997 | and the caller is not privileged; see | |
998 | .BR pipe (7). | |
999 | .TP | |
1000 | .B ENOMEM | |
fea681da MK |
1001 | Insufficient kernel memory was available. |
1002 | .TP | |
1003 | .B ENOSPC | |
1004 | .I pathname | |
1005 | was to be created but the device containing | |
1006 | .I pathname | |
1007 | has no room for the new file. | |
1008 | .TP | |
1009 | .B ENOTDIR | |
1010 | A component used as a directory in | |
1011 | .I pathname | |
a8d55537 | 1012 | is not, in fact, a directory, or \fBO_DIRECTORY\fP was specified and |
fea681da MK |
1013 | .I pathname |
1014 | was not a directory. | |
1015 | .TP | |
1016 | .B ENXIO | |
682edefb | 1017 | .BR O_NONBLOCK " | " O_WRONLY |
103ea4f6 MK |
1018 | is set, the named file is a FIFO, and |
1019 | no process has the FIFO open for reading. | |
7b032b23 MK |
1020 | .TP |
1021 | .B ENXIO | |
1022 | The file is a device special file and no corresponding device exists. | |
fea681da | 1023 | .TP |
bbe02b45 MK |
1024 | .BR EOPNOTSUPP |
1025 | The filesystem containing | |
1026 | .I pathname | |
1027 | does not support | |
1028 | .BR O_TMPFILE . | |
1029 | .TP | |
7c7fb552 MK |
1030 | .B EOVERFLOW |
1031 | .I pathname | |
1032 | refers to a regular file that is too large to be opened. | |
1033 | The usual scenario here is that an application compiled | |
1034 | on a 32-bit platform without | |
5e4dc269 | 1035 | .I -D_FILE_OFFSET_BITS=64 |
7c7fb552 | 1036 | tried to open a file whose size exceeds |
4e1a4d72 MK |
1037 | .I (1<<31)-1 |
1038 | bytes; | |
7c7fb552 MK |
1039 | see also |
1040 | .B O_LARGEFILE | |
1041 | above. | |
c84d3aa3 | 1042 | This is the error specified by POSIX.1; |
7c7fb552 MK |
1043 | in kernels before 2.6.24, Linux gave the error |
1044 | .B EFBIG | |
1045 | for this case. | |
1046 | .\" See http://bugzilla.kernel.org/show_bug.cgi?id=7253 | |
1047 | .\" "Open of a large file on 32-bit fails with EFBIG, should be EOVERFLOW" | |
1048 | .\" Reported 2006-10-03 | |
1049 | .TP | |
1c1e15ed MK |
1050 | .B EPERM |
1051 | The | |
1052 | .B O_NOATIME | |
1053 | flag was specified, but the effective user ID of the caller | |
9ee4a2b6 | 1054 | .\" Strictly speaking, it's the filesystem UID... (MTK) |
47c906e5 | 1055 | did not match the owner of the file and the caller was not privileged. |
1c1e15ed | 1056 | .TP |
fbab10e5 MK |
1057 | .B EPERM |
1058 | The operation was prevented by a file seal; see | |
1059 | .BR fcntl (2). | |
1060 | .TP | |
fea681da MK |
1061 | .B EROFS |
1062 | .I pathname | |
9ee4a2b6 | 1063 | refers to a file on a read-only filesystem and write access was |
fea681da MK |
1064 | requested. |
1065 | .TP | |
1066 | .B ETXTBSY | |
1067 | .I pathname | |
1068 | refers to an executable image which is currently being executed and | |
1069 | write access was requested. | |
d3952311 MK |
1070 | .TP |
1071 | .B EWOULDBLOCK | |
1072 | The | |
1073 | .B O_NONBLOCK | |
1074 | flag was specified, and an incompatible lease was held on the file | |
1075 | (see | |
1076 | .BR fcntl (2)). | |
7b8ba76c MK |
1077 | .PP |
1078 | The following additional errors can occur for | |
1079 | .BR openat (): | |
1080 | .TP | |
1081 | .B EBADF | |
1082 | .I dirfd | |
1083 | is not a valid file descriptor. | |
1084 | .TP | |
1085 | .B ENOTDIR | |
1086 | .I pathname | |
2feae602 | 1087 | is a relative pathname and |
7b8ba76c MK |
1088 | .I dirfd |
1089 | is a file descriptor referring to a file other than a directory. | |
1090 | .SH VERSIONS | |
1091 | .BR openat () | |
1092 | was added to Linux in kernel 2.6.16; | |
1093 | library support was added to glibc in version 2.4. | |
47297adb | 1094 | .SH CONFORMING TO |
7b8ba76c MK |
1095 | .BR open (), |
1096 | .BR creat () | |
72ac7268 MK |
1097 | SVr4, 4.3BSD, POSIX.1-2001, POSIX.1-2008. |
1098 | ||
7b8ba76c MK |
1099 | .BR openat (): |
1100 | POSIX.1-2008. | |
7b8ba76c | 1101 | |
fea681da | 1102 | The |
72ac7268 | 1103 | .BR O_DIRECT , |
1c1e15ed | 1104 | .BR O_NOATIME , |
72ac7268 | 1105 | .BR O_PATH , |
fea681da | 1106 | and |
72ac7268 MK |
1107 | .BR O_TMPFILE |
1108 | flags are Linux-specific. | |
1109 | One must define | |
61b7c1e1 MK |
1110 | .B _GNU_SOURCE |
1111 | to obtain their definitions. | |
9f91e36c MK |
1112 | |
1113 | The | |
72ac7268 MK |
1114 | .BR O_CLOEXEC , |
1115 | .BR O_DIRECTORY , | |
1116 | and | |
1117 | .BR O_NOFOLLOW | |
1118 | flags are not specified in POSIX.1-2001, | |
1119 | but are specified in POSIX.1-2008. | |
1120 | Since glibc 2.12, one can obtain their definitions by defining either | |
1121 | .B _POSIX_C_SOURCE | |
1122 | with a value greater than or equal to 200809L or | |
1123 | .BR _XOPEN_SOURCE | |
1124 | with a value greater than or equal to 700. | |
1125 | In glibc 2.11 and earlier, one obtains the definitions by defining | |
1126 | .BR _GNU_SOURCE . | |
9f91e36c | 1127 | |
72ac7268 MK |
1128 | As noted in |
1129 | .BR feature_test_macros (7), | |
84fc2a6e | 1130 | feature test macros such as |
72ac7268 MK |
1131 | .BR _POSIX_C_SOURCE , |
1132 | .BR _XOPEN_SOURCE , | |
1133 | and | |
fe75ec04 | 1134 | .B _GNU_SOURCE |
72ac7268 | 1135 | must be defined before including |
e417acb0 | 1136 | .I any |
72ac7268 | 1137 | header files. |
a1d5f77c | 1138 | .SH NOTES |
988db661 | 1139 | Under Linux, the |
a1d5f77c MK |
1140 | .B O_NONBLOCK |
1141 | flag indicates that one wants to open | |
1142 | but does not necessarily have the intention to read or write. | |
1143 | This is typically used to open devices in order to get a file descriptor | |
1144 | for use with | |
1145 | .BR ioctl (2). | |
fea681da MK |
1146 | .LP |
1147 | The (undefined) effect of | |
1148 | .B O_RDONLY | O_TRUNC | |
c13182ef | 1149 | varies among implementations. |
bcdd964e | 1150 | On many systems the file is actually truncated. |
fea681da MK |
1151 | .\" Linux 2.0, 2.5: truncate |
1152 | .\" Solaris 5.7, 5.8: truncate | |
1153 | .\" Irix 6.5: truncate | |
1154 | .\" Tru64 5.1B: truncate | |
1155 | .\" HP-UX 11.22: truncate | |
1156 | .\" FreeBSD 4.7: truncate | |
a1d5f77c | 1157 | |
5dc8986d MK |
1158 | Note that |
1159 | .BR open () | |
1160 | can open device special files, but | |
1161 | .BR creat () | |
1162 | cannot create them; use | |
1163 | .BR mknod (2) | |
1164 | instead. | |
1165 | ||
1166 | If the file is newly created, its | |
1167 | .IR st_atime , | |
1168 | .IR st_ctime , | |
1169 | .I st_mtime | |
1170 | fields | |
1171 | (respectively, time of last access, time of last status change, and | |
1172 | time of last modification; see | |
1173 | .BR stat (2)) | |
1174 | are set | |
1175 | to the current time, and so are the | |
1176 | .I st_ctime | |
1177 | and | |
1178 | .I st_mtime | |
1179 | fields of the | |
1180 | parent directory. | |
1181 | Otherwise, if the file is modified because of the | |
1182 | .B O_TRUNC | |
3a9c5a29 MK |
1183 | flag, its |
1184 | .I st_ctime | |
1185 | and | |
1186 | .I st_mtime | |
1187 | fields are set to the current time. | |
aaf7a574 MK |
1188 | |
1189 | The files in the | |
1190 | .I /proc/[pid]/fd | |
1191 | directory show the open file descriptors of the process with the PID | |
1192 | .IR pid . | |
1193 | The files in the | |
1194 | .I /proc/[pid]/fdinfo | |
1195 | directory show even more information about these files descriptors. | |
1196 | See | |
1197 | .BR proc (5) | |
1198 | for further details of both of these directories. | |
5dc8986d MK |
1199 | .\" |
1200 | .\" | |
d20d9d33 MK |
1201 | .SS Open file descriptions |
1202 | The term open file description is the one used by POSIX to refer to the | |
1203 | entries in the system-wide table of open files. | |
91085d85 | 1204 | In other contexts, this object is |
d20d9d33 MK |
1205 | variously also called an "open file object", |
1206 | a "file handle", an "open file table entry", | |
1207 | or\(emin kernel-developer parlance\(ema | |
1208 | .IR "struct file" . | |
1209 | ||
1210 | When a file descriptor is duplicated (using | |
1211 | .BR dup (2) | |
1212 | or similar), | |
1213 | the duplicate refers to the same open file description | |
1214 | as the original file descriptor, | |
1215 | and the two file descriptors consequently share | |
1216 | the file offset and file status flags. | |
1217 | Such sharing can also occur between processes: | |
1218 | a child process created via | |
91085d85 | 1219 | .BR fork (2) |
d20d9d33 MK |
1220 | inherits duplicates of its parent's file descriptors, |
1221 | and those duplicates refer to the same open file descriptions. | |
1222 | ||
1223 | Each | |
bf7bc8b8 | 1224 | .BR open () |
d20d9d33 MK |
1225 | of a file creates a new open file description; |
1226 | thus, there may be multiple open file descriptions | |
1227 | corresponding to a file inode. | |
9539ebc9 MK |
1228 | |
1229 | On Linux, one can use the | |
1230 | .BR kcmp (2) | |
1231 | .B KCMP_FILE | |
1232 | operation to test whether two file descriptors | |
1233 | (in the same process or in two different processes) | |
1234 | refer to the same open file description. | |
d20d9d33 MK |
1235 | .\" |
1236 | .\" | |
5dc8986d | 1237 | .SS Synchronized I/O |
6cf19e62 MK |
1238 | The POSIX.1-2008 "synchronized I/O" option |
1239 | specifies different variants of synchronized I/O, | |
1240 | and specifies the | |
1241 | .BR open () | |
1242 | flags | |
015221ef CH |
1243 | .BR O_SYNC , |
1244 | .BR O_DSYNC , | |
1245 | and | |
6cf19e62 MK |
1246 | .BR O_RSYNC |
1247 | for controlling the behavior. | |
1248 | Regardless of whether an implementation supports this option, | |
1249 | it must at least support the use of | |
1250 | .BR O_SYNC | |
1251 | for regular files. | |
1252 | ||
89851a00 | 1253 | Linux implements |
6cf19e62 MK |
1254 | .BR O_SYNC |
1255 | and | |
1256 | .BR O_DSYNC , | |
1257 | but not | |
015221ef | 1258 | .BR O_RSYNC . |
6cf19e62 MK |
1259 | (Somewhat incorrectly, glibc defines |
1260 | .BR O_RSYNC | |
1261 | to have the same value as | |
1262 | .BR O_SYNC .) | |
1263 | ||
1264 | .BR O_SYNC | |
1265 | provides synchronized I/O | |
1266 | .I file | |
1267 | integrity completion, | |
1268 | meaning write operations will flush data and all associated metadata | |
1269 | to the underlying hardware. | |
1270 | .BR O_DSYNC | |
1271 | provides synchronized I/O | |
1272 | .I data | |
1273 | integrity completion, | |
1274 | meaning write operations will flush data | |
1275 | to the underlying hardware, | |
1276 | but will only flush metadata updates that are required | |
1277 | to allow a subsequent read operation to complete successfully. | |
1278 | Data integrity completion can reduce the number of disk operations | |
1279 | that are required for applications that don't need the guarantees | |
1280 | of file integrity completion. | |
1281 | ||
a83923ca | 1282 | To understand the difference between the two types of completion, |
6cf19e62 MK |
1283 | consider two pieces of file metadata: |
1284 | the file last modification timestamp | |
1285 | .RI ( st_mtime ) | |
1286 | and the file length. | |
1287 | All write operations will update the last file modification timestamp, | |
1288 | but only writes that add data to the end of the | |
1289 | file will change the file length. | |
1290 | The last modification timestamp is not needed to ensure that | |
1291 | a read completes successfully, but the file length is. | |
1292 | Thus, | |
1293 | .BR O_DSYNC | |
1294 | would only guarantee to flush updates to the file length metadata | |
1295 | (whereas | |
1296 | .BR O_SYNC | |
1297 | would also always flush the last modification timestamp metadata). | |
1298 | ||
1299 | Before Linux 2.6.33, Linux implemented only the | |
1300 | .BR O_SYNC | |
89851a00 | 1301 | flag for |
6cf19e62 MK |
1302 | .BR open (). |
1303 | However, when that flag was specified, | |
1304 | most filesystems actually provided the equivalent of synchronized I/O | |
1305 | .I data | |
1306 | integrity completion (i.e., | |
1307 | .BR O_SYNC | |
1308 | was actually implemented as the equivalent of | |
1309 | .BR O_DSYNC ). | |
1310 | ||
1311 | Since Linux 2.6.33, proper | |
1312 | .BR O_SYNC | |
1313 | support is provided. | |
1314 | However, to ensure backward binary compatibility, | |
1315 | .BR O_DSYNC | |
1316 | was defined with the same value as the historical | |
015221ef | 1317 | .BR O_SYNC , |
015221ef | 1318 | and |
6cf19e62 | 1319 | .BR O_SYNC |
89851a00 | 1320 | was defined as a new (two-bit) flag value that includes the |
6cf19e62 MK |
1321 | .BR O_DSYNC |
1322 | flag value. | |
1323 | This ensures that applications compiled against | |
1324 | new headers get at least | |
1325 | .BR O_DSYNC | |
1326 | semantics on pre-2.6.33 kernels. | |
5dc8986d MK |
1327 | .\" |
1328 | .\" | |
1329 | .SS NFS | |
1330 | There are many infelicities in the protocol underlying NFS, affecting | |
1331 | amongst others | |
1332 | .BR O_SYNC " and " O_NDELAY . | |
a1d5f77c | 1333 | |
9ee4a2b6 | 1334 | On NFS filesystems with UID mapping enabled, |
a1d5f77c MK |
1335 | .BR open () |
1336 | may | |
75b94dc3 | 1337 | return a file descriptor but, for example, |
a1d5f77c MK |
1338 | .BR read (2) |
1339 | requests are denied | |
1340 | with \fBEACCES\fP. | |
1341 | This is because the client performs | |
1342 | .BR open () | |
1343 | by checking the | |
1344 | permissions, but UID mapping is performed by the server upon | |
1345 | read and write requests. | |
5dc8986d MK |
1346 | .\" |
1347 | .\" | |
1bdc161d MK |
1348 | .SS FIFOs |
1349 | Opening the read or write end of a FIFO blocks until the other | |
1350 | end is also opened (by another process or thread). | |
1351 | See | |
1352 | .BR fifo (7) | |
1353 | for further details. | |
1354 | .\" | |
1355 | .\" | |
5dc8986d MK |
1356 | .SS File access mode |
1357 | Unlike the other values that can be specified in | |
1358 | .IR flags , | |
1359 | the | |
1360 | .I "access mode" | |
1361 | values | |
1362 | .BR O_RDONLY ", " O_WRONLY ", and " O_RDWR | |
1363 | do not specify individual bits. | |
1364 | Rather, they define the low order two bits of | |
1365 | .IR flags , | |
1366 | and are defined respectively as 0, 1, and 2. | |
1367 | In other words, the combination | |
1368 | .B "O_RDONLY | O_WRONLY" | |
1369 | is a logical error, and certainly does not have the same meaning as | |
1370 | .BR O_RDWR . | |
a1d5f77c | 1371 | |
5dc8986d MK |
1372 | Linux reserves the special, nonstandard access mode 3 (binary 11) in |
1373 | .I flags | |
1374 | to mean: | |
d9cb0d7d | 1375 | check for read and write permission on the file and return a file descriptor |
5dc8986d MK |
1376 | that can't be used for reading or writing. |
1377 | This nonstandard access mode is used by some Linux drivers to return a | |
d9cb0d7d | 1378 | file descriptor that is to be used only for device-specific |
5dc8986d MK |
1379 | .BR ioctl (2) |
1380 | operations. | |
1381 | .\" See for example util-linux's disk-utils/setfdprm.c | |
1382 | .\" For some background on access mode 3, see | |
1383 | .\" http://thread.gmane.org/gmane.linux.kernel/653123 | |
1384 | .\" "[RFC] correct flags to f_mode conversion in __dentry_open" | |
1385 | .\" LKML, 12 Mar 2008 | |
7b8ba76c MK |
1386 | .\" |
1387 | .\" | |
80d250b4 | 1388 | .SS Rationale for openat() and other "directory file descriptor" APIs |
7b8ba76c | 1389 | .BR openat () |
80d250b4 MK |
1390 | and the other system calls and library functions that take |
1391 | a directory file descriptor argument | |
7b8ba76c | 1392 | (i.e., |
c6a16783 | 1393 | .BR execveat (2), |
7b8ba76c | 1394 | .BR faccessat (2), |
80d250b4 | 1395 | .BR fanotify_mark (2), |
7b8ba76c MK |
1396 | .BR fchmodat (2), |
1397 | .BR fchownat (2), | |
1398 | .BR fstatat (2), | |
1399 | .BR futimesat (2), | |
1400 | .BR linkat (2), | |
1401 | .BR mkdirat (2), | |
1402 | .BR mknodat (2), | |
80d250b4 | 1403 | .BR name_to_handle_at (2), |
7b8ba76c MK |
1404 | .BR readlinkat (2), |
1405 | .BR renameat (2), | |
1406 | .BR symlinkat (2), | |
1407 | .BR unlinkat (2), | |
f37759b1 | 1408 | .BR utimensat (2), |
80d250b4 | 1409 | .BR mkfifoat (3), |
7b8ba76c | 1410 | and |
80d250b4 | 1411 | .BR scandirat (3)) |
7b8ba76c MK |
1412 | are supported |
1413 | for two reasons. | |
92692952 | 1414 | Here, the explanation is in terms of the |
7b8ba76c | 1415 | .BR openat () |
d26f8a31 | 1416 | call, but the rationale is analogous for the other interfaces. |
7b8ba76c MK |
1417 | |
1418 | First, | |
1419 | .BR openat () | |
1420 | allows an application to avoid race conditions that could | |
1421 | occur when using | |
cadd38ba | 1422 | .BR open () |
7b8ba76c MK |
1423 | to open files in directories other than the current working directory. |
1424 | These race conditions result from the fact that some component | |
1425 | of the directory prefix given to | |
cadd38ba | 1426 | .BR open () |
7b8ba76c | 1427 | could be changed in parallel with the call to |
cadd38ba | 1428 | .BR open (). |
54305f5b MK |
1429 | Suppose, for example, that we wish to create the file |
1430 | .I path/to/xxx.dep | |
1431 | if the file | |
1432 | .I path/to/xxx | |
1433 | exists. | |
1434 | The problem is that between the existence check and the file creation step, | |
1435 | .I path | |
1436 | or | |
1437 | .I to | |
1438 | (which might be symbolic links) | |
1439 | could be modified to point to a different location. | |
7b8ba76c MK |
1440 | Such races can be avoided by |
1441 | opening a file descriptor for the target directory, | |
1442 | and then specifying that file descriptor as the | |
1443 | .I dirfd | |
54305f5b MK |
1444 | argument of (say) |
1445 | .BR fstatat (2) | |
1446 | and | |
7b8ba76c MK |
1447 | .BR openat (). |
1448 | ||
1449 | Second, | |
1450 | .BR openat () | |
1451 | allows the implementation of a per-thread "current working | |
1452 | directory", via file descriptor(s) maintained by the application. | |
1453 | (This functionality can also be obtained by tricks based | |
1454 | on the use of | |
1455 | .IR /proc/self/fd/ dirfd, | |
1456 | but less efficiently.) | |
1457 | .\" | |
1458 | .\" | |
ddc4d339 MK |
1459 | .SS O_DIRECT |
1460 | .LP | |
1461 | The | |
1462 | .B O_DIRECT | |
1463 | flag may impose alignment restrictions on the length and address | |
7fac88a9 | 1464 | of user-space buffers and the file offset of I/Os. |
ddc4d339 | 1465 | In Linux alignment |
9ee4a2b6 | 1466 | restrictions vary by filesystem and kernel version and might be |
ddc4d339 | 1467 | absent entirely. |
9ee4a2b6 | 1468 | However there is currently no filesystem\-independent |
ddc4d339 | 1469 | interface for an application to discover these restrictions for a given |
9ee4a2b6 MK |
1470 | file or filesystem. |
1471 | Some filesystems provide their own interfaces | |
ddc4d339 MK |
1472 | for doing so, for example the |
1473 | .B XFS_IOC_DIOINFO | |
1474 | operation in | |
1475 | .BR xfsctl (3). | |
1476 | .LP | |
85c2bdba MK |
1477 | Under Linux 2.4, transfer sizes, and the alignment of the user buffer |
1478 | and the file offset must all be multiples of the logical block size | |
9ee4a2b6 | 1479 | of the filesystem. |
21557928 | 1480 | Since Linux 2.6.0, alignment to the logical block size of the |
e6042e4a | 1481 | underlying storage (typically 512 bytes) suffices. |
21557928 | 1482 | The logical block size can be determined using the |
e6042e4a PS |
1483 | .BR ioctl (2) |
1484 | .B BLKSSZGET | |
21557928 MK |
1485 | operation or from the shell using the command: |
1486 | ||
1487 | blockdev \-\-getss | |
1847167b NP |
1488 | .LP |
1489 | .B O_DIRECT | |
1490 | I/Os should never be run concurrently with the | |
04cd7f64 | 1491 | .BR fork (2) |
1847167b NP |
1492 | system call, |
1493 | if the memory buffer is a private mapping | |
1494 | (i.e., any mapping created with the | |
02ace852 | 1495 | .BR mmap (2) |
1847167b | 1496 | .BR MAP_PRIVATE |
0ab8aeec | 1497 | flag; |
1847167b NP |
1498 | this includes memory allocated on the heap and statically allocated buffers). |
1499 | Any such I/Os, whether submitted via an asynchronous I/O interface or from | |
1500 | another thread in the process, | |
1501 | should be completed before | |
1502 | .BR fork (2) | |
1503 | is called. | |
1504 | Failure to do so can result in data corruption and undefined behavior in | |
1505 | parent and child processes. | |
1506 | This restriction does not apply when the memory buffer for the | |
1507 | .B O_DIRECT | |
1508 | I/Os was created using | |
1509 | .BR shmat (2) | |
1510 | or | |
1511 | .BR mmap (2) | |
1512 | with the | |
1513 | .B MAP_SHARED | |
1514 | flag. | |
1515 | Nor does this restriction apply when the memory buffer has been advised as | |
1516 | .B MADV_DONTFORK | |
0ab8aeec | 1517 | with |
02ace852 | 1518 | .BR madvise (2), |
1847167b NP |
1519 | ensuring that it will not be available |
1520 | to the child after | |
1521 | .BR fork (2). | |
ddc4d339 MK |
1522 | .LP |
1523 | The | |
1524 | .B O_DIRECT | |
1525 | flag was introduced in SGI IRIX, where it has alignment | |
1526 | restrictions similar to those of Linux 2.4. | |
1527 | IRIX has also a | |
1528 | .BR fcntl (2) | |
1529 | call to query appropriate alignments, and sizes. | |
1530 | FreeBSD 4.x introduced | |
1531 | a flag of the same name, but without alignment restrictions. | |
1532 | .LP | |
1533 | .B O_DIRECT | |
1534 | support was added under Linux in kernel version 2.4.10. | |
1535 | Older Linux kernels simply ignore this flag. | |
9ee4a2b6 | 1536 | Some filesystems may not implement the flag and |
ddc4d339 MK |
1537 | .BR open () |
1538 | will fail with | |
1539 | .B EINVAL | |
1540 | if it is used. | |
1541 | .LP | |
1542 | Applications should avoid mixing | |
1543 | .B O_DIRECT | |
1544 | and normal I/O to the same file, | |
1545 | and especially to overlapping byte regions in the same file. | |
9ee4a2b6 | 1546 | Even when the filesystem correctly handles the coherency issues in |
ddc4d339 MK |
1547 | this situation, overall I/O throughput is likely to be slower than |
1548 | using either mode alone. | |
1549 | Likewise, applications should avoid mixing | |
1550 | .BR mmap (2) | |
1551 | of files with direct I/O to the same files. | |
1552 | .LP | |
a1fa36af | 1553 | The behavior of |
ddc4d339 | 1554 | .B O_DIRECT |
9ee4a2b6 | 1555 | with NFS will differ from local filesystems. |
ddc4d339 MK |
1556 | Older kernels, or |
1557 | kernels configured in certain ways, may not support this combination. | |
1558 | The NFS protocol does not support passing the flag to the server, so | |
1559 | .B O_DIRECT | |
33a0ccb2 | 1560 | I/O will bypass the page cache only on the client; the server may |
ddc4d339 MK |
1561 | still cache the I/O. |
1562 | The client asks the server to make the I/O | |
1563 | synchronous to preserve the synchronous semantics of | |
1564 | .BR O_DIRECT . | |
1565 | Some servers will perform poorly under these circumstances, especially | |
1566 | if the I/O size is small. | |
1567 | Some servers may also be configured to | |
1568 | lie to clients about the I/O having reached stable storage; this | |
1569 | will avoid the performance penalty at some risk to data integrity | |
1570 | in the event of server power failure. | |
1571 | The Linux NFS client places no alignment restrictions on | |
1572 | .B O_DIRECT | |
1573 | I/O. | |
1574 | .PP | |
1575 | In summary, | |
1576 | .B O_DIRECT | |
1577 | is a potentially powerful tool that should be used with caution. | |
1578 | It is recommended that applications treat use of | |
1579 | .B O_DIRECT | |
1580 | as a performance option which is disabled by default. | |
1581 | .PP | |
1582 | .RS | |
fea681da MK |
1583 | "The thing that has always disturbed me about O_DIRECT is that the whole |
1584 | interface is just stupid, and was probably designed by a deranged monkey | |
5503c85e | 1585 | on some serious mind-controlling substances."\(emLinus |
ddc4d339 MK |
1586 | .RE |
1587 | .SH BUGS | |
b50582eb MK |
1588 | Currently, it is not possible to enable signal-driven |
1589 | I/O by specifying | |
1590 | .B O_ASYNC | |
c13182ef | 1591 | when calling |
b50582eb MK |
1592 | .BR open (); |
1593 | use | |
1594 | .BR fcntl (2) | |
1595 | to enable this flag. | |
0e1ad98c | 1596 | .\" FIXME . Check bugzilla report on open(O_ASYNC) |
92057f4d | 1597 | .\" See http://bugzilla.kernel.org/show_bug.cgi?id=5993 |
0d730fcc MK |
1598 | |
1599 | One must check for two different error codes, | |
1600 | .B EISDIR | |
1601 | and | |
1602 | .BR ENOENT , | |
1603 | when trying to determine whether the kernel supports | |
0d55b37f | 1604 | .B O_TMPFILE |
0d730fcc | 1605 | functionality. |
320f8a8e MK |
1606 | |
1607 | When both | |
1608 | .B O_CREAT | |
1609 | and | |
1610 | .B O_DIRECTORY | |
1611 | are specified in | |
1612 | .IR flags | |
1613 | and the file specified by | |
1614 | .I pathname | |
1615 | does not exist, | |
1616 | .BR open () | |
1617 | will create a regular file (i.e., | |
1618 | .B O_DIRECTORY | |
1619 | is ignored). | |
47297adb | 1620 | .SH SEE ALSO |
a3bf8022 MK |
1621 | .BR chmod (2), |
1622 | .BR chown (2), | |
fea681da | 1623 | .BR close (2), |
e366dbc4 | 1624 | .BR dup (2), |
fea681da MK |
1625 | .BR fcntl (2), |
1626 | .BR link (2), | |
1f6ceb40 | 1627 | .BR lseek (2), |
fea681da | 1628 | .BR mknod (2), |
e366dbc4 | 1629 | .BR mmap (2), |
f0c34053 | 1630 | .BR mount (2), |
fa5d243f | 1631 | .BR open_by_handle_at (2), |
fea681da MK |
1632 | .BR read (2), |
1633 | .BR socket (2), | |
1634 | .BR stat (2), | |
1635 | .BR umask (2), | |
1636 | .BR unlink (2), | |
1637 | .BR write (2), | |
1638 | .BR fopen (3), | |
b31056e3 | 1639 | .BR acl (5), |
f0c34053 | 1640 | .BR fifo (7), |
a9cfde1d MK |
1641 | .BR path_resolution (7), |
1642 | .BR symlink (7) |