POSIX_FALLOCATE(3POSIX)
π POSIX_FALLOCATE π
ok so bestie, this one lives in the POSIX Programmer's Manual (yes, POSIX_FALLOCATE(3POSIX), that's her full name π
), and before we even get into it β
πΈ PROLOG πΈ
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.
okay so real talk β if you're on Linux, don't just trust this page blindly, go check the Linux one too, because implementations can absolutely do their own thing π
β¨ NAME β¨
posix_fallocate β file space control (ADVANCED REALTIME)
π SYNOPSIS π
#include <fcntl.h>
int posix_fallocate(int fd, off_t offset, off_t len);
π¦ DESCRIPTION π¦
So what does posix_fallocate() actually do? She makes sure that any required storage for regular file data starting at offset and continuing for len bytes is allocated on the file system storage media. That's it, that's the whole vibe. And here's the payoff: if posix_fallocate() returns successfully, then subsequent writes to the specified file data shall not fail due to lack of free space on the file system storage media. no more "oops ran out of disk mid-write" jumpscare π iconic behavior honestly.
If the offset+len is beyond the current file size, then posix_fallocate() shall adjust the file size to offset+len. Otherwise, the file size shall not be changed. so either she grows the file to fit, or she leaves the size alone entirely, no in-between. β¨
It is implementation-defined whether a previous posix_fadvise() call influences allocation strategy. (iykyk β that's a "your mileage may vary, ask your implementation" situation π)
Space allocated via posix_fallocate() shall be freed by a successful call to creat() or open() that truncates the size of the file. Space allocated via posix_fallocate() may be freed by a successful call to ftruncate() that reduces the file size to a size smaller than offset+len.
π RETURN VALUE π
Upon successful completion, posix_fallocate() shall return zero; otherwise, an error number shall be returned to indicate the error. zero = slay, anything else = go read the errors section bestie.
π₯ ERRORS π₯
The posix_fallocate() function shall fail if:
EBADFβ The fd argument is not a valid file descriptor.EBADFβ The fd argument references a file that was opened without write permission. (yes she can throw this one two different ways, stay mad π)EFBIGβ The value ofoffset+lenis greater than the maximum file size.EINTRβ A signal was caught during execution.EINVALβ The len argument is less than zero, or the offset argument is less than zero, or the underlying file system does not support this operation.EIOβ An I/O error occurred while reading from or writing to a file system.ENODEVβ The fd argument does not refer to a regular file.ENOSPCβ There is insufficient free space remaining on the file system storage media. (the whole point was to avoid this bestie π)ESPIPEβ The fd argument is associated with a pipe or FIFO.
The posix_fallocate() function may fail if:
EINVALβ The len argument is zero.
heads up: the last section is "may fail", not "shall fail", so that one's a little more vibes-based β don't count on it, don't count it out π«Ά
The following sections are informative.
π EXAMPLES π
None.
π APPLICATION USAGE π
The posix_fallocate() function is part of the Advisory Information option and need not be provided on all implementations. so likeβ¦ check before you commit, because she might just not be there π
π§ RATIONALE π§
None.
β FUTURE DIRECTIONS β
None.
π SEE ALSO π
creat(), ftruncate(), open(), unlink()
The Base Definitions volume of POSIX.1β2017, <fcntl.h>
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page bestie π«Ά brought to you by IEEE/The Open Group, dated 2017, and yeah she really is signed POSIX_FALLOCATE(3POSIX) at the bottom like the main character she is. go forth and preallocate your disk space responsibly π
β¨
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms