POSIX_FALLOCATE(2)
π POSIX_FALLOCATE π
okay so this is posix_fallocate from the System Calls Manual, section 2 β yes bestie, we're in the syscall girlies section, pull up a chair π
β¨ NAME β¨
posix_fallocate β pre-allocate storage for a range in a file. it's giving "reserve my spot" energy, no cap πΈ
π LIBRARY π
Standard C Library (libc, -lc) β link her in and you're good to go π«Ά
π¦ SYNOPSIS π¦
#include <fcntl.h>
int
posix_fallocate(int fd, off_t offset, off_t len);
three little args, one big slay β¨
π DESCRIPTION π
so here's the vibe π₯: the storage that's required for the range from offset to offset + len in the file that fd points at is guaranteed to be allocated by the time this returns successfully. like, actually guaranteed. not "probably", not "fingers crossed", not "manifesting it" β guaranteed π
which means: if posix_fallocate() returns successfully, your later writes into that file data will not fail because lol there's no free space left on the file system storage media. she pre-booked the whole venue for you. periodt π
any file data that's already chillin' inside the specified range? untouched. unmodified. not even a little bit π
and if offset + len lands beyond the current file size, then posix_fallocate() will adjust the file size to offset + len. otherwise? file size stays exactly where it was, no notes π
important lore: space thatposix_fallocate()allocated gets freed by a successful call tocreat(2)oropen(2)that truncates the file's size. and space allocated viaposix_fallocate()may be freed by a successful call toftruncate(2)that shrinks the file size down belowoffset + len. she giveth, she taketh away π
π RETURN VALUES π
if it works out: posix_fallocate() returns zero. iconic, flawless, no drama π
if it fails: it returns an error without setting errno. yes bestie, read that again β no errno for you. she's different like that π
π ERRORS π
the possible failure conditions, aka the ways this can go sideways:
[EBADF]β thefdargument is not a valid file descriptor. that's not a file, that's nothing, bestie π¬[EBADF]β thefdargument references a file that was opened without write permission. you showed up to write but you don't have the write pass π«[EFBIG]β the value ofoffset + lenis greater than the maximum file size. girl that's not a file size, that's a fantasy β¨[EINTR]β a signal was caught during execution. rude interruption, blocked the whole vibe π€[EINVAL]β thelenargument was less than or equal to zero, theoffsetargument was less than zero, or the operation is not supported by the file system. ngl this one covers a lot of crimes π§[EIO]β an I/O error occurred while reading from or writing to a file system. the disk said "not today" π[EINTEGRITY]β corrupted data was detected while reading from the file system. the tea was spoiled, we had to throw it out π«[ENODEV]β thefdargument does not refer to a file that supportsposix_fallocate. wrong kind of file entirely, sweetie π[ENOSPC]β there is insufficient free space remaining on the file system storage media. the venue was full, main character denied at the door π[ENOTCAPABLE]β the file descriptorfdhas insufficient rights. you don't have the clearance, this party is invite-only π[ESPIPE]β thefdargument is associated with a pipe or FIFO. bestie... that's not even a file ππ
π SEE ALSO π
creat(2), ftruncate(2), open(2), unlink(2) β the whole friend group, go read them too π«Ά
β STANDARDS β
the posix_fallocate() system call conforms to IEEE Std 1003.1-2004 ("POSIX.1"). certified, official, legally iconic π
π HISTORY π
the posix_fallocate() function appeared in FreeBSD 9.0. she's been serving looks since way back π
π 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 π§ no thoughts, just pre-allocated storage. this beauty came to you from Debian, dated March 30, 2020 β mwah, go touch grass (or a file descriptor) πβ¨
π¦ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (c) 1980, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms