POSIX_FADVISE(3P)

โœจ PROLOG โœจ

Okay bestie, quick heads-up before we dive in: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for the deets on Linux behavior), or honestly the interface may not even be implemented on Linux. Vibe check accordingly. ๐Ÿ’€


๐Ÿฆ‹ NAME ๐Ÿฆ‹

posix_fadvise โ€” file advisory information (ADVANCED REALTIME) ๐Ÿ’…


๐ŸŒธ SYNOPSIS ๐ŸŒธ

#include <fcntl.h>

int posix_fadvise(int fd, off_t offset, off_t len, int advice);

๐Ÿ’– DESCRIPTION ๐Ÿ’–

So the posix_fadvise() function is literally just you sliding a lil note to the implementation, being like "hey girl, here's what I'm expecting to do with this data." Specifically, it advises on the expected behavior of the application with respect to the data in the file associated with the open file descriptor fd, starting at offset and continuing for len bytes. โœจ

Notably: the specified range doesn't even need to currently exist in the file. Iconic, no notes. And if len is zero, that means all data following offset is specified. ๐ŸŽ€

The implementation may use this information to optimize handling of the specified data. And lowkey the best part โ€” posix_fadvise() shall have no effect on the semantics of other operations on the specified data, though it may affect the performance of other operations. So it's all vibes, zero side effects. ๐Ÿฆ‹

The advice you're applying to the data is specified by the advice parameter, and it may be one of the following values:

  • POSIX_FADV_NORMAL โ€” says the application has no advice to give on its behavior with respect to the specified data. This is the default characteristic if no advice is given for an open file. (The "no thoughts, head empty" option ๐Ÿซถ)
  • POSIX_FADV_SEQUENTIAL โ€” says the application expects to access the specified data sequentially, from lower offsets to higher offsets. One direction, forward, main character energy. โญ
  • POSIX_FADV_RANDOM โ€” says the application expects to access the specified data in a random order. Chaos. We love her. ๐ŸŒ€
  • POSIX_FADV_WILLNEED โ€” says the application expects to access the specified data in the near future. Manifesting it early, fr fr. ๐Ÿ”ฎ
  • POSIX_FADV_DONTNEED โ€” says the application expects that it will not access the specified data in the near future. Not me ghosting this data ๐Ÿ™ˆ
  • POSIX_FADV_NOREUSE โ€” says the application expects to access the specified data once and then not reuse it thereafter. One and done, periodt. ๐Ÿ’…

These values are defined in <fcntl.h>.


๐ŸŒˆ RETURN VALUE ๐ŸŒˆ

Upon successful completion, posix_fadvise() shall return zero. ๐ŸŽ‰ Otherwise, an error number shall be returned to indicate the error.


๐Ÿ”ฅ ERRORS ๐Ÿ”ฅ

The posix_fadvise() function shall fail if:

  • EBADF โ€” The fd argument is not a valid file descriptor.
  • EINVAL โ€” The value of advice is invalid, or the value of len is less than zero.
  • ESPIPE โ€” The fd argument is associated with a pipe or FIFO.
The following sections are informative.

๐Ÿงš EXAMPLES ๐Ÿงš

None. (Yeah, bestie, we got nothing. The void. The emptiness. ๐Ÿ’€)


๐Ÿ’œ APPLICATION USAGE ๐Ÿ’œ

The posix_fadvise() function is part of the Advisory Information option and need not be provided on all implementations. So like, don't be shocked if your platform's like "never heard of her." ๐Ÿ˜ญ


๐Ÿ“ RATIONALE ๐Ÿ“

None. (Same energy as above. Empty. Void-coded. ๐Ÿ™ˆ)


๐Ÿ‘‘ FUTURE DIRECTIONS ๐Ÿ‘‘

None. (The future is a mystery and this page is not about to spoil it. โœจ)


๐ŸŒŸ SEE ALSO ๐ŸŒŸ

  • posix_madvise()
  • The Base Definitions volume of POSIX.1โ€2017, <fcntl.h>

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 the POSIX Programmer's Manual โ€” IEEE/The Open Group, 2017 โ€” POSIX_FADVISE(3P). Slay, go advise some files, and remember: the range doesn't have to exist for you to manifest it. โœจ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from