offset_readdir(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– offset_readdir(9) πŸ’–

okay bestie, welcome to offset_readdir β€” straight out of the Kernel API Manual, and yes it's a section 9 page so it's ~kernel internals~ core, we're in the big leagues now 🫢


✨ NAME ✨

offset_readdir β€” emit entries starting at offset @ctx->pos πŸ’…

✨ SYNOPSIS ✨

int offset_readdir (struct file *file , struct dir_context *ctx );

✨ ARGUMENTS ✨

  • file β€” an open directory that we're gonna iterate over πŸ“‚
  • ctx β€” the directory iteration context, aka the vibe tracker for where we're at πŸ‘‘

✨ DESCRIPTION ✨

so the caller must hold the file's i_rwsem β€” like, non-negotiable β€” because that's literally what stops entries from being inserted or removed while this call is running 😀 no cap, that's the whole point.

On entry, ctx->pos holds an offset that represents the first entry to be read from the directory ✨

Then the operation just keeps going β€” until there are no more entries to read, or until the ctx->actor says there's no more space in the caller's output buffer, whichever hits first 🫠

On return, ctx->pos contains an offset that will read the next entry in this directory when offset_readdir gets called again with ctx πŸ” the caller then places this value in the d_off field of the last entry in the user's buffer. yeah. that's the ritual. πŸ•―οΈ

Return values: 0 - Complete βœ…

✨ SEE ALSO ✨

Kernel file ./fs/libfs.c has the whole friend group, and honestly they all ate:


okay that's the page!! πŸ’– this one came from ./fs, dated October 2026, and it's filed under offset_readdir(9) β€” slay, go read some directories babes πŸŒΈπŸ¦‹

πŸ“¦ where this page comes from