VOP_READDIR(9)
π VOP_READDIR β like, reading a directory, bestie
okay so this is a page from the Kernel Developer's Manual (section 9, kernel-adjacent things, iykyk) and it's all about VOP_READDIR, which is literally the vnode operation that reads what's inside a directory. yes. that. let's go π¦
β¨ NAME β¨
VOP_READDIR β read contents of a directory π
πΈ SYNOPSIS πΈ
#include <sys/param.h>
#include <sys/dirent.h>
#include <sys/vnode.h>
int
VOP_READDIR(struct vnode *vp, struct uio *uio, struct ucred *cred,
int *eofflag, int *ncookies, u_long **cookies);
like... look at that signature. it's giving many arguments. we love her for it tho π«Ά
π DESCRIPTION π
Read directory entries. that's the whole vibe. but let's break down every single one of these lil parameters because each one matters, no cap:
vpβ the vnode of the directory. the actual folder. the main character πuioβ where to read the directory contents. this is where the good stuff goes.credβ the caller's credentials. who even are you, prove it πeofflagβ return end of file status (NULLif not wanted).ncookiesβ number of directory cookies generated for NFS (NULLif not wanted).cookiesβ directory seek cookies generated for NFS (NULLif not wanted).
The directory contents are read into struct dirent structures. and if the on-disc data structures differ from this, then bestie, they should be translated. periodt. π₯
π LOCKS π
The directory should be locked on entry and will still be locked on exit. so like, she goes in locked, she comes out locked. no unlocked entries in this house. not on my watch. π
π RETURN VALUES π
Zero is returned on success, otherwise an error code is returned. classic. zero equals good, anything else equals uh oh π
If this is called from the NFS server, the extra arguments eofflag, ncookies and cookies are given. The value of *eofflag should be set to TRUE if the end of the directory is reached while reading. The directory seek cookies are returned to the NFS client and may be used later to restart a directory read part way through the directory. There should be one cookie returned per directory entry. The value of the cookie should be the offset within the directory where the on-disc version of the appropriate directory entry starts.
Memory for the cookies should be allocated using:
...;
*ncookies = number of entries read;
*cookies = malloc(*ncookies * sizeof(u_long), M_TEMP, M_WAITOK);
like, that's the exact allocation ritual, do not improvise β¨
π¨ ERRORS π¨
[EINVAL]β An attempt was made to read from an illegal offset in the directory. rude. illegal even. we don't do that here.[EIO]β A read error occurred while reading the directory. the directory said "i'm not okay rn" π[EINTEGRITY]β Corrupted data was detected while reading the directory. the data got caught lacking. integrity check said absolutely not π
π SEE ALSO π
go read that one too, it's the prequel, iykyk π
π AUTHORS π
This manual page was written by Doug Rabson. thank you Doug, we stan π«Ά
a little note from me to you: keep the directory locked, return those cookies correctly, and always check your error codes. slay responsibly π
okay that's the whole page!! this was written from the Debian version dated March 30, 2020 β mwah, bye bestie, go read some vnodes πΈβ¨π
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1996 Doug Rabson
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms