xref: /freebsd/lib/libsys/posix_fallocate.2 (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
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 March 30, 2020
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,
109or the operation is not supported by the file system.
110.It Bq Er EIO
111An I/O error occurred while reading from or writing to a file system.
112.It Bq Er EINTEGRITY
113Corrupted data was detected while reading from the file system.
114.It Bq Er ENODEV
115The
116.Fa fd
117argument does not refer to a file that supports
118.Nm .
119.It Bq Er ENOSPC
120There is insufficient free space remaining on the file system storage
121media.
122.It Bq Er ENOTCAPABLE
123The file descriptor
124.Fa fd
125has insufficient rights.
126.It Bq Er ESPIPE
127The
128.Fa fd
129argument is associated with a pipe or FIFO.
130.El
131.Sh SEE ALSO
132.Xr creat 2 ,
133.Xr ftruncate 2 ,
134.Xr open 2 ,
135.Xr unlink 2
136.Sh STANDARDS
137The
138.Fn posix_fallocate
139system call conforms to
140.St -p1003.1-2004 .
141.Sh HISTORY
142The
143.Fn posix_fallocate
144function appeared in
145.Fx 9.0 .
146.Sh AUTHORS
147.Fn posix_fallocate
148and this manual page were initially written by
149.An Matthew Fleming Aq Mt mdf@FreeBSD.org .
150