VOP_ADVISE(9)

πŸ’– VOP_ADVISE πŸ’–

okay bestie, so this one lives in section 9 of the Kernel Developer's Manual β€” it's VOP_ADVISE, and it's the vnode operation that gives the kernel a little heads up about how a file's data is gonna get used. it's giving "hey, just so you know" energy. πŸ¦‹


✨ NAME ✨

VOP_ADVISE β€” apply advice about use of file data πŸ’…


✨ SYNOPSIS ✨

#include <sys/param.h>
#include <sys/vnode.h>

int
VOP_ADVISE(struct vnode *vp, off_t start, off_t end, int advice);

✨ DESCRIPTION ✨

so this call applies advice for a range of a file's data. it's the behind-the-scenes queen that implements the posix_fadvise system call. πŸŽ€

and here's the cast of arguments, bestie:

  • vp β€” the vnode of the file. the main character, literally.
  • start β€” the start of the range of file data.
  • end β€” the end of the range of file data. a value of OFF_MAX means "apply the advice all the way to the end of the file," periodt.
  • advice β€” the type of operation to apply to the file data. possible values are:
    • POSIX_FADV_WILLNEED β€” initiate an asynchronous read of the file data if it's not already resident. like pre-gaming the read, iykyk. 🌸
    • POSIX_FADV_DONTNEED β€” decrease the in-memory priority of clean file data, or discard clean file data. it's giving "we're done here, no cap." πŸ’€

if the start and end offsets are both zero, then the operation should be applied to the entire file. 🌈

okay and this is the important part, don't skip it: this call is advisory only. it may perform the requested operation on a subset of the requested range β€” including not performing it at all β€” and still return success. so don't come for it when it doesn't do the thing. it literally warned you. 🫢

✨ LOCKS ✨

the file should be unlocked on entry. yes bestie, unlocked. don't be holding anything when you walk in. πŸ”“


✨ RETURN VALUES ✨

zero is returned if the call is successful. otherwise, an appropriate error code is returned. that's it, that's the vibe check. ⭐


✨ ERRORS ✨

  • [EINVAL] β€” an invalid value was given for advice. πŸ™ˆ

✨ SEE ALSO ✨


and that's the whole page, babe. this one came out of the Debian edition of the manual, dated September 26, 2015 β€” so it's a lil vintage, but she still slays. πŸŽ€βœ¨ bye bestie, go advise some files responsibly! πŸ‘‘

πŸ“¦ where this page comes from