166492cf0SYuri Pankov.\" 266492cf0SYuri Pankov.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for 366492cf0SYuri Pankov.\" permission to reproduce portions of its copyrighted documentation. 466492cf0SYuri Pankov.\" Original documentation from The Open Group can be obtained online at 566492cf0SYuri Pankov.\" http://www.opengroup.org/bookstore/. 666492cf0SYuri Pankov.\" 766492cf0SYuri Pankov.\" The Institute of Electrical and Electronics Engineers and The Open 866492cf0SYuri Pankov.\" Group, have given us permission to reprint portions of their 966492cf0SYuri Pankov.\" documentation. 1066492cf0SYuri Pankov.\" 1166492cf0SYuri Pankov.\" In the following statement, the phrase ``this text'' refers to portions 1266492cf0SYuri Pankov.\" of the system documentation. 1366492cf0SYuri Pankov.\" 1466492cf0SYuri Pankov.\" Portions of this text are reprinted and reproduced in electronic form 1566492cf0SYuri Pankov.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition, 1666492cf0SYuri Pankov.\" Standard for Information Technology -- Portable Operating System 1766492cf0SYuri Pankov.\" Interface (POSIX), The Open Group Base Specifications Issue 6, 1866492cf0SYuri Pankov.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics 1966492cf0SYuri Pankov.\" Engineers, Inc and The Open Group. In the event of any discrepancy 2066492cf0SYuri Pankov.\" between these versions and the original IEEE and The Open Group 2166492cf0SYuri Pankov.\" Standard, the original IEEE and The Open Group Standard is the referee 2266492cf0SYuri Pankov.\" document. The original Standard can be obtained online at 2366492cf0SYuri Pankov.\" http://www.opengroup.org/unix/online.html. 2466492cf0SYuri Pankov.\" 2566492cf0SYuri Pankov.\" This notice shall appear on any product containing this material. 2666492cf0SYuri Pankov.\" 2766492cf0SYuri Pankov.\" The contents of this file are subject to the terms of the 2866492cf0SYuri Pankov.\" Common Development and Distribution License (the "License"). 2966492cf0SYuri Pankov.\" You may not use this file except in compliance with the License. 3066492cf0SYuri Pankov.\" 3166492cf0SYuri Pankov.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 3266492cf0SYuri Pankov.\" or http://www.opensolaris.org/os/licensing. 3366492cf0SYuri Pankov.\" See the License for the specific language governing permissions 3466492cf0SYuri Pankov.\" and limitations under the License. 3566492cf0SYuri Pankov.\" 3666492cf0SYuri Pankov.\" When distributing Covered Code, include this CDDL HEADER in each 3766492cf0SYuri Pankov.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. 3866492cf0SYuri Pankov.\" If applicable, add the following below this CDDL HEADER, with the 3966492cf0SYuri Pankov.\" fields enclosed by brackets "[]" replaced with your own identifying 4066492cf0SYuri Pankov.\" information: Portions Copyright [yyyy] [name of copyright owner] 4166492cf0SYuri Pankov.\" 4266492cf0SYuri Pankov.\" 43c10c16deSRichard Lowe.\" Copyright 1989 AT&T 44c10c16deSRichard Lowe.\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved. 4566492cf0SYuri Pankov.\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved. 4666492cf0SYuri Pankov.\" Portions Copyright (c) 2013, OmniTI Computer Consulting, Inc. 4766492cf0SYuri Pankov.\" All Rights Reserved. 4866492cf0SYuri Pankov.\" Copyright 2015 Nexenta Systems, Inc. All rights reserved. 49edd58064SJerry Jelinek.\" Copyright 2020 Joyent, Inc. 501fa2a664SJoshua M. Clulow.\" Copyright 2022 Oxide Computer Company 5166492cf0SYuri Pankov.\" 521fa2a664SJoshua M. Clulow.Dd February 5, 2022 531fa2a664SJoshua M. Clulow.Dt OPEN 2 541fa2a664SJoshua M. Clulow.Os 551fa2a664SJoshua M. Clulow.Sh NAME 561fa2a664SJoshua M. Clulow.Nm open , 571fa2a664SJoshua M. Clulow.Nm openat 581fa2a664SJoshua M. Clulow.Nd open a file 591fa2a664SJoshua M. Clulow.Sh SYNOPSIS 601fa2a664SJoshua M. Clulow.In sys/types.h 611fa2a664SJoshua M. Clulow.In sys/stat.h 621fa2a664SJoshua M. Clulow.In fcntl.h 631fa2a664SJoshua M. Clulow.Ft int 641fa2a664SJoshua M. Clulow.Fo open 651fa2a664SJoshua M. Clulow.Fa "const char *path" 661fa2a664SJoshua M. Clulow.Fa "int oflag" 671fa2a664SJoshua M. Clulow.Op , Fa "mode_t mode" 681fa2a664SJoshua M. Clulow.Fc 691fa2a664SJoshua M. Clulow.Ft int 701fa2a664SJoshua M. Clulow.Fo openat 711fa2a664SJoshua M. Clulow.Fa "int fildes" 721fa2a664SJoshua M. Clulow.Fa "const char *path" 731fa2a664SJoshua M. Clulow.Fa "int oflag" 741fa2a664SJoshua M. Clulow.Op , Fa "mode_t mode" 751fa2a664SJoshua M. Clulow.Fc 761fa2a664SJoshua M. Clulow.Sh DESCRIPTION 771fa2a664SJoshua M. ClulowThe 781fa2a664SJoshua M. Clulow.Fn open 791fa2a664SJoshua M. Clulowfunction establishes the connection between a file and a file descriptor. 801fa2a664SJoshua M. ClulowIt creates an open file description that refers to a file and a file descriptor 811fa2a664SJoshua M. Clulowthat refers to that open file description. 821fa2a664SJoshua M. ClulowThe file descriptor is used by other I/O functions to refer to that file. 831fa2a664SJoshua M. ClulowThe 841fa2a664SJoshua M. Clulow.Fa path 851fa2a664SJoshua M. Clulowargument points to a pathname naming the file. 861fa2a664SJoshua M. Clulow.Pp 871fa2a664SJoshua M. ClulowThe 881fa2a664SJoshua M. Clulow.Fn openat 891fa2a664SJoshua M. Clulowfunction is identical to the 901fa2a664SJoshua M. Clulow.Fn open 911fa2a664SJoshua M. Clulowfunction except 921fa2a664SJoshua M. Clulowthat the 931fa2a664SJoshua M. Clulow.Fa path 941fa2a664SJoshua M. Clulowargument is interpreted relative to the starting point 951fa2a664SJoshua M. Clulowimplied by the 961fa2a664SJoshua M. Clulow.Fa fildes 971fa2a664SJoshua M. Clulowargument. 981fa2a664SJoshua M. ClulowIf the 991fa2a664SJoshua M. Clulow.Fa fildes 1001fa2a664SJoshua M. Clulowargument has the special value 1011fa2a664SJoshua M. Clulow.Dv AT_FDCWD , 1021fa2a664SJoshua M. Clulowa relative path argument will be resolved relative to the current working 1031fa2a664SJoshua M. Clulowdirectory. 1041fa2a664SJoshua M. ClulowIf the 1051fa2a664SJoshua M. Clulow.Fa path 1061fa2a664SJoshua M. Clulowargument is absolute, the 1071fa2a664SJoshua M. Clulow.Fa fildes 1081fa2a664SJoshua M. Clulowargument is ignored. 1091fa2a664SJoshua M. Clulow.Pp 1101fa2a664SJoshua M. ClulowThe 1111fa2a664SJoshua M. Clulow.Fn open 1121fa2a664SJoshua M. Clulowfunction returns a file descriptor for the named file that is the lowest file 1131fa2a664SJoshua M. Clulowdescriptor not currently open for that process. 1141fa2a664SJoshua M. ClulowThe open file description is new, and therefore the file descriptor does not 1151fa2a664SJoshua M. Clulowshare it with any other process in the system. 1161fa2a664SJoshua M. ClulowThe 1171fa2a664SJoshua M. Clulow.Dv FD_CLOEXEC 1181fa2a664SJoshua M. Clulowfile descriptor flag associated with the new file descriptor is cleared. 1191fa2a664SJoshua M. Clulow.Pp 120c10c16deSRichard LoweThe file offset used to mark the current position within the file is set to the 121c10c16deSRichard Lowebeginning of the file. 1221fa2a664SJoshua M. Clulow.Pp 123c10c16deSRichard LoweThe file status flags and file access modes of the open file description are 1241fa2a664SJoshua M. Clulowset according to the value of 1251fa2a664SJoshua M. Clulow.Fa oflag . 1261fa2a664SJoshua M. ClulowThe 1271fa2a664SJoshua M. Clulow.Fa mode 1281fa2a664SJoshua M. Clulowargument is used only 1291fa2a664SJoshua M. Clulowwhen 1301fa2a664SJoshua M. Clulow.Dv O_CREAT 1311fa2a664SJoshua M. Clulowis specified 1321fa2a664SJoshua M. Clulow.Pq "see below" . 1331fa2a664SJoshua M. Clulow.Pp 1341fa2a664SJoshua M. ClulowValues for 1351fa2a664SJoshua M. Clulow.Fa oflag 1361fa2a664SJoshua M. Cluloware constructed by a bitwise-inclusive-OR of flags from 1371fa2a664SJoshua M. Clulowthe following list, defined in 1381fa2a664SJoshua M. Clulow.Xr fcntl.h 3HEAD . 1391fa2a664SJoshua M. ClulowApplications must specify exactly one of the first three values (file access 1401fa2a664SJoshua M. Clulowmodes) below in the value of 1411fa2a664SJoshua M. Clulow.Fa oflag : 1421fa2a664SJoshua M. Clulow.Bl -tag -width Ds 1431fa2a664SJoshua M. Clulow.It Dv O_RDONLY 144c10c16deSRichard LoweOpen for reading only. 1451fa2a664SJoshua M. Clulow.It Dv O_WRONLY 146c10c16deSRichard LoweOpen for writing only. 1471fa2a664SJoshua M. Clulow.It Dv O_RDWR 1481fa2a664SJoshua M. ClulowOpen for reading and writing. 1491fa2a664SJoshua M. ClulowThe result is undefined if this flag is applied to a FIFO. 1501fa2a664SJoshua M. Clulow.El 1511fa2a664SJoshua M. Clulow.Pp 152c10c16deSRichard LoweAny combination of the following may be used: 1531fa2a664SJoshua M. Clulow.Bl -tag -width Ds 1541fa2a664SJoshua M. Clulow.It Dv O_APPEND 155c10c16deSRichard LoweIf set, the file offset is set to the end of the file prior to each write. 1561fa2a664SJoshua M. Clulow.It Dv O_CREAT 1571fa2a664SJoshua M. ClulowCreate the file if it does not exist. 1581fa2a664SJoshua M. ClulowThis flag requires that the 1591fa2a664SJoshua M. Clulow.Fa mode 160c10c16deSRichard Loweargument be specified. 1611fa2a664SJoshua M. Clulow.Pp 1621fa2a664SJoshua M. ClulowIf the file exists, this flag has no effect except as noted under 1631fa2a664SJoshua M. Clulow.Dv O_EXCL 1641fa2a664SJoshua M. Clulowbelow. 1651fa2a664SJoshua M. ClulowOtherwise, the file is created with the user ID of the file set to the 1661fa2a664SJoshua M. Cluloweffective user ID of the process. 1671fa2a664SJoshua M. ClulowThe group ID of the file is set to the effective group IDs of the process, or 1681fa2a664SJoshua M. Clulowif the 1691fa2a664SJoshua M. Clulow.Dv S_ISGID 170c10c16deSRichard Lowebit is set in the directory in which the file is being created, the file's 1711fa2a664SJoshua M. Clulowgroup ID is set to the group ID of its parent directory. 1721fa2a664SJoshua M. ClulowIf the group ID of the new file does not match the effective group 1731fa2a664SJoshua M. ClulowID or one of the supplementary groups IDs, the 1741fa2a664SJoshua M. Clulow.Dv S_ISGID bit is cleared. 1751fa2a664SJoshua M. Clulow.Pp 1761fa2a664SJoshua M. ClulowThe access permission bits 1771fa2a664SJoshua M. Clulow.Po 1781fa2a664SJoshua M. Clulowsee 1791fa2a664SJoshua M. Clulow.Xr stat.h 3HEAD 1801fa2a664SJoshua M. Clulow.Pc 1811fa2a664SJoshua M. Clulowof the file mode are set to the value of 1821fa2a664SJoshua M. Clulow.Fa mode , 1831fa2a664SJoshua M. Clulowmodified as follows 1841fa2a664SJoshua M. Clulow.Po 1851fa2a664SJoshua M. Clulowsee 1861fa2a664SJoshua M. Clulow.Xr creat 2 1871fa2a664SJoshua M. Clulow.Pc : 1881fa2a664SJoshua M. Clulowa bitwise-AND is performed on the file-mode bits and the corresponding bits in 1891fa2a664SJoshua M. Clulowthe complement of the process's file mode creation mask. 1901fa2a664SJoshua M. ClulowThus, all bits set in the process's file mode creation mask 1911fa2a664SJoshua M. Clulow.Po 1921fa2a664SJoshua M. Clulowsee 1931fa2a664SJoshua M. Clulow.Xr umask 2 1941fa2a664SJoshua M. Clulow.Pc 1951fa2a664SJoshua M. Cluloware correspondingly cleared in the file's permission mask. 1961fa2a664SJoshua M. ClulowThe 1971fa2a664SJoshua M. Clulow.Dq save text image after execution bit 1981fa2a664SJoshua M. Clulowof the mode is cleared 1991fa2a664SJoshua M. Clulow.Po 2001fa2a664SJoshua M. Clulowsee 2011fa2a664SJoshua M. Clulow.Xr chmod 2 2021fa2a664SJoshua M. Clulow.Pc . 2031fa2a664SJoshua M. ClulowWhen bits other than the file permission bits are set, the effect is 2041fa2a664SJoshua M. Clulowunspecified. 2051fa2a664SJoshua M. ClulowThe 2061fa2a664SJoshua M. Clulow.Fa mode 2071fa2a664SJoshua M. Clulowargument does not affect whether the file is open for reading, writing or for 2081fa2a664SJoshua M. Clulowboth. 2091fa2a664SJoshua M. Clulow.It Dv O_DIRECT 210edd58064SJerry JelinekIndicates that the file data is not going to be reused in the near future. 211edd58064SJerry JelinekWhen possible, data is read or written directly between the application's 2121fa2a664SJoshua M. Clulowmemory and the device when the data is accessed with 2131fa2a664SJoshua M. Clulow.Xr read 2 2141fa2a664SJoshua M. Clulowand 2151fa2a664SJoshua M. Clulow.Xr write 2 2161fa2a664SJoshua M. Clulowoperations. 2171fa2a664SJoshua M. ClulowSee 2181fa2a664SJoshua M. Clulow.Xr directio 3C 2191fa2a664SJoshua M. Clulowfor more details. 2201fa2a664SJoshua M. Clulow.It Dv O_DIRECTORY 22169c811abSRobert MustacchiIndicates that attempts to open 2221fa2a664SJoshua M. Clulow.Fa path 22369c811abSRobert Mustacchishould fail unless 2241fa2a664SJoshua M. Clulow.Fa path 22569c811abSRobert Mustacchiis a directory. 22669c811abSRobert MustacchiIf both 2271fa2a664SJoshua M. Clulow.Dv O_CREAT 22869c811abSRobert Mustacchiand 2291fa2a664SJoshua M. Clulow.Dv O_DIRECTORY 23069c811abSRobert Mustacchiare specified then the call will fail if it would result in a file being 23169c811abSRobert Mustacchicreated. 23269c811abSRobert MustacchiIf a directory already exists at 2331fa2a664SJoshua M. Clulow.Fa path 23469c811abSRobert Mustacchithen it will behave as if the 2351fa2a664SJoshua M. Clulow.Dv O_DIRECTORY 23669c811abSRobert Mustacchiflag had not been present. 23769c811abSRobert MustacchiIf the 2381fa2a664SJoshua M. Clulow.Dv O_EXCL 23969c811abSRobert Mustacchiand 2401fa2a664SJoshua M. Clulow.Dv O_CREAT 2411fa2a664SJoshua M. Clulowflags are specified, then the call will always fail as they imply a file should 2421fa2a664SJoshua M. Clulowalways be created. 2431fa2a664SJoshua M. Clulow.It Dv O_DSYNC 244c10c16deSRichard LoweWrite I/O operations on the file descriptor complete as defined by synchronized 245c10c16deSRichard LoweI/O data integrity completion. 2461fa2a664SJoshua M. Clulow.It Dv O_EXCL 2471fa2a664SJoshua M. ClulowIf 2481fa2a664SJoshua M. Clulow.Dv O_CREAT 2491fa2a664SJoshua M. Clulowand 2501fa2a664SJoshua M. Clulow.Dv O_EXCL 2511fa2a664SJoshua M. Cluloware set, 2521fa2a664SJoshua M. Clulow.Fn open 2531fa2a664SJoshua M. Clulowfails if the file exists. 2541fa2a664SJoshua M. ClulowThe check for the existence of the file and the creation of the file if 255c10c16deSRichard Loweit does not exist is atomic with respect to other threads executing 2561fa2a664SJoshua M. Clulow.Fn open 2571fa2a664SJoshua M. Clulownaming the same filename in the same directory with 2581fa2a664SJoshua M. Clulow.Dv O_EXCL 2591fa2a664SJoshua M. Clulowand 2601fa2a664SJoshua M. Clulow.Dv O_CREAT 2611fa2a664SJoshua M. Clulowset. 2621fa2a664SJoshua M. ClulowIf 2631fa2a664SJoshua M. Clulow.Dv O_EXCL 2641fa2a664SJoshua M. Clulowand 2651fa2a664SJoshua M. Clulow.Dv O_CREAT 2661fa2a664SJoshua M. Cluloware set, and 2671fa2a664SJoshua M. Clulow.Fa path 2681fa2a664SJoshua M. Clulownames a symbolic link, 2691fa2a664SJoshua M. Clulow.Fn open 2701fa2a664SJoshua M. Clulowfails and sets 2711fa2a664SJoshua M. Clulow.Va errno 2721fa2a664SJoshua M. Clulowto 2731fa2a664SJoshua M. Clulow.Er EEXIST , 2741fa2a664SJoshua M. Clulowregardless of the contents of the symbolic link. 2751fa2a664SJoshua M. ClulowIf 2761fa2a664SJoshua M. Clulow.Dv O_EXCL 2771fa2a664SJoshua M. Clulowis set and 2781fa2a664SJoshua M. Clulow.Dv O_CREAT 2791fa2a664SJoshua M. Clulowis not set, the result is undefined. 2801fa2a664SJoshua M. Clulow.It Dv O_EXEC 2811fcc078aSRobert MustacchiIf set, indicates that the file should be opened for execute permission. 2821fa2a664SJoshua M. ClulowThis option is only valid for regular files; an error will be returned if the 2831fa2a664SJoshua M. Clulowtarget is not a regular file. 2841fa2a664SJoshua M. Clulow.It Dv O_LARGEFILE 285c10c16deSRichard LoweIf set, the offset maximum in the open file description is the largest value 2861fa2a664SJoshua M. Clulowthat can be represented correctly in an object of type 2871fa2a664SJoshua M. Clulow.Vt off64_t . 2881fa2a664SJoshua M. Clulow.It Dv O_NOCTTY 2891fa2a664SJoshua M. ClulowIf set and 2901fa2a664SJoshua M. Clulow.Fa path 2911fa2a664SJoshua M. Clulowidentifies a terminal device, 2921fa2a664SJoshua M. Clulow.Fn open 2931fa2a664SJoshua M. Clulowdoes not cause the terminal device to become the controlling terminal for the 2941fa2a664SJoshua M. Clulowprocess. 2951fa2a664SJoshua M. Clulow.It Dv O_NOFOLLOW 2961fa2a664SJoshua M. ClulowIf the path names a symbolic link, 2971fa2a664SJoshua M. Clulow.Fn open 2981fa2a664SJoshua M. Clulowfails and sets 2991fa2a664SJoshua M. Clulow.Va errno 3001fa2a664SJoshua M. Clulowto 3011fa2a664SJoshua M. Clulow.Er ELOOP . 3021fa2a664SJoshua M. Clulow.It Dv O_NOLINKS 3031fa2a664SJoshua M. ClulowIf the link count of the named file is greater than 3041fa2a664SJoshua M. Clulow.Sy 1 , 3051fa2a664SJoshua M. Clulow.Fn open 3061fa2a664SJoshua M. Clulowfails and sets 3071fa2a664SJoshua M. Clulow.Va errno 3081fa2a664SJoshua M. Clulowto 3091fa2a664SJoshua M. Clulow.Er EMLINK . 3101fa2a664SJoshua M. Clulow.It Dv O_CLOEXEC 311b075ad5bSTheo SchlossnagleIf set, the file descriptor returned will be closed prior to any future 3121fa2a664SJoshua M. Clulow.Xr exec 2 3131fa2a664SJoshua M. Clulowcalls. 3141fa2a664SJoshua M. Clulow.It Dv O_NONBLOCK O_NDELAY 3151fa2a664SJoshua M. ClulowThese flags can affect subsequent reads and writes 3161fa2a664SJoshua M. Clulow.Po 3171fa2a664SJoshua M. Clulowsee 3181fa2a664SJoshua M. Clulow.Xr read 2 3191fa2a664SJoshua M. Clulowand 3201fa2a664SJoshua M. Clulow.Xr write 2 3211fa2a664SJoshua M. Clulow.Pc . 3221fa2a664SJoshua M. ClulowIf both 3231fa2a664SJoshua M. Clulow.Dv O_NDELAY 3241fa2a664SJoshua M. Clulowand 3251fa2a664SJoshua M. Clulow.Dv O_NONBLOCK 3261fa2a664SJoshua M. Cluloware set, 3271fa2a664SJoshua M. Clulow.Dv O_NONBLOCK 3281fa2a664SJoshua M. Clulowtakes precedence. 3291fa2a664SJoshua M. Clulow.Pp 3301fa2a664SJoshua M. ClulowWhen opening a FIFO with 3311fa2a664SJoshua M. Clulow.Dv O_RDONLY 3321fa2a664SJoshua M. Clulowor 3331fa2a664SJoshua M. Clulow.Dv O_WRONLY 3341fa2a664SJoshua M. Clulowset: 3351fa2a664SJoshua M. Clulow.Bl -bullet 3361fa2a664SJoshua M. Clulow.It 3371fa2a664SJoshua M. ClulowIf 3381fa2a664SJoshua M. Clulow.Dv O_NONBLOCK 3391fa2a664SJoshua M. Clulowor 3401fa2a664SJoshua M. Clulow.Dv O_NDELAY 3411fa2a664SJoshua M. Clulowis set, an 3421fa2a664SJoshua M. Clulow.Fn open 3431fa2a664SJoshua M. Clulowfor reading only returns without delay. 3441fa2a664SJoshua M. ClulowAn 3451fa2a664SJoshua M. Clulow.Fn open 3461fa2a664SJoshua M. Clulowfor writing only returns an error if no process currently has the file open for 347c10c16deSRichard Lowereading. 3481fa2a664SJoshua M. Clulow.It 3491fa2a664SJoshua M. ClulowIf 3501fa2a664SJoshua M. Clulow.Dv O_NONBLOCK 3511fa2a664SJoshua M. Clulowand 3521fa2a664SJoshua M. Clulow.Dv O_NDELAY 3531fa2a664SJoshua M. Cluloware clear, an 3541fa2a664SJoshua M. Clulow.Fn open 3551fa2a664SJoshua M. Clulowfor reading only blocks until a thread opens the file for writing. 3561fa2a664SJoshua M. ClulowAn 3571fa2a664SJoshua M. Clulow.Fn open 3581fa2a664SJoshua M. Clulowfor writing only blocks the calling thread until a thread opens the file for 3591fa2a664SJoshua M. Clulowreading. 3601fa2a664SJoshua M. Clulow.El 3611fa2a664SJoshua M. Clulow.Pp 3621fa2a664SJoshua M. ClulowAfter both ends of a FIFO have been opened once, there is no guarantee that 3631fa2a664SJoshua M. Clulowfurther calls to 3641fa2a664SJoshua M. Clulow.Fn open 3651fa2a664SJoshua M. Clulow.Dv O_RDONLY 3661fa2a664SJoshua M. Clulow.Pq Dv O_WRONLY 3671fa2a664SJoshua M. Clulowwill synchronize with later calls to 3681fa2a664SJoshua M. Clulow.Fn open 3691fa2a664SJoshua M. Clulow.Dv O_WRONLY 3701fa2a664SJoshua M. Clulow.Pq Dv O_RDONLY 3711fa2a664SJoshua M. Clulowuntil both ends of the FIFO have been closed by all readers and writers. 3721fa2a664SJoshua M. ClulowAny data written into a FIFO will be lost if both ends of the FIFO are closed 3731fa2a664SJoshua M. Clulowbefore the data is read. 3741fa2a664SJoshua M. Clulow.Pp 375c10c16deSRichard LoweWhen opening a block special or character special file that supports 376c10c16deSRichard Lowenon-blocking opens: 3771fa2a664SJoshua M. Clulow.Bl -bullet 3781fa2a664SJoshua M. Clulow.It 3791fa2a664SJoshua M. ClulowIf 3801fa2a664SJoshua M. Clulow.Dv O_NONBLOCK 3811fa2a664SJoshua M. Clulowor 3821fa2a664SJoshua M. Clulow.Dv O_NDELAY 3831fa2a664SJoshua M. Clulowis set, the 3841fa2a664SJoshua M. Clulow.Fn open 3851fa2a664SJoshua M. Clulowfunction returns without blocking for the device to be ready or available. 3861fa2a664SJoshua M. ClulowSubsequent behavior of the device is device-specific. 3871fa2a664SJoshua M. Clulow.It 3881fa2a664SJoshua M. ClulowIf 3891fa2a664SJoshua M. Clulow.Dv O_NONBLOCK 39069c811abSRobert Mustacchiand 3911fa2a664SJoshua M. Clulow.Dv O_NDELAY 3921fa2a664SJoshua M. Cluloware clear, the 3931fa2a664SJoshua M. Clulow.Fn open 3941fa2a664SJoshua M. Clulowfunction blocks the calling thread until the device is ready or available 3951fa2a664SJoshua M. Clulowbefore returning. 3961fa2a664SJoshua M. Clulow.El 3971fa2a664SJoshua M. Clulow.Pp 3981fa2a664SJoshua M. ClulowOtherwise, the behavior of 3991fa2a664SJoshua M. Clulow.Dv O_NONBLOCK 4001fa2a664SJoshua M. Clulowand 4011fa2a664SJoshua M. Clulow.Dv O_NDELAY 4021fa2a664SJoshua M. Clulowis unspecified. 4031fa2a664SJoshua M. Clulow.It Dv O_RSYNC 4041fa2a664SJoshua M. ClulowRead I/O operations on the file descriptor complete at the same level of 4051fa2a664SJoshua M. Clulowintegrity as specified by the 4061fa2a664SJoshua M. Clulow.Dv O_DSYNC 4071fa2a664SJoshua M. Clulowand 4081fa2a664SJoshua M. Clulow.Dv O_SYNC 4091fa2a664SJoshua M. Clulowflags. 4101fa2a664SJoshua M. ClulowIf both 4111fa2a664SJoshua M. Clulow.Dv O_DSYNC 4121fa2a664SJoshua M. Clulowand 4131fa2a664SJoshua M. Clulow.Dv O_RSYNC 4141fa2a664SJoshua M. Cluloware set in 4151fa2a664SJoshua M. Clulow.Fa oflag , 4161fa2a664SJoshua M. Clulowall I/O operations on the file descriptor complete as defined by synchronized 4171fa2a664SJoshua M. ClulowI/O data integrity completion. 4181fa2a664SJoshua M. ClulowIf both 4191fa2a664SJoshua M. Clulow.Dv O_SYNC 4201fa2a664SJoshua M. Clulowand 4211fa2a664SJoshua M. Clulow.Dv O_RSYNC 4221fa2a664SJoshua M. Cluloware set in 4231fa2a664SJoshua M. Clulow.Fa oflag , 4241fa2a664SJoshua M. Clulowall I/O operations on the file descriptor complete as defined by synchronized 4251fa2a664SJoshua M. ClulowI/O file integrity completion. 4261fa2a664SJoshua M. Clulow.It Dv O_SEARCH 4271fa2a664SJoshua M. ClulowIf set, indicates that the directory should be opened for searching. 4281fa2a664SJoshua M. ClulowThis option is only valid for a directory; an error will be returned if the 4291fa2a664SJoshua M. Clulowtarget is not a directory. 4301fa2a664SJoshua M. Clulow.It Dv O_SYNC 4311fa2a664SJoshua M. ClulowWrite I/O operations on the file descriptor complete as defined by synchronized 4321fa2a664SJoshua M. ClulowI/O file integrity completion 4331fa2a664SJoshua M. Clulow.Po 4341fa2a664SJoshua M. Clulowsee 4351fa2a664SJoshua M. Clulow.Xr fcntl.h 3HEAD 4361fa2a664SJoshua M. Clulow.Pc 4371fa2a664SJoshua M. Clulowdefinition of 4381fa2a664SJoshua M. Clulow.Dv O_SYNC . 4391fa2a664SJoshua M. Clulow.It Dv O_TRUNC 4401fa2a664SJoshua M. ClulowIf the file exists and is a regular file, and the file is successfully opened 4411fa2a664SJoshua M. Clulow.Dv O_RDWR 4421fa2a664SJoshua M. Clulowor 4431fa2a664SJoshua M. Clulow.Dv O_WRONLY , 4441fa2a664SJoshua M. Clulowits length is truncated to 4451fa2a664SJoshua M. Clulow.Sy 0 4461fa2a664SJoshua M. Clulowand the mode and owner are unchanged. 4471fa2a664SJoshua M. ClulowIt has no effect on FIFO special files or terminal device files. 4481fa2a664SJoshua M. ClulowIts effect on other file types is implementation-dependent. 4491fa2a664SJoshua M. ClulowThe result of using 4501fa2a664SJoshua M. Clulow.Dv O_TRUNC 4511fa2a664SJoshua M. Clulowwith 4521fa2a664SJoshua M. Clulow.Dv O_RDONLY 4531fa2a664SJoshua M. Clulowis undefined. 4541fa2a664SJoshua M. Clulow.It Dv O_XATTR 4551fa2a664SJoshua M. ClulowIf set in 4561fa2a664SJoshua M. Clulow.Fn openat , 4571fa2a664SJoshua M. Clulowa relative path argument is interpreted as a reference to an extended attribute 4581fa2a664SJoshua M. Clulowof the file associated with the supplied file descriptor. 4591fa2a664SJoshua M. ClulowThis flag therefore requires the presence of a legal 4601fa2a664SJoshua M. Clulow.Fa fildes 4611fa2a664SJoshua M. Clulowargument. 4621fa2a664SJoshua M. ClulowIf set in 4631fa2a664SJoshua M. Clulow.Fn open , 4641fa2a664SJoshua M. Clulowthe implied file descriptor is that for the current working directory. 4651fa2a664SJoshua M. ClulowExtended attributes must be referenced with a relative path; providing an 4661fa2a664SJoshua M. Clulowabsolute path results in a normal file reference. 4671fa2a664SJoshua M. Clulow.El 4681fa2a664SJoshua M. Clulow.Pp 4691fa2a664SJoshua M. ClulowIf 4701fa2a664SJoshua M. Clulow.Dv O_CREAT 4711fa2a664SJoshua M. Clulowis set and the file did not previously exist, upon successful completion, 4721fa2a664SJoshua M. Clulow.Fn open 4731fa2a664SJoshua M. Clulowmarks for update the 4741fa2a664SJoshua M. Clulow.Fa st_atime , 4751fa2a664SJoshua M. Clulow.Fa st_ctime , 4761fa2a664SJoshua M. Clulowand 4771fa2a664SJoshua M. Clulow.Fa st_mtime 4781fa2a664SJoshua M. Clulowfields of the file and the 4791fa2a664SJoshua M. Clulow.Fa st_ctime 4801fa2a664SJoshua M. Clulowand 4811fa2a664SJoshua M. Clulow.Fa st_mtime 4821fa2a664SJoshua M. Clulowfields of the parent directory. 4831fa2a664SJoshua M. Clulow.Pp 4841fa2a664SJoshua M. ClulowIf 4851fa2a664SJoshua M. Clulow.Dv O_TRUNC 4861fa2a664SJoshua M. Clulowis set and the file did previously exist, upon successful completion, 4871fa2a664SJoshua M. Clulow.Fn open 4881fa2a664SJoshua M. Clulowmarks for update the 4891fa2a664SJoshua M. Clulow.Fa st_ctime 4901fa2a664SJoshua M. Clulowand 4911fa2a664SJoshua M. Clulow.Fa st_mtime 4921fa2a664SJoshua M. Clulowfields of the file. 4931fa2a664SJoshua M. Clulow.Pp 4941fa2a664SJoshua M. ClulowIf both the 4951fa2a664SJoshua M. Clulow.Dv O_SYNC 4961fa2a664SJoshua M. Clulowand 4971fa2a664SJoshua M. Clulow.Dv O_DSYNC 4981fa2a664SJoshua M. Clulowflags are set, the effect is as if only the 4991fa2a664SJoshua M. Clulow.Dv O_SYNC 5001fa2a664SJoshua M. Clulowflag was set. 5011fa2a664SJoshua M. Clulow.Pp 5021fa2a664SJoshua M. ClulowIf 5031fa2a664SJoshua M. Clulow.Fa path 5041fa2a664SJoshua M. Clulowrefers to a STREAMS file, 5051fa2a664SJoshua M. Clulow.Fa oflag 5061fa2a664SJoshua M. Clulowmay be constructed from 5071fa2a664SJoshua M. Clulow.Dv O_NONBLOCK 5081fa2a664SJoshua M. Clulowor 5091fa2a664SJoshua M. Clulow.Dv O_NODELAY 5101fa2a664SJoshua M. ClulowOR-ed with either 5111fa2a664SJoshua M. Clulow.Dv O_RDONLY , 5121fa2a664SJoshua M. Clulow.Dv O_WRONLY , 5131fa2a664SJoshua M. Clulowor 5141fa2a664SJoshua M. Clulow.Dv O_RDWR . 5151fa2a664SJoshua M. ClulowOther flag values are not applicable to STREAMS devices and have no effect on 5161fa2a664SJoshua M. Clulowthem. 5171fa2a664SJoshua M. ClulowThe values 5181fa2a664SJoshua M. Clulow.Dv O_NONBLOCK 5191fa2a664SJoshua M. Clulowand 5201fa2a664SJoshua M. Clulow.Dv O_NODELAY 5211fa2a664SJoshua M. Clulowaffect the operation of STREAMS drivers and certain functions 5221fa2a664SJoshua M. Clulow.Po 5231fa2a664SJoshua M. Clulowsee 5241fa2a664SJoshua M. Clulow.Xr read 2 , 5251fa2a664SJoshua M. Clulow.Xr getmsg 2 , 5261fa2a664SJoshua M. Clulow.Xr putmsg 2 , 5271fa2a664SJoshua M. Clulowand 5281fa2a664SJoshua M. Clulow.Xr write 2 5291fa2a664SJoshua M. Clulow.Pc 5301fa2a664SJoshua M. Clulowapplied to file descriptors associated with STREAMS files. 5311fa2a664SJoshua M. ClulowFor STREAMS drivers, the implementation of 5321fa2a664SJoshua M. Clulow.Dv O_NONBLOCK 5331fa2a664SJoshua M. Clulowand 5341fa2a664SJoshua M. Clulow.Dv O_NODELAY 5351fa2a664SJoshua M. Clulowis device-specific. 5361fa2a664SJoshua M. Clulow.Pp 5371fa2a664SJoshua M. ClulowWhen 5381fa2a664SJoshua M. Clulow.Fn open 5391fa2a664SJoshua M. Clulowis invoked to open a named stream, and the 540*bbf21555SRichard Lowe.Xr connld 4M 5411fa2a664SJoshua M. Clulowmodule has been pushed on the pipe, 5421fa2a664SJoshua M. Clulow.Fn open 5431fa2a664SJoshua M. Clulowblocks until the server process has issued an 5441fa2a664SJoshua M. Clulow.Dv I_RECVFD 5451fa2a664SJoshua M. Clulow.Xr ioctl 2 5461fa2a664SJoshua M. Clulow.Po 5471fa2a664SJoshua M. Clulowsee 548*bbf21555SRichard Lowe.Xr streamio 4I 5491fa2a664SJoshua M. Clulow.Pc 5501fa2a664SJoshua M. Clulowto receive the file descriptor. 5511fa2a664SJoshua M. Clulow.Pp 5521fa2a664SJoshua M. ClulowIf 5531fa2a664SJoshua M. Clulow.Fa path 5541fa2a664SJoshua M. Clulownames the manager side of a pseudo-terminal device, then it is unspecified 5551fa2a664SJoshua M. Clulowwhether 5561fa2a664SJoshua M. Clulow.Fn open 5571fa2a664SJoshua M. Clulowlocks the subsidiary side so that it cannot be opened. 5581fa2a664SJoshua M. ClulowPortable applications must call 5591fa2a664SJoshua M. Clulow.Xr unlockpt 3C 5601fa2a664SJoshua M. Clulowbefore opening the subsidiary side. 5611fa2a664SJoshua M. Clulow.Pp 5621fa2a664SJoshua M. ClulowIf the file is a regular file and the local file system is mounted with the 5631fa2a664SJoshua M. Clulow.Cm nbmand 5641fa2a664SJoshua M. Clulowmount option, then a mandatory share reservation is automatically obtained on 5651fa2a664SJoshua M. Clulowthe file. 5661fa2a664SJoshua M. ClulowThe share reservation is obtained as if 5671fa2a664SJoshua M. Clulow.Xr fcntl 2 5681fa2a664SJoshua M. Clulowwere called with 5691fa2a664SJoshua M. Clulow.Fa cmd 5701fa2a664SJoshua M. Clulow.Dv F_SHARE_NBMAND 5711fa2a664SJoshua M. Clulowand the 5721fa2a664SJoshua M. Clulow.Vt fshare_t 5731fa2a664SJoshua M. Clulowvalues set as follows: 5741fa2a664SJoshua M. Clulow.Bl -tag -width Ds -offset Ds 5751fa2a664SJoshua M. Clulow.It Fa f_access 5761fa2a664SJoshua M. ClulowSet to the type of read/write access for which the file is opened. 5771fa2a664SJoshua M. Clulow.It Fa f_deny 5781fa2a664SJoshua M. Clulow.Dv F_NODNY 5791fa2a664SJoshua M. Clulow.It Fa f_id 5801fa2a664SJoshua M. ClulowThe file descriptor value returned from 5811fa2a664SJoshua M. Clulow.Fn open . 5821fa2a664SJoshua M. Clulow.El 5831fa2a664SJoshua M. Clulow.Pp 5841fa2a664SJoshua M. ClulowIf 5851fa2a664SJoshua M. Clulow.Fa path 5861fa2a664SJoshua M. Clulowis a symbolic link and 5871fa2a664SJoshua M. Clulow.Dv O_CREAT 5881fa2a664SJoshua M. Clulowand 5891fa2a664SJoshua M. Clulow.Dv O_EXCL 5901fa2a664SJoshua M. Cluloware set, the link is not followed. 5911fa2a664SJoshua M. Clulow.Pp 5921fa2a664SJoshua M. ClulowCertain flag values can be set following 5931fa2a664SJoshua M. Clulow.Fn open 5941fa2a664SJoshua M. Clulowas described in 5951fa2a664SJoshua M. Clulow.Xr fcntl 2 . 5961fa2a664SJoshua M. Clulow.Pp 5971fa2a664SJoshua M. ClulowThe largest value that can be represented correctly in an object of type 5981fa2a664SJoshua M. Clulow.Vt off_t 5991fa2a664SJoshua M. Clulowis established as the offset maximum in the open file description. 6001fa2a664SJoshua M. Clulow.Sh RETURN VALUES 60169c811abSRobert MustacchiThe 6021fa2a664SJoshua M. Clulow.Fn open 6031fa2a664SJoshua M. Clulowand 6041fa2a664SJoshua M. Clulow.Fn openat 6051fa2a664SJoshua M. Clulowfunctions open the file and, if successful, return a non-negative integer 6061fa2a664SJoshua M. Clulowrepresenting the lowest numbered unused file descriptor; otherwise the 6071fa2a664SJoshua M. Clulowvalue 6081fa2a664SJoshua M. Clulow.Sy -1 6091fa2a664SJoshua M. Clulowis returned and the global variable 6101fa2a664SJoshua M. Clulow.Va errno 6111fa2a664SJoshua M. Clulowis set to indicate the error and no files are created or modified. 6121fa2a664SJoshua M. Clulow.Sh EXAMPLES 6131fa2a664SJoshua M. Clulow.Sy Example 1 6141fa2a664SJoshua M. ClulowOpen a file for writing by the owner. 6151fa2a664SJoshua M. Clulow.Pp 6161fa2a664SJoshua M. ClulowThe following example opens the file 6171fa2a664SJoshua M. Clulow.Pa /tmp/file , 6181fa2a664SJoshua M. Cluloweither by creating it if it does not already exist, or by truncating its length 6191fa2a664SJoshua M. Clulowto 6201fa2a664SJoshua M. Clulow.Sy 0 6211fa2a664SJoshua M. Clulowif it does exist. 622c10c16deSRichard LoweIf the call creates a new file, the access permission bits in the file mode of 623c10c16deSRichard Lowethe file are set to permit reading and writing by the owner, and to permit 624c10c16deSRichard Lowereading only by group members and others. 6251fa2a664SJoshua M. Clulow.Pp 6261fa2a664SJoshua M. ClulowIf the call to 6271fa2a664SJoshua M. Clulow.Fn open 6281fa2a664SJoshua M. Clulowis successful, the file is opened for writing. 6291fa2a664SJoshua M. Clulow.Bd -literal -offset Ds 630c10c16deSRichard Lowe#include <fcntl.h> 631c10c16deSRichard Lowe\&... 632c10c16deSRichard Loweint fd; 633c10c16deSRichard Lowemode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; 634c10c16deSRichard Lowechar *filename = "/tmp/file"; 635c10c16deSRichard Lowe\&... 636c10c16deSRichard Lowefd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, mode); 637c10c16deSRichard Lowe\&... 6381fa2a664SJoshua M. Clulow.Ed 6391fa2a664SJoshua M. Clulow.Pp 6401fa2a664SJoshua M. Clulow.Sy Example 2 6411fa2a664SJoshua M. ClulowOpen a file using an existence check. 6421fa2a664SJoshua M. Clulow.Pp 6431fa2a664SJoshua M. ClulowThe following example uses the 6441fa2a664SJoshua M. Clulow.Fn open 6451fa2a664SJoshua M. Clulowfunction to try to create the 6461fa2a664SJoshua M. Clulow.Dv LOCKFILE 6471fa2a664SJoshua M. Clulowfile and open it for writing. 6481fa2a664SJoshua M. ClulowSince the 6491fa2a664SJoshua M. Clulow.Fn open 6501fa2a664SJoshua M. Clulowfunction specifies the 6511fa2a664SJoshua M. Clulow.Dv O_EXCL 6521fa2a664SJoshua M. Clulowflag, the call fails if the file already exists. 6531fa2a664SJoshua M. ClulowIn that case, the application assumes that someone else is updating the 6541fa2a664SJoshua M. Clulowpassword file and exits. 6551fa2a664SJoshua M. Clulow.Bd -literal -offset Ds 656c10c16deSRichard Lowe#include <fcntl.h> 657c10c16deSRichard Lowe#include <stdio.h> 658c10c16deSRichard Lowe#include <stdlib.h> 6591fa2a664SJoshua M. Clulow#include <err.h> 6601fa2a664SJoshua M. Clulow\&... 661c10c16deSRichard Lowe#define LOCKFILE "/etc/ptmp" 662c10c16deSRichard Lowe\&... 663c10c16deSRichard Loweint pfd; /* Integer for file descriptor returned by open() call. */ 664c10c16deSRichard Lowe\&... 665c10c16deSRichard Loweif ((pfd = open(LOCKFILE, O_WRONLY | O_CREAT | O_EXCL, 6661fa2a664SJoshua M. Clulow S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0) { 6671fa2a664SJoshua M. Clulow err(1, "Cannot open %s. Try again later.", LOCKFILE); 668c10c16deSRichard Lowe} 669c10c16deSRichard Lowe\&... 6701fa2a664SJoshua M. Clulow.Ed 6711fa2a664SJoshua M. Clulow.Pp 6721fa2a664SJoshua M. Clulow.Sy Example 3 6731fa2a664SJoshua M. ClulowOpen a file for writing. 6741fa2a664SJoshua M. Clulow.Pp 675c10c16deSRichard LoweThe following example opens a file for writing, creating the file if it does 6761fa2a664SJoshua M. Clulownot already exist. 6771fa2a664SJoshua M. ClulowIf the file does exist, the system truncates the file to zero bytes. 6781fa2a664SJoshua M. Clulow.Bd -literal -offset Ds 679c10c16deSRichard Lowe#include <fcntl.h> 680c10c16deSRichard Lowe#include <stdio.h> 681c10c16deSRichard Lowe#include <stdlib.h> 6821fa2a664SJoshua M. Clulow#include <err.h> 683c10c16deSRichard Lowe\&... 684c10c16deSRichard Loweint pfd; 685c10c16deSRichard Lowechar filename[PATH_MAX+1]; 686c10c16deSRichard Lowe\&... 687c10c16deSRichard Loweif ((pfd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 6881fa2a664SJoshua M. Clulow S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0) { 6891fa2a664SJoshua M. Clulow err(1, "Cannot open output file"); 690c10c16deSRichard Lowe} 691c10c16deSRichard Lowe\&... 6921fa2a664SJoshua M. Clulow.Ed 6931fa2a664SJoshua M. Clulow.Sh ERRORS 6941fa2a664SJoshua M. ClulowThe 6951fa2a664SJoshua M. Clulow.Fn open 6961fa2a664SJoshua M. Clulowand 6971fa2a664SJoshua M. Clulow.Fn openat 6981fa2a664SJoshua M. Clulowfunctions will fail if: 6991fa2a664SJoshua M. Clulow.Bl -tag -width Er 7001fa2a664SJoshua M. Clulow.It Er EACCES 7011fa2a664SJoshua M. ClulowSearch permission is denied on a component of the path prefix. 7021fa2a664SJoshua M. Clulow.Pp 7031fa2a664SJoshua M. ClulowThe file exists and the permissions specified by 7041fa2a664SJoshua M. Clulow.Fa oflag 7051fa2a664SJoshua M. Cluloware denied. 7061fa2a664SJoshua M. Clulow.Pp 7071fa2a664SJoshua M. ClulowThe file does not exist and write permission is denied for the parent directory 7081fa2a664SJoshua M. Clulowof the file to be created. 7091fa2a664SJoshua M. Clulow.Pp 7101fa2a664SJoshua M. Clulow.Dv O_TRUNC 7111fa2a664SJoshua M. Clulowis specified and write permission is denied. 7121fa2a664SJoshua M. Clulow.Pp 7131fa2a664SJoshua M. ClulowThe 7141fa2a664SJoshua M. Clulow.Brq Dv PRIV_FILE_DAC_SEARCH 7151fa2a664SJoshua M. Clulowprivilege allows processes to search directories regardless of permission bits. 7161fa2a664SJoshua M. ClulowThe 7171fa2a664SJoshua M. Clulow.Brq Dv PRIV_FILE_DAC_WRITE 7181fa2a664SJoshua M. Clulowprivilege allows processes to open files for writing regardless of permission 7191fa2a664SJoshua M. Clulowbits. 7201fa2a664SJoshua M. ClulowSee 721*bbf21555SRichard Lowe.Xr privileges 7 722*bbf21555SRichard Lowefor special considerations when opening files owned by user ID 7231fa2a664SJoshua M. Clulow.Sy 0 7241fa2a664SJoshua M. Clulowfor writing. 7251fa2a664SJoshua M. ClulowThe 7261fa2a664SJoshua M. Clulow.Brq Dv PRIV_FILE_DAC_READ 7271fa2a664SJoshua M. Clulowprivilege allows 7281fa2a664SJoshua M. Clulowprocesses to open files for reading regardless of permission bits. 7291fa2a664SJoshua M. Clulow.It Er EAGAIN 7301fa2a664SJoshua M. ClulowA mandatory share reservation could not be obtained because the desired access 7311fa2a664SJoshua M. Clulowconflicts with an existing 7321fa2a664SJoshua M. Clulow.Fa f_deny 7331fa2a664SJoshua M. Clulowshare reservation 7341fa2a664SJoshua M. Clulow.Po 7351fa2a664SJoshua M. Clulowsee 7361fa2a664SJoshua M. Clulow.Xr fcntl 2 7371fa2a664SJoshua M. Clulow.Pc . 7381fa2a664SJoshua M. Clulow.It Er EDQUOT 7391fa2a664SJoshua M. ClulowThe file does not exist, 7401fa2a664SJoshua M. Clulow.Dv O_CREAT 7411fa2a664SJoshua M. Clulowis specified, and either the directory where the new file entry is being placed 7421fa2a664SJoshua M. Clulowcannot be extended because the user's quota of disk blocks on that file system 7431fa2a664SJoshua M. Clulowhas been exhausted, or the user's quota of inodes on the file system where the 7441fa2a664SJoshua M. Clulowfile is being created has been exhausted. 7451fa2a664SJoshua M. Clulow.It Er EEXIST 7461fa2a664SJoshua M. ClulowThe 7471fa2a664SJoshua M. Clulow.Dv O_CREAT 7481fa2a664SJoshua M. Clulowand 7491fa2a664SJoshua M. Clulow.Dv O_EXCL 7501fa2a664SJoshua M. Clulowflags are set and the named file already exists. 7511fa2a664SJoshua M. Clulow.It Er EILSEQ 7521fa2a664SJoshua M. ClulowThe 7531fa2a664SJoshua M. Clulow.Fa path 7541fa2a664SJoshua M. Clulowargument includes bytes that are not valid UTF-8 characters, and the file 7551fa2a664SJoshua M. Clulowsystem accepts only file names where all characters are part of the UTF-8 7561fa2a664SJoshua M. Clulowcharacter codeset. 7571fa2a664SJoshua M. Clulow.It Er EINTR 7581fa2a664SJoshua M. ClulowA signal was caught during 7591fa2a664SJoshua M. Clulow.Fn open . 7601fa2a664SJoshua M. Clulow.It Er EFAULT 7611fa2a664SJoshua M. ClulowThe 7621fa2a664SJoshua M. Clulow.Fa path 7631fa2a664SJoshua M. Clulowargument points to an illegal address. 7641fa2a664SJoshua M. Clulow.It Er EINVAL 7651fa2a664SJoshua M. ClulowEither the system does not support synchronized or direct I/O for this file, or 7661fa2a664SJoshua M. Clulowthe 7671fa2a664SJoshua M. Clulow.Dv O_XATTR 7681fa2a664SJoshua M. Clulowflag was supplied and the underlying file system does not support extended file 7691fa2a664SJoshua M. Clulowattributes. 7701fa2a664SJoshua M. Clulow.It Er EIO 7711fa2a664SJoshua M. ClulowThe 7721fa2a664SJoshua M. Clulow.Fa path 7731fa2a664SJoshua M. Clulowargument names a STREAMS file and a hangup or error occurred during the 7741fa2a664SJoshua M. Clulow.Fn open . 7751fa2a664SJoshua M. Clulow.It Er EISDIR 7761fa2a664SJoshua M. ClulowThe named file is a directory and 7771fa2a664SJoshua M. Clulow.Fa oflag 7781fa2a664SJoshua M. Clulowincludes 7791fa2a664SJoshua M. Clulow.Dv O_WRONLY 7801fa2a664SJoshua M. Clulowor 7811fa2a664SJoshua M. Clulow.Dv O_RDWR . 7821fa2a664SJoshua M. Clulow.It Er ELOOP 7831fa2a664SJoshua M. ClulowToo many symbolic links were encountered in resolving 7841fa2a664SJoshua M. Clulow.Fa path . 7851fa2a664SJoshua M. Clulow.Pp 7861fa2a664SJoshua M. ClulowA loop exists in symbolic links encountered during resolution of the 7871fa2a664SJoshua M. Clulow.Fa path 7881fa2a664SJoshua M. Clulowargument. 7891fa2a664SJoshua M. Clulow.Pp 7901fa2a664SJoshua M. ClulowThe 7911fa2a664SJoshua M. Clulow.Dv O_NOFOLLOW 7921fa2a664SJoshua M. Clulowflag is set and the final component of path is a symbolic link. 7931fa2a664SJoshua M. Clulow.It Er EMFILE 7941fa2a664SJoshua M. ClulowThere are currently 7951fa2a664SJoshua M. Clulow.Brq Dv OPEN_MAX 7961fa2a664SJoshua M. Clulowfile descriptors open in the calling process. 7971fa2a664SJoshua M. Clulow.It Er EMLINK 7981fa2a664SJoshua M. ClulowThe 7991fa2a664SJoshua M. Clulow.Dv O_NOLINKS 8001fa2a664SJoshua M. Clulowflag is set and the named file has a link count greater than 8011fa2a664SJoshua M. Clulow.Sy 1 . 8021fa2a664SJoshua M. Clulow.It Er EMULTIHOP 8031fa2a664SJoshua M. ClulowComponents of 8041fa2a664SJoshua M. Clulow.Fa path 8051fa2a664SJoshua M. Clulowrequire hopping to multiple remote machines and the file system does not allow 8061fa2a664SJoshua M. Clulowit. 8071fa2a664SJoshua M. Clulow.It Er ENAMETOOLONG 8081fa2a664SJoshua M. ClulowThe length of the 8091fa2a664SJoshua M. Clulow.Fa path 8101fa2a664SJoshua M. Clulowargument exceeds 8111fa2a664SJoshua M. Clulow.Brq Dv PATH_MAX 8121fa2a664SJoshua M. Clulowor a pathname component is longer than 8131fa2a664SJoshua M. Clulow.Brq Dv NAME_MAX . 8141fa2a664SJoshua M. Clulow.It Er ENFILE 8151fa2a664SJoshua M. ClulowThe maximum allowable number of files is currently open in the system. 8161fa2a664SJoshua M. Clulow.It Er ENOENT 8171fa2a664SJoshua M. ClulowThe 8181fa2a664SJoshua M. Clulow.Dv O_CREAT 8191fa2a664SJoshua M. Clulowflag is not set and the named file does not exist; or the 8201fa2a664SJoshua M. Clulow.Dv O_CREAT 8211fa2a664SJoshua M. Clulowflag is set and either the path prefix does not exist or the 8221fa2a664SJoshua M. Clulow.Fa path 8231fa2a664SJoshua M. Clulowargument points to an empty string. 8241fa2a664SJoshua M. Clulow.Pp 8251fa2a664SJoshua M. ClulowThe 8261fa2a664SJoshua M. Clulow.Dv O_CREAT 8271fa2a664SJoshua M. Clulowand 8281fa2a664SJoshua M. Clulow.Dv O_DIRECTORY 8291fa2a664SJoshua M. Clulowflags were both set and 8301fa2a664SJoshua M. Clulow.Fa path 8311fa2a664SJoshua M. Clulowdid not point to a file. 8321fa2a664SJoshua M. Clulow.It Er ENOEXEC 8331fa2a664SJoshua M. ClulowThe 8341fa2a664SJoshua M. Clulow.Dv O_EXEC 8351fa2a664SJoshua M. Clulowflag is set and 8361fa2a664SJoshua M. Clulow.Fa path 8371fa2a664SJoshua M. Clulowdoes not point to a regular file. 8381fa2a664SJoshua M. Clulow.It Er ENOLINK 8391fa2a664SJoshua M. ClulowThe 8401fa2a664SJoshua M. Clulow.Fa path 8411fa2a664SJoshua M. Clulowargument points to a remote machine, and the link to that machine is no longer 8421fa2a664SJoshua M. Clulowactive. 8431fa2a664SJoshua M. Clulow.It Er ENOSR 8441fa2a664SJoshua M. ClulowTh 8451fa2a664SJoshua M. Clulow.Fa path 8461fa2a664SJoshua M. Clulowargument names a STREAMS-based file and the system is unable to allocate a 8471fa2a664SJoshua M. ClulowSTREAM. 8481fa2a664SJoshua M. Clulow.It Er ENOSPC 8491fa2a664SJoshua M. ClulowThe directory or file system that would contain the new file cannot be 8501fa2a664SJoshua M. Clulowexpanded, the file does not exist, and 8511fa2a664SJoshua M. Clulow.Dv O_CREAT 8521fa2a664SJoshua M. Clulowis specified. 8531fa2a664SJoshua M. Clulow.It Er ENOSYS 8541fa2a664SJoshua M. ClulowThe device specified by 8551fa2a664SJoshua M. Clulow.Fa path 8561fa2a664SJoshua M. Clulowdoes not support the open operation. 8571fa2a664SJoshua M. Clulow.It Er ENOTDIR 8581fa2a664SJoshua M. ClulowA component of the path prefix is not a directory or a relative path was 8591fa2a664SJoshua M. Clulowsupplied to 8601fa2a664SJoshua M. Clulow.Fn openat , 8611fa2a664SJoshua M. Clulowthe 8621fa2a664SJoshua M. Clulow.Dv O_XATTR 8631fa2a664SJoshua M. Clulowflag was not supplied, and the file descriptor does not refer to a directory. 8641fa2a664SJoshua M. ClulowThe 8651fa2a664SJoshua M. Clulow.Dv O_SEARCH 8661fa2a664SJoshua M. Clulowflag was passed and 8671fa2a664SJoshua M. Clulow.Fa path 8681fa2a664SJoshua M. Clulowdoes not refer to a directory. 8691fa2a664SJoshua M. Clulow.Pp 8701fa2a664SJoshua M. ClulowThe 8711fa2a664SJoshua M. Clulow.Dv O_DIRECTORY 8721fa2a664SJoshua M. Clulowflag was set and the file was not a directory. 8731fa2a664SJoshua M. Clulow.It Er ENXIO 8741fa2a664SJoshua M. ClulowThe 8751fa2a664SJoshua M. Clulow.Dv O_NONBLOCK 8761fa2a664SJoshua M. Clulowflag is set, the named file is a FIFO, the 8771fa2a664SJoshua M. Clulow.Dv O_WRONLY 8781fa2a664SJoshua M. Clulowflag is set, and no process has the file open for reading; or the named file is 8791fa2a664SJoshua M. Clulowa character special or block special file and the device associated with this 8801fa2a664SJoshua M. Clulowspecial file does not exist or has been retired by the fault management 8811fa2a664SJoshua M. Clulowframework. 8821fa2a664SJoshua M. Clulow.It Er EOPNOTSUPP 8831fa2a664SJoshua M. ClulowAn attempt was made to open a path that corresponds to an 8841fa2a664SJoshua M. Clulow.Dv AF_UNIX 8851fa2a664SJoshua M. Clulowsocket. 8861fa2a664SJoshua M. Clulow.It Er EOVERFLOW 8871fa2a664SJoshua M. ClulowThe named file is a regular file and either 8881fa2a664SJoshua M. Clulow.Dv O_LARGEFILE 8891fa2a664SJoshua M. Clulowis not set and the size of the file cannot be represented correctly in an 8901fa2a664SJoshua M. Clulowobject of type 8911fa2a664SJoshua M. Clulow.Vt off_t 8921fa2a664SJoshua M. Clulowor 8931fa2a664SJoshua M. Clulow.Dv O_LARGEFILE 8941fa2a664SJoshua M. Clulowis set and the size of the file cannot be represented correctly in an object of 8951fa2a664SJoshua M. Clulowtype 8961fa2a664SJoshua M. Clulow.Vt off64_t . 8971fa2a664SJoshua M. Clulow.It Er EROFS 8981fa2a664SJoshua M. ClulowThe named file resides on a read-only file system and either 8991fa2a664SJoshua M. Clulow.Dv O_WRONLY , 9001fa2a664SJoshua M. Clulow.Dv O_RDWR , 9011fa2a664SJoshua M. Clulow.Dv O_CREAT 9021fa2a664SJoshua M. Clulow(if file does not exist), or 9031fa2a664SJoshua M. Clulow.Dv O_TRUNC 9041fa2a664SJoshua M. Clulowis set in the 9051fa2a664SJoshua M. Clulow.Fa oflag 9061fa2a664SJoshua M. Clulowargument. 9071fa2a664SJoshua M. Clulow.El 9081fa2a664SJoshua M. Clulow.Pp 9091fa2a664SJoshua M. ClulowThe 9101fa2a664SJoshua M. Clulow.Fn openat 9111fa2a664SJoshua M. Clulowfunction will fail if: 9121fa2a664SJoshua M. Clulow.Bl -tag -width Er 9131fa2a664SJoshua M. Clulow.It Er EBADF 9141fa2a664SJoshua M. ClulowThe 9151fa2a664SJoshua M. Clulow.Fa fildes 9161fa2a664SJoshua M. Clulowargument is not a valid open file descriptor or is not 9171fa2a664SJoshua M. Clulow.Dv AT_FTCWD . 9181fa2a664SJoshua M. Clulow.El 9191fa2a664SJoshua M. Clulow.Pp 9201fa2a664SJoshua M. ClulowThe 9211fa2a664SJoshua M. Clulow.Fn open 9221fa2a664SJoshua M. Clulowfunction may fail if: 9231fa2a664SJoshua M. Clulow.Bl -tag -width Er 9241fa2a664SJoshua M. Clulow.It Er EAGAIN 9251fa2a664SJoshua M. ClulowThe 9261fa2a664SJoshua M. Clulow.Fa path 9271fa2a664SJoshua M. Clulowargument names the subsidiary side of a pseudo-terminal device that is locked. 9281fa2a664SJoshua M. Clulow.It Er EINVAL 9291fa2a664SJoshua M. ClulowThe value of the 9301fa2a664SJoshua M. Clulow.Fa oflag 9311fa2a664SJoshua M. Clulowargument is not valid. 9321fa2a664SJoshua M. Clulow.It Er ENAMETOOLONG 9331fa2a664SJoshua M. ClulowPathname resolution of a symbolic link produced an intermediate result whose 9341fa2a664SJoshua M. Clulowlength exceeds 9351fa2a664SJoshua M. Clulow.Brq Dv PATH_MAX . 9361fa2a664SJoshua M. Clulow.It Er ENOMEM 9371fa2a664SJoshua M. ClulowThe 9381fa2a664SJoshua M. Clulow.Fa path 9391fa2a664SJoshua M. Clulowargument names a STREAMS file and the system is unable to allocate resources. 9401fa2a664SJoshua M. Clulow.It Er ETXTBSY 9411fa2a664SJoshua M. ClulowThe file is a pure procedure (shared text) file that is being executed and 9421fa2a664SJoshua M. Clulow.Fa oflag 9431fa2a664SJoshua M. Clulowis 9441fa2a664SJoshua M. Clulow.Dv O_WRONLY 9451fa2a664SJoshua M. Clulowor 9461fa2a664SJoshua M. Clulow.Dv O_RDWR . 9471fa2a664SJoshua M. Clulow.El 9481fa2a664SJoshua M. Clulow.Sh USAGE 9491fa2a664SJoshua M. ClulowThe 9501fa2a664SJoshua M. Clulow.Fn open 9511fa2a664SJoshua M. Clulowfunction has a transitional interface for 64-bit file offsets. 9521fa2a664SJoshua M. ClulowSee 953*bbf21555SRichard Lowe.Xr lf64 7 . 9541fa2a664SJoshua M. ClulowNote that using 9551fa2a664SJoshua M. Clulow.Fn open64 9561fa2a664SJoshua M. Clulowis equivalent to using 9571fa2a664SJoshua M. Clulow.Fn open with 9581fa2a664SJoshua M. Clulow.Dv O_LARGEFILE 9591fa2a664SJoshua M. Clulowset in 9601fa2a664SJoshua M. Clulow.Fa oflag . 9611fa2a664SJoshua M. Clulow.Sh INTERFACE STABILITY 9621fa2a664SJoshua M. Clulow.Sy Committed 9631fa2a664SJoshua M. Clulow.Sh MT LEVEL 9641fa2a664SJoshua M. Clulow.Sy Async-Signal-Safe 9651fa2a664SJoshua M. Clulow.Sh SEE ALSO 9661fa2a664SJoshua M. Clulow.Xr chmod 2 , 9671fa2a664SJoshua M. Clulow.Xr close 2 , 9681fa2a664SJoshua M. Clulow.Xr creat 2 , 9691fa2a664SJoshua M. Clulow.Xr dup 2 , 9701fa2a664SJoshua M. Clulow.Xr exec 2 , 9711fa2a664SJoshua M. Clulow.Xr fcntl 2 , 9721fa2a664SJoshua M. Clulow.Xr getmsg 2 , 9731fa2a664SJoshua M. Clulow.Xr getrlimit 2 , 9741fa2a664SJoshua M. Clulow.Xr Intro 2 , 9751fa2a664SJoshua M. Clulow.Xr lseek 2 , 9761fa2a664SJoshua M. Clulow.Xr putmsg 2 , 9771fa2a664SJoshua M. Clulow.Xr read 2 , 9781fa2a664SJoshua M. Clulow.Xr stat 2 , 9791fa2a664SJoshua M. Clulow.Xr umask 2 , 9801fa2a664SJoshua M. Clulow.Xr write 2 , 9811fa2a664SJoshua M. Clulow.Xr attropen 3C , 9821fa2a664SJoshua M. Clulow.Xr directio 3C , 9831fa2a664SJoshua M. Clulow.Xr unlockpt 3C , 9841fa2a664SJoshua M. Clulow.Xr fcntl.h 3HEAD , 9851fa2a664SJoshua M. Clulow.Xr stat.h 3HEAD , 986*bbf21555SRichard Lowe.Xr streamio 4I , 987*bbf21555SRichard Lowe.Xr connld 4M , 988*bbf21555SRichard Lowe.Xr attributes 7 , 989*bbf21555SRichard Lowe.Xr lf64 7 , 990*bbf21555SRichard Lowe.Xr privileges 7 , 991*bbf21555SRichard Lowe.Xr standards 7 9921fa2a664SJoshua M. Clulow.Sh NOTES 9931fa2a664SJoshua M. ClulowHierarchical Storage Management 9941fa2a664SJoshua M. Clulow.Pq HSM 9951fa2a664SJoshua M. Clulowfile systems can sometimes cause long delays when opening a file, since HSM 9961fa2a664SJoshua M. Clulowfiles must be recalled from secondary storage. 997