DEVINFO(3)
π DEVINFO(3) β like, the whole devinfo manual, bestie π
okay so this is the page for DEVINFO(3) from the Library Functions Manual β yes, that manual, section 3, the "library functions" one. Sit down, grab a strawberry drink π, and let me tell you about the little library that lets you peek at your kernel's device tree and I/O resource manager. it's giving backstage pass energy fr fr.
β¨ NAME β¨
devinfo, devinfo_init, devinfo_free, devinfo_handle_to_device, devinfo_handle_to_resource, devinfo_handle_to_rman, devinfo_foreach_device_child, devinfo_foreach_device_resource, devinfo_foreach_rman_resource, devinfo_foreach_rman β the device and resource information utility library π
π LIBRARY π
Device and Resource Information Utility Library (libdevinfo, -ldevinfo)
π¦ SYNOPSIS π¦
#include <devinfo.h>
int
devinfo_init(void);
void
devinfo_free(void);
struct devinfo_dev *
devinfo_handle_to_device(devinfo_handle_t handle);
struct devinfo_res *
devinfo_handle_to_resource(devinfo_handle_t handle);
struct devinfo_rman *
devinfo_handle_to_rman(devinfo_handle_t handle);
int
devinfo_foreach_device_child(struct devinfo_dev *parent,
int (*fn)(struct devinfo_dev *child, void *arg), void *arg);
int
devinfo_foreach_device_resource(struct devinfo_dev *dev,
int (*fn)(struct devinfo_dev *dev,
struct devinfo_res *res, void *arg), void *arg);
int
devinfo_foreach_rman_resource(struct devinfo_rman *rman,
int (*fn)(struct devinfo_res *res, void *arg), void *arg);
int
devinfo_foreach_rman(int (*fn)(struct devinfo_rman *rman, void *arg),
void *arg);
πΈ DESCRIPTION πΈ
The devinfo library is your hookup to the kernel's internal device hierarchy and to the I/O resource manager. iconic. it does the whole thing through a sysctl(3) interface β it grabs a snapshot of the kernel's state and then hands that snapshot to your application. no cap, that's the entire trick β¨
and here's the vibe: because this information can logically be arranged in like a million different ways, the library does not try to force any structure onto the data. it's not gonna tell you how to feel about it. it just gives you the raw material and lets you, the main character, organize it however you want π
Device, resource, and resource manager info comes back in data structures defined in <devinfo.h>, and they look exactly like this:
struct devinfo_dev {
devinfo_handle_t dd_handle; /* device handle */
devinfo_handle_t dd_parent; /* parent handle */
char *dd_name; /* name of device */
char *dd_desc; /* device description */
char *dd_drivername; /* name of attached driver */
char *dd_pnpinfo; /* pnp info from parent bus */
char *dd_location; /* Where bus thinks dev at */
uint32_t dd_devflags; /* API flags */
uint16_t dd_flags; /* internal dev flags */
device_state_t dd_state; /* attachment state of dev */
};
struct devinfo_rman {
devinfo_handle_t dm_handle; /* resource manager handle */
rman_res_t dm_start; /* resource start */
rman_res_t dm_size; /* resource size */
char *dm_desc; /* resource description */
};
struct devinfo_res {
devinfo_handle_t dr_handle; /* resource handle */
devinfo_handle_t dr_rman; /* resource manager handle */
devinfo_handle_t dr_device; /* owning device */
rman_res_t dr_start; /* region start */
rman_res_t dr_size; /* region size */
};
The devinfo_handle_t values are your lil lookup keys β you use them to find the correspondingly referenced structures. iykyk π
devinfo_init()β takes a snapshot of the kernel's internal device and resource state. it returns nonzero if, after a bunch of retries, it just can't get a consistent snapshot. and listen: you must calldevinfo_init()before you can use any of the other functions. it's the entry fee, bestie ποΈdevinfo_free()β releases the memory associated with the snapshot. and it's lowkey brutal about it: any pointers returned by the other functions get invalidated by this, and you have to calldevinfo_init()again before using any other functions. so don't be out here using stale pointers, that's not the vibe πdevinfo_handle_to_device(),devinfo_handle_to_resource(), anddevinfo_handle_to_rman()β these return pointers todevinfo_dev,devinfo_res, anddevinfo_rmanstructures respectively, based on thedevinfo_handle_tyou hand them. you can use them to traverse the tree from any node to any other node. and a fun one: if you pass the constantDEVINFO_ROOT_DEVICEtodevinfo_handle_to_device(), it returns the handle to the root of the device tree. the origin story π±devinfo_foreach_device_child()β invokes its callback argumentfnon every device that's an immediate child of device.fnalso gets passedarg, so you can sneak state into the callback. and iffnreturns a nonzero error value? boom, traversal halts, anddevinfo_foreach_device_child()returns that error value right back to the caller. early exit slay πdevinfo_foreach_device_resource()β invokes its callback argumentfnon every resource owned by device.fnalso getsdeviceandarg, so state travels with you. iffnreturns a nonzero error value the traversal halts anddevinfo_foreach_device_resource()returns the error value to its caller. same energy π«Άdevinfo_foreach_rman_resource()β invokes its callback argumentfnon every resource within the resource manager rman.fnalso getsarg. nonzero fromfnβ traversal halts βdevinfo_foreach_rman_resource()returns that error value to its caller. periodt βdevinfo_foreach_rman()β invokes its callback argumentfnon every resource manager.fnalso getsarg, bestie, state travels. iffnreturns a nonzero error value the traversal halts anddevinfo_foreach_rman()returns the error value to its caller. consistent queen π
π SEE ALSO π
devstat(3) β go look at that one too, it's friends with this one π¦
π§ HISTORY π§
The devinfo library first appeared in FreeBSD 5.0. a legend from day one, honestly π
π AUTHORS π
Michael Smith <msmith@FreeBSD.org> β thank you for your service, king π
π BUGS π
- okay so this is the first implementation of the library, and ngl the interface is still subject to refinement. it's a work in progress, we love a growing girl π
- also: the interface does not report device classes or drivers, which makes it hard to sort by class or driver. yeah. that's the whole bug. it's giving "organized chaos" π
and that's the page, bestie! π this one came from Debian, dated April 19, 2001 β like, a vintage. wear it with pride, and remember: call devinfo_init() first, always π«Άβ¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2001 Michael Smith <msmith@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms