VOP_RDWR(9)

πŸ’– VOP_RDWR β€” read or write a file πŸ’–

okay bestie, pull up a chair, we're doing the VOP_READ / VOP_WRITE page from the Kernel Developer's Manual (that's section 9, the kernel girlies' section, iykyk) ✨


✨ NAME ✨

VOP_READ, VOP_WRITE β€” read or write a file 🫢


🌸 SYNOPSIS 🌸

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

int
VOP_READ(struct vnode *vp, struct uio *uio, int ioflag,
    struct ucred *cred);

int
VOP_WRITE(struct vnode *vp, struct uio *uio, int ioflag,
    struct ucred *cred);

πŸ¦‹ DESCRIPTION πŸ¦‹

so these two entry points read or write the contents of a file. that's it, that's the vibe. πŸ“–βœοΈ

here's the cast of arguments, no cap:

  • vp β€” the vnode of the file.
  • uio β€” the location of the data to be read or written.
  • ioflag β€” various flags.
  • cnp β€” the credentials of the caller.
πŸ’€ not the arg list saying cnp while the synopsis says cred… she contains multitudes. keeping both exactly as the page says them, don't @ me.

the ioflag argument is literally how you give directives and hints to the file system. πŸŽ€

when you're attempting a read, the high 16 bits are used to provide a read-ahead hint (in units of file system blocks) that the file system should attempt. the low 16 bits are a bit mask, and that mask can contain these flags:

  • IO_UNIT β€” do I/O as atomic unit.
  • IO_APPEND β€” append write to end.
  • IO_SYNC β€” do I/O synchronously.
  • IO_NODELOCKED β€” underlying node already locked.
  • IO_NDELAY β€” FNDELAY flag set in file table.
  • IO_VMIO β€” data already in VMIO space.

πŸ”’ LOCKS πŸ”’

the file should be locked on entry and will still be locked on exit. she arrives locked, she leaves locked, main character consistency. πŸ‘‘


⭐ RETURN VALUES ⭐

Zero is returned on success β€” slay. otherwise, an error code is returned. 😭


🚨 ERRORS 🚨

  • [EFBIG] β€” an attempt was made to write a file that exceeds the process's file size limit or the maximum file size.
  • [ENOSPC] β€” the file system is full.
  • [EPERM] β€” an append-only flag is set on the file, but the caller is attempting to write before the current end of file.
πŸ™ˆ yes bestie, writing past the end on an append-only file is gonna get you an EPERM, that's just the rules.

πŸ‘€ SEE ALSO πŸ‘€


πŸ’œ AUTHORS πŸ’œ

this manual page was written by Doug Rabson. icon behavior, honestly. 🫢


and that's the whole page, bestie β€” go read and write some files, but lock your vnodes first. πŸ’…βœ¨

this lil number came from the Debian crew, dated July 24, 1996 β€” yeah she's vintage, she's still iconic, periodt. πŸŽ€πŸŒˆβ­

πŸ“¦ where this page comes from