Section: Linux Programmer's Manual (3)
Return to Main Contents
posix_fallocate - allocate file space
int posix_fallocate(int fd, off_t offset, off_t len);
Feature Test Macro Requirements for glibc (see
_POSIX_C_SOURCE >= 200112L
ensures that disk space is allocated for the file referred to by the
for the bytes in the range starting at
and continuing for
After a successful call to
subsequent writes to bytes in the specified range are
guaranteed not to fail because of lack of disk space.
If the size of the file is less than
then the file is increased to this size;
otherwise the file size is left unchanged.
returns zero on success, or an error number on failure.
is not set.
is not a valid file descriptor, or is not opened for writing.
exceeds the maximum file size.
A signal was caught during execution.
was less than 0, or
was less than or equal to 0, or the underlying filesystem does not
support the operation.
does not refer to a regular file.
There is not enough space left on the device containing the file
referred to by
refers to a pipe.
is available since glibc 2.1.94.
For an explanation of the terms used in this section, see
||Thread safety||MT-Safe (but see NOTES)|
POSIX.1-2008 says that an implementation
was 0, or
was less than 0.
POSIX.1-2001 says that an implementation
is less than 0, or
was less than 0, and
give the error if
In the glibc implementation,
is implemented using the
system call, which is MT-safe.
If the underlying filesystem does not support
then the operation is emulated with the following caveats:
The emulation is inefficient.
There is a race condition where concurrent writes from another thread or
process could be overwritten with null bytes.
There is a race condition where concurrent file size increases by
another thread or process could result in a file whose size is smaller
has been opened with the
flags, the function fails with the error
In general, the emulation is not MT-safe.
On Linux, applications may use
if they cannot tolerate the emulation caveats.
In general, this is
only recommended if the application plans to terminate the operation if
is returned, otherwise the application itself will need to implement a
fallback with all the same problems as the emulation provided by glibc.
This page is part of release 4.15 of the Linux
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
- RETURN VALUE
- CONFORMING TO
- SEE ALSO
This document was created by
using the manual pages.
Time: 03:38:14 GMT, September 19, 2018