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