POSIX_FALLOCATE(2)
π POSIX_FALLOCATE(2) π
okay so bestie, welcome to the System Calls Manual, section 2 β this is where the kernel-adjacent girlies live, and today we're doing posix_fallocate πΈ
β¨ NAME β¨
posix_fallocate β pre-allocate storage for a range in a file π«Ά
π LIBRARY π
Standard C Library (libc, -lc) β she's built in, no extra shopping required π
π SYNOPSIS π
#include <fcntl.h>
int
posix_fallocate(int fd, off_t offset, off_t len);
π DESCRIPTION π
So here's the tea, bestie: the required storage for the range from offset to offset + len in the file that fd points at is guaranteed to be allocated the moment this call returns successfully. β¨
That means β if posix_fallocate() comes back slaying, any writes you do later to that file data are not gonna fail because the file system storage media ran out of free space. The reservation is locked in, no cap. π
Any file data that already lives in the specified range? Untouched, unbothered, exactly as it was. π
And if offset + len goes past the current file size, then posix_fallocate() will adjust the file size to offset + len. Otherwise, the file size stays exactly the same β no sneaky resizing. πΈ
Space that posix_fallocate() allocated gets freed by a successful call to creat(2) or open(2) that truncates the size of the file. π§
Also β space allocated via posix_fallocate() may be freed by a successful call to ftruncate(2) that reduces the file size to something smaller than offset + len. π
β RETURN VALUES β
- Success? She returns zero. That's the slay. π
- Failure? She returns an error, and β plot twist β she does not set
errno. π
bestie, read that again. noerrnoon failure. the return value IS the error code. do not go checkingerrno, she will not be there for you. π
π ERRORS π
Possible failure conditions, aka the vibe-ruiners:
[EBADF]β thefdargument is not a valid file descriptor. π[EBADF]β thefdargument references a file that was opened without write permission. (same error code, different crime β¨)[EFBIG]β the value ofoffset + lenis greater than the maximum file size. too big bestie π[EINTR]β a signal was caught during execution. rude interruption fr fr π[EINVAL]β thelenargument was less than or equal to zero, theoffsetargument was less than zero, or the operation is not supported by the file system. (three-for-one special π )[EIO]β an I/O error occurred while reading from or writing to a file system. π«[EINTEGRITY]β corrupted data was detected while reading from the file system. π[ENODEV]β thefdargument does not refer to a regular file. not a regular file? not a regular girlie. π«[ENOSPC]β there is insufficient free space remaining on the file system storage media. the disk said "no <3" π[ENOTCAPABLE]β the file descriptorfdhas insufficient rights. π[ESPIPE]β thefdargument is associated with a pipe or FIFO. wrong kind of thing entirely, bestie π¦
π SEE ALSO π
creat(2), ftruncate(2), open(2), unlink(2) β the friend group π«Ά
π STANDARDS π
The posix_fallocate() system call conforms to IEEE Std 1003.1-2004 (βPOSIX.1β). certified iconic, periodt. π
π¦ HISTORY π¦
The posix_fallocate() function appeared in FreeBSD 9.0. a whole era. β¨
π AUTHORS π
posix_fallocate() and this manual page were initially written by Matthew Fleming <mdf@FreeBSD.org>. thank you for your service, king π«‘π
and that's the whole page, bestie!! this lil Debian build of the page is dated March 30, 2020 β yeah she's a vintage, she's still slaying, she's still canon πΈπ mwah, go reserve some disk space responsibly πβ¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1980, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms