kernfs_path_from_node(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… kernfs_path_from_node β€” the kernfs_path_from_node(9) glow-up πŸŽ€

okay so bestie, you know how every single thing in the kernel lives at some address in a tree and you're like "but what's its path tho"? yeah. this is the function for that. welcome to the group chat πŸ’– (also hi, this is section 9 of the Kernel API Manual, we're doing kernel internals today, vibe check passed ✨)


✨ NAME ✨

kernfs_path_from_node β€” literally builds the path of node @to relative to @from. that's it. that's the whole job. slay. πŸ’…


🌸 SYNOPSIS 🌸

int kernfs_path_from_node (struct kernfs_node *to , struct kernfs_node *from , char *buf , size_t buflen );

yes the spacing is exactly like that, don't come for me, it's what the manpage says 🫢


πŸŽ€ ARGUMENTS πŸŽ€

  • to β€” the kernfs_node you actually care about, the main character of this operation πŸ‘‘
  • from β€” the parent kernfs_node that we're building the path relative to. yeah, the starting point. the home base 🏠
  • buf β€” the buffer where to's path gets copied. drop it in here bestie πŸ“
  • buflen β€” the size of buf. please make it big enough, i'm begging πŸ™ˆ

πŸ¦‹ DESCRIPTION πŸ¦‹

so what it does is: it builds to's path relative to from, and it writes that into buf. that's the whole thing. no cap. ✨

the big rule: from and to must be on the same kernfs-root. like, non-negotiable. same tree or it's not gonna work out πŸ’€

and here's the part that's lowkey iconic: if from is not a parent of to, then it doesn't just give up β€” it hands you back a relative path (which includes '..'s) as needed to reach from from to to. so it'll walk you out and back in. path finding with extra steps, and honestly? we respect it 🧚


⭐ RETURN ⭐

it returns the length of the constructed path. πŸ“

and if the path would have been greater than buflen, then buf contains the truncated path with the trailing

nope, that's not me getting cut off β€” that's literally how the original ends. sentence just. stops. "with the trailing" and then nothing. leaving us on a cliffhanger, main character energy, absolute icon behavior πŸ˜­πŸ’€ i'm not making anything up to fill it in either, so enjoy the mystery πŸ’œ

🌈 SEE ALSO 🌈

the whole squad, fr fr. also worth peeping the Kernel file ./fs/kernfs/dir.c. 🫢


and that's the page!! πŸ’œ this little beauty comes to you from the Kernel file ./fs/kernfs, dated October 2026 β€” mwah, tysm, ily, go build some paths bestie πŸ’…βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from