Skip to content

Commit 826509a

Browse files
committed
open.2: Editorial pass
- Use a typical tagged list for the open flags instead of a literal block. This permits using markup in the flag descriptions. Also, drop the offset to avoid indenting the entire list. - Note that O_RESOLVE_BENEATH only applies to openat(2) - Use a clearer description of O_CLOEXEC (what it means, not the internal flag it sets) - Note that exactly one permission flag is required. - Split up a paragraph on various flags so that each flag gets its own paragraph. Some flags already had their own paragraph, so this is more consistent. It also makes it clearer which flag a sentence is talking about when a flag has more than one sentence. - Appease some errors from igor and man2ps - In the discussion about a returned directory descriptor opened with O_SEARCH, avoid the use of Fa fd since the descriptor in question is a return value and not an argument to open or openat. - Various and sundry markup and language tweaks Reviewed by: kib, emaste Differential Revision: https://reviews.freebsd.org/D48253
1 parent f586d52 commit 826509a

File tree

1 file changed

+123
-61
lines changed

1 file changed

+123
-61
lines changed

lib/libsys/open.2

Lines changed: 123 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2626
.\" SUCH DAMAGE.
2727
.\"
28-
.Dd August 25, 2024
28+
.Dd January 3, 2025
2929
.Dt OPEN 2
3030
.Os
3131
.Sh NAME
@@ -114,7 +114,8 @@ The
114114
argument to
115115
.Fn openat
116116
must be strictly relative to a file descriptor
117-
.Fa fd .
117+
.Fa fd ;
118+
that is,
118119
.Fa path
119120
must not be an absolute path and must not contain ".." components
120121
which cause the path resolution to escape the directory hierarchy
@@ -137,54 +138,107 @@ If the
137138
.Dv vfs.lookup_cap_dotdot_nonlocal
138139
MIB is set to zero, ".." is not allowed if found on non-local filesystem.
139140
.Pp
140-
The flags specified are formed by
141+
The
142+
.Fa flags
143+
are formed by
141144
.Em or Ns 'ing
142-
the following values
143-
.Pp
144-
.Bd -literal -offset indent -compact
145-
O_RDONLY open for reading only
146-
O_WRONLY open for writing only
147-
O_RDWR open for reading and writing
148-
O_EXEC open for execute only
149-
O_SEARCH open for search only, an alias for O_EXEC
150-
O_NONBLOCK do not block on open
151-
O_APPEND append on each write
152-
O_CREAT create file if it does not exist
153-
O_TRUNC truncate size to 0
154-
O_EXCL error if create and file exists
155-
O_SHLOCK atomically obtain a shared lock
156-
O_EXLOCK atomically obtain an exclusive lock
157-
O_DIRECT eliminate or reduce cache effects
158-
O_FSYNC synchronous writes (historical synonym for O_SYNC)
159-
O_SYNC synchronous writes
160-
O_DSYNC synchronous data writes
161-
O_NOFOLLOW do not follow symlinks
162-
O_NOCTTY ignored
163-
O_TTY_INIT ignored
164-
O_DIRECTORY error if file is not a directory
165-
O_CLOEXEC set FD_CLOEXEC upon open
166-
O_VERIFY verify the contents of the file
167-
O_RESOLVE_BENEATH path resolution must not cross the fd directory
168-
O_PATH record only the target path in the opened descriptor
169-
O_EMPTY_PATH openat, open file referenced by fd if path is empty
170-
.Ed
145+
the following values:
146+
.Pp
147+
.Bl -tag -width O_RESOLVE_BENEATH
148+
.It Dv O_RDONLY
149+
open for reading only
150+
.It Dv O_WRONLY
151+
open for writing only
152+
.It Dv O_RDWR
153+
open for reading and writing
154+
.It Dv O_EXEC
155+
open for execute only
156+
.It Dv O_SEARCH
157+
open for search only
158+
(an alias for
159+
.Dv O_EXEC
160+
typically used with
161+
.Dv O_DIRECTORY )
162+
.It Dv O_NONBLOCK
163+
do not block on open
164+
.It Dv O_APPEND
165+
set file pointer to the end of the file before each write
166+
.It Dv O_CREAT
167+
create file if it does not exist
168+
.It Dv O_TRUNC
169+
truncate size to 0
170+
.It Dv O_EXCL
171+
fail if
172+
.Dv O_CREAT
173+
is set and the file exists
174+
.It Dv O_SHLOCK
175+
atomically obtain a shared lock
176+
.It Dv O_EXLOCK
177+
atomically obtain an exclusive lock
178+
.It Dv O_DIRECT
179+
read and write directly from the backing store
180+
.It Dv O_FSYNC
181+
synchronous data and metadata writes
182+
.Pq historical synonym for Dv O_SYNC
183+
.It Dv O_SYNC
184+
synchronous data and metadata writes
185+
.It Dv O_DSYNC
186+
synchronous data writes
187+
.It Dv O_NOFOLLOW
188+
do not follow symlinks
189+
.It Dv O_NOCTTY
190+
ignored
191+
.It Dv O_TTY_INIT
192+
ignored
193+
.It Dv O_DIRECTORY
194+
error if file is not a directory
195+
.It Dv O_CLOEXEC
196+
automatically close file on
197+
.Xr execve 2
198+
.It Dv O_VERIFY
199+
verify the contents of the file with
200+
.Xr mac_veriexec 4
201+
.It Dv O_RESOLVE_BENEATH
202+
.Pq Xr openat 2 only
203+
path resolution must not cross the
204+
.Fa fd
205+
directory
206+
.It Dv O_PATH
207+
record only the target path in the opened descriptor
208+
.It Dv O_EMPTY_PATH
209+
.Pq Xr openat 2 only
210+
open file referenced by
211+
.Fa fd
212+
if path is empty
213+
.El
214+
.Pp
215+
Exactly one of the flags
216+
.Dv O_RDONLY ,
217+
.Dv O_WRONLY ,
218+
.Dv O_RDWR ,
219+
or
220+
.Dv O_EXEC
221+
must be provided.
171222
.Pp
172223
Opening a file with
173224
.Dv O_APPEND
174-
set causes each write on the file
175-
to be appended to the end.
225+
set causes each write on the resulting file descriptor
226+
to be appended to the end of the file.
227+
.Pp
176228
If
177229
.Dv O_TRUNC
178230
is specified and the
179231
file exists, the file is truncated to zero length.
232+
.Pp
180233
If
181234
.Dv O_EXCL
182235
is set with
183236
.Dv O_CREAT
184237
and the file already
185238
exists,
186239
.Fn open
187-
returns an error.
240+
fails with
241+
.Er EEXIST .
188242
This may be used to
189243
implement a simple exclusive access locking mechanism.
190244
If
@@ -194,12 +248,13 @@ a symbolic link,
194248
.Fn open
195249
will fail even if the symbolic
196250
link points to a non-existent name.
197-
If the
251+
.Pp
252+
If
198253
.Dv O_NONBLOCK
199-
flag is specified and the
254+
is specified and the
200255
.Fn open
201-
system call would result
202-
in the process being blocked for some reason (e.g., waiting for
256+
system call would
257+
block for some reason (for example, waiting for
203258
carrier on a dialup line),
204259
.Fn open
205260
returns immediately.
@@ -245,6 +300,8 @@ The system will attempt to avoid caching the data you read or write.
245300
If it cannot avoid caching the data,
246301
it will minimize the impact the data has on the cache.
247302
Use of this flag can drastically reduce performance if not used with care.
303+
The semantics of this flag are filesystem dependent,
304+
and some filesystems may ignore it entirely.
248305
.Pp
249306
.Dv O_NOCTTY
250307
may be used to ensure the OS does not assign this file as the
@@ -302,24 +359,24 @@ reside in the directory hierarchy beneath the starting directory.
302359
Absolute paths or even the temporal escape from beneath of the starting
303360
directory is not allowed.
304361
.Pp
305-
When
306-
.Fa fd
362+
When a directory
307363
is opened with
308364
.Dv O_SEARCH ,
309365
execute permissions are checked at open time.
310-
The
311-
.Fa fd
366+
The returned file descriptor
312367
may not be used for any read operations like
313368
.Xr getdirentries 2 .
314-
The primary use for this descriptor will be as the lookup descriptor for the
369+
The primary use of this descriptor is as the lookup descriptor for the
315370
.Fn *at
316371
family of functions.
317372
If
318373
.Dv O_SEARCH
319374
was not requested at open time, then the
320375
.Fn *at
321376
functions use the current directory permissions for the directory referenced
322-
by the descriptor at the time of the call.
377+
by the descriptor at the time of the
378+
.Fn *at
379+
call.
323380
.Pp
324381
.Dv O_PATH
325382
returns a file descriptor that can be used as a directory file descriptor for
@@ -328,9 +385,9 @@ and other system calls taking a file descriptor argument, like
328385
.Xr fstatat 2
329386
and others.
330387
The other functionality of the returned file descriptor is limited to
331-
the descriptor-level operations.
332-
It can be used for
333-
.Bl -tag -width readlinkat(2) -offset indent -compact
388+
the following descriptor-level operations:
389+
.Pp
390+
.Bl -tag -width __acl_aclcheck_fd -offset indent -compact
334391
.It Xr fcntl 2
335392
but advisory locking is not allowed
336393
.It Xr dup 2
@@ -344,12 +401,14 @@ socket using a
344401
.Dv SCM_RIGHTS
345402
message
346403
.It Xr kqueue 2
347-
using for
404+
only with
348405
.Dv EVFILT_VNODE
349406
.It Xr readlinkat 2
350-
.It Xr __acl_get_fd 2 , Xr __acl_aclcheck_fd 2
407+
.It Xr __acl_get_fd 2
408+
.It Xr __acl_aclcheck_fd 2
351409
.El
352-
But operations like
410+
.Pp
411+
Other operations like
353412
.Xr read 2 ,
354413
.Xr ftruncate 2 ,
355414
and any other that operate on file and not on file descriptor (except
@@ -358,18 +417,19 @@ are not allowed.
358417
.Pp
359418
A file descriptor created with the
360419
.Dv O_PATH
361-
flag can be opened into normal (operable) file descriptor by
420+
flag can be opened as a normal (operable) file descriptor by
362421
specifying it as the
363422
.Fa fd
364423
argument to
365424
.Fn openat
366-
with empty
425+
with an empty
367426
.Fa path
368-
and flag
369-
.Dv O_EMPTY_PATH .
427+
and the
428+
.Dv O_EMPTY_PATH
429+
flag.
370430
Such an open behaves as if the current path of the file referenced by
371431
.Fa fd
372-
is passed, except that the path walk permissions are not checked.
432+
is passed, except that path walk permissions are not checked.
373433
See also the description of
374434
.Dv AT_EMPTY_PATH
375435
flag for
@@ -380,6 +440,8 @@ If successful,
380440
.Fn open
381441
returns a non-negative integer, termed a file descriptor.
382442
It returns \-1 on failure.
443+
The file descriptor value returned is the lowest numbered descriptor
444+
currently not in use by the process.
383445
The file pointer used to mark the current position within the
384446
file is set to the beginning of the file.
385447
.Pp
@@ -394,7 +456,7 @@ A sleeping open of a fifo (see
394456
.Xr mkfifo 2 )
395457
is restarted as normal.
396458
.Pp
397-
When a new file is created it is given the group of the directory
459+
When a new file is created, it is assigned the group of the directory
398460
which contains it.
399461
.Pp
400462
Unless
@@ -405,9 +467,9 @@ the new descriptor is set to remain open across
405467
system calls; see
406468
.Xr close 2 ,
407469
.Xr fcntl 2
408-
and
470+
and the description of the
409471
.Dv O_CLOEXEC
410-
description.
472+
flag.
411473
.Pp
412474
The system imposes a limit on the number of file descriptors
413475
open simultaneously by one process.
@@ -511,7 +573,7 @@ or
511573
is specified but the underlying file system does not support locking.
512574
.It Bq Er EOPNOTSUPP
513575
The named file is a special file mounted through a file system that
514-
does not support access to it (e.g.\& NFS).
576+
does not support access to it (for example, NFS).
515577
.It Bq Er EWOULDBLOCK
516578
.Dv O_NONBLOCK
517579
and one of
@@ -688,7 +750,7 @@ system call is believed to be compatible with
688750
.\" .St -p1003.1-2017 ,
689751
.\" XXX: This should be replaced in the future when an appropriate argument to
690752
.\" the St macro is available: -p1003.1-2017
691-
.No IEEE Std 1003.1-2008, 2017 Edition (\\(LqPOSIX.1\\(Rq) ,
753+
.No IEEE Std 1003.1-2008, 2017 Edition ("POSIX.1") ,
692754
which specifies that behavior for
693755
.Dv O_SEARCH ,
694756
in the absence of the flag the implementation checks the current

0 commit comments

Comments
 (0)