DEVICE_GET_CHILDREN(9)

πŸ’– DEVICE_GET_CHILDREN πŸ’–

okay bestie, welcome to section 9 of the Kernel Developer's Manual β€” yes, we're in the kernel dev manual, we're doing big brain stuff today, and honestly? it's giving main character energy. this is the page for device_get_children, and it's here to help you find out who's hanging out under a device. yes literally, its children. the whole little device family tree 🌳✨


✨ NAME ✨

device_get_children β€” get a list of devices connected to a device

like, the actual roster of who's attached. no cap. πŸ‘‘


✨ SYNOPSIS ✨

#include <sys/param.h>
#include <sys/bus.h>

int
device_get_children(device_t dev, device_t **devlistp, int *devcountp);

first you gotta pull in those headers, <sys/param.h> and <sys/bus.h>, and then boom β€” that's the function signature, exactly like that. don't freestyle it 🫢


✨ DESCRIPTION ✨

so here's the vibe: you call device_get_children and it retrieves a list of all the device instances that are currently connected to dev, and it hands you back that list in *devlistp plus the count in *devcountp. like, here's your kids, and here's how many there are πŸ’…

πŸŽ€ important, bestie: the memory allocated for that list? you gotta free it yourself with free(*devlistp, M_TEMP). the function is not gonna clean up after you. it's not your mom, it's a kernel function.

and one more thing β€” devlistp and devcountp are not changed when an error is returned. so if things go sideways, your pointers stay exactly where they were. no mystery edits. periodt.


✨ RETURN VALUES ✨

Zero comes back on success, obviously, slay. otherwise an appropriate error is returned β€” so like, check your return value, bestie, don't just assume it worked 😭


✨ SEE ALSO ✨

go read those too, iykyk πŸ“š


✨ AUTHORS ✨

this manual page was written by Doug Rabson. iconic behavior, we love a documented kernel πŸ’–


and that's the whole page, bestie! this lil' beauty lives in the Debian build of the Kernel Developer's Manual and it was last dated August 23, 2008 β€” yes, it's been serving accurate kernel facts since way before you were cool. go forth and enumerate those children πŸŒΈπŸ¦‹β­

πŸ“¦ where this page comes from