]>
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 | |
1c1e15ed MK |
186 | avoid denial-of-service problems if \fBopendir\fR(3) is called on a |
187 | FIFO or tape device, but should not be used outside of the | |
188 | implementation of \fBopendir\fR. | |
189 | .TP | |
fea681da MK |
190 | .B O_EXCL |
191 | When used with | |
192 | .BR O_CREAT , | |
193 | if the file already exists it is an error and the | |
1c1e15ed | 194 | .BR open () |
c13182ef MK |
195 | will fail. |
196 | In this context, a symbolic link exists, regardless | |
1f6ceb40 | 197 | of where it points to. |
fea681da | 198 | .B O_EXCL |
1f6ceb40 | 199 | is broken on NFS file systems; programs which rely on it for performing |
c13182ef MK |
200 | locking tasks will contain a race condition. |
201 | The solution for performing | |
1c1e15ed MK |
202 | atomic file locking using a lockfile is to create a unique file on |
203 | the same file system (e.g., incorporating hostname and pid), use | |
fea681da | 204 | .BR link (2) |
c13182ef | 205 | to make a link to the lockfile. |
0bfa087b | 206 | If \fBlink\fP(2) returns 0, the lock is |
c13182ef MK |
207 | successful. |
208 | Otherwise, use | |
fea681da MK |
209 | .BR stat (2) |
210 | on the unique file to check if its link count has increased to 2, | |
211 | in which case the lock is also successful. | |
212 | .TP | |
1c1e15ed MK |
213 | .B O_LARGEFILE |
214 | (LFS) | |
215 | Allow files whose sizes cannot be represented in an | |
8478ee02 | 216 | .I off_t |
1c1e15ed | 217 | (but can be represented in an |
8478ee02 | 218 | .IR off64_t ) |
1c1e15ed | 219 | to be opened. |
c13182ef | 220 | The |
bcdd964e MK |
221 | .B _LARGEFILE64_SOURCE |
222 | macro must be defined in order to obtain this definition. | |
c13182ef | 223 | Setting the |
bcdd964e | 224 | .B _FILE_OFFSET_BITS |
9f3d8b28 MK |
225 | feature test macro to 64 (rather than using |
226 | .BR O_LARGEFILE ) | |
227 | is the preferred method of obtaining | |
228 | method of accessing large files on 32-bit systems (see | |
2dcbf4f7 | 229 | .BR feature_test_macros (7)). |
1c1e15ed MK |
230 | .TP |
231 | .B O_NOATIME | |
232 | (Since Linux 2.6.8) | |
310b7919 MK |
233 | Do not update the file last access time (st_atime in the inode) |
234 | when the file is | |
1c1e15ed MK |
235 | .BR read (2). |
236 | This flag is intended for use by indexing or backup programs, | |
237 | where its use can significantly reduce the amount of disk activity. | |
238 | This flag may not be effective on all filesystems. | |
239 | One example is NFS, where the server maintains the access time. | |
c13182ef | 240 | .\" FIXME? The O_NOATIME flag also affects the treatment of st_atime |
92057f4d | 241 | .\" by mmap() and readdir(2), MTK, Dec 04. |
1c1e15ed | 242 | .TP |
fea681da MK |
243 | .B O_NOCTTY |
244 | If | |
245 | .I pathname | |
246 | refers to a terminal device \(em see | |
247 | .BR tty (4) | |
248 | \(em it will not become the process's controlling terminal even if the | |
249 | process does not have one. | |
250 | .TP | |
1c1e15ed | 251 | .B O_NOFOLLOW |
c13182ef MK |
252 | If \fIpathname\fR is a symbolic link, then the open fails. |
253 | This is a FreeBSD extension, which was added to Linux in version 2.1.126. | |
1c1e15ed | 254 | Symbolic links in earlier components of the pathname will still be |
e366dbc4 MK |
255 | followed. |
256 | .\" The headers from glibc 2.0.100 and later include a | |
257 | .\" definition of this flag; \fIkernels before 2.1.126 will ignore it if | |
258 | .\" used\fR. | |
fea681da MK |
259 | .TP |
260 | .BR O_NONBLOCK " or " O_NDELAY | |
c13182ef MK |
261 | When possible, the file is opened in non-blocking mode. |
262 | Neither the | |
1c1e15ed | 263 | .BR open () |
fea681da MK |
264 | nor any subsequent operations on the file descriptor which is |
265 | returned will cause the calling process to wait. | |
266 | For the handling of FIFOs (named pipes), see also | |
af5b2ef2 | 267 | .BR fifo (7). |
db28bfac MK |
268 | For a discussion of the effect of |
269 | .BR O_NONBLOCK | |
270 | in conjunction with mandatory file locks and with file leases, see | |
271 | .BR fcntl (2). | |
fea681da MK |
272 | .TP |
273 | .B O_SYNC | |
c13182ef MK |
274 | The file is opened for synchronous I/O. |
275 | Any | |
0bfa087b | 276 | .BR write (2)s |
fea681da MK |
277 | on the resulting file descriptor will block the calling process until |
278 | the data has been physically written to the underlying hardware. | |
db28bfac | 279 | .IR "But see RESTRICTIONS below" . |
fea681da | 280 | .TP |
1c1e15ed MK |
281 | .B O_TRUNC |
282 | If the file already exists and is a regular file and the open mode allows | |
283 | writing (i.e., is O_RDWR or O_WRONLY) it will be truncated to length 0. | |
284 | If the file is a FIFO or terminal device file, the O_TRUNC | |
c13182ef MK |
285 | flag is ignored. |
286 | Otherwise the effect of O_TRUNC is unspecified. | |
fea681da MK |
287 | .PP |
288 | Some of these optional flags can be altered using | |
0bfa087b | 289 | .BR fcntl (2) |
fea681da MK |
290 | after the file has been opened. |
291 | ||
292 | The argument | |
293 | .I mode | |
c13182ef MK |
294 | specifies the permissions to use in case a new file is created. |
295 | It is | |
fea681da MK |
296 | modified by the process's |
297 | .BR umask | |
298 | in the usual way: the permissions of the created file are | |
299 | .BR "(mode & ~umask)" . | |
300 | Note that this mode only applies to future accesses of the | |
301 | newly created file; the | |
1c1e15ed | 302 | .BR open () |
fea681da MK |
303 | call that creates a read-only file may well return a read/write |
304 | file descriptor. | |
305 | .PP | |
306 | The following symbolic constants are provided for | |
307 | .IR mode : | |
308 | .TP | |
309 | .B S_IRWXU | |
310 | 00700 user (file owner) has read, write and execute permission | |
311 | .TP | |
cc513f7f | 312 | .B S_IRUSR |
fea681da MK |
313 | 00400 user has read permission |
314 | .TP | |
cc513f7f | 315 | .B S_IWUSR |
fea681da MK |
316 | 00200 user has write permission |
317 | .TP | |
cc513f7f | 318 | .B S_IXUSR |
fea681da MK |
319 | 00100 user has execute permission |
320 | .TP | |
321 | .B S_IRWXG | |
322 | 00070 group has read, write and execute permission | |
323 | .TP | |
324 | .B S_IRGRP | |
325 | 00040 group has read permission | |
326 | .TP | |
327 | .B S_IWGRP | |
328 | 00020 group has write permission | |
329 | .TP | |
330 | .B S_IXGRP | |
331 | 00010 group has execute permission | |
332 | .TP | |
333 | .B S_IRWXO | |
334 | 00007 others have read, write and execute permission | |
335 | .TP | |
336 | .B S_IROTH | |
337 | 00004 others have read permission | |
338 | .TP | |
339 | .B S_IWOTH | |
d301ee6c | 340 | 00002 others have write permission |
fea681da MK |
341 | .TP |
342 | .B S_IXOTH | |
343 | 00001 others have execute permission | |
344 | .PP | |
345 | .I mode | |
346 | must be specified when | |
347 | .B O_CREAT | |
348 | is in the | |
349 | .IR flags , | |
350 | and is ignored otherwise. | |
351 | ||
1c1e15ed | 352 | .BR creat () |
fea681da | 353 | is equivalent to |
1c1e15ed | 354 | .BR open () |
fea681da MK |
355 | with |
356 | .I flags | |
357 | equal to | |
358 | .BR O_CREAT|O_WRONLY|O_TRUNC . | |
359 | .SH "RETURN VALUE" | |
c13182ef MK |
360 | .BR open () |
361 | and | |
e1d6264d | 362 | .BR creat () |
1c1e15ed MK |
363 | return the new file descriptor, or \-1 if an error occurred |
364 | (in which case, | |
fea681da MK |
365 | .I errno |
366 | is set appropriately). | |
28c54d45 | 367 | .SH NOTES |
fea681da | 368 | Note that |
1c1e15ed | 369 | .BR open () |
fea681da | 370 | can open device special files, but |
1c1e15ed | 371 | .BR creat () |
e9496f74 | 372 | cannot create them; use |
fea681da MK |
373 | .BR mknod (2) |
374 | instead. | |
375 | .LP | |
c13182ef | 376 | On NFS file systems with UID mapping enabled, \fBopen\fP() may |
1c1e15ed MK |
377 | return a file descriptor but e.g. \fBread\fP(2) requests are denied |
378 | with \fBEACCES\fP. | |
e366dbc4 | 379 | This is because the client performs \fBopen\fP() by checking the |
1c1e15ed MK |
380 | permissions, but UID mapping is performed by the server upon |
381 | read and write requests. | |
fea681da | 382 | |
310b7919 MK |
383 | If the file is newly created, its st_atime, st_ctime, st_mtime fields |
384 | (respectively, time of last access, time of last status change, and | |
385 | time of last modification; see | |
386 | .BR stat (2)) | |
387 | are set | |
388 | to the current time, and so are the st_ctime and st_mtime fields of the | |
fea681da MK |
389 | parent directory. |
390 | Otherwise, if the file is modified because of the O_TRUNC flag, | |
310b7919 | 391 | its st_ctime and st_mtime fields are set to the current time. |
fea681da MK |
392 | .SH ERRORS |
393 | .TP | |
394 | .B EACCES | |
395 | The requested access to the file is not allowed, or search permission | |
396 | is denied for one of the directories in the path prefix of | |
397 | .IR pathname , | |
398 | or the file did not exist yet and write access to the parent directory | |
399 | is not allowed. | |
400 | (See also | |
401 | .BR path_resolution (2).) | |
402 | .TP | |
403 | .B EEXIST | |
404 | .I pathname | |
405 | already exists and | |
406 | .BR O_CREAT " and " O_EXCL | |
407 | were used. | |
408 | .TP | |
409 | .B EFAULT | |
c13182ef | 410 | .IR pathname |
e1d6264d | 411 | points outside your accessible address space. |
fea681da | 412 | .TP |
9f5773f7 MK |
413 | .B EFBIG |
414 | .I pathname | |
415 | refers to a regular file, too large to be opened; see O_LARGEFILE above. | |
c13182ef | 416 | (POSIX.1-2001 specifies the error |
9f5773f7 MK |
417 | .B EOVERFLOW |
418 | for this case.) | |
419 | .\" FIXME Maybe this deviation from the standard will get repaired. | |
420 | .\" See http://bugzilla.kernel.org/show_bug.cgi?id=7253 | |
421 | .\" "Open of a large file on 32-bit fails with EFBIG, should be EOVERFLOW" | |
422 | .\" Reported 2006-10-03 | |
423 | .TP | |
fea681da MK |
424 | .B EISDIR |
425 | .I pathname | |
426 | refers to a directory and the access requested involved writing | |
427 | (that is, | |
428 | .B O_WRONLY | |
429 | or | |
430 | .B O_RDWR | |
431 | is set). | |
432 | .TP | |
433 | .B ELOOP | |
434 | Too many symbolic links were encountered in resolving | |
435 | .IR pathname , | |
436 | or \fBO_NOFOLLOW\fR was specified but | |
437 | .I pathname | |
438 | was a symbolic link. | |
439 | .TP | |
440 | .B EMFILE | |
441 | The process already has the maximum number of files open. | |
442 | .TP | |
443 | .B ENAMETOOLONG | |
e1d6264d MK |
444 | .IR pathname |
445 | was too long. | |
fea681da MK |
446 | .TP |
447 | .B ENFILE | |
448 | The system limit on the total number of open files has been reached. | |
449 | .TP | |
450 | .B ENODEV | |
451 | .I pathname | |
452 | refers to a device special file and no corresponding device exists. | |
e9496f74 | 453 | (This is a Linux kernel bug; in this situation ENXIO must be returned.) |
fea681da MK |
454 | .TP |
455 | .B ENOENT | |
456 | O_CREAT is not set and the named file does not exist. | |
457 | Or, a directory component in | |
458 | .I pathname | |
459 | does not exist or is a dangling symbolic link. | |
460 | .TP | |
461 | .B ENOMEM | |
462 | Insufficient kernel memory was available. | |
463 | .TP | |
464 | .B ENOSPC | |
465 | .I pathname | |
466 | was to be created but the device containing | |
467 | .I pathname | |
468 | has no room for the new file. | |
469 | .TP | |
470 | .B ENOTDIR | |
471 | A component used as a directory in | |
472 | .I pathname | |
473 | is not, in fact, a directory, or \fBO_DIRECTORY\fR was specified and | |
474 | .I pathname | |
475 | was not a directory. | |
476 | .TP | |
477 | .B ENXIO | |
478 | O_NONBLOCK | O_WRONLY is set, the named file is a FIFO and | |
479 | no process has the file open for reading. | |
480 | Or, the file is a device special file and no corresponding device exists. | |
481 | .TP | |
1c1e15ed MK |
482 | .B EPERM |
483 | The | |
484 | .B O_NOATIME | |
485 | flag was specified, but the effective user ID of the caller | |
486 | .\" Strictly speaking, it's the file system UID... (MTK) | |
487 | did not match the owner of the file and the caller was not privileged | |
488 | .RB ( CAP_FOWNER ). | |
489 | .TP | |
fea681da MK |
490 | .B EROFS |
491 | .I pathname | |
492 | refers to a file on a read-only filesystem and write access was | |
493 | requested. | |
494 | .TP | |
495 | .B ETXTBSY | |
496 | .I pathname | |
497 | refers to an executable image which is currently being executed and | |
498 | write access was requested. | |
d3952311 MK |
499 | .TP |
500 | .B EWOULDBLOCK | |
501 | The | |
502 | .B O_NONBLOCK | |
503 | flag was specified, and an incompatible lease was held on the file | |
504 | (see | |
505 | .BR fcntl (2)). | |
fea681da MK |
506 | .SH NOTE |
507 | Under Linux, the O_NONBLOCK flag indicates that one wants to open | |
508 | but does not necessarily have the intention to read or write. | |
509 | This is typically used to open devices in order to get a file descriptor | |
510 | for use with | |
511 | .BR ioctl (2). | |
512 | .SH "CONFORMING TO" | |
97c1eac8 | 513 | SVr4, 4.3BSD, POSIX.1-2001. |
fea681da | 514 | The |
1c1e15ed MK |
515 | .BR O_NOATIME , |
516 | .BR O_NOFOLLOW , | |
fea681da MK |
517 | and |
518 | .B O_DIRECTORY | |
75b48e9d | 519 | flags are Linux specific. |
fea681da MK |
520 | One may have to define the |
521 | .B _GNU_SOURCE | |
522 | macro to get their definitions. | |
523 | .LP | |
524 | The (undefined) effect of | |
525 | .B O_RDONLY | O_TRUNC | |
c13182ef | 526 | varies among implementations. |
bcdd964e | 527 | On many systems the file is actually truncated. |
fea681da MK |
528 | .\" Linux 2.0, 2.5: truncate |
529 | .\" Solaris 5.7, 5.8: truncate | |
530 | .\" Irix 6.5: truncate | |
531 | .\" Tru64 5.1B: truncate | |
532 | .\" HP-UX 11.22: truncate | |
533 | .\" FreeBSD 4.7: truncate | |
534 | .LP | |
535 | The | |
536 | .B O_DIRECT | |
537 | flag was introduced in SGI IRIX, where it has alignment restrictions | |
c13182ef MK |
538 | similar to those of Linux 2.4. |
539 | IRIX has also a fcntl(2) call to | |
540 | query appropriate alignments, and sizes. | |
541 | FreeBSD 4.x introduced | |
fea681da MK |
542 | a flag of same name, but without alignment restrictions. |
543 | Support was added under Linux in kernel version 2.4.10. | |
544 | Older Linux kernels simply ignore this flag. | |
1f6ceb40 MK |
545 | One may have to define the |
546 | .B _GNU_SOURCE | |
547 | macro to get its definition. | |
fea681da MK |
548 | .SH BUGS |
549 | "The thing that has always disturbed me about O_DIRECT is that the whole | |
550 | interface is just stupid, and was probably designed by a deranged monkey | |
e9496f74 | 551 | on some serious mind-controlling substances." \(em Linus |
b50582eb MK |
552 | |
553 | Currently, it is not possible to enable signal-driven | |
554 | I/O by specifying | |
555 | .B O_ASYNC | |
c13182ef | 556 | when calling |
b50582eb MK |
557 | .BR open (); |
558 | use | |
559 | .BR fcntl (2) | |
560 | to enable this flag. | |
92057f4d MK |
561 | .\" FIXME Check bugzilla report on open(O_ASYNC) |
562 | .\" See http://bugzilla.kernel.org/show_bug.cgi?id=5993 | |
fea681da MK |
563 | .SH RESTRICTIONS |
564 | There are many infelicities in the protocol underlying NFS, affecting | |
565 | amongst others | |
566 | .BR O_SYNC " and " O_NDELAY . | |
567 | ||
568 | POSIX provides for three different variants of synchronised I/O, | |
569 | corresponding to the flags \fBO_SYNC\fR, \fBO_DSYNC\fR and | |
c13182ef MK |
570 | \fBO_RSYNC\fR. |
571 | Currently (2.1.130) these are all synonymous under Linux. | |
fea681da MK |
572 | .SH "SEE ALSO" |
573 | .BR close (2), | |
e366dbc4 | 574 | .BR dup (2), |
fea681da MK |
575 | .BR fcntl (2), |
576 | .BR link (2), | |
1f6ceb40 | 577 | .BR lseek (2), |
fea681da MK |
578 | .BR mknod (2), |
579 | .BR mount (2), | |
e366dbc4 | 580 | .BR mmap (2), |
28c54d45 | 581 | .BR openat (2), |
fea681da MK |
582 | .BR path_resolution (2), |
583 | .BR read (2), | |
584 | .BR socket (2), | |
585 | .BR stat (2), | |
586 | .BR umask (2), | |
587 | .BR unlink (2), | |
588 | .BR write (2), | |
589 | .BR fopen (3), | |
50e5322c | 590 | .BR fifo (7), |
a8e7c990 | 591 | .BR feature_test_macros (7) |