]>
Commit | Line | Data |
---|---|---|
b0d623f7 | 1 | .\" |
6d2010ae | 2 | .\" Copyright (c) 2011 Apple Inc. All rights reserved. |
b0d623f7 A |
3 | .\" |
4 | .\" @APPLE_LICENSE_HEADER_START@ | |
5 | .\" | |
6 | .\" This file contains Original Code and/or Modifications of Original Code | |
7 | .\" as defined in and that are subject to the Apple Public Source License | |
8 | .\" Version 2.0 (the 'License'). You may not use this file except in | |
9 | .\" compliance with the License. Please obtain a copy of the License at | |
10 | .\" http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | .\" file. | |
12 | .\" | |
13 | .\" The Original Code and all software distributed under the License are | |
14 | .\" distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
15 | .\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
16 | .\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
17 | .\" FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
18 | .\" Please see the License for the specific language governing rights and | |
19 | .\" limitations under the License. | |
20 | .\" | |
21 | .\" @APPLE_LICENSE_HEADER_END@ | |
22 | .\" | |
23 | .\" | |
9bccf70c A |
24 | .\" $NetBSD: fcntl.2,v 1.6 1995/02/27 12:32:29 cgd Exp $ |
25 | .\" | |
26 | .\" Copyright (c) 1983, 1993 | |
27 | .\" The Regents of the University of California. All rights reserved. | |
28 | .\" | |
29 | .\" Redistribution and use in source and binary forms, with or without | |
30 | .\" modification, are permitted provided that the following conditions | |
31 | .\" are met: | |
32 | .\" 1. Redistributions of source code must retain the above copyright | |
33 | .\" notice, this list of conditions and the following disclaimer. | |
34 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
35 | .\" notice, this list of conditions and the following disclaimer in the | |
36 | .\" documentation and/or other materials provided with the distribution. | |
37 | .\" 3. All advertising materials mentioning features or use of this software | |
38 | .\" must display the following acknowledgement: | |
39 | .\" This product includes software developed by the University of | |
40 | .\" California, Berkeley and its contributors. | |
41 | .\" 4. Neither the name of the University nor the names of its contributors | |
42 | .\" may be used to endorse or promote products derived from this software | |
43 | .\" without specific prior written permission. | |
44 | .\" | |
45 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
46 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
47 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
48 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
49 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
50 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
51 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
52 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
53 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
54 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
55 | .\" SUCH DAMAGE. | |
56 | .\" | |
57 | .\" @(#)fcntl.2 8.2 (Berkeley) 1/12/94 | |
58 | .\" | |
0a7de745 | 59 | .Dd August 8, 2018 |
9bccf70c A |
60 | .Dt FCNTL 2 |
61 | .Os BSD 4.2 | |
62 | .Sh NAME | |
63 | .Nm fcntl | |
64 | .Nd file control | |
65 | .Sh SYNOPSIS | |
66 | .Fd #include <fcntl.h> | |
67 | .Ft int | |
2d21ac55 A |
68 | .Fo fcntl |
69 | .Fa "int fildes" | |
70 | .Fa "int cmd" | |
71 | .Fa "..." | |
72 | .Fc | |
9bccf70c | 73 | .Sh DESCRIPTION |
39037602 | 74 | .Fn fcntl |
9bccf70c A |
75 | provides for control over descriptors. |
76 | The argument | |
2d21ac55 | 77 | .Fa fildes |
9bccf70c A |
78 | is a descriptor to be operated on by |
79 | .Fa cmd | |
80 | as follows: | |
81 | .Bl -tag -width F_WRITEBOOTSTRAPX | |
82 | .It Dv F_DUPFD | |
83 | Return a new descriptor as follows: | |
84 | .Pp | |
85 | .Bl -bullet -compact -offset 4n | |
86 | .It | |
87 | Lowest numbered available descriptor greater than or equal to | |
88 | .Fa arg . | |
89 | .It | |
90 | Same object references as the original descriptor. | |
91 | .It | |
92 | New descriptor shares the same file offset if the object | |
93 | was a file. | |
94 | .It | |
95 | Same access mode (read, write or read/write). | |
96 | .It | |
97 | Same file status flags (i.e., both file descriptors | |
98 | share the same file status flags). | |
99 | .It | |
100 | The close-on-exec flag associated with the new file descriptor | |
6d2010ae | 101 | is cleared so that the descriptor remains open across an |
9bccf70c | 102 | .Xr execv 2 |
6d2010ae | 103 | system call. |
9bccf70c | 104 | .El |
6d2010ae A |
105 | .It Dv F_DUPFD_CLOEXEC |
106 | Like | |
107 | .Dv F_DUPFD , | |
108 | except that the close-on-exec flag associated with the new file descriptor | |
109 | is set. | |
9bccf70c | 110 | .It Dv F_GETFD |
6d2010ae A |
111 | Get the flags associated with the file descriptor |
112 | .Fa fildes , | |
113 | as described below | |
9bccf70c A |
114 | .Fa ( arg |
115 | is ignored). | |
116 | .It Dv F_SETFD | |
6d2010ae A |
117 | Set the file descriptor flags to |
118 | .Fa arg . | |
9bccf70c A |
119 | .It Dv F_GETFL |
120 | Get descriptor status flags, as described below | |
121 | .Fa ( arg | |
122 | is ignored). | |
123 | .It Dv F_SETFL | |
124 | Set descriptor status flags to | |
125 | .Fa arg . | |
126 | .It Dv F_GETOWN | |
127 | Get the process ID or process group | |
128 | currently receiving | |
129 | .Dv SIGIO | |
130 | and | |
131 | .Dv SIGURG | |
132 | signals; process groups are returned | |
133 | as negative values | |
134 | .Fa ( arg | |
135 | is ignored). | |
136 | .It Dv F_SETOWN | |
137 | Set the process or process group | |
138 | to receive | |
139 | .Dv SIGIO | |
140 | and | |
141 | .Dv SIGURG | |
142 | signals; | |
143 | process groups are specified by supplying | |
144 | .Fa arg | |
145 | as negative, otherwise | |
146 | .Fa arg | |
147 | is interpreted as a process ID. | |
2d21ac55 | 148 | .It Dv F_GETPATH |
cb323159 A |
149 | Get the path of the file descriptor |
150 | .It Dv F_GETPATH_NOFIRMLINK | |
151 | Get the non firmlinked path of the file descriptor | |
2d21ac55 A |
152 | .Fa Fildes . |
153 | The argument must be a buffer of size | |
154 | .Sy MAXPATHLEN | |
155 | or greater. | |
9bccf70c | 156 | .It Dv F_PREALLOCATE |
b0d623f7 | 157 | Preallocate file storage space. Note: upon success, |
a39ff7e2 A |
158 | the space that is allocated can be the size requested, |
159 | larger than the size requested, or (if the | |
160 | .Dv F_ALLOCATEALL | |
161 | flag is not provided) smaller than the space requested. | |
813fb2f6 A |
162 | .It Dv F_PUNCHHOLE |
163 | Deallocate a region and replace it with a hole. Subsequent reads of the | |
164 | affected region will return bytes of zeros that are usually not backed by | |
165 | physical blocks. This will not change the actual file size. Holes must be | |
166 | aligned to file system block boundaries. This will fail on | |
167 | file systems that do not support this interface. | |
9bccf70c A |
168 | .It Dv F_SETSIZE |
169 | Truncate a file without zeroing space. | |
170 | The calling process must have root privileges. | |
171 | .It Dv F_RDADVISE | |
172 | Issue an advisory read async with no copy to user. | |
173 | .It Dv F_RDAHEAD | |
174 | Turn read ahead off/on. | |
175 | A zero value in | |
176 | .Fa arg | |
177 | disables read ahead. | |
178 | A non-zero value in | |
179 | .Fa arg | |
180 | turns read ahead on. | |
9bccf70c A |
181 | .It Dv F_NOCACHE |
182 | Turns data caching off/on. A non-zero value in | |
183 | .Fa arg | |
184 | turns data caching off. | |
185 | A value of zero in | |
186 | .Fa arg | |
187 | turns data caching on. | |
188 | .It Dv F_LOG2PHYS | |
189 | Get disk device information. | |
5ba3f43e | 190 | Currently this only returns the |
9bccf70c | 191 | disk device address that corresponds |
5ba3f43e A |
192 | to the current file offset. Note that the system |
193 | may return -1 as the disk device address if the file is not | |
194 | backed by physical blocks. This is subject | |
39236c6e | 195 | to change. |
6d2010ae A |
196 | .It Dv F_LOG2PHYS_EXT |
197 | Variant of F_LOG2PHYS that uses the passed in | |
198 | file offset and length. | |
cb323159 A |
199 | .It Dv F_BARRIERFSYNC |
200 | Does the same thing as | |
201 | .Xr fsync 2 | |
202 | then issues a barrier command to the drive | |
203 | .Fa ( arg | |
204 | is ignored). | |
205 | The barrier applies to I/O that have been flushed with | |
206 | .Xr fsync 2 | |
207 | on the same device before. These operations are guaranteed to | |
208 | be persisted before any other I/O that would follow the barrier, | |
209 | although no assumption should be made on what has been persisted | |
210 | or not when this call returns. After the barrier has been issued, | |
211 | operations on other FDs that have been fsync'd before can still be | |
212 | re-ordered by the device, but not after the barrier. This is | |
213 | typically useful to guarantee valid state on disk when ordering is a | |
214 | concern but durability is not. A barrier can be used to order two phases of operations on | |
215 | a set of file descriptors and ensure that no file can possibly get persisted | |
216 | with the effect of the second phase without the effect of the first one. To do so, | |
217 | execute operations of phase one, then | |
218 | .Xr fsync 2 | |
219 | each FD and issue a single barrier. Finally execute operations of phase two. | |
220 | This is currently implemented on HFS and APFS. It requires hardware support, | |
221 | which Apple SSDs are guaranteed to provide. | |
91447636 A |
222 | .It Dv F_FULLFSYNC |
223 | Does the same thing as | |
224 | .Xr fsync 2 | |
225 | then asks the drive to | |
226 | flush all buffered data to | |
227 | the permanent storage device | |
228 | .Fa ( arg | |
229 | is ignored). | |
cb323159 A |
230 | As this drains the entire queue of the device and acts as a |
231 | barrier, data that had been fsync'd on the same device before | |
232 | is guaranteed to be persisted when this call returns. | |
2d21ac55 | 233 | This is currently implemented on HFS, MS-DOS (FAT), |
cb323159 | 234 | Universal Disk Format (UDF) and APFS file systems. |
2d21ac55 A |
235 | The operation may take quite a while to complete. |
236 | Certain FireWire drives have also been known | |
237 | to ignore the request to flush their buffered data. | |
6d2010ae A |
238 | .It Dv F_SETNOSIGPIPE |
239 | Determines whether a | |
240 | .Dv SIGPIPE | |
241 | signal will be generated when a write fails on a pipe or socket for | |
242 | which there is no reader. If | |
243 | .Fa arg | |
244 | is non-zero, | |
245 | .Dv SIGPIPE | |
246 | generation is disabled for descriptor | |
247 | .Fa fildes , | |
248 | while an | |
249 | .Fa arg | |
250 | of zero enables it (the default). | |
251 | .It Dv F_GETNOSIGPIPE | |
252 | Returns whether a | |
253 | .Dv SIGPIPE | |
254 | signal will be generated when a write fails on a pipe or socket | |
255 | for which there is no reader. The semantics of the return value | |
256 | match those of the | |
257 | .Fa arg | |
258 | of | |
259 | .Dv F_SETNOSIGPIPE . | |
260 | .El | |
261 | .Pp | |
262 | The flags for the | |
263 | .Dv F_GETFD | |
264 | and | |
265 | .Dv F_SETFD | |
266 | commands are as follows: | |
267 | .Bl -tag -width FD_CLOEXECX -offset indent | |
268 | .It Dv FD_CLOEXEC | |
269 | Close-on-exec; the given file descriptor will be automatically | |
270 | closed in the successor process image when one of the | |
271 | .Xr execv 2 | |
272 | or | |
273 | .Xr posix_spawn 2 | |
274 | family of system calls is invoked. | |
9bccf70c A |
275 | .El |
276 | .Pp | |
277 | The flags for the | |
278 | .Dv F_GETFL | |
279 | and | |
280 | .Dv F_SETFL | |
281 | commands are as follows: | |
282 | .Bl -tag -width O_NONBLOCKX -offset indent | |
283 | .It Dv O_NONBLOCK | |
284 | Non-blocking I/O; if no data is available to a | |
285 | .Xr read | |
286 | call, or if a | |
287 | .Xr write | |
288 | operation would block, | |
289 | the read or write call returns -1 with the error | |
290 | .Er EAGAIN . | |
291 | .It Dv O_APPEND | |
292 | Force each write to append at the end of file; | |
293 | corresponds to the | |
294 | .Dv O_APPEND | |
295 | flag of | |
296 | .Xr open 2 . | |
297 | .It Dv O_ASYNC | |
298 | Enable the | |
299 | .Dv SIGIO | |
300 | signal to be sent to the process group | |
301 | when I/O is possible, e.g., | |
302 | upon availability of data to be read. | |
303 | .El | |
304 | .Pp | |
305 | Several commands are available for doing advisory file locking; | |
306 | they all operate on the following structure: | |
307 | .ne 7v | |
308 | .Bd -literal | |
309 | struct flock { | |
310 | off_t l_start; /* starting offset */ | |
311 | off_t l_len; /* len = 0 means until end of file */ | |
312 | pid_t l_pid; /* lock owner */ | |
313 | short l_type; /* lock type: read/write, etc. */ | |
314 | short l_whence; /* type of l_start */ | |
315 | }; | |
316 | .Ed | |
317 | .Pp | |
318 | The commands available for advisory record locking are as follows: | |
319 | .Bl -tag -width F_SETLKWX | |
320 | .It Dv F_GETLK | |
321 | Get the first lock that blocks the lock description pointed to by the | |
322 | third argument, | |
323 | .Fa arg , | |
324 | taken as a pointer to a | |
325 | .Fa "struct flock" | |
326 | (see above). | |
327 | The information retrieved overwrites the information passed to | |
328 | .Nm fcntl | |
329 | in the | |
330 | .Fa flock | |
331 | structure. | |
332 | If no lock is found that would prevent this lock from being created, | |
333 | the structure is left unchanged by this function call except for the | |
334 | lock type which is set to | |
335 | .Dv F_UNLCK . | |
336 | .It Dv F_SETLK | |
337 | Set or clear a file segment lock according to the lock description | |
338 | pointed to by the third argument, | |
339 | .Fa arg , | |
340 | taken as a pointer to a | |
341 | .Fa "struct flock" | |
342 | (see above). | |
343 | .Dv F_SETLK | |
344 | is used to establish shared (or read) locks | |
345 | .Dv (F_RDLCK) | |
346 | or exclusive (or write) locks, | |
347 | .Dv (F_WRLCK) , | |
348 | as well as remove either type of lock | |
349 | .Dv (F_UNLCK) . | |
350 | If a shared or exclusive lock cannot be set, | |
351 | .Nm fcntl | |
352 | returns immediately with | |
b0d623f7 | 353 | .Er EAGAIN . |
9bccf70c A |
354 | .It Dv F_SETLKW |
355 | This command is the same as | |
356 | .Dv F_SETLK | |
357 | except that if a shared or exclusive lock is blocked by other locks, | |
358 | the process waits until the request can be satisfied. | |
359 | If a signal that is to be caught is received while | |
360 | .Nm fcntl | |
361 | is waiting for a region, the | |
362 | .Nm fcntl | |
363 | will be interrupted if the signal handler has not specified the | |
364 | .Dv SA_RESTART | |
365 | (see | |
366 | .Xr sigaction 2 ) . | |
367 | .El | |
368 | .Pp | |
369 | When a shared lock has been set on a segment of a file, | |
370 | other processes can set shared locks on that segment | |
371 | or a portion of it. | |
372 | A shared lock prevents any other process from setting an exclusive | |
373 | lock on any portion of the protected area. | |
374 | A request for a shared lock fails if the file descriptor was not | |
375 | opened with read access. | |
376 | .Pp | |
377 | An exclusive lock prevents any other process from setting a shared lock or | |
378 | an exclusive lock on any portion of the protected area. | |
379 | A request for an exclusive lock fails if the file was not | |
380 | opened with write access. | |
381 | .Pp | |
382 | The value of | |
383 | .Fa l_whence | |
384 | is | |
385 | .Dv SEEK_SET , | |
386 | .Dv SEEK_CUR , | |
387 | or | |
388 | .Dv SEEK_END | |
389 | to indicate that the relative offset, | |
390 | .Fa l_start | |
391 | bytes, will be measured from the start of the file, | |
392 | current position, or end of the file, respectively. | |
393 | The value of | |
394 | .Fa l_len | |
395 | is the number of consecutive bytes to be locked. | |
396 | If | |
397 | .Fa l_len | |
398 | is negative, the result is undefined. | |
399 | The | |
400 | .Fa l_pid | |
401 | field is only used with | |
402 | .Dv F_GETLK | |
403 | to return the process ID of the process holding a blocking lock. | |
404 | After a successful | |
405 | .Dv F_GETLK | |
406 | request, the value of | |
407 | .Fa l_whence | |
408 | is | |
409 | .Dv SEEK_SET . | |
410 | .Pp | |
411 | Locks may start and extend beyond the current end of a file, | |
412 | but may not start or extend before the beginning of the file. | |
413 | A lock is set to extend to the largest possible value of the | |
414 | file offset for that file if | |
415 | .Fa l_len | |
416 | is set to zero. If | |
417 | .Fa l_whence | |
418 | and | |
419 | .Fa l_start | |
420 | point to the beginning of the file, and | |
421 | .Fa l_len | |
422 | is zero, the entire file is locked. | |
423 | If an application wishes only to do entire file locking, the | |
424 | .Xr flock 2 | |
425 | system call is much more efficient. | |
426 | .Pp | |
427 | There is at most one type of lock set for each byte in the file. | |
428 | Before a successful return from an | |
429 | .Dv F_SETLK | |
430 | or an | |
431 | .Dv F_SETLKW | |
432 | request when the calling process has previously existing locks | |
433 | on bytes in the region specified by the request, | |
434 | the previous lock type for each byte in the specified | |
435 | region is replaced by the new lock type. | |
436 | As specified above under the descriptions | |
437 | of shared locks and exclusive locks, an | |
438 | .Dv F_SETLK | |
439 | or an | |
440 | .Dv F_SETLKW | |
441 | request fails or blocks respectively when another process has existing | |
442 | locks on bytes in the specified region and the type of any of those | |
443 | locks conflicts with the type specified in the request. | |
444 | .Pp | |
445 | This interface follows the completely stupid semantics of System V and | |
446 | .St -p1003.1-88 | |
447 | that require that all locks associated with a file for a given process are | |
448 | removed when \fIany\fP file descriptor for that file is closed by that process. | |
449 | This semantic means that applications must be aware of any files that | |
450 | a subroutine library may access. | |
451 | For example if an application for updating the password file locks the | |
452 | password file database while making the update, and then calls | |
453 | .Xr getpwname 3 | |
454 | to retrieve a record, | |
455 | the lock will be lost because | |
456 | .Xr getpwname 3 | |
457 | opens, reads, and closes the password database. | |
458 | The database close will release all locks that the process has | |
459 | associated with the database, even if the library routine never | |
460 | requested a lock on the database. | |
461 | Another minor semantic problem with this interface is that | |
462 | locks are not inherited by a child process created using the | |
463 | .Xr fork 2 | |
464 | function. | |
465 | The | |
466 | .Xr flock 2 | |
467 | interface has much more rational last close semantics and | |
468 | allows locks to be inherited by child processes. | |
469 | .Xr Flock 2 | |
470 | is recommended for applications that want to ensure the integrity | |
471 | of their locks when using library routines or wish to pass locks | |
472 | to their children. | |
473 | Note that | |
474 | .Xr flock 2 | |
475 | and | |
476 | .Xr fcntl 2 | |
477 | locks may be safely used concurrently. | |
478 | .Pp | |
479 | All locks associated with a file for a given process are | |
480 | removed when the process terminates. | |
481 | .Pp | |
482 | A potential for deadlock occurs if a process controlling a locked region | |
483 | is put to sleep by attempting to lock the locked region of another process. | |
484 | This implementation detects that sleeping until a locked region is unlocked | |
485 | would cause a deadlock and fails with an | |
486 | .Er EDEADLK | |
487 | error. | |
488 | .Pp | |
489 | The | |
490 | .Dv F_PREALLOCATE | |
491 | command operates on the following structure: | |
492 | .ne 7v | |
493 | .Bd -literal | |
494 | typedef struct fstore { | |
495 | u_int32_t fst_flags; /* IN: flags word */ | |
496 | int fst_posmode; /* IN: indicates offset field */ | |
497 | off_t fst_offset; /* IN: start of the region */ | |
498 | off_t fst_length; /* IN: size of the region */ | |
499 | off_t fst_bytesalloc; /* OUT: number of bytes allocated */ | |
500 | } fstore_t; | |
501 | .Ed | |
502 | .Pp | |
503 | The flags (fst_flags) for the | |
504 | .Dv F_PREALLOCATE | |
505 | command are as follows: | |
506 | .Bl -tag -width F_ALLOCATECONTIGX -offset indent | |
507 | .It Dv F_ALLOCATECONTIG | |
508 | Allocate contiguous space. | |
509 | .It Dv F_ALLOCATEALL | |
510 | Allocate all requested space or no space at all. | |
511 | .El | |
512 | .Pp | |
513 | The position modes (fst_posmode) for the | |
514 | .Dv F_PREALLOCATE | |
515 | command indicate how to use the offset field. | |
516 | The modes are as follows: | |
517 | .Bl -tag -width F_PEOFPOSMODEX -offset indent | |
518 | .It Dv F_PEOFPOSMODE | |
519 | Allocate from the physical end of file. | |
0a7de745 A |
520 | In this case, |
521 | .Fa fst_length | |
522 | indicates the number of newly allocated bytes desired. | |
9bccf70c A |
523 | .It Dv F_VOLPOSMODE |
524 | Allocate from the volume offset. | |
525 | .El | |
526 | .Pp | |
527 | The | |
813fb2f6 A |
528 | .Dv F_PUNCHHOLE |
529 | command operates on the following structure: | |
530 | .ne 7v | |
531 | .Bd -literal | |
532 | typedef struct fpunchhole { | |
533 | u_int32_t fp_flags; /* unused */ | |
534 | u_int32_t reserved; /* (to maintain 8-byte alignment) */ | |
535 | off_t fp_offset; /* IN: start of the region */ | |
536 | off_t fp_length; /* IN: size of the region */ | |
537 | } fpunchhole_t; | |
538 | .Ed | |
539 | .Pp | |
540 | The | |
9bccf70c A |
541 | .Dv F_RDADVISE |
542 | command operates on the following structure | |
543 | which holds information passed from the | |
544 | user to the system: | |
545 | .ne 7v | |
546 | .Bd -literal | |
547 | struct radvisory { | |
548 | off_t ra_offset; /* offset into the file */ | |
549 | int ra_count; /* size of the read */ | |
550 | }; | |
551 | .Ed | |
552 | .Pp | |
553 | The | |
554 | .Dv F_READBOOTSTRAP and F_WRITEBOOTSTRAP | |
555 | commands operate on the following structure. | |
556 | .ne 7v | |
557 | .Bd -literal | |
558 | typedef struct fbootstraptransfer { | |
559 | off_t fbt_offset; /* IN: offset to start read/write */ | |
560 | size_t fbt_length; /* IN: number of bytes to transfer */ | |
561 | void *fbt_buffer; /* IN: buffer to be read/written */ | |
562 | } fbootstraptransfer_t; | |
563 | .Ed | |
564 | .Pp | |
565 | The | |
566 | .Dv F_LOG2PHYS | |
6d2010ae | 567 | command operates on the following structure: |
9bccf70c A |
568 | .ne 7v |
569 | .Bd -literal | |
570 | struct log2phys { | |
6d2010ae A |
571 | u_int32_t l2p_flags; /* unused so far */ |
572 | off_t l2p_contigbytes; /* unused so far */ | |
573 | off_t l2p_devoffset; /* bytes into device */ | |
9bccf70c A |
574 | }; |
575 | .Ed | |
6d2010ae A |
576 | .Pp |
577 | The | |
578 | .Dv F_LOG2PHYS_EXT | |
579 | command operates on the same structure as F_LOG2PHYS but treats it as an in/out: | |
580 | .ne 7v | |
581 | .Bd -literal | |
582 | struct log2phys { | |
583 | u_int32_t l2p_flags; /* unused so far */ | |
584 | off_t l2p_contigbytes; /* IN: number of bytes to be queried; | |
585 | OUT: number of contiguous bytes allocated at this position */ | |
586 | off_t l2p_devoffset; /* IN: bytes into file; | |
587 | OUT: bytes into device */ | |
588 | }; | |
589 | .Ed | |
590 | .Pp | |
591 | If | |
592 | .Fa fildes | |
593 | is a socket, then the | |
594 | .Dv F_SETNOSIGPIPE | |
595 | and | |
596 | .Dv F_GETNOSIGPIPE | |
597 | commands are directly analogous, and fully interoperate with the | |
598 | .Dv SO_NOSIGPIPE | |
599 | option of | |
600 | .Xr setsockopt 2 | |
601 | and | |
602 | .Xr getsockopt 2 | |
603 | respectively. | |
9bccf70c A |
604 | .Sh RETURN VALUES |
605 | Upon successful completion, the value returned depends on | |
606 | .Fa cmd | |
607 | as follows: | |
608 | .Bl -tag -width F_GETOWNX -offset indent | |
609 | .It Dv F_DUPFD | |
610 | A new file descriptor. | |
611 | .It Dv F_GETFD | |
612 | Value of flag (only the low-order bit is defined). | |
613 | .It Dv F_GETFL | |
614 | Value of flags. | |
615 | .It Dv F_GETOWN | |
616 | Value of file descriptor owner. | |
617 | .It other | |
618 | Value other than -1. | |
619 | .El | |
620 | .Pp | |
621 | Otherwise, a value of -1 is returned and | |
622 | .Va errno | |
623 | is set to indicate the error. | |
624 | .Sh ERRORS | |
2d21ac55 A |
625 | The |
626 | .Fn fcntl | |
627 | system call will fail if: | |
9bccf70c | 628 | .Bl -tag -width Er |
2d21ac55 | 629 | .\" ========== |
b0d623f7 | 630 | .It Bq Er EAGAIN |
9bccf70c A |
631 | The argument |
632 | .Fa cmd | |
633 | is | |
634 | .Dv F_SETLK , | |
635 | the type of lock | |
636 | .Fa (l_type) | |
637 | is a shared lock | |
638 | .Dv (F_RDLCK) | |
639 | or exclusive lock | |
640 | .Dv (F_WRLCK) , | |
641 | and the segment of a file to be locked is already | |
642 | exclusive-locked by another process; | |
643 | or the type is an exclusive lock and some portion of the | |
644 | segment of a file to be locked is already shared-locked or | |
645 | exclusive-locked by another process. | |
b0d623f7 | 646 | .It Bq Er EACCESS |
9bccf70c A |
647 | The argument |
648 | .Fa cmd | |
649 | is either | |
650 | .Dv F_SETSIZE | |
651 | or | |
652 | .Dv F_WRITEBOOTSTRAP | |
653 | and the calling process does not have root privileges. | |
2d21ac55 | 654 | .\" ========== |
9bccf70c A |
655 | .It Bq Er EBADF |
656 | .Fa Fildes | |
657 | is not a valid open file descriptor. | |
658 | .Pp | |
659 | The argument | |
660 | .Fa cmd | |
661 | is | |
662 | .Dv F_SETLK | |
663 | or | |
664 | .Dv F_SETLKW , | |
665 | the type of lock | |
666 | .Fa (l_type) | |
667 | is a shared lock | |
668 | .Dv (F_RDLCK) , | |
669 | and | |
670 | .Fa fildes | |
671 | is not a valid file descriptor open for reading. | |
672 | .Pp | |
673 | The argument | |
674 | .Fa cmd | |
675 | is | |
676 | .Dv F_SETLK | |
677 | or | |
678 | .Dv F_SETLKW , | |
679 | the type of lock | |
680 | .Fa (l_type) | |
681 | is an exclusive lock | |
682 | .Dv (F_WRLCK) , | |
683 | and | |
684 | .Fa fildes | |
685 | is not a valid file descriptor open for writing. | |
686 | .Pp | |
687 | The argument | |
688 | .Fa cmd | |
689 | is | |
690 | .Dv F_PREALLOCATE | |
691 | and the calling process does not have | |
692 | file write permission. | |
693 | .Pp | |
694 | The argument | |
695 | .Fa cmd | |
696 | is | |
697 | .Dv F_LOG2PHYS | |
6d2010ae A |
698 | or |
699 | .Dv F_LOG2PHYS_EXT | |
9bccf70c A |
700 | and |
701 | .Fa fildes | |
702 | is not a valid file descriptor open for reading. | |
2d21ac55 | 703 | .\" ========== |
9bccf70c A |
704 | .It Bq Er EDEADLK |
705 | The argument | |
706 | .Fa cmd | |
707 | is | |
708 | .Dv F_SETLKW , | |
709 | and a deadlock condition was detected. | |
2d21ac55 | 710 | .\" ========== |
9bccf70c A |
711 | .It Bq Er EINTR |
712 | The argument | |
713 | .Fa cmd | |
714 | is | |
715 | .Dv F_SETLKW , | |
716 | and the function was interrupted by a signal. | |
2d21ac55 | 717 | .\" ========== |
9bccf70c A |
718 | .It Bq Er EINVAL |
719 | .Fa Cmd | |
720 | is | |
721 | .Dv F_DUPFD | |
722 | and | |
723 | .Fa arg | |
724 | is negative or greater than the maximum allowable number | |
725 | (see | |
726 | .Xr getdtablesize 2 ) . | |
727 | .Pp | |
728 | The argument | |
729 | .Fa cmd | |
730 | is | |
731 | .Dv F_GETLK , | |
732 | .Dv F_SETLK , | |
733 | or | |
734 | .Dv F_SETLKW | |
735 | and the data to which | |
736 | .Fa arg | |
737 | points is not valid, or | |
738 | .Fa fildes | |
739 | refers to a file that does not support locking. | |
740 | .Pp | |
741 | The argument | |
742 | .Fa cmd | |
743 | is | |
744 | .Dv F_PREALLOCATE | |
745 | and the | |
746 | .Fa fst_posmode | |
747 | is not a valid mode, | |
748 | or when | |
749 | .Dv F_PEOFPOSMODE | |
750 | is set and | |
751 | .Fa fst_offset | |
752 | is a non-zero value, | |
753 | or when | |
754 | .Dv F_VOLPOSMODE | |
755 | is set and | |
756 | .Fa fst_offset | |
757 | is a negative or zero value. | |
758 | .Pp | |
759 | The argument | |
760 | .Fa cmd | |
813fb2f6 A |
761 | is |
762 | .Dv F_PUNCHHOLE | |
763 | and | |
764 | either | |
765 | .Fa fp_offset | |
766 | or | |
767 | .Fa fp_length | |
768 | are negative, or both | |
769 | .Fa fp_offset | |
770 | and | |
771 | .Fa fp_length | |
772 | are not multiples of the file system block size. | |
773 | .Pp | |
774 | The argument | |
775 | .Fa cmd | |
9bccf70c A |
776 | is either |
777 | .Dv F_READBOOTSTRAP | |
778 | or | |
779 | .Dv F_WRITEBOOTSTRAP | |
780 | and the operation was attempted on a non-HFS disk type. | |
2d21ac55 A |
781 | .\" ========== |
782 | .It Bq Er EMFILE | |
783 | .Fa Cmd | |
784 | is | |
785 | .Dv F_DUPFD | |
786 | and the maximum allowed number of file descriptors are currently | |
787 | open. | |
788 | .\" ========== | |
9bccf70c A |
789 | .It Bq Er EMFILE |
790 | The argument | |
791 | .Fa cmd | |
792 | is | |
793 | .Dv F_DUPED | |
794 | and the maximum number of file descriptors permitted for the | |
795 | process are already in use, | |
796 | or no file descriptors greater than or equal to | |
797 | .Fa arg | |
798 | are available. | |
2d21ac55 | 799 | .\" ========== |
9bccf70c A |
800 | .It Bq Er ENOLCK |
801 | The argument | |
802 | .Fa cmd | |
803 | is | |
804 | .Dv F_SETLK | |
805 | or | |
806 | .Dv F_SETLKW , | |
807 | and satisfying the lock or unlock request would result in the | |
808 | number of locked regions in the system exceeding a system-imposed limit. | |
2d21ac55 | 809 | .\" ========== |
a39ff7e2 A |
810 | .It Bq Er ENOSPC |
811 | The argument | |
812 | .Fa cmd | |
813 | is | |
814 | .Dv F_PREALLOCATE | |
815 | and either there is no space available on the volume containing | |
816 | .Fa fildes | |
817 | or | |
818 | .Fa fst_flags | |
819 | contains | |
820 | .Dv F_ALLOCATEALL | |
821 | and there is not enough space available on the volume containing | |
822 | .Fa fildes | |
823 | to satisfy the entire request. | |
824 | .Pp | |
825 | The argument | |
826 | .Fa cmd | |
827 | is | |
828 | .Dv F_PUNCHHOLE | |
829 | and there is not enough space available on the volume containing | |
830 | .Fa fildes | |
831 | to satisfy the request. As an example, a filesystem that supports | |
832 | cloned files may return this error if punching a hole requires the | |
833 | creation of a clone and there is not enough space available to do so. | |
834 | .\" ========== | |
2d21ac55 A |
835 | .It Bq Er EOVERFLOW |
836 | A return value would overflow its representation. | |
837 | For example, | |
838 | .Fa cmd | |
839 | is F_GETLK, F_SETLK, or F_SETLKW | |
840 | and the smallest (or, if l_len is non-zero, the largest) offset | |
841 | of a byte in the requested segment | |
842 | will not fit in an object of type off_t. | |
843 | .\" ========== | |
a39ff7e2 A |
844 | .It Bq Er EPERM |
845 | The argument cmd is | |
846 | .Dv F_PUNCHHOLE | |
847 | and the calling process does not have file write permission. | |
848 | .\" ========== | |
9bccf70c A |
849 | .It Bq Er ESRCH |
850 | .Fa Cmd | |
851 | is | |
852 | .Dv F_SETOWN | |
853 | and | |
854 | the process ID given as argument is not in use. | |
855 | .El | |
856 | .Sh SEE ALSO | |
857 | .Xr close 2 , | |
858 | .Xr execve 2 , | |
859 | .Xr flock 2 , | |
860 | .Xr getdtablesize 2 , | |
861 | .Xr open 2 , | |
6d2010ae A |
862 | .Xr pipe 2 , |
863 | .Xr socket 2 , | |
864 | .Xr setsockopt 2 , | |
9bccf70c A |
865 | .Xr sigaction 3 |
866 | .Sh HISTORY | |
867 | The | |
868 | .Fn fcntl | |
869 | function call appeared in | |
870 | .Bx 4.2 . |