]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/open.2
memset.3: ATTRIBUTES: Note function that is thread-safe
[thirdparty/man-pages.git] / man2 / open.2
CommitLineData
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.\"
6cf19e62 51.TH OPEN 2 2014-03-16 "Linux" "Linux Programmer's Manual"
fea681da 52.SH NAME
7b8ba76c 53open, 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
71Feature 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
80Since glibc 2.10:
81_XOPEN_SOURCE\ >=\ 700 || _POSIX_C_SOURCE\ >=\ 200809L
82.TP
83Before glibc 2.10:
84_ATFILE_SOURCE
85.RE
86.ad
87.PD
fea681da 88.SH DESCRIPTION
e366dbc4 89Given a
0daa9e92 90.I pathname
e366dbc4 91for a file,
1f6ceb40 92.BR open ()
2fda57bd 93returns a file descriptor, a small, nonnegative integer
e366dbc4
MK
94for use in subsequent system calls
95.RB ( read "(2), " write "(2), " lseek "(2), " fcntl "(2), etc.)."
96The file descriptor returned by a successful call will be
2c4bff36 97the lowest-numbered file descriptor not currently open for the process.
e366dbc4 98.PP
fe75ec04 99By 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
103file descriptor flag described in
104.BR fcntl (2)
fd3ac440 105is initially disabled; the
fe75ec04
MK
106.B O_CLOEXEC
107flag, described below, can be used to change this default).
1f6ceb40 108The file offset is set to the beginning of the file (see
c13182ef 109.BR lseek (2)).
e366dbc4
MK
110.PP
111A call to
112.BR open ()
113creates a new
114.IR "open file description" ,
115an entry in the system-wide table of open files.
e366dbc4
MK
116This entry records the file offset and the file status flags
117(modifiable via the
0bfa087b 118.BR fcntl (2)
e366dbc4
MK
119.B F_SETFL
120operation).
2c4bff36
MK
121A file descriptor is a reference to one of these entries;
122this reference is unaffected if
123.I pathname
124is subsequently removed or modified to refer to a different file.
e366dbc4 125The new open file description is initially not shared
2c4bff36
MK
126with any other process,
127but sharing may arise via
128.BR fork (2).
e366dbc4 129.PP
c4bb193f 130The argument
fea681da 131.I flags
e366dbc4
MK
132must include one of the following
133.IR "access modes" :
c7992edc 134.BR O_RDONLY ", " O_WRONLY ", or " O_RDWR .
e366dbc4
MK
135These request opening the file read-only, write-only, or read/write,
136respectively.
bfe9ba67
MK
137
138In addition, zero or more file creation flags and file status flags
c13182ef 139can be
fea681da 140.RI bitwise- or 'd
e366dbc4 141in
bfe9ba67 142.IR flags .
c13182ef
MK
143The
144.I file creation flags
145are
0e40804c 146.BR O_CLOEXEC ,
b072a788 147.BR O_CREAT ,
0e40804c
MK
148.BR O_DIRECTORY ,
149.BR O_EXCL ,
150.BR O_NOCTTY ,
151.BR O_NOFOLLOW ,
f2698a42 152.BR O_TMPFILE ,
0e40804c
MK
153.BR O_TRUNC ,
154and
155.BR O_TTY_INIT .
c13182ef
MK
156The
157.I file status flags
bfe9ba67 158are all of the remaining flags listed below.
0e40804c 159.\" SUSv4 divides the flags into:
93ee8f96
MK
160.\" * Access mode
161.\" * File creation
162.\" * File status
163.\" * Other (O_CLOEXEC, O_DIRECTORY, O_NOFOLLOW)
164.\" though it's not clear what the difference between "other" and
0e40804c
MK
165.\" "File creation" flags is. I raised an Aardvark to see if this
166.\" can be clarified in SUSv4; 10 Oct 2008.
167.\" http://thread.gmane.org/gmane.comp.standards.posix.austin.general/64/focus=67
168.\" TC1 (balloted in 2013), resolved this, so that those three constants
169.\" are also categorized" as file status flags.
170.\"
bfe9ba67
MK
171The distinction between these two groups of flags is that
172the file status flags can be retrieved and (in some cases)
566b427d
MK
173modified; see
174.BR fcntl (2)
175for details.
176
bfe9ba67 177The full list of file creation flags and file status flags is as follows:
fea681da 178.TP
1c1e15ed 179.B O_APPEND
c13182ef
MK
180The file is opened in append mode.
181Before each
0bfa087b 182.BR write (2),
1e568304 183the file offset is positioned at the end of the file,
1c1e15ed 184as if with
0bfa087b 185.BR lseek (2).
1c1e15ed 186.B O_APPEND
9ee4a2b6 187may lead to corrupted files on NFS filesystems if more than one process
c13182ef 188appends data to a file at once.
a4391429
MK
189.\" For more background, see
190.\" http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=453946
191.\" http://nfs.sourceforge.net/
c13182ef 192This is because NFS does not support
1c1e15ed
MK
193appending to a file, so the client kernel has to simulate it, which
194can't be done without a race condition.
195.TP
196.B O_ASYNC
b50582eb 197Enable signal-driven I/O:
8bd58774
MK
198generate a signal
199.RB ( SIGIO
200by default, but this can be changed via
1c1e15ed
MK
201.BR fcntl (2))
202when input or output becomes possible on this file descriptor.
33a0ccb2 203This feature is available only for terminals, pseudoterminals,
1f6ceb40
MK
204sockets, and (since Linux 2.6) pipes and FIFOs.
205See
1c1e15ed
MK
206.BR fcntl (2)
207for further details.
9bde4908 208See also BUGS, below.
fe75ec04 209.TP
31c1f2b0 210.BR O_CLOEXEC " (since Linux 2.6.23)"
fe75ec04 211Enable the close-on-exec flag for the new file descriptor.
24ec631f 212Specifying this flag permits a program to avoid additional
fe75ec04
MK
213.BR fcntl (2)
214.B F_SETFD
24ec631f 215operations to set the
0daa9e92 216.B FD_CLOEXEC
fe75ec04
MK
217flag.
218Additionally,
219use of this flag is essential in some multithreaded programs
220since using a separate
221.BR fcntl (2)
222.B F_SETFD
223operation to set the
0daa9e92 224.B FD_CLOEXEC
fe75ec04
MK
225flag does not suffice to avoid race conditions
226where one thread opens a file descriptor at the same
227time as another thread does a
228.BR fork (2)
229plus
230.BR execve (2).
231.\" This flag fixes only one form of the race condition;
232.\" The race can also occur with, for example, descriptors
233.\" returned by accept(), pipe(), etc.
1c1e15ed 234.TP
fea681da
MK
235.B O_CREAT
236If the file does not exist it will be created.
237The owner (user ID) of the file is set to the effective user ID
c13182ef
MK
238of the process.
239The group ownership (group ID) is set either to
fea681da 240the effective group ID of the process or to the group ID of the
9ee4a2b6 241parent directory (depending on filesystem type and mount options,
0fb83d00 242and the mode of the parent directory; see the mount options
fea681da
MK
243.I bsdgroups
244and
245.I sysvgroups
8b39ad66 246described in
fea681da 247.BR mount (8)).
8b39ad66
MK
248.\" As at 2.6.25, bsdgroups is supported by ext2, ext3, ext4, and
249.\" XFS (since 2.6.14).
4e698277
MK
250.RS
251.PP
252.I mode
253specifies the permissions to use in case a new file is created.
254This argument must be supplied when
255.B O_CREAT
f2698a42
AL
256or
257.B O_TMPFILE
4e698277
MK
258is specified in
259.IR flags ;
f2698a42 260if neither
4e698277 261.B O_CREAT
f2698a42
AL
262nor
263.B O_TMPFILE
264is specified, then
4e698277
MK
265.I mode
266is ignored.
267The effective permissions are modified by
268the process's
269.I umask
270in the usual way: The permissions of the created file are
84a275c4 271.IR "(mode\ &\ ~umask)" .
33a0ccb2 272Note that this mode applies only to future accesses of the
4e698277
MK
273newly created file; the
274.BR open ()
275call that creates a read-only file may well return a read/write
276file descriptor.
277.PP
278The following symbolic constants are provided for
279.IR mode :
280.TP 9
281.B S_IRWXU
28200700 user (file owner) has read, write and execute permission
283.TP
284.B S_IRUSR
28500400 user has read permission
286.TP
287.B S_IWUSR
28800200 user has write permission
289.TP
290.B S_IXUSR
29100100 user has execute permission
292.TP
293.B S_IRWXG
29400070 group has read, write and execute permission
295.TP
296.B S_IRGRP
29700040 group has read permission
298.TP
299.B S_IWGRP
30000020 group has write permission
301.TP
302.B S_IXGRP
30300010 group has execute permission
304.TP
305.B S_IRWXO
30600007 others have read, write and execute permission
307.TP
308.B S_IROTH
30900004 others have read permission
310.TP
311.B S_IWOTH
31200002 others have write permission
313.TP
314.B S_IXOTH
31500001 others have execute permission
316.RE
fea681da 317.TP
31c1f2b0 318.BR O_DIRECT " (since Linux 2.4.10)"
1c1e15ed
MK
319Try to minimize cache effects of the I/O to and from this file.
320In general this will degrade performance, but it is useful in
321special situations, such as when applications do their own caching.
bce0482f 322File I/O is done directly to/from user-space buffers.
015221ef
CH
323The
324.B O_DIRECT
0deb3ce9 325flag on its own makes an effort to transfer data synchronously,
015221ef
CH
326but does not give the guarantees of the
327.B O_SYNC
0deb3ce9
JM
328flag that data and necessary metadata are transferred.
329To guarantee synchronous I/O,
015221ef
CH
330.B O_SYNC
331must be used in addition to
332.BR O_DIRECT .
be02e49f 333See NOTES below for further discussion.
9b54d4fa 334.sp
c13182ef 335A semantically similar (but deprecated) interface for block devices
9b54d4fa 336is described in
1c1e15ed
MK
337.BR raw (8).
338.TP
339.B O_DIRECTORY
a8d55537 340If \fIpathname\fP is not a directory, cause the open to fail.
9f8d688a
MK
341.\" But see the following and its replies:
342.\" http://marc.theaimsgroup.com/?t=112748702800001&r=1&w=2
343.\" [PATCH] open: O_DIRECTORY and O_CREAT together should fail
344.\" O_DIRECTORY | O_CREAT causes O_DIRECTORY to be ignored.
8382f16d 345This flag is Linux-specific, and was added in kernel version 2.1.126, to
60a90ecd
MK
346avoid denial-of-service problems if
347.BR opendir (3)
348is called on a
a3041a58 349FIFO or tape device.
1c1e15ed 350.TP
6cf19e62
MK
351.B O_DSYNC
352Write operations on the file will complete according to the requirements of
353synchronized I/O
354.I data
355integrity completion.
356
357By the time
358.BR write (2)
359(and similar)
360return, the output data
361has been transferred to the underlying hardware,
362along with any file metadata that would be required to retrieve that data
363(i.e., as though each
364.BR write (2)
365was followed by a call to
366.BR fdatasync (2)).
367.IR "See NOTES below" .
368.TP
fea681da 369.B O_EXCL
f4b9d6a5
MK
370Ensure that this call creates the file:
371if this flag is specified in conjunction with
fea681da 372.BR O_CREAT ,
f4b9d6a5
MK
373and
374.I pathname
375already exists, then
1c1e15ed 376.BR open ()
c13182ef 377will fail.
f4b9d6a5
MK
378
379When these two flags are specified, symbolic links are not followed:
380.\" POSIX.1-2001 explicitly requires this behavior.
381if
382.I pathname
383is a symbolic link, then
384.BR open ()
385fails regardless of where the symbolic link points to.
386
10b7a945
IHV
387In general, the behavior of
388.B O_EXCL
389is undefined if it is used without
390.BR O_CREAT .
391There is one exception: on Linux 2.6 and later,
392.B O_EXCL
393can be used without
394.B O_CREAT
395if
396.I pathname
397refers to a block device.
6303d401
DB
398If the block device is in use by the system (e.g., mounted),
399.BR open ()
10b7a945
IHV
400fails with the error
401.BR EBUSY .
402
efe08656 403On NFS,
f4b9d6a5 404.B O_EXCL
33a0ccb2 405is supported only when using NFSv3 or later on kernel 2.6 or later.
efe08656 406In NFS environments where
fea681da 407.B O_EXCL
f4b9d6a5
MK
408support is not provided, programs that rely on it
409for performing locking tasks will contain a race condition.
410Portable programs that want to perform atomic file locking using a lockfile,
411and need to avoid reliance on NFS support for
412.BR O_EXCL ,
413can create a unique file on
9ee4a2b6 414the same filesystem (e.g., incorporating hostname and PID), and use
fea681da 415.BR link (2)
c13182ef 416to make a link to the lockfile.
60a90ecd
MK
417If
418.BR link (2)
f4b9d6a5 419returns 0, the lock is successful.
c13182ef 420Otherwise, use
fea681da
MK
421.BR stat (2)
422on the unique file to check if its link count has increased to 2,
423in which case the lock is also successful.
424.TP
1c1e15ed
MK
425.B O_LARGEFILE
426(LFS)
427Allow files whose sizes cannot be represented in an
8478ee02 428.I off_t
1c1e15ed 429(but can be represented in an
8478ee02 430.IR off64_t )
1c1e15ed 431to be opened.
c13182ef 432The
bcdd964e 433.B _LARGEFILE64_SOURCE
e417acb0
MK
434macro must be defined
435(before including
436.I any
437header files)
438in order to obtain this definition.
c13182ef 439Setting the
bcdd964e 440.B _FILE_OFFSET_BITS
9f3d8b28
MK
441feature test macro to 64 (rather than using
442.BR O_LARGEFILE )
12e263f1 443is the preferred
9f3d8b28 444method of accessing large files on 32-bit systems (see
2dcbf4f7 445.BR feature_test_macros (7)).
1c1e15ed 446.TP
31c1f2b0 447.BR O_NOATIME " (since Linux 2.6.8)"
1bb72c96
MK
448Do not update the file last access time
449.RI ( st_atime
450in the inode)
310b7919 451when the file is
1c1e15ed
MK
452.BR read (2).
453This flag is intended for use by indexing or backup programs,
454where its use can significantly reduce the amount of disk activity.
9ee4a2b6 455This flag may not be effective on all filesystems.
1c1e15ed 456One example is NFS, where the server maintains the access time.
0e1ad98c 457.\" The O_NOATIME flag also affects the treatment of st_atime
92057f4d 458.\" by mmap() and readdir(2), MTK, Dec 04.
1c1e15ed 459.TP
fea681da
MK
460.B O_NOCTTY
461If
462.I pathname
5503c85e 463refers to a terminal device\(emsee
1bb72c96
MK
464.BR tty (4)\(emit
465will not become the process's controlling terminal even if the
fea681da
MK
466process does not have one.
467.TP
1c1e15ed 468.B O_NOFOLLOW
a8d55537 469If \fIpathname\fP is a symbolic link, then the open fails.
c13182ef 470This is a FreeBSD extension, which was added to Linux in version 2.1.126.
1c1e15ed 471Symbolic links in earlier components of the pathname will still be
e366dbc4 472followed.
1135dbe1 473See also
843068bd 474.BR O_PATH
1135dbe1 475below.
e366dbc4
MK
476.\" The headers from glibc 2.0.100 and later include a
477.\" definition of this flag; \fIkernels before 2.1.126 will ignore it if
a8d55537 478.\" used\fP.
fea681da
MK
479.TP
480.BR O_NONBLOCK " or " O_NDELAY
ff40dbb3 481When possible, the file is opened in nonblocking mode.
c13182ef 482Neither the
1c1e15ed 483.BR open ()
fea681da
MK
484nor any subsequent operations on the file descriptor which is
485returned will cause the calling process to wait.
486For the handling of FIFOs (named pipes), see also
af5b2ef2 487.BR fifo (7).
db28bfac 488For a discussion of the effect of
0daa9e92 489.B O_NONBLOCK
db28bfac
MK
490in conjunction with mandatory file locks and with file leases, see
491.BR fcntl (2).
fea681da 492.TP
1135dbe1
MK
493.BR O_PATH " (since Linux 2.6.39)"
494.\" commit 1abf0c718f15a56a0a435588d1b104c7a37dc9bd
495.\" commit 326be7b484843988afe57566b627fb7a70beac56
496.\" commit 65cfc6722361570bfe255698d9cd4dccaf47570d
497.\"
498.\" http://thread.gmane.org/gmane.linux.man/2790/focus=3496
499.\" Subject: Re: [PATCH] open(2): document O_PATH
500.\" Newsgroups: gmane.linux.man, gmane.linux.kernel
501.\"
1135dbe1 502Obtain a file descriptor that can be used for two purposes:
9ee4a2b6 503to indicate a location in the filesystem tree and
1135dbe1
MK
504to perform operations that act purely at the file descriptor level.
505The file itself is not opened, and other file operations (e.g.,
506.BR read (2),
507.BR write (2),
508.BR fchmod (2),
509.BR fchown (2),
2510e4e5
RH
510.BR fgetxattr (2),
511.BR mmap (2))
1135dbe1
MK
512fail with the error
513.BR EBADF .
514
515The following operations
516.I can
517be performed on the resulting file descriptor:
518.RS
519.IP * 3
520.BR close (2);
521.BR fchdir (2)
522(since Linux 3.5);
523.\" commit 332a2e1244bd08b9e3ecd378028513396a004a24
524.BR fstat (2)
525(since Linux 3.6).
526.\" fstat(): commit 55815f70147dcfa3ead5738fd56d3574e2e3c1c2
527.IP *
528Duplicating the file descriptor
529.RB ( dup (2),
530.BR fcntl (2)
531.BR F_DUPFD ,
532etc.).
533.IP *
534Getting and setting file descriptor flags
535.RB ( fcntl (2)
536.BR F_GETFD
537and
538.BR F_SETFD ).
09f677a3
MK
539.IP *
540Retrieving open file status flags using the
541.BR fcntl (2)
13a082cb 542.BR F_GETFL
09f677a3
MK
543operation: the returned flags will include the bit
544.BR O_PATH .
545
1135dbe1
MK
546.IP *
547Passing the file descriptor as the
548.IR dirfd
549argument of
550.BR openat (2)
551and the other "*at()" system calls.
552.IP *
553Passing the file descriptor to another process via a UNIX domain socket
554(see
555.BR SCM_RIGHTS
556in
557.BR unix (7)).
558.RE
559.IP
560When
561.B O_PATH
562is specified in
563.IR flags ,
564flag bits other than
565.BR O_DIRECTORY
566and
567.BR O_NOFOLLOW
568are ignored.
569
570If the
571.BR O_NOFOLLOW
572flag is also specified,
573then the call returns a file descriptor referring to the symbolic link.
574This file descriptor can be used as the
575.I dirfd
576argument in calls to
577.BR fchownat (2),
578.BR fstatat (2),
579.BR linkat (2),
580and
581.BR readlinkat (2)
582with an empty pathname to have the calls operate on the symbolic link.
583.TP
fea681da 584.B O_SYNC
6cf19e62
MK
585Write operations on the file will complete according to the requirements of
586synchronized I/O
587.I file
588integrity completion
589(by contrast with contrast with the
590synchronized I/O
591.I data
592integrity completion
593provided by
594.BR O_DSYNC .)
595
596By the time
597.BR write (2)
598(and similar)
599return, the output data and associated file metadata
600have been transferred to the underlying hardware
601(i.e., as though each
602.BR write (2)
603was followed by a call to
604.BR fsync (2)).
605.IR "See NOTES below" .
fea681da 606.TP
40398c1a
MK
607.BR O_TMPFILE " (since Linux 3.11)"
608.\" commit 60545d0d4610b02e55f65d141c95b18ccf855b6e
609.\" commit f4e0c30c191f87851c4a53454abb55ee276f4a7e
610.\" commit bb458c644a59dbba3a1fe59b27106c5e68e1c4bd
611Create an unnamed temporary file.
612The
613.I pathname
614argument specifies a directory;
615an unnamed inode will be created in that directory's filesystem.
616Anything written to the resulting file will be lost when
617the last file descriptor is closed, unless the file is given a name.
618
619.B O_TMPFILE
620must be specified with one of
621.B O_RDWR
622or
623.B O_WRONLY
624and, optionally,
625.BR O_EXCL .
626If
627.B O_EXCL
628is not specified, then
629.BR linkat (2)
630can be used to link the temporary file into the filesystem, making it
631permanent, using code like the following:
632
633.in +4n
634.nf
635char path[PATH_MAX];
636fd = open("/path/to/dir", O_TMPFILE | O_RDWR,
0fb83d00
MK
637 S_IRUSR | S_IWUSR);
638
40398c1a 639/* File I/O on 'fd'... */
0fb83d00 640
40398c1a 641snprintf(path, PATH_MAX, "/proc/self/fd/%d", fd);
e1252130 642linkat(AT_FDCWD, path, AT_FDCWD, "/path/for/file",
0fb83d00 643 AT_SYMLINK_FOLLOW);
40398c1a
MK
644.fi
645.in
646
647In this case,
648the
649.BR open ()
650.I mode
651argument determines the file permission mode, as with
652.BR O_CREAT .
653
0115aaed
MK
654Specifying
655.B O_EXCL
656in conjunction with
657.B O_TMPFILE
658prevents a temporary file from being linked into the filesystem
659in the above manner.
660(Note that the meaning of
661.B O_EXCL
662in this case is different from the meaning of
663.B O_EXCL
664otherwise.)
665
666
40398c1a
MK
667There are two main use cases for
668.\" Inspired by http://lwn.net/Articles/559147/
669.BR O_TMPFILE :
670.RS
671.IP * 3
672Improved
673.BR tmpfile (3)
674functionality: race-free creation of temporary files that
675(1) are automatically deleted when closed;
676(2) can never be reached via any pathname;
677(3) are not subject to symlink attacks; and
678(4) do not require the caller to devise unique names.
679.IP *
680Creating a file that is initially invisible, which is then populated
8b04592d 681with data and adjusted to have appropriate filesystem attributes
40398c1a
MK
682.RB ( chown (2),
683.BR chmod (2),
684.BR fsetxattr (2),
685etc.)
686before being atomically linked into the filesystem
687in a fully formed state (using
688.BR linkat (2)
689as described above).
690.RE
691.IP
692.B O_TMPFILE
693requires support by the underlying filesystem;
694.\" As at 3.13, there's support for at least ext2, ext3, ext4
695only a subset of Linux filesystems provide that support.
696.TP
1c1e15ed 697.B O_TRUNC
4d61d36a 698If the file already exists and is a regular file and the access mode allows
682edefb
MK
699writing (i.e., is
700.B O_RDWR
701or
702.BR O_WRONLY )
703it will be truncated to length 0.
704If the file is a FIFO or terminal device file, the
705.B O_TRUNC
c13182ef 706flag is ignored.
682edefb
MK
707Otherwise the effect of
708.B O_TRUNC
709is unspecified.
7b8ba76c 710.SS creat()
1c1e15ed 711.BR creat ()
fea681da 712is equivalent to
1c1e15ed 713.BR open ()
fea681da
MK
714with
715.I flags
716equal to
717.BR O_CREAT|O_WRONLY|O_TRUNC .
7b8ba76c
MK
718.SS openat()
719The
720.BR openat ()
721system call operates in exactly the same way as
cadd38ba 722.BR open (),
7b8ba76c
MK
723except for the differences described here.
724
725If the pathname given in
726.I pathname
727is relative, then it is interpreted relative to the directory
5dc8986d 728 to by the file descriptor
7b8ba76c
MK
729.I dirfd
730(rather than relative to the current working directory of
731the calling process, as is done by
cadd38ba 732.BR open ()
7b8ba76c
MK
733for a relative pathname).
734
735If
736.I pathname
737is relative and
738.I dirfd
739is the special value
740.BR AT_FDCWD ,
741then
742.I pathname
743is interpreted relative to the current working
744directory of the calling process (like
cadd38ba 745.BR open ()).
7b8ba76c
MK
746
747If
748.I pathname
749is absolute, then
750.I dirfd
751is ignored.
47297adb 752.SH RETURN VALUE
7b8ba76c
MK
753.BR open (),
754.BR openat (),
c13182ef 755and
e1d6264d 756.BR creat ()
1c1e15ed
MK
757return the new file descriptor, or \-1 if an error occurred
758(in which case,
fea681da
MK
759.I errno
760is set appropriately).
fea681da 761.SH ERRORS
7b8ba76c
MK
762.BR open (),
763.BR openat (),
764and
765.BR creat ()
766can fail with the following errors:
fea681da
MK
767.TP
768.B EACCES
769The requested access to the file is not allowed, or search permission
770is denied for one of the directories in the path prefix of
771.IR pathname ,
772or the file did not exist yet and write access to the parent directory
773is not allowed.
774(See also
ad7cc990 775.BR path_resolution (7).)
fea681da 776.TP
a1f01685
MH
777.B EDQUOT
778Where
779.B O_CREAT
780is specified, the file does not exist, and the user's quota of disk
9ee4a2b6 781blocks or inodes on the filesystem has been exhausted.
a1f01685 782.TP
fea681da
MK
783.B EEXIST
784.I pathname
785already exists and
786.BR O_CREAT " and " O_EXCL
787were used.
788.TP
789.B EFAULT
0daa9e92 790.I pathname
e1d6264d 791points outside your accessible address space.
fea681da 792.TP
9f5773f7 793.B EFBIG
7c7fb552
MK
794See
795.BR EOVERFLOW .
9f5773f7 796.TP
e51412ea
MK
797.B EINTR
798While blocked waiting to complete an open of a slow device
799(e.g., a FIFO; see
800.BR fifo (7)),
801the call was interrupted by a signal handler; see
802.BR signal (7).
803.TP
ef490193
DG
804.B EINVAL
805The filesystem does not support the
806.BR O_DIRECT
e6f89ed2
MK
807flag.
808See
ef490193
DG
809.BR NOTES
810for more information.
811.TP
8e335391
MK
812.B EINVAL
813Invalid value in
814.\" In particular, __O_TMPFILE instead of O_TMPFILE
815.IR flags .
816.TP
817.B EINVAL
818.B O_TMPFILE
819was specified in
820.IR flags ,
821but neither
822.B O_WRONLY
823nor
824.B O_RDWR
825was specified.
826.TP
fea681da
MK
827.B EISDIR
828.I pathname
829refers to a directory and the access requested involved writing
830(that is,
831.B O_WRONLY
832or
833.B O_RDWR
834is set).
835.TP
8e335391 836.B EISDIR
843068bd
MK
837.I pathname
838refers to an existing directory,
8e335391
MK
839.B O_TMPFILE
840and one of
841.B O_WRONLY
842or
843.B O_RDWR
844were specified in
845.IR flags ,
846but this kernel version does not provide the
847.B O_TMPFILE
848functionality.
849.TP
fea681da
MK
850.B ELOOP
851Too many symbolic links were encountered in resolving
852.IR pathname ,
a8d55537 853or \fBO_NOFOLLOW\fP was specified but
fea681da
MK
854.I pathname
855was a symbolic link.
856.TP
857.B EMFILE
858The process already has the maximum number of files open.
859.TP
860.B ENAMETOOLONG
0daa9e92 861.I pathname
e1d6264d 862was too long.
fea681da
MK
863.TP
864.B ENFILE
865The system limit on the total number of open files has been reached.
866.TP
867.B ENODEV
868.I pathname
869refers to a device special file and no corresponding device exists.
682edefb
MK
870(This is a Linux kernel bug; in this situation
871.B ENXIO
872must be returned.)
fea681da
MK
873.TP
874.B ENOENT
682edefb
MK
875.B O_CREAT
876is not set and the named file does not exist.
fea681da
MK
877Or, a directory component in
878.I pathname
879does not exist or is a dangling symbolic link.
880.TP
ba03011f
MK
881.B ENOENT
882.I pathname
883refers to a nonexistent directory,
884.B O_TMPFILE
885and one of
886.B O_WRONLY
887or
888.B O_RDWR
889were specified in
890.IR flags ,
891but this kernel version does not provide the
892.B O_TMPFILE
893functionality.
894.TP
fea681da
MK
895.B ENOMEM
896Insufficient kernel memory was available.
897.TP
898.B ENOSPC
899.I pathname
900was to be created but the device containing
901.I pathname
902has no room for the new file.
903.TP
904.B ENOTDIR
905A component used as a directory in
906.I pathname
a8d55537 907is not, in fact, a directory, or \fBO_DIRECTORY\fP was specified and
fea681da
MK
908.I pathname
909was not a directory.
910.TP
911.B ENXIO
682edefb
MK
912.BR O_NONBLOCK " | " O_WRONLY
913is set, the named file is a FIFO and
fea681da
MK
914no process has the file open for reading.
915Or, the file is a device special file and no corresponding device exists.
916.TP
bbe02b45
MK
917.BR EOPNOTSUPP
918The filesystem containing
919.I pathname
920does not support
921.BR O_TMPFILE .
922.TP
7c7fb552
MK
923.B EOVERFLOW
924.I pathname
925refers to a regular file that is too large to be opened.
926The usual scenario here is that an application compiled
927on a 32-bit platform without
5e4dc269 928.I -D_FILE_OFFSET_BITS=64
7c7fb552
MK
929tried to open a file whose size exceeds
930.I (2<<31)-1
931bits;
932see also
933.B O_LARGEFILE
934above.
935This is the error specified by POSIX.1-2001;
936in kernels before 2.6.24, Linux gave the error
937.B EFBIG
938for this case.
939.\" See http://bugzilla.kernel.org/show_bug.cgi?id=7253
940.\" "Open of a large file on 32-bit fails with EFBIG, should be EOVERFLOW"
941.\" Reported 2006-10-03
942.TP
1c1e15ed
MK
943.B EPERM
944The
945.B O_NOATIME
946flag was specified, but the effective user ID of the caller
9ee4a2b6 947.\" Strictly speaking, it's the filesystem UID... (MTK)
1c1e15ed
MK
948did not match the owner of the file and the caller was not privileged
949.RB ( CAP_FOWNER ).
950.TP
fea681da
MK
951.B EROFS
952.I pathname
9ee4a2b6 953refers to a file on a read-only filesystem and write access was
fea681da
MK
954requested.
955.TP
956.B ETXTBSY
957.I pathname
958refers to an executable image which is currently being executed and
959write access was requested.
d3952311
MK
960.TP
961.B EWOULDBLOCK
962The
963.B O_NONBLOCK
964flag was specified, and an incompatible lease was held on the file
965(see
966.BR fcntl (2)).
7b8ba76c
MK
967.PP
968The following additional errors can occur for
969.BR openat ():
970.TP
971.B EBADF
972.I dirfd
973is not a valid file descriptor.
974.TP
975.B ENOTDIR
976.I pathname
977is relative and
978.I dirfd
979is a file descriptor referring to a file other than a directory.
980.SH VERSIONS
981.BR openat ()
982was added to Linux in kernel 2.6.16;
983library support was added to glibc in version 2.4.
47297adb 984.SH CONFORMING TO
7b8ba76c
MK
985.BR open (),
986.BR creat ()
72ac7268
MK
987SVr4, 4.3BSD, POSIX.1-2001, POSIX.1-2008.
988
7b8ba76c
MK
989.BR openat ():
990POSIX.1-2008.
7b8ba76c 991
fea681da 992The
72ac7268 993.BR O_DIRECT ,
1c1e15ed 994.BR O_NOATIME ,
72ac7268 995.BR O_PATH ,
fea681da 996and
72ac7268
MK
997.BR O_TMPFILE
998flags are Linux-specific.
999One must define
61b7c1e1
MK
1000.B _GNU_SOURCE
1001to obtain their definitions.
9f91e36c
MK
1002
1003The
72ac7268
MK
1004.BR O_CLOEXEC ,
1005.BR O_DIRECTORY ,
1006and
1007.BR O_NOFOLLOW
1008flags are not specified in POSIX.1-2001,
1009but are specified in POSIX.1-2008.
1010Since glibc 2.12, one can obtain their definitions by defining either
1011.B _POSIX_C_SOURCE
1012with a value greater than or equal to 200809L or
1013.BR _XOPEN_SOURCE
1014with a value greater than or equal to 700.
1015In glibc 2.11 and earlier, one obtains the definitions by defining
1016.BR _GNU_SOURCE .
9f91e36c 1017
72ac7268
MK
1018As noted in
1019.BR feature_test_macros (7),
84fc2a6e 1020feature test macros such as
72ac7268
MK
1021.BR _POSIX_C_SOURCE ,
1022.BR _XOPEN_SOURCE ,
1023and
fe75ec04 1024.B _GNU_SOURCE
72ac7268 1025must be defined before including
e417acb0 1026.I any
72ac7268 1027header files.
a1d5f77c 1028.SH NOTES
988db661 1029Under Linux, the
a1d5f77c
MK
1030.B O_NONBLOCK
1031flag indicates that one wants to open
1032but does not necessarily have the intention to read or write.
1033This is typically used to open devices in order to get a file descriptor
1034for use with
1035.BR ioctl (2).
c734b9f2 1036
fea681da
MK
1037.LP
1038The (undefined) effect of
1039.B O_RDONLY | O_TRUNC
c13182ef 1040varies among implementations.
bcdd964e 1041On many systems the file is actually truncated.
fea681da
MK
1042.\" Linux 2.0, 2.5: truncate
1043.\" Solaris 5.7, 5.8: truncate
1044.\" Irix 6.5: truncate
1045.\" Tru64 5.1B: truncate
1046.\" HP-UX 11.22: truncate
1047.\" FreeBSD 4.7: truncate
a1d5f77c 1048
5dc8986d
MK
1049Note that
1050.BR open ()
1051can open device special files, but
1052.BR creat ()
1053cannot create them; use
1054.BR mknod (2)
1055instead.
1056
1057If the file is newly created, its
1058.IR st_atime ,
1059.IR st_ctime ,
1060.I st_mtime
1061fields
1062(respectively, time of last access, time of last status change, and
1063time of last modification; see
1064.BR stat (2))
1065are set
1066to the current time, and so are the
1067.I st_ctime
1068and
1069.I st_mtime
1070fields of the
1071parent directory.
1072Otherwise, if the file is modified because of the
1073.B O_TRUNC
1074flag, its st_ctime and st_mtime fields are set to the current time.
1075.\"
1076.\"
1077.SS Synchronized I/O
6cf19e62
MK
1078The POSIX.1-2008 "synchronized I/O" option
1079specifies different variants of synchronized I/O,
1080and specifies the
1081.BR open ()
1082flags
015221ef
CH
1083.BR O_SYNC ,
1084.BR O_DSYNC ,
1085and
6cf19e62
MK
1086.BR O_RSYNC
1087for controlling the behavior.
1088Regardless of whether an implementation supports this option,
1089it must at least support the use of
1090.BR O_SYNC
1091for regular files.
1092
1093Linux implements
1094.BR O_SYNC
1095and
1096.BR O_DSYNC ,
1097but not
015221ef 1098.BR O_RSYNC .
6cf19e62
MK
1099(Somewhat incorrectly, glibc defines
1100.BR O_RSYNC
1101to have the same value as
1102.BR O_SYNC .)
1103
1104.BR O_SYNC
1105provides synchronized I/O
1106.I file
1107integrity completion,
1108meaning write operations will flush data and all associated metadata
1109to the underlying hardware.
1110.BR O_DSYNC
1111provides synchronized I/O
1112.I data
1113integrity completion,
1114meaning write operations will flush data
1115to the underlying hardware,
1116but will only flush metadata updates that are required
1117to allow a subsequent read operation to complete successfully.
1118Data integrity completion can reduce the number of disk operations
1119that are required for applications that don't need the guarantees
1120of file integrity completion.
1121
1122To understand the difference between the the two types of completion,
1123consider two pieces of file metadata:
1124the file last modification timestamp
1125.RI ( st_mtime )
1126and the file length.
1127All write operations will update the last file modification timestamp,
1128but only writes that add data to the end of the
1129file will change the file length.
1130The last modification timestamp is not needed to ensure that
1131a read completes successfully, but the file length is.
1132Thus,
1133.BR O_DSYNC
1134would only guarantee to flush updates to the file length metadata
1135(whereas
1136.BR O_SYNC
1137would also always flush the last modification timestamp metadata).
1138
1139Before Linux 2.6.33, Linux implemented only the
1140.BR O_SYNC
1141flag for
1142.BR open ().
1143However, when that flag was specified,
1144most filesystems actually provided the equivalent of synchronized I/O
1145.I data
1146integrity completion (i.e.,
1147.BR O_SYNC
1148was actually implemented as the equivalent of
1149.BR O_DSYNC ).
1150
1151Since Linux 2.6.33, proper
1152.BR O_SYNC
1153support is provided.
1154However, to ensure backward binary compatibility,
1155.BR O_DSYNC
1156was defined with the same value as the historical
015221ef 1157.BR O_SYNC ,
015221ef 1158and
6cf19e62
MK
1159.BR O_SYNC
1160was defined as a new (two-bit) flag value that includes the
1161.BR O_DSYNC
1162flag value.
1163This ensures that applications compiled against
1164new headers get at least
1165.BR O_DSYNC
1166semantics on pre-2.6.33 kernels.
5dc8986d
MK
1167.\"
1168.\"
1169.SS NFS
1170There are many infelicities in the protocol underlying NFS, affecting
1171amongst others
1172.BR O_SYNC " and " O_NDELAY .
a1d5f77c 1173
9ee4a2b6 1174On NFS filesystems with UID mapping enabled,
a1d5f77c
MK
1175.BR open ()
1176may
75b94dc3 1177return a file descriptor but, for example,
a1d5f77c
MK
1178.BR read (2)
1179requests are denied
1180with \fBEACCES\fP.
1181This is because the client performs
1182.BR open ()
1183by checking the
1184permissions, but UID mapping is performed by the server upon
1185read and write requests.
5dc8986d
MK
1186.\"
1187.\"
1188.SS File access mode
1189Unlike the other values that can be specified in
1190.IR flags ,
1191the
1192.I "access mode"
1193values
1194.BR O_RDONLY ", " O_WRONLY ", and " O_RDWR
1195do not specify individual bits.
1196Rather, they define the low order two bits of
1197.IR flags ,
1198and are defined respectively as 0, 1, and 2.
1199In other words, the combination
1200.B "O_RDONLY | O_WRONLY"
1201is a logical error, and certainly does not have the same meaning as
1202.BR O_RDWR .
a1d5f77c 1203
5dc8986d
MK
1204Linux reserves the special, nonstandard access mode 3 (binary 11) in
1205.I flags
1206to mean:
1207check for read and write permission on the file and return a descriptor
1208that can't be used for reading or writing.
1209This nonstandard access mode is used by some Linux drivers to return a
1210descriptor that is to be used only for device-specific
1211.BR ioctl (2)
1212operations.
1213.\" See for example util-linux's disk-utils/setfdprm.c
1214.\" For some background on access mode 3, see
1215.\" http://thread.gmane.org/gmane.linux.kernel/653123
1216.\" "[RFC] correct flags to f_mode conversion in __dentry_open"
1217.\" LKML, 12 Mar 2008
7b8ba76c
MK
1218.\"
1219.\"
1220.SS Rationale for openat() and the other *at() calls
1221.BR openat ()
1222and other similar system calls and library functions suffixed "at"
1223(i.e.,
1224.BR faccessat (2),
1225.BR fchmodat (2),
1226.BR fchownat (2),
1227.BR fstatat (2),
1228.BR futimesat (2),
1229.BR linkat (2),
1230.BR mkdirat (2),
1231.BR mknodat (2),
1232.BR readlinkat (2),
1233.BR renameat (2),
1234.BR symlinkat (2),
1235.BR unlinkat (2),
1236.BR utimensat (2)
1237and
1238.BR mkfifoat (3))
1239are supported
1240for two reasons.
92692952 1241Here, the explanation is in terms of the
7b8ba76c
MK
1242.BR openat ()
1243call, but the rationale is the analogous for the other interfaces.
1244
1245First,
1246.BR openat ()
1247allows an application to avoid race conditions that could
1248occur when using
cadd38ba 1249.BR open ()
7b8ba76c
MK
1250to open files in directories other than the current working directory.
1251These race conditions result from the fact that some component
1252of the directory prefix given to
cadd38ba 1253.BR open ()
7b8ba76c 1254could be changed in parallel with the call to
cadd38ba 1255.BR open ().
7b8ba76c
MK
1256Such races can be avoided by
1257opening a file descriptor for the target directory,
1258and then specifying that file descriptor as the
1259.I dirfd
1260argument of
1261.BR openat ().
1262
1263Second,
1264.BR openat ()
1265allows the implementation of a per-thread "current working
1266directory", via file descriptor(s) maintained by the application.
1267(This functionality can also be obtained by tricks based
1268on the use of
1269.IR /proc/self/fd/ dirfd,
1270but less efficiently.)
1271.\"
1272.\"
ddc4d339
MK
1273.SS O_DIRECT
1274.LP
1275The
1276.B O_DIRECT
1277flag may impose alignment restrictions on the length and address
7fac88a9 1278of user-space buffers and the file offset of I/Os.
ddc4d339 1279In Linux alignment
9ee4a2b6 1280restrictions vary by filesystem and kernel version and might be
ddc4d339 1281absent entirely.
9ee4a2b6 1282However there is currently no filesystem\-independent
ddc4d339 1283interface for an application to discover these restrictions for a given
9ee4a2b6
MK
1284file or filesystem.
1285Some filesystems provide their own interfaces
ddc4d339
MK
1286for doing so, for example the
1287.B XFS_IOC_DIOINFO
1288operation in
1289.BR xfsctl (3).
1290.LP
85c2bdba
MK
1291Under Linux 2.4, transfer sizes, and the alignment of the user buffer
1292and the file offset must all be multiples of the logical block size
9ee4a2b6 1293of the filesystem.
04cd7f64 1294Under Linux 2.6, alignment to 512-byte boundaries suffices.
1847167b
NP
1295.LP
1296.B O_DIRECT
1297I/Os should never be run concurrently with the
04cd7f64 1298.BR fork (2)
1847167b
NP
1299system call,
1300if the memory buffer is a private mapping
1301(i.e., any mapping created with the
02ace852 1302.BR mmap (2)
1847167b 1303.BR MAP_PRIVATE
0ab8aeec 1304flag;
1847167b
NP
1305this includes memory allocated on the heap and statically allocated buffers).
1306Any such I/Os, whether submitted via an asynchronous I/O interface or from
1307another thread in the process,
1308should be completed before
1309.BR fork (2)
1310is called.
1311Failure to do so can result in data corruption and undefined behavior in
1312parent and child processes.
1313This restriction does not apply when the memory buffer for the
1314.B O_DIRECT
1315I/Os was created using
1316.BR shmat (2)
1317or
1318.BR mmap (2)
1319with the
1320.B MAP_SHARED
1321flag.
1322Nor does this restriction apply when the memory buffer has been advised as
1323.B MADV_DONTFORK
0ab8aeec 1324with
02ace852 1325.BR madvise (2),
1847167b
NP
1326ensuring that it will not be available
1327to the child after
1328.BR fork (2).
ddc4d339
MK
1329.LP
1330The
1331.B O_DIRECT
1332flag was introduced in SGI IRIX, where it has alignment
1333restrictions similar to those of Linux 2.4.
1334IRIX has also a
1335.BR fcntl (2)
1336call to query appropriate alignments, and sizes.
1337FreeBSD 4.x introduced
1338a flag of the same name, but without alignment restrictions.
1339.LP
1340.B O_DIRECT
1341support was added under Linux in kernel version 2.4.10.
1342Older Linux kernels simply ignore this flag.
9ee4a2b6 1343Some filesystems may not implement the flag and
ddc4d339
MK
1344.BR open ()
1345will fail with
1346.B EINVAL
1347if it is used.
1348.LP
1349Applications should avoid mixing
1350.B O_DIRECT
1351and normal I/O to the same file,
1352and especially to overlapping byte regions in the same file.
9ee4a2b6 1353Even when the filesystem correctly handles the coherency issues in
ddc4d339
MK
1354this situation, overall I/O throughput is likely to be slower than
1355using either mode alone.
1356Likewise, applications should avoid mixing
1357.BR mmap (2)
1358of files with direct I/O to the same files.
1359.LP
1360The behaviour of
1361.B O_DIRECT
9ee4a2b6 1362with NFS will differ from local filesystems.
ddc4d339
MK
1363Older kernels, or
1364kernels configured in certain ways, may not support this combination.
1365The NFS protocol does not support passing the flag to the server, so
1366.B O_DIRECT
33a0ccb2 1367I/O will bypass the page cache only on the client; the server may
ddc4d339
MK
1368still cache the I/O.
1369The client asks the server to make the I/O
1370synchronous to preserve the synchronous semantics of
1371.BR O_DIRECT .
1372Some servers will perform poorly under these circumstances, especially
1373if the I/O size is small.
1374Some servers may also be configured to
1375lie to clients about the I/O having reached stable storage; this
1376will avoid the performance penalty at some risk to data integrity
1377in the event of server power failure.
1378The Linux NFS client places no alignment restrictions on
1379.B O_DIRECT
1380I/O.
1381.PP
1382In summary,
1383.B O_DIRECT
1384is a potentially powerful tool that should be used with caution.
1385It is recommended that applications treat use of
1386.B O_DIRECT
1387as a performance option which is disabled by default.
1388.PP
1389.RS
fea681da
MK
1390"The thing that has always disturbed me about O_DIRECT is that the whole
1391interface is just stupid, and was probably designed by a deranged monkey
5503c85e 1392on some serious mind-controlling substances."\(emLinus
ddc4d339
MK
1393.RE
1394.SH BUGS
b50582eb
MK
1395Currently, it is not possible to enable signal-driven
1396I/O by specifying
1397.B O_ASYNC
c13182ef 1398when calling
b50582eb
MK
1399.BR open ();
1400use
1401.BR fcntl (2)
1402to enable this flag.
0e1ad98c 1403.\" FIXME . Check bugzilla report on open(O_ASYNC)
92057f4d 1404.\" See http://bugzilla.kernel.org/show_bug.cgi?id=5993
0d730fcc
MK
1405
1406One must check for two different error codes,
1407.B EISDIR
1408and
1409.BR ENOENT ,
1410when trying to determine whether the kernel supports
0d55b37f 1411.B O_TMPFILE
0d730fcc 1412functionality.
47297adb 1413.SH SEE ALSO
a3bf8022
MK
1414.BR chmod (2),
1415.BR chown (2),
fea681da 1416.BR close (2),
e366dbc4 1417.BR dup (2),
fea681da
MK
1418.BR fcntl (2),
1419.BR link (2),
1f6ceb40 1420.BR lseek (2),
fea681da 1421.BR mknod (2),
e366dbc4 1422.BR mmap (2),
f0c34053 1423.BR mount (2),
fea681da
MK
1424.BR read (2),
1425.BR socket (2),
1426.BR stat (2),
1427.BR umask (2),
1428.BR unlink (2),
1429.BR write (2),
1430.BR fopen (3),
f0c34053 1431.BR fifo (7),
a9cfde1d
MK
1432.BR path_resolution (7),
1433.BR symlink (7)