kernfs_path_..._node_locked(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… kernfs_path_..._node_locked(9) πŸ’…

okay so this is a page from the Kernel API Manual bestie, and the function it's about is truly the main character of path-building. it lives in <kernel> and it's giving "i know where everything is" energy. let's get into it 🫢


✨ NAME ✨

kernfs_path_from_node_locked β€” finds you a pseudo-absolute path to @kn_to, where kn_from is treated as the root of that path. yeah. that's the whole vibe πŸŽ€


🌸 SYNOPSIS 🌸

int kernfs_path_from_node_locked (struct kernfs_node *kn_to , struct
kernfs_node *kn_from , char *buf , size_t buflen );

πŸ’– ARGUMENTS πŸ’–

  • kn_to β€” the kernfs node whose path you actually want. the destination. the moment. the ~where am i going~ of it all.
  • kn_from β€” the kernfs node that gets treated as the root for this path. so like, you're pretending this one is the top of the world πŸ‘‘
  • buf β€” the buffer you're copying the path into. the lil home for the string 🏠
  • buflen β€” the size of buf. gotta know how much room we're working with, fr fr.

πŸ¦‹ DESCRIPTION πŸ¦‹

so there are a couple of scenarios we gotta handle here, and honestly? each one is its own little era:

[1] when kn_from is an ancestor of kn_to at some level. like:

  • kn_from: /n1/n2/n3
  • kn_to: /n1/n2/n3/n4/n5
  • result: /n4/n5

[2] when kn_from is on a different hierarchy and we need to find the common ancestor between kn_from and kn_to. this is where the .. girlies come out πŸ’…

  • kn_from: /n1/n2/n3/n4
  • kn_to: /n1/n2/n5
  • result: /../../n5

OR

  • kn_from: /n1/n2/n3/n4/n5 [depth=5]
  • kn_to: /n1/n2/n3 [depth=3]
  • result: /../..

[3] when kn_to is NULL, the result will be "(null)". yes literally that string. no cap.


⭐ RETURN ⭐

it returns the length of the constructed path.

okay important caveat bestie 🚨 if the path would have been greater than buflen, then buf contains the truncated path with the trailing

(and that's exactly where the original page ends, so i'm not gonna invent the rest β€” do not come for me πŸ™ˆ)


πŸ”₯ SEE ALSO πŸ”₯

Kernel file ./fs/kernfs/dir.c, plus the whole friend group:

kernfs_name(9), kernfs_path_from_node(9), pr_cont_kernfs_name(9), pr_cont_kernfs_path(9), kernfs_get_parent(9), kernfs_name_hash(9), kernfs_link_sibling(9), kernfs_unlink_sibling(9), kernfs_get_active(9), kernfs_put_active(9), kernfs_drain(9), kernfs_get(9), kernfs_put(9), kernfs_node_from_dentry(9), kernfs_add_one(9), kernfs_find_ns(9), kernfs_find_and_get_ns(9), kernfs_walk_and_get_ns(9), kernfs_create_root(9), kernfs_destroy_root(9), kernfs_root_to_node(9), kernfs_create_dir_ns(9), kernfs_create_empty_dir(9), kernfs_next_descendant_post(9), kernfs_activate(9), kernfs_show(9), kernfs_remove(9), kernfs_break_active_protection(9), kernfs_unbreak_active_protection(9), kernfs_remove_self(9), kernfs_remove_by_name_ns(9), kernfs_rename_ns(9)

every single one accounted for. i counted. twice. πŸ“


and that's the page!! πŸ’œ this one came out of ./fs/kernfs, dated October 2026, and it's filed under kernfs_path_..._node_locked(9) β€” so if you need it again, you know exactly where to look bestie. mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from