2 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH DI_INIT 3DEVINFO "May 15, 2008"
8 di_init, di_fini \- create and destroy a snapshot of kernel device tree
12 \fBcc\fR [ \fIflag\fR... ] \fIfile\fR... \fB-ldevinfo\fR [ \fIlibrary\fR... ]
13 #include <libdevinfo.h>
15 \fBdi_node_t\fR \fBdi_init\fR(\fBconst char *\fR\fIphys_path\fR, \fBuint_t\fR \fIflags\fR);
20 \fBvoid\fR \fBdi_fini\fR(\fBdi_node_t\fR \fIroot\fR);
30 Snapshot content specification. The possible values can be a bitwise OR of at
31 least one of the following:
35 \fB\fBDINFOSUBTREE\fR\fR
53 \fB\fBDINFOMINOR\fR\fR
56 Include minor node data.
62 \fB\fBDINFOCPYALL\fR\fR
65 Include all of the above.
74 Include multipath path node data.
83 Include device layering data.
89 \fB\fBDINFOCPYONE\fR\fR
92 Include only a single node without properties, minor nodes, or path nodes.
100 \fB\fIphys_path\fR\fR
103 Physical path of the \fIroot\fR device node of the snapshot. See
104 \fBdi_devfs_path\fR(3DEVINFO).
113 Handle obtained by calling \fBdi_init()\fR.
119 The \fBdi_init()\fR function creates a snapshot of the kernel device tree and
120 returns a handle of the \fIroot\fR device node. The caller specifies the
121 contents of the snapshot by providing \fIflag\fR and \fIphys_path\fR.
124 The \fBdi_fini()\fR function destroys the snapshot of the kernel device tree
125 and frees the associated memory. All handles associated with this snapshot
126 become invalid after the call to \fBdi_fini()\fR.
130 Upon success, \fBdi_init()\fR returns a handle. Otherwise, \fBDI_NODE_NIL\fR is
131 returned and \fIerrno\fR is set to indicate the error.
135 The \fBdi_init()\fR function can set \fIerrno\fR to any error code that can
136 also be set by \fBopen\fR(2), \fBioctl\fR(2) or \fBmmap\fR(2). The most common
144 Insufficient privilege for accessing device configuration data.
153 Either the device named by \fIphys_path\fR is not present in the system, or the
154 \fBdevinfo\fR(7D) driver is not installed properly.
163 Either \fIphys_path\fR is incorrectly formed or the \fIflags\fR argument is
169 \fBExample 1 \fRUsing the \fBlibdevinfo\fR Interfaces To Print All Device Tree
173 The following is an example using the \fBlibdevinfo\fR interfaces to print all
174 device tree device node names:
180 * Code to print all device tree device node names
184 #include <libdevinfo.h>
187 prt_nodename(di_node_t node, void *arg)
189 printf("%s\en", di_node_name(node));
190 return (DI_WALK_CONTINUE);
196 if((root_node = di_init("/", DINFOSUBTREE)) == DI_NODE_NIL) {
197 fprintf(stderr, "di_init() failed\en");
200 di_walk_node(root_node, DI_WALK_CLDFIRST, NULL, prt_nodename);
207 \fBExample 2 \fRUsing the \fBlibdevinfo\fR Interfaces To Print The Physical
211 The following example uses the \fBlibdevinfo\fR interfaces to print the
212 physical path of SCSI disks:
218 * Code to print physical path of scsi disks
222 #include <libdevinfo.h>
223 #define DISK_DRIVER "sd" /* driver name */
226 prt_diskinfo(di_node_t node)
232 * If the device node exports no minor nodes,
233 * there is no physical disk.
235 if (di_minor_next(node, DI_MINOR_NIL) == DI_MINOR_NIL) {
239 instance = di_instance(node);
240 phys_path = di_devfs_path(node);
241 printf("%s%d: %s\en", DISK_DRIVER, instance, phys_path);
242 di_devfs_path_free(phys_path);
246 walk_disknodes(di_node_t node)
248 node = di_drv_first_node(DISK_DRIVER, node);
249 while (node != DI_NODE_NIL) {
251 node = di_drv_next_node(node);
258 if ((root_node = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) {
259 fprintf(stderr, "di_init() failed\en");
262 walk_disknodes(root_node);
271 See \fBattributes\fR(5) for descriptions of the following attributes:
279 ATTRIBUTE TYPE ATTRIBUTE VALUE
281 Interface Stability Committed
289 \fBopen\fR(2), \fBioctl\fR(2), \fBmmap\fR(2), \fBlibdevinfo\fR(3LIB),
293 \fIWriting Device Drivers\fR