POSIX_FALLOCATE(3P)
π POSIX_FALLOCATE(3P) π
hiii bestie π welcome to the POSIX Programmer's Manual β yes, the whole entire thing, and this page right here is posix_fallocate(3P). buckle up, we're allocating some disk space and it's gonna be iconic.
π PROLOG π
okay so first things first, no skipping: this manual page is part of the POSIX Programmer's Manual. that's the vibe.
β οΈ real talk though β the Linux implementation of this interface may differ, so pls go consult the corresponding Linux manual page for the details on Linux behavior. or honestly? the interface might just not be implemented on Linux at all. π i know. tragic. check before you ship, fr fr.
β¨ NAME β¨
posix_fallocate β file space control (ADVANCED REALTIME)
like the name says, she controls your file space. main character energy, obviously. π
π¦ SYNOPSIS π¦
#include <fcntl.h>
int posix_fallocate(int fd, off_t offset, off_t len);
three little args, one big slay. π
πΈ DESCRIPTION πΈ
okay so what does she actually do? the posix_fallocate() function shall ensure that any required storage for regular file data starting at offset and continuing for len bytes is allocated on the file system storage media. periodt. and here's the best part: if posix_fallocate() returns successfully, subsequent writes to the specified file data shall not fail due to the lack of free space on the file system storage media. no more "oops i ran out of space mid-write" jumpscare. we love to see it. π«Ά
now, about your file size β it's giving β¨ conditional β¨:
- if
offset+lenis beyond the current file size, thenposix_fallocate()shall adjust the file size tooffset+len. - otherwise, the file size shall not be changed. not even a little. leave her alone.
and here's a lil mystery for you: it is implementation-defined whether a previous posix_fadvise() call influences allocation strategy. so likeβ¦ maybe it does, maybe it doesn't, that's between you and your implementation. π
lastly, the freeing rules, because nothing lasts forever bestie:
- space allocated via
posix_fallocate()shall be freed by a successful call tocreat()oropen()that truncates the size of the file. - space allocated via
posix_fallocate()may be freed by a successful call toftruncate()that reduces the file size to a size smaller thanoffset+len.
note the shall vs may β that distinction is doing so much work and i respect it deeply. π
β RETURN VALUE β
upon successful completion, posix_fallocate() shall return zero. slay.
otherwise, an error number shall be returned to indicate the error. not a vibe, but at least she tells you why. π
π ERRORS π
the posix_fallocate() function shall fail if:
EBADFβ thefdargument is not a valid file descriptor.EBADFβ thefdargument references a file that was opened without write permission. (yes, there are twoEBADFs. yes, that's on purpose. they're different problems, bestie.)EFBIGβ the value ofoffset+lenis greater than the maximum file size.EINTRβ a signal was caught during execution.EINVALβ thelenargument is less than zero, or theoffsetargument 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β thefdargument does not refer to a regular file.ENOSPCβ there is insufficient free space remaining on the file system storage media.ESPIPEβ thefdargument is associated with a pipe or FIFO.
the posix_fallocate() function may fail if:
EINVALβ thelenargument is zero.
π« yeah, that last one is a may β so a zero-length request is not guaranteed to blow up. keep it in mind. no cap.
the following sections are informative. π
π EXAMPLES π
None.
(i know. i wanted examples too. she said no. iconic of her honestly. π)
π§ APPLICATION USAGE π§
the posix_fallocate() function is part of the Advisory Information option and need not be provided on all implementations. so like β vibe check your platform before you assume she's there, bestie. π
π RATIONALE π
None.
π₯ FUTURE DIRECTIONS π₯
None.
π SEE ALSO π
creat()ftruncate()open()unlink()- The Base Definitions volume of POSIX.1β2017,
<fcntl.h>
iykyk. go read those next, they're all linked in spirit. πΈ
π COPYRIGHT π
okay bestie, legal moment, but make it cute:
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!! π¦π this one came to you courtesy of IEEE/The Open Group, 2017 β yeah, that's the source and the date, and yes i'm putting it in the sign-off because we give credit in this house. now go allocate responsibly, mwah. πβ¨π
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms