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