offset_readdir(9)
π 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:
simple_offset_init(9)simple_offset_add(9)simple_offset_remove(9)simple_offset_rename(9)simple_offset_rename_exchange(9)simple_offset_destroy(9)offset_dir_llseek(9)simple_rename_timestamp(9)simple_setattr(9)simple_write_end(9)simple_read_from_buffer(9)simple_write_to_buffer(9)memory_read_from_buffer(9)generic_encode_ino32_fh(9)generic_fh_to_dentry(9)generic_fh_to_parent(9)simple_fsync_noflush(9)simple_fsync(9)generic_check_addressable(9)simple_get_link(9)generic_ci_d_compare(9)generic_ci_d_hash(9)generic_ci_match(9)generic_set_sb_d_ops(9)inode_maybe_inc_iversion(9)inode_query_iversion(9)simple_inode_init_ts(9)path_from_stashed(9)simple_start_creating(9)
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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms