---
name: "devinfo"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/devinfo/3"
---

# devinfo(3)

device and resource information utility library

## 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** – device and resource information utility library

## LIBRARY

library “libdevinfo”

## 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 \*fnstruct devinfo\_dev \*child, void \*arg*, *void \*arg*);

*int*\

**devinfo\_foreach\_device\_resource**(*struct devinfo\_dev \*dev*, *int \*fnstruct devinfo\_dev \*dev, struct devinfo\_res \*res, void \*arg*, *void \*arg*);

*int*\

**devinfo\_foreach\_rman\_resource**(*struct devinfo\_rman \*rman*, *int \*fnstruct devinfo\_res \*res, void \*arg*, *void \*arg*);

*int*\

**devinfo\_foreach\_rman**(*int \*fnstruct devinfo\_rman \*rman, void \*arg*, *void \*arg*);

## DESCRIPTION

The **devinfo** library provides access to the kernel's internal device hierarchy and to the I/O resource manager. The library uses a [sysctl(3)](/sysctl/3.md) interface to obtain a snapshot of the kernel's state, which is then made available to the application.

Due to the fact that the information may be logically arranged in a number of different fashions, the library does not attempt to impose any structure on the data.

Device, resource, and resource manager information is returned in data structures defined in ⟨devinfo.h⟩:

```
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 can be used to look up the correspondingly referenced structures.

**devinfo\_init**() takes a snapshot of the kernel's internal device and resource state. It returns nonzero if after a number of retries a consistent snapshot cannot be obtained. **devinfo\_init**() must be called before any other functions can be used.

**devinfo\_free**() releases the memory associated with the snapshot. Any pointers returned by other functions are invalidated by this, and **devinfo\_init**() must be called again before using any other functions.

**devinfo\_handle\_to\_device**(), **devinfo\_handle\_to\_resource**() and **devinfo\_handle\_to\_rman**() return pointers to *devinfo\_dev*, *devinfo\_res* and *devinfo\_rman* structures respectively based on the *devinfo\_handle\_t* passed to them. These functions can be used to traverse the tree from any node to any other node. If **devinfo\_handle\_to\_device**() is passed the constant DEVINFO\_ROOT\_DEVICE it will return the handle to the root of the device tree.

**devinfo\_foreach\_device\_child**() invokes its callback argument *fn* on every device which is an immediate child of *device*. The *fn* function is also passed *arg*, allowing state to be passed to the callback function. If *fn* returns a nonzero error value the traversal is halted, and **devinfo\_foreach\_device\_child**() returns the error value to its caller.

**devinfo\_foreach\_device\_resource**() invokes its callback argument *fn* on every resource which is owned by *device*. The *fn* function is also passed *device* and *arg*, allowing state to be passed to the callback function. If *fn* returns a nonzero error value the traversal is halted, and **devinfo\_foreach\_device\_resource**() returns the error value to its caller.

**devinfo\_foreach\_rman\_resource**() invokes its callback argument *fn* on every resource within the resource manager *rman*. The *fn* function is also passed *arg*, allowing state to be passed to the callback function. If *fn* returns a nonzero error value the traversal is halted, and **devinfo\_foreach\_rman\_resource**() returns the error value to its caller.

**devinfo\_foreach\_rman**() invokes its callback argument *fn* on every resource manager. The *fn* function is also passed *arg*, allowing state to be passed to the callback function. If *fn* returns a nonzero error value the traversal is halted, and **devinfo\_foreach\_rman**() returns the error value to its caller.

## SEE ALSO

[devstat(3)](/devstat/3.md)

## HISTORY

The **devinfo** library first appeared in FreeBSD 5.0.

## AUTHORS

Michael Smith ⟨*msmith@FreeBSD.org*⟩

## BUGS

This is the first implementation of the library, and the interface is still subject to refinement.

The interface does not report device classes or drivers, making it hard to sort by class or driver.
