POSIX_FALLOCATE(2)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

πŸ’… 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 that posix_fallocate() allocated gets freed by a successful call to creat(2) or open(2) that truncates the file's size. and space allocated via posix_fallocate() may be freed by a successful call to ftruncate(2) that shrinks the file size down below offset + 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] β€” the fd argument is not a valid file descriptor. that's not a file, that's nothing, bestie 😬
  • [EBADF] β€” the fd argument 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 of offset + len is 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] β€” the len argument was less than or equal to zero, the offset argument 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] β€” the fd argument does not refer to a file that supports posix_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 descriptor fd has insufficient rights. you don't have the clearance, this party is invite-only πŸ”’
  • [ESPIPE] β€” the fd argument 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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms