OF_CHILD(9)

πŸ’– OF_CHILD(9) πŸ’–

okay bestie, so this is a page from the Kernel Developer's Manual, and it's literally about walking around the device tree like it's a group chat and you're scrolling through who's related to who 🌳✨


🌸 NAME 🌸

OF_child, OF_parent, OF_peer β€” navigate device tree


✨ SYNOPSIS ✨

#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>

phandle_t
OF_child(phandle_t node);

phandle_t
OF_parent(phandle_t node);

phandle_t
OF_peer(phandle_t node);

πŸ¦‹ DESCRIPTION πŸ¦‹

so basically you've got a node and you wanna know who's around it in the device tree. these three functions are your little tour guides, no cap πŸ’…

  • OF_child() β€” hands you the phandle value of the first child of node. If there are literally no children? You get 0. bye πŸ‘‹
  • OF_parent() β€” gives you the phandle of node's parent. But if node is the root node, you get 0, because root has no parent, she's the main character πŸ‘‘
  • OF_peer() β€” returns the phandle value of the next sibling of node. And if there's no sibling node? Yep, 0. sad but true 😭
lowkey the pattern here is: 0 always means "nobody's home". keep that in mind and you're golden ✨

🌈 EXAMPLES 🌈

classic walk-the-children loop, look at her go 🫢

phandle_t node, child;
 ...
for (child = OF_child(node); child != 0; child = OF_peer(child) {
        ...
}

πŸŽ€ SEE ALSO πŸŽ€


πŸ‘‘ AUTHORS πŸ‘‘

This manual page was written by Oleksandr Tymoshenko <gonzo@FreeBSD.org>. thank u for ur service, icon πŸ«‘πŸ’–


and that's the whole vibe bestie β€” this one's from Debian, dated April 9, 2018, filed under OF_CHILD(9). go forth and traverse that tree, periodt πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from