prepend_path(9)
π prepend_path β a kernel API manual, but make it make sense π
okay bestie, so this is a page from the Kernel API Manual, and the star of the show is prepend_path. yes we're in the kernel, yes it's giving β¨filesystem internalsβ¨, no you cannot skip it. sit with me π«Ά
πΈ NAME πΈ
prepend_path β literally what it says on the tin: prepend a path string to a buffer π
π¦ SYNOPSIS π¦
int prepend_path (const struct path *path , const struct path *root ,
struct prepend_buffer *p );
π ARGUMENTS π
pathβ the dentry/vfsmount you're reporting on. this is the thing whose pathname we're about to spit out πrootβ the root vfsmnt/dentry. the top of the tree, the place we stop climbing π§pβ the prepend buffer, which lowkey contains the buffer pointer and the allocated length. it's not just a buffer, it's the whole package π
π₯ DESCRIPTION π₯
okay so here's the vibe of what actually happens when you call this thing:
First, the function will try to write out the pathname without taking any lock other than the RCU read lock β and the whole point of that RCU lock is just to make sure the dentries don't go poof π (as in, won't go away while we're looking at them).
While doing that, it only checks the sequence number of the global rename_lock. why? because any change in the dentry's d_seq will be preceded by changes in the rename_lock sequence number. it's giving "one source of truth" energy π
But β and this is the plot twist π β if the sequence number had been changed, it restarts the whole pathname back-tracing sequence again by taking the rename_lock. and in that case? no need to take the RCU read lock, because the recursive parent pointer references will keep the dentry chain alive as long as no rename operation is performed. fr fr, that's the deal π«Ά
bestie this is real kernel code, so likeβ¦ respect the locking rules. the details above are the actual contract, no ad-libbing π
π SEE ALSO π
Kernel file ./fs/d_path.c plus these iconic siblings β¨
π the sign-off π
and that's the page, bestie π it ships out of ./fs, stamped October 2026 β go forth and prepend responsibly, mwah π§π
π¦ 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