diff options
Diffstat (limited to 'man2/open.2')
-rw-r--r-- | man2/open.2 | 320 |
1 files changed, 161 insertions, 159 deletions
diff --git a/man2/open.2 b/man2/open.2 index f37ddbed0..300046bde 100644 --- a/man2/open.2 +++ b/man2/open.2 @@ -53,7 +53,7 @@ Standard C library .P .RS -4 Feature Test Macro Requirements for glibc (see -.BR feature_test_macros (7)): +.MR feature_test_macros 7 ): .RE .P .BR openat (): @@ -83,26 +83,26 @@ to an entry in the process's table of open file descriptors. The file descriptor is used in subsequent system calls (\c -.BR read (2), -.BR write (2), -.BR lseek (2), -.BR fcntl (2), +.MR read 2 , +.MR write 2 , +.MR lseek 2 , +.MR fcntl 2 , etc.) to refer to the open file. The file descriptor returned by a successful call will be the lowest-numbered file descriptor not currently open for the process. .P By default, the new file descriptor is set to remain open across an -.BR execve (2) +.MR execve 2 (i.e., the .B FD_CLOEXEC file descriptor flag described in -.BR fcntl (2) +.MR fcntl 2 is initially disabled); the .B O_CLOEXEC flag, described below, can be used to change this default. The file offset is set to the beginning of the file (see -.BR lseek (2)). +.MR lseek 2 ). .P A call to .BR open () @@ -162,7 +162,7 @@ the file creation flags affect the semantics of the open operation itself, while the file status flags affect the semantics of subsequent I/O operations. The file status flags can be retrieved and (in some cases) modified; see -.BR fcntl (2) +.MR fcntl 2 for details. .P The full list of file creation flags and file status flags is as follows: @@ -170,10 +170,10 @@ The full list of file creation flags and file status flags is as follows: .B O_APPEND The file is opened in append mode. Before each -.BR write (2), +.MR write 2 , the file offset is positioned at the end of the file, as if with -.BR lseek (2). +.MR lseek 2 . The modification of the file offset and the write operation are performed as a single atomic step. .IP @@ -192,12 +192,12 @@ Enable signal-driven I/O: generate a signal .RB ( SIGIO by default, but this can be changed via -.BR fcntl (2)) +.MR fcntl 2 ) when input or output becomes possible on this file descriptor. This feature is available only for terminals, pseudoterminals, sockets, and (since Linux 2.6) pipes and FIFOs. See -.BR fcntl (2) +.MR fcntl 2 for further details. See also BUGS, below. .TP @@ -209,7 +209,7 @@ Enable the close-on-exec flag for the new file descriptor. .\" http://austingroupbugs.net/tag_view_page.php?tag_id=8 .\" http://austingroupbugs.net/view.php?id=368 Specifying this flag permits a program to avoid additional -.BR fcntl (2) +.MR fcntl 2 .B F_SETFD operations to set the .B FD_CLOEXEC @@ -217,24 +217,24 @@ flag. .IP Note that the use of this flag is essential in some multithreaded programs, because using a separate -.BR fcntl (2) +.MR fcntl 2 .B F_SETFD operation to set the .B FD_CLOEXEC flag does not suffice to avoid race conditions where one thread opens a file descriptor and attempts to set its close-on-exec flag using -.BR fcntl (2) +.MR fcntl 2 at the same time as another thread does a -.BR fork (2) +.MR fork 2 plus -.BR execve (2). +.MR execve 2 . Depending on the order of execution, the race may lead to the file descriptor returned by .BR open () being unintentionally leaked to the program executed by the child process created by -.BR fork (2). +.MR fork 2 . (This kind of race is in principle possible for any system call that creates a file descriptor whose close-on-exec flag should be set, and various other Linux system calls provide an equivalent of the @@ -264,7 +264,7 @@ For some filesystems, the behavior also depends on the and .I sysvgroups mount options described in -.BR mount (8). +.MR mount 8 . .\" As at Linux 2.6.25, bsdgroups is supported by ext2, ext3, ext4, and .\" XFS (since Linux 2.6.14). .IP @@ -360,11 +360,11 @@ On Linux, the following bits are also honored in .TP .B S_ISGID 0002000 set-group-ID bit (see -.BR inode (7)). +.MR inode 7 ). .TP .B S_ISVTX 0001000 sticky bit (see -.BR inode (7)). +.MR inode 7 ). .RE .TP .BR O_DIRECT " (since Linux 2.4.10)" @@ -386,7 +386,7 @@ See NOTES below for further discussion. .IP A semantically similar (but deprecated) interface for block devices is described in -.BR raw (8). +.MR raw 8 . .TP .B O_DIRECTORY If \fIpathname\fP is not a directory, cause the open to fail. @@ -396,7 +396,7 @@ If \fIpathname\fP is not a directory, cause the open to fail. .\" O_DIRECTORY | O_CREAT causes O_DIRECTORY to be ignored. This flag was added in Linux 2.1.126, to avoid denial-of-service problems if -.BR opendir (3) +.MR opendir 3 is called on a FIFO or tape device. .TP @@ -407,15 +407,15 @@ synchronized I/O integrity completion. .IP By the time -.BR write (2) +.MR write 2 (and similar) return, the output data has been transferred to the underlying hardware, along with any file metadata that would be required to retrieve that data (i.e., as though each -.BR write (2) +.MR write 2 was followed by a call to -.BR fdatasync (2)). +.MR fdatasync 2 ). .IR "See NOTES below" . .TP .B O_EXCL @@ -465,13 +465,13 @@ and need to avoid reliance on NFS support for .BR O_EXCL , can create a unique file on the same filesystem (e.g., incorporating hostname and PID), and use -.BR link (2) +.MR link 2 to make a link to the lockfile. If -.BR link (2) +.MR link 2 returns 0, the lock is successful. Otherwise, use -.BR stat (2) +.MR stat 2 on the unique file to check if its link count has increased to 2, in which case the lock is also successful. .TP @@ -495,14 +495,14 @@ feature test macro to 64 (rather than using .BR O_LARGEFILE ) is the preferred method of accessing large files on 32-bit systems (see -.BR feature_test_macros (7)). +.MR feature_test_macros 7 ). .TP .BR O_NOATIME " (since Linux 2.6.8)" Do not update the file last access time .RI ( st_atime in the inode) when the file is -.BR read (2). +.MR read 2 . .IP This flag can be employed only if one of the following conditions is true: .RS @@ -528,7 +528,7 @@ One example is NFS, where the server maintains the access time. If .I pathname refers to a terminal device\[em]see -.BR tty (4)\[em]it +.MR tty 4 \[em]it will not become the process's controlling terminal even if the process does not have one. .TP @@ -563,9 +563,9 @@ nor any subsequent I/O operations on the file descriptor which is returned will cause the calling process to wait. .IP Note that the setting of this flag has no effect on the operation of -.BR poll (2), -.BR select (2), -.BR epoll (7), +.MR poll 2 , +.MR select 2 , +.MR epoll 7 , and similar, since those interfaces merely inform the caller about whether a file descriptor is "ready", @@ -588,11 +588,11 @@ applications should not depend upon blocking behavior when specifying this flag for regular files and block devices. .IP For the handling of FIFOs (named pipes), see also -.BR fifo (7). +.MR fifo 7 . For a discussion of the effect of .B O_NONBLOCK in conjunction with mandatory file locks and with file leases, see -.BR fcntl (2). +.MR fcntl 2 . .TP .BR O_PATH " (since Linux 2.6.39)" .\" commit 1abf0c718f15a56a0a435588d1b104c7a37dc9bd @@ -607,13 +607,13 @@ Obtain a file descriptor that can be used for two purposes: to indicate a location in the filesystem tree and to perform operations that act purely at the file descriptor level. The file itself is not opened, and other file operations (e.g., -.BR read (2), -.BR write (2), -.BR fchmod (2), -.BR fchown (2), -.BR fgetxattr (2), -.BR ioctl (2), -.BR mmap (2)) +.MR read 2 , +.MR write 2 , +.MR fchmod 2 , +.MR fchown 2 , +.MR fgetxattr 2 , +.MR ioctl 2 , +.MR mmap 2 ) fail with the error .BR EBADF . .IP @@ -622,24 +622,25 @@ The following operations be performed on the resulting file descriptor: .RS .IP \[bu] 3 -.BR close (2). +.MR close 2 . .IP \[bu] -.BR fchdir (2), +.MR fchdir 2 , if the file descriptor refers to a directory (since Linux 3.5). .\" commit 332a2e1244bd08b9e3ecd378028513396a004a24 .IP \[bu] -.BR fstat (2) +.MR fstat 2 (since Linux 3.6). .IP \[bu] .\" fstat(): commit 55815f70147dcfa3ead5738fd56d3574e2e3c1c2 -.BR fstatfs (2) +.MR fstatfs 2 (since Linux 3.12). .\" fstatfs(): commit 9d05746e7b16d8565dddbe3200faa1e669d23bbf .IP \[bu] Duplicating the file descriptor -.RB ( dup (2), -.BR fcntl (2) +\%(\c +.MR dup 2 , +.MR fcntl 2 .BR F_DUPFD , etc.). .IP \[bu] @@ -650,7 +651,7 @@ and .BR F_SETFD ). .IP \[bu] Retrieving open file status flags using the -.BR fcntl (2) +.MR fcntl 2 .B F_GETFL operation: the returned flags will include the bit .BR O_PATH . @@ -661,7 +662,7 @@ argument of .BR openat () and the other "*at()" system calls. This includes -.BR linkat (2) +.MR linkat 2 with .B AT_EMPTY_PATH (or via procfs using @@ -672,7 +673,7 @@ Passing the file descriptor to another process via a UNIX domain socket (see .B SCM_RIGHTS in -.BR unix (7)). +.MR unix 7 ). .RE .IP When @@ -692,7 +693,7 @@ flag requires no permissions on the object itself (but does require execute permission on the directories in the path prefix). Depending on the subsequent operation, a check for suitable file permissions may be performed (e.g., -.BR fchdir (2) +.MR fchdir 2 requires execute permission on the directory referred to by its file descriptor argument). By contrast, @@ -700,8 +701,8 @@ obtaining a reference to a filesystem object by opening it with the .B O_RDONLY flag requires that the caller have read permission on the object, even when the subsequent operation (e.g., -.BR fchdir (2), -.BR fstat (2)) +.MR fchdir 2 , +.MR fstat 2 ) does not require read permission on the object. .IP If @@ -713,11 +714,11 @@ then the call returns a file descriptor referring to the symbolic link. This file descriptor can be used as the .I dirfd argument in calls to -.BR fchownat (2), -.BR fstatat (2), -.BR linkat (2), +.MR fchownat 2 , +.MR fstatat 2 , +.MR linkat 2 , and -.BR readlinkat (2) +.MR readlinkat 2 with an empty pathname to have the calls operate on the symbolic link. .IP If @@ -725,7 +726,7 @@ If refers to an automount point that has not yet been triggered, so no other filesystem is mounted on it, then the call returns a file descriptor referring to the automount directory without triggering a mount. -.BR fstatfs (2) +.MR fstatfs 2 can then be used to determine if it is, in fact, an untriggered automount point .RB ( ".f_type == AUTOFS_SUPER_MAGIC" ). @@ -751,7 +752,7 @@ execl(buf, "some_prog", (char *) NULL); An .B O_PATH file descriptor can also be passed as the argument of -.BR fexecve (3). +.MR fexecve 3 . .TP .B O_SYNC Write operations on the file will complete according to the requirements of @@ -766,14 +767,14 @@ provided by .BR O_DSYNC .) .IP By the time -.BR write (2) +.MR write 2 (or similar) returns, the output data and associated file metadata have been transferred to the underlying hardware (i.e., as though each -.BR write (2) +.MR write 2 was followed by a call to -.BR fsync (2)). +.MR fsync 2 ). .IR "See NOTES below" . .TP .BR O_TMPFILE " (since Linux 3.11)" @@ -798,7 +799,7 @@ and, optionally, If .B O_EXCL is not specified, then -.BR linkat (2) +.MR linkat 2 can be used to link the temporary file into the filesystem, making it permanent, using code like the following: .IP @@ -849,7 +850,7 @@ There are two main use cases for .RS .IP \[bu] 3 Improved -.BR tmpfile (3) +.MR tmpfile 3 functionality: race-free creation of temporary files that (1) are automatically deleted when closed; (2) can never be reached via any pathname; @@ -858,13 +859,14 @@ functionality: race-free creation of temporary files that .IP \[bu] Creating a file that is initially invisible, which is then populated with data and adjusted to have appropriate filesystem attributes -.RB ( fchown (2), -.BR fchmod (2), -.BR fsetxattr (2), +\%(\c +.MR fchown 2 , +.MR fchmod 2 , +.MR fsetxattr 2 , etc.) before being atomically linked into the filesystem in a fully formed state (using -.BR linkat (2) +.MR linkat 2 as described above). .RE .IP @@ -969,13 +971,13 @@ is absolute.) .\" .SS openat2(2) The -.BR openat2 (2) +.MR openat2 2 system call is an extension of .BR openat (), and provides a superset of the features of .BR openat (). It is documented separately, in -.BR openat2 (2). +.MR openat2 2 . .SH RETURN VALUE On success, .BR open (), @@ -1000,7 +1002,7 @@ is denied for one of the directories in the path prefix of or the file did not exist yet and write access to the parent directory is not allowed. (See also -.BR path_resolution (7).) +.MR path_resolution 7 .) .TP .B EACCES .\" commit 30aba6656f61ed44cba445a3c0d38b296fa9e8f5 @@ -1019,7 +1021,7 @@ For details, see the descriptions of and .I /proc/sys/fs/protected_regular in -.BR proc (5). +.MR proc 5 . .TP .B EBADF .RB ( openat ()) @@ -1061,9 +1063,9 @@ See .B EINTR While blocked waiting to complete an open of a slow device (e.g., a FIFO; see -.BR fifo (7)), +.MR fifo 7 ), the call was interrupted by a signal handler; see -.BR signal (7). +.MR signal 7 . .TP .B EINVAL The filesystem does not support the @@ -1144,7 +1146,7 @@ The per-process limit on the number of open file descriptors has been reached (see the description of .B RLIMIT_NOFILE in -.BR getrlimit (2)). +.MR getrlimit 2 ). .TP .B ENAMETOOLONG .I pathname @@ -1188,7 +1190,7 @@ The named file is a FIFO, but memory for the FIFO buffer can't be allocated because the per-user hard limit on memory allocation for pipes has been reached and the caller is not privileged; see -.BR pipe (7). +.MR pipe 7 . .TP .B ENOMEM Insufficient kernel memory was available. @@ -1259,7 +1261,7 @@ did not match the owner of the file and the caller was not privileged. .TP .B EPERM The operation was prevented by a file seal; see -.BR fcntl (2). +.MR fcntl 2 . .TP .B EROFS .I pathname @@ -1287,7 +1289,7 @@ The .B O_NONBLOCK flag was specified, and an incompatible lease was held on the file (see -.BR fcntl (2)). +.MR fcntl 2 ). .SH VERSIONS The (undefined) effect of .B O_RDONLY | O_TRUNC @@ -1414,7 +1416,7 @@ For certain architectures, this is also true before glibc 2.26. .BR openat () POSIX.1-2008. .P -.BR openat2 (2) +.MR openat2 2 Linux. .P The @@ -1461,14 +1463,14 @@ but does not necessarily have the intention to read or write. For example, this may be used to open a device in order to get a file descriptor for use with -.BR ioctl (2). +.MR ioctl 2 . .P Note that .BR open () can open device special files, but .BR creat () cannot create them; use -.BR mknod (2) +.MR mknod 2 instead. .P If the file is newly created, its @@ -1478,7 +1480,7 @@ If the file is newly created, its fields (respectively, time of last access, time of last status change, and time of last modification; see -.BR stat (2)) +.MR stat 2 ) are set to the current time, and so are the .I st_ctime @@ -1502,7 +1504,7 @@ The files in the .IR /proc/ pid /fdinfo directory show even more information about these file descriptors. See -.BR proc (5) +.MR proc 5 for further details of both of these directories. .P The Linux header file @@ -1524,7 +1526,7 @@ or\[em]in kernel-developer parlance\[em]a .IR "struct file" . .P When a file descriptor is duplicated (using -.BR dup (2) +.MR dup 2 or similar), the duplicate refers to the same open file description as the original file descriptor, @@ -1532,7 +1534,7 @@ and the two file descriptors consequently share the file offset and file status flags. Such sharing can also occur between processes: a child process created via -.BR fork (2) +.MR fork 2 inherits duplicates of its parent's file descriptors, and those duplicates refer to the same open file descriptions. .P @@ -1543,7 +1545,7 @@ thus, there may be multiple open file descriptions corresponding to a file inode. .P On Linux, one can use the -.BR kcmp (2) +.MR kcmp 2 .B KCMP_FILE operation to test whether two file descriptors (in the same process or in two different processes) @@ -1558,7 +1560,7 @@ On NFS filesystems with UID mapping enabled, .BR open () may return a file descriptor but, for example, -.BR read (2) +.MR read 2 requests are denied with .BR EACCES . @@ -1573,7 +1575,7 @@ read and write requests. Opening the read or write end of a FIFO blocks until the other end is also opened (by another process or thread). See -.BR fifo (7) +.MR fifo 7 for further details. .\" .\" @@ -1600,7 +1602,7 @@ check for read and write permission on the file and return a file descriptor that can't be used for reading or writing. This nonstandard access mode is used by some Linux drivers to return a file descriptor that is to be used only for device-specific -.BR ioctl (2) +.MR ioctl 2 operations. .\" See for example util-linux's disk-utils/setfdprm.c .\" For some background on access mode 3, see @@ -1614,32 +1616,32 @@ operations. and the other system calls and library functions that take a directory file descriptor argument (i.e., -.BR execveat (2), -.BR faccessat (2), -.BR fanotify_mark (2), -.BR fchmodat (2), -.BR fchownat (2), -.BR fspick (2), -.BR fstatat (2), -.BR futimesat (2), -.BR linkat (2), -.BR mkdirat (2), -.BR mknodat (2), -.BR mount_setattr (2), -.BR move_mount (2), -.BR name_to_handle_at (2), -.BR open_tree (2), -.BR openat2 (2), -.BR readlinkat (2), -.BR renameat (2), -.BR renameat2 (2), -.BR statx (2), -.BR symlinkat (2), -.BR unlinkat (2), -.BR utimensat (2), -.BR mkfifoat (3), +.MR execveat 2 , +.MR faccessat 2 , +.MR fanotify_mark 2 , +.MR fchmodat 2 , +.MR fchownat 2 , +.MR fspick 2 , +.MR fstatat 2 , +.MR futimesat 2 , +.MR linkat 2 , +.MR mkdirat 2 , +.MR mknodat 2 , +.MR mount_setattr 2 , +.MR move_mount 2 , +.MR name_to_handle_at 2 , +.MR open_tree 2 , +.MR openat2 2 , +.MR readlinkat 2 , +.MR renameat 2 , +.MR renameat2 2 , +.MR statx 2 , +.MR symlinkat 2 , +.MR unlinkat 2 , +.MR utimensat 2 , +.MR mkfifoat 3 , and -.BR scandirat (3)) +.MR scandirat 3 ) address two problems with the older interfaces that preceded them. Here, the explanation is in terms of the .BR openat () @@ -1672,7 +1674,7 @@ opening a file descriptor for the target directory, and then specifying that file descriptor as the .I dirfd argument of (say) -.BR fstatat (2) +.MR fstatat 2 and .BR openat (). The use of the @@ -1707,9 +1709,9 @@ or the .B O_PATH flag). Alternatively, such a file descriptor can be obtained by applying -.BR dirfd (3) +.MR dirfd 3 to a directory stream created using -.BR opendir (3). +.MR opendir 3 . .P When these APIs are given a .I dirfd @@ -1742,7 +1744,7 @@ or fall back to buffered I/O. Since Linux 6.1, .B O_DIRECT support and alignment restrictions for a file can be queried using -.BR statx (2), +.MR statx 2 , using the .B STATX_DIOALIGN flag. @@ -1750,7 +1752,7 @@ Support for .B STATX_DIOALIGN varies by filesystem; see -.BR statx (2). +.MR statx 2 . .P Some filesystems provide their own interfaces for querying .B O_DIRECT @@ -1758,7 +1760,7 @@ alignment restrictions, for example the .B XFS_IOC_DIOINFO operation in -.BR xfsctl (3). +.MR xfsctl 3 . .B STATX_DIOALIGN should be used instead when it is available. .P @@ -1777,7 +1779,7 @@ In Linux 2.6.0, this was relaxed to the logical block size of the block device (typically 512 bytes). A block device's logical block size can be determined using the -.BR ioctl (2) +.MR ioctl 2 .B BLKSSZGET operation or from the shell using the command: .P @@ -1789,44 +1791,44 @@ blockdev \-\-getss .P .B O_DIRECT I/Os should never be run concurrently with the -.BR fork (2) +.MR fork 2 system call, if the memory buffer is a private mapping (i.e., any mapping created with the -.BR mmap (2) +.MR mmap 2 .B MAP_PRIVATE flag; this includes memory allocated on the heap and statically allocated buffers). Any such I/Os, whether submitted via an asynchronous I/O interface or from another thread in the process, should be completed before -.BR fork (2) +.MR fork 2 is called. Failure to do so can result in data corruption and undefined behavior in parent and child processes. This restriction does not apply when the memory buffer for the .B O_DIRECT I/Os was created using -.BR shmat (2) +.MR shmat 2 or -.BR mmap (2) +.MR mmap 2 with the .B MAP_SHARED flag. Nor does this restriction apply when the memory buffer has been advised as .B MADV_DONTFORK with -.BR madvise (2), +.MR madvise 2 , ensuring that it will not be available to the child after -.BR fork (2). +.MR fork 2 . .P The .B O_DIRECT flag was introduced in SGI IRIX, where it has alignment restrictions similar to those of Linux 2.4. IRIX has also a -.BR fcntl (2) +.MR fcntl 2 call to query appropriate alignments, and sizes. FreeBSD 4.x introduced a flag of the same name, but without alignment restrictions. @@ -1848,7 +1850,7 @@ Even when the filesystem correctly handles the coherency issues in this situation, overall I/O throughput is likely to be slower than using either mode alone. Likewise, applications should avoid mixing -.BR mmap (2) +.MR mmap 2 of files with direct I/O to the same files. .P The behavior of @@ -1886,7 +1888,7 @@ I/O by specifying when calling .BR open (); use -.BR fcntl (2) +.MR fcntl 2 to enable this flag. .\" FIXME . Check bugzilla report on open(O_ASYNC) .\" See http://bugzilla.kernel.org/show_bug.cgi?id=5993 @@ -1913,27 +1915,27 @@ will create a regular file (i.e., .B O_DIRECTORY is ignored). .SH SEE ALSO -.BR chmod (2), -.BR chown (2), -.BR close (2), -.BR dup (2), -.BR fcntl (2), -.BR link (2), -.BR lseek (2), -.BR mknod (2), -.BR mmap (2), -.BR mount (2), -.BR open_by_handle_at (2), -.BR openat2 (2), -.BR read (2), -.BR socket (2), -.BR stat (2), -.BR umask (2), -.BR unlink (2), -.BR write (2), -.BR fopen (3), -.BR acl (5), -.BR fifo (7), -.BR inode (7), -.BR path_resolution (7), -.BR symlink (7) +.MR chmod 2 , +.MR chown 2 , +.MR close 2 , +.MR dup 2 , +.MR fcntl 2 , +.MR link 2 , +.MR lseek 2 , +.MR mknod 2 , +.MR mmap 2 , +.MR mount 2 , +.MR open_by_handle_at 2 , +.MR openat2 2 , +.MR read 2 , +.MR socket 2 , +.MR stat 2 , +.MR umask 2 , +.MR unlink 2 , +.MR write 2 , +.MR fopen 3 , +.MR acl 5 , +.MR fifo 7 , +.MR inode 7 , +.MR path_resolution 7 , +.MR symlink 7 |