xref: /freebsd-14.2/lib/libc/sys/posix_fallocate.2 (revision b2c76c41)
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.\"     @(#)open.2	8.2 (Berkeley) 11/16/93
29.\"
30.Dd March 30, 2020
31.Dt POSIX_FALLOCATE 2
32.Os
33.Sh NAME
34.Nm posix_fallocate
35.Nd pre-allocate storage for a range in a file
36.Sh LIBRARY
37.Lb libc
38.Sh SYNOPSIS
39.In fcntl.h
40.Ft int
41.Fn posix_fallocate "int fd" "off_t offset" "off_t len"
42.Sh DESCRIPTION
43Required storage for the range
44.Fa offset
45to
46.Fa offset +
47.Fa len
48in the file referenced by
49.Fa fd
50is guaranteed to be allocated upon successful return.
51That is, if
52.Fn posix_fallocate
53returns successfully, subsequent writes to the specified file data
54will not fail due to lack of free space on the file system storage
55media.
56Any existing file data in the specified range is unmodified.
57If
58.Fa offset +
59.Fa len
60is beyond the current file size, then
61.Fn posix_fallocate
62will adjust the file size to
63.Fa offset +
64.Fa len .
65Otherwise, the file size will not be changed.
66.Pp
67Space allocated by
68.Fn posix_fallocate
69will be freed by a successful call to
70.Xr creat 2
71or
72.Xr open 2
73that truncates the size of the file.
74Space allocated via
75.Fn posix_fallocate
76may be freed by a successful call to
77.Xr ftruncate 2
78that reduces the file size to a size smaller than
79.Fa offset +
80.Fa len .
81.Sh RETURN VALUES
82If successful,
83.Fn posix_fallocate
84returns zero.
85It returns an error on failure, without setting
86.Va errno .
87.Sh ERRORS
88Possible failure conditions:
89.Bl -tag -width Er
90.It Bq Er EBADF
91The
92.Fa fd
93argument is not a valid file descriptor.
94.It Bq Er EBADF
95The
96.Fa fd
97argument references a file that was opened without write permission.
98.It Bq Er EFBIG
99The value of
100.Fa offset +
101.Fa len
102is greater than the maximum file size.
103.It Bq Er EINTR
104A signal was caught during execution.
105.It Bq Er EINVAL
106The
107.Fa len
108argument was less than or equal to zero, the
109.Fa offset
110argument was less than zero,
111or the operation is not supported by the file system.
112.It Bq Er EIO
113An I/O error occurred while reading from or writing to a file system.
114.It Bq Er EINTEGRITY
115Corrupted data was detected while reading from the file system.
116.It Bq Er ENODEV
117The
118.Fa fd
119argument does not refer to a file that supports
120.Nm .
121.It Bq Er ENOSPC
122There is insufficient free space remaining on the file system storage
123media.
124.It Bq Er ENOTCAPABLE
125The file descriptor
126.Fa fd
127has insufficient rights.
128.It Bq Er ESPIPE
129The
130.Fa fd
131argument is associated with a pipe or FIFO.
132.El
133.Sh SEE ALSO
134.Xr creat 2 ,
135.Xr ftruncate 2 ,
136.Xr open 2 ,
137.Xr unlink 2
138.Sh STANDARDS
139The
140.Fn posix_fallocate
141system call conforms to
142.St -p1003.1-2004 .
143.Sh HISTORY
144The
145.Fn posix_fallocate
146function appeared in
147.Fx 9.0 .
148.Sh AUTHORS
149.Fn posix_fallocate
150and this manual page were initially written by
151.An Matthew Fleming Aq Mt [email protected] .
152