VOP_FSYNC(9)

✨ VOP_FSYNC β€” flush file system buffers for a file ✨

okay bestie, welcome to the Kernel Developer's Manual, section 9 πŸŽ€ this one's about VOP_FDATASYNC and VOP_FSYNC, and no cap, it's giving "make sure your data is actually, for real, on the disk" energy πŸ’Ύβœ¨


🌸 SYNOPSIS 🌸

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

int
VOP_FDATASYNC(struct vnode *vp, struct thread *td);

int
VOP_FSYNC(struct vnode *vp, int waitfor, struct thread *td);

πŸ’– DESCRIPTION πŸ’–

so VOP_FSYNC() is the icon that makes sure a file can be recovered to its current state after a crash 😭 like if the power just dips and everything's chaos, this is what saves you. that typically means flushing the file's dirty buffers, its inode, and possibly other filesystem metadata out to persistent media 🫢

and the way it's used? it's literally the implementation behind the sync(2) and fsync(2) system calls. main character behaviour fr fr πŸ‘‘

its arguments are:

  • vp β€” the vnode of the file πŸ¦‹
  • waitfor β€” whether the function should wait for I/O to complete. possible values are:
    • MNT_WAIT β€” synchronously wait for I/O to complete ⏳
    • MNT_NOWAIT β€” start all I/O, but do not wait for it πŸ’¨
    • MNT_LAZY β€” push data not written by file system syncer 🧚
  • td β€” the calling thread 🧡

VOP_FDATASYNC() is similar, but it does not require that all of the file's metadata be flushed. it only requires that the file's data be recoverable after a crash. that implies that the data itself must be flushed to disk, as well as some metadata such as the file's size β€” but not necessarily its attributes πŸ‘€

VOP_FDATASYNC() should always wait for I/O to complete, as if called with MNT_WAIT. no shortcuts bestie. and it's used to implement fdatasync(2) πŸ’…


πŸ”’ LOCKS πŸ”’

the vnode should be exclusively locked on entry, and it stays locked on return. yes, it walks in holding the lock and it walks out holding the lock. consistent queen πŸ’œ


⭐ RETURN VALUES ⭐

zero is returned if the call is successful πŸŽ‰ otherwise an appropriate error code is returned πŸ™ˆ


πŸ’€ ERRORS πŸ’€

  • [ENOSPC] β€” the file system is full. it's giving "no room, babe" 😭
  • [EDQUOT] β€” quota exceeded. you ate too much, respectfully πŸ“

🌈 SEE ALSO 🌈


πŸŽ€ AUTHORS πŸŽ€

this manual page was written by Doug Rabson. thank you for your service king 🫑✨


lowkey if you're poking at vnodes at 3am, hydrate, lock exclusively, and remember: MNT_WAIT is your friend πŸ’–

this was the VOP_FSYNC(9) page from the Debian edition of the Kernel Developer's Manual, dated March 22, 2019 🌸 slay, stay synced, periodt πŸ’…πŸ¦‹

πŸ“¦ where this page comes from