User Tools

Site Tools


solaris:di_init.3devinfo

di_init


NAME

di_init, di_fini - create and destroy a snapshot of kernel device tree

SYNOPSIS

cc [ flag… ] file-ldevinfo [ library… ]
#include <libdevinfo.h>

di_node_t di_init(const char *phys_path, uint_t flags);

void di_fini(di_node_t root);

PARAMETERS

flags

Snapshot content specification. The possible values can be a bitwise OR of at least one of the following:

DINFOCACHE

This flag returns cached device information. It is incompatible with all the other flags.

Most callers should use this flag since it avoids device tree traversals (which can negatively impact system performance).

The cached snapshot will contain device information for all the devices discovered by the system at this time, where as other flags may not return information for devices that are not currently attached.

The cached snapshot includes information about each configured device, including paths, minor nodes, and properties.

System operations that configure or remove a device, a path to a device, or a device’s minor nodes will all result in a cache update. Some property value updates will also trigger cache updates. For dynamic properties updated by a driver’s prop_op implementation, the cached value will always be stale.

DINFOSUBTREE

Include subtree.

DINFOPROP

Include properties.

DINFOMINOR

Include minor node data.

DINFOCPYALL

Include all of the above.

DINFOPATH

Include multipath path node data.

DINFOLYR

Include device layering data.

DINFOCPYONE

Include only a single node without properties, minor nodes, or path nodes.

phys_path

Physical path of the root device node of the snapshot. for more information, see the di_devfs_path(3DEVINFO) man page.

root

Handle obtained by calling di_init().

DESCRIPTION

The di_init() function creates a snapshot of the kernel device tree and returns a handle of the root device node. The caller specifies the contents of the snapshot by providing flag and phys_path.

The di_fini() function destroys the snapshot of the kernel device tree and frees the associated memory. All handles associated with this snapshot become invalid after the call to the di_fini() function.

RETURN VALUES

Upon success, the di_init() function returns a handle. Otherwise, DI_NODE_NIL is returned and errno is set to indicate the error.

ERRORS

The di_init() function can set errno to any error code that can also be set by open(2), ioctl(2) or mmap(2). The most common error codes include:

EACCES

Insufficient privilege for accessing device configuration data.

ENXIO

Either the device named by phys_path is not present in the system, or the devinfo(4D) driver is not installed properly.

EINVAL

Either phys_path is incorrectly formed or the flags argument is invalid.

EXAMPLES

Example 1 Using the libdevinfo Interfaces To Print All Device Tree Node
Names

The following is an example using the libdevinfo interfaces to print all device tree device node names:

/*
* Code to print all device tree device node names
*/

#include <stdio.h>
#include <libdevinfo.h>

int
prt_nodename(di_node_t node, void *arg)
{
printf(“%s\n”, di_node_name(node));
return (DI_WALK_CONTINUE);
}

main()
{
di_node_t root_node;
if1) == DI_NODE_NIL) {
fprintf(stderr, “di_init() failed\n”);
exit(1);
}
di_walk_node(root_node, DI_WALK_CLDFIRST, NULL, prt_nodename);
di_fini(root_node);
}

Example 2 Using the libdevinfo Interfaces To Print The Physical Path Of
SCSI Disks

The following example uses the libdevinfo interfaces to print the physical path of SCSI disks:

/*
* Code to print physical path of scsi disks
*/

#include <stdio.h>
#include <libdevinfo.h>

#defineDISK_DRIVER“sd”/* driver name */

void
prt_diskinfo(di_node_t node)
{
int instance;
char *phys_path;

/*
* If the device node exports no minor nodes,
* there is no physical disk.
*/
if (di_minor_next(node, DI_MINOR_NIL) == DI_MINOR_NIL) {
return;
}

instance = di_instance(node);
phys_path = di_devfs_path(node);
printf(“%s%d: %s\n”, DISK_DRIVER, instance, phys_path);
di_devfs_path_free(phys_path);
}

void
walk_disknodes(di_node_t node)
{
node = di_drv_first_node(DISK_DRIVER, node);
while (node != DI_NODE_NIL) {
prt_diskinfo(node);
node = di_drv_next_node(node);
}
}

main()
{
di_node_t root_node;
if 2) == DI_NODE_NIL) {
fprintf(stderr, “di_init() failed\n”);
exit(1);
}
walk_disknodes(root_node);
di_fini(root_node);
}

ATTRIBUTES

See attributes(7) for descriptions of the following attributes:

SEE ALSO

ioctl(2), mmap(2), open(2), libdevinfo(3LIB), attributes(7)

Writing Device Drivers in Oracle Solaris 11.4


1)
root_node = di_init(“/”, DINFOSUBTREE
2)
root_node = di_init(“/”, DINFOCPYALL
solaris/di_init.3devinfo.txt · Last modified: 2023/07/19 08:57 by A User Not Logged in