Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/sys/open.2
Show All 22 Lines | |||||||||||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||||||||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||||||||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||||||||||
.\" SUCH DAMAGE. | .\" SUCH DAMAGE. | ||||||||||||
.\" | .\" | ||||||||||||
.\" @(#)open.2 8.2 (Berkeley) 11/16/93 | .\" @(#)open.2 8.2 (Berkeley) 11/16/93 | ||||||||||||
.\" $FreeBSD$ | .\" $FreeBSD$ | ||||||||||||
.\" | .\" | ||||||||||||
.Dd February 23, 2021 | .Dd March 18, 2021 | ||||||||||||
.Dt OPEN 2 | .Dt OPEN 2 | ||||||||||||
.Os | .Os | ||||||||||||
.Sh NAME | .Sh NAME | ||||||||||||
.Nm open , openat | .Nm open , openat | ||||||||||||
.Nd open or create a file for reading, writing or executing | .Nd open or create a file for reading, writing or executing | ||||||||||||
.Sh LIBRARY | .Sh LIBRARY | ||||||||||||
.Lb libc | .Lb libc | ||||||||||||
.Sh SYNOPSIS | .Sh SYNOPSIS | ||||||||||||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | |||||||||||||
O_DSYNC synchronous data writes | O_DSYNC synchronous data writes | ||||||||||||
O_NOFOLLOW do not follow symlinks | O_NOFOLLOW do not follow symlinks | ||||||||||||
O_NOCTTY ignored | O_NOCTTY ignored | ||||||||||||
O_TTY_INIT ignored | O_TTY_INIT ignored | ||||||||||||
O_DIRECTORY error if file is not a directory | O_DIRECTORY error if file is not a directory | ||||||||||||
O_CLOEXEC set FD_CLOEXEC upon open | O_CLOEXEC set FD_CLOEXEC upon open | ||||||||||||
O_VERIFY verify the contents of the file | O_VERIFY verify the contents of the file | ||||||||||||
O_RESOLVE_BENEATH path resolution must not cross the fd directory | O_RESOLVE_BENEATH path resolution must not cross the fd directory | ||||||||||||
O_PATH record only the target path in the opened descriptor | |||||||||||||
.Ed | .Ed | ||||||||||||
.Pp | .Pp | ||||||||||||
Opening a file with | Opening a file with | ||||||||||||
.Dv O_APPEND | .Dv O_APPEND | ||||||||||||
set causes each write on the file | set causes each write on the file | ||||||||||||
to be appended to the end. | to be appended to the end. | ||||||||||||
If | If | ||||||||||||
.Dv O_TRUNC | .Dv O_TRUNC | ||||||||||||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | |||||||||||||
execute permissions are checked at open time. | execute permissions are checked at open time. | ||||||||||||
The | The | ||||||||||||
.Fa fd | .Fa fd | ||||||||||||
may not be used for any read operations like | may not be used for any read operations like | ||||||||||||
.Xr getdirentries 2 . | .Xr getdirentries 2 . | ||||||||||||
The primary use for this descriptor will be as the lookup descriptor for the | The primary use for this descriptor will be as the lookup descriptor for the | ||||||||||||
.Fn *at | .Fn *at | ||||||||||||
family of functions. | family of functions. | ||||||||||||
.Pp | |||||||||||||
.Dv O_PATH | |||||||||||||
returns a file descriptor that can be used as a directory file descriptor for | |||||||||||||
markjUnsubmitted Done Inline Actions
markj: | |||||||||||||
.Xr openat 2 | |||||||||||||
and other system calls taking a file descriptor argument, like | |||||||||||||
Done Inline Actions
markj: | |||||||||||||
.Xr fstatat 2 | |||||||||||||
Done Inline Actions
markj: | |||||||||||||
Done Inline Actions
markj: | |||||||||||||
and others. | |||||||||||||
The other functionality of the returned file descriptor is limited to | |||||||||||||
the descriptor-level operations. | |||||||||||||
It can be used for | |||||||||||||
Done Inline Actions
markj: | |||||||||||||
.Bl -tag -width SCM_RIGHTS -offset indent -compact | |||||||||||||
.It Xr fcntl 2 | |||||||||||||
but advisory locking is not allowed | |||||||||||||
.It Xr dup 2 | |||||||||||||
.It Xr close 2 | |||||||||||||
Done Inline Actions.Xr unix 4? markj: .Xr unix 4? | |||||||||||||
Done Inline Actions
markj: | |||||||||||||
.It Xr fstat 2 | |||||||||||||
.It Xr fexecve 2 | |||||||||||||
requires that | |||||||||||||
.Dv O_EXEC | |||||||||||||
was also specified at open time | |||||||||||||
.It Dv SCM_RIGHTS | |||||||||||||
can be passed over a | |||||||||||||
.Xr unix 4 | |||||||||||||
socket using a | |||||||||||||
.Dv SCM_RIGHTS | |||||||||||||
message | |||||||||||||
.It Xr kqueue 2 | |||||||||||||
using for | |||||||||||||
.Dv EVFILT_VNODE | |||||||||||||
.El | |||||||||||||
But operations like | |||||||||||||
.Xr read 2 , | |||||||||||||
.Xr ftruncate 2 , | |||||||||||||
and any other that operate on file and not on file descriptor (except | |||||||||||||
.Xr fstat 2 ), | |||||||||||||
are not allowed. | |||||||||||||
File opened with the | |||||||||||||
.Dv O_PATH | |||||||||||||
flag does not prevent non-forced unmount of the volume it belongs to. | |||||||||||||
See also the description of | |||||||||||||
.Dv AT_EMPTY_PATH | |||||||||||||
flag for | |||||||||||||
.Xr fstatat 2 | |||||||||||||
and related syscalls. | |||||||||||||
.Pp | .Pp | ||||||||||||
If successful, | If successful, | ||||||||||||
.Fn open | .Fn open | ||||||||||||
returns a non-negative integer, termed a file descriptor. | returns a non-negative integer, termed a file descriptor. | ||||||||||||
It returns \-1 on failure. | It returns \-1 on failure. | ||||||||||||
The file pointer used to mark the current position within the | The file pointer used to mark the current position within the | ||||||||||||
file is set to the beginning of the file. | file is set to the beginning of the file. | ||||||||||||
.Pp | .Pp | ||||||||||||
▲ Show 20 Lines • Show All 299 Lines • Show Last 20 Lines |