xref: /freebsd/lib/libsys/posix_fallocate.2 (revision 8ccc0d235c226d84112561d453c49904398d085c)
1.\" Copyright (c) 1980, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd November 2, 2025
29.Dt POSIX_FALLOCATE 2
30.Os
31.Sh NAME
32.Nm posix_fallocate
33.Nd pre-allocate storage for a range in a file
34.Sh LIBRARY
35.Lb libc
36.Sh SYNOPSIS
37.In fcntl.h
38.Ft int
39.Fn posix_fallocate "int fd" "off_t offset" "off_t len"
40.Sh DESCRIPTION
41Required storage for the range
42.Fa offset
43to
44.Fa offset +
45.Fa len
46in the file referenced by
47.Fa fd
48is guaranteed to be allocated upon successful return.
49That is, if
50.Fn posix_fallocate
51returns successfully, subsequent writes to the specified file data
52will not fail due to lack of free space on the file system storage
53media.
54Any existing file data in the specified range is unmodified.
55If
56.Fa offset +
57.Fa len
58is beyond the current file size, then
59.Fn posix_fallocate
60will adjust the file size to
61.Fa offset +
62.Fa len .
63Otherwise, the file size will not be changed.
64.Pp
65Space allocated by
66.Fn posix_fallocate
67will be freed by a successful call to
68.Xr creat 2
69or
70.Xr open 2
71that truncates the size of the file.
72Space allocated via
73.Fn posix_fallocate
74may be freed by a successful call to
75.Xr ftruncate 2
76that reduces the file size to a size smaller than
77.Fa offset +
78.Fa len .
79.Sh RETURN VALUES
80If successful,
81.Fn posix_fallocate
82returns zero.
83It returns an error on failure, without setting
84.Va errno .
85.Sh ERRORS
86Possible failure conditions:
87.Bl -tag -width Er
88.It Bq Er EBADF
89The
90.Fa fd
91argument is not a valid file descriptor.
92.It Bq Er EBADF
93The
94.Fa fd
95argument references a file that was opened without write permission.
96.It Bq Er EFBIG
97The value of
98.Fa offset +
99.Fa len
100is greater than the maximum file size.
101.It Bq Er EINTR
102A signal was caught during execution.
103.It Bq Er EINVAL
104The
105.Fa len
106argument was less than or equal to zero, the
107.Fa offset
108argument was less than zero.
109.It Bq Er EIO
110An I/O error occurred while reading from or writing to a file system.
111.It Bq Er EINTEGRITY
112Corrupted data was detected while reading from the file system.
113.It Bq Er ENODEV
114The
115.Fa fd
116argument does not refer to a file that supports
117.Nm .
118.It Bq Er ENOSPC
119There is insufficient free space remaining on the file system storage
120media.
121.It Bq Er ENOTCAPABLE
122The file descriptor
123.Fa fd
124has insufficient rights.
125.It Bq Er EOPNOTSUPP
126The operation is not supported by the file system.
127.It Bq Er ESPIPE
128The
129.Fa fd
130argument is associated with a pipe or FIFO.
131.El
132.Sh SEE ALSO
133.Xr creat 2 ,
134.Xr ftruncate 2 ,
135.Xr open 2 ,
136.Xr unlink 2
137.Sh STANDARDS
138The
139.Fn posix_fallocate
140system call conforms to
141.St -p1003.1-2024 .
142.Sh HISTORY
143The
144.Fn posix_fallocate
145function appeared in
146.Fx 9.0 .
147.Pp
148Previous versions of
149.Nm
150used
151.Er EINVAL
152to indicate that the operation is not supported by the file system, as specified
153in
154.St -p1003.1
155Base Specifications, Issue 7.
156.St -p1003.1
157Base Specifications, Issue 8 switched to requiring
158.Er EOPNOTSUPP
159for this error case.
160ZFS adopted the latter convention in
161.Fx 15.0 ,
162and the remaining filesystems in base adopted it in
163.Fx 15.1 .
164.Sh AUTHORS
165.Fn posix_fallocate
166and this manual page were initially written by
167.An Matthew Fleming Aq Mt mdf@FreeBSD.org .
168