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