getconf: don't include xpg4 bits, gcc7 includes xpg6 bits for us
[unleashed.git] / share / man / man3devinfo / di_init.3devinfo
blob8586dd059768662fd75b125aaf5fa19d07779c11
1 '\" te
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"
7 .SH NAME
8 di_init, di_fini \- create and destroy a snapshot of kernel device tree
9 .SH SYNOPSIS
10 .LP
11 .nf
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);
16 .fi
18 .LP
19 .nf
20 \fBvoid\fR \fBdi_fini\fR(\fBdi_node_t\fR \fIroot\fR);
21 .fi
23 .SH PARAMETERS
24 .sp
25 .ne 2
26 .na
27 \fB\fIflags\fR\fR
28 .ad
29 .RS 13n
30 Snapshot content specification. The possible values can be a bitwise OR of at
31 least one of the following:
32 .sp
33 .ne 2
34 .na
35 \fB\fBDINFOSUBTREE\fR\fR
36 .ad
37 .RS 16n
38 Include subtree.
39 .RE
41 .sp
42 .ne 2
43 .na
44 \fB\fBDINFOPROP\fR\fR
45 .ad
46 .RS 16n
47 Include properties.
48 .RE
50 .sp
51 .ne 2
52 .na
53 \fB\fBDINFOMINOR\fR\fR
54 .ad
55 .RS 16n
56 Include minor node data.
57 .RE
59 .sp
60 .ne 2
61 .na
62 \fB\fBDINFOCPYALL\fR\fR
63 .ad
64 .RS 16n
65 Include all of the above.
66 .RE
68 .sp
69 .ne 2
70 .na
71 \fB\fBDINFOPATH\fR\fR
72 .ad
73 .RS 16n
74 Include multipath path node data.
75 .RE
77 .sp
78 .ne 2
79 .na
80 \fB\fBDINFOLYR\fR\fR
81 .ad
82 .RS 16n
83 Include device layering data.
84 .RE
86 .sp
87 .ne 2
88 .na
89 \fB\fBDINFOCPYONE\fR\fR
90 .ad
91 .RS 16n
92 Include only a single node without properties, minor nodes, or path nodes.
93 .RE
95 .RE
97 .sp
98 .ne 2
99 .na
100 \fB\fIphys_path\fR\fR
102 .RS 13n
103 Physical path of the \fIroot\fR device node of the snapshot. See
104 \fBdi_devfs_path\fR(3DEVINFO).
108 .ne 2
110 \fB\fIroot\fR\fR
112 .RS 13n
113 Handle obtained by calling \fBdi_init()\fR.
116 .SH DESCRIPTION
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.
127 .SH RETURN VALUES
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.
132 .SH ERRORS
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
137 error codes include:
139 .ne 2
141 \fB\fBEACCES\fR\fR
143 .RS 10n
144 Insufficient privilege for accessing device configuration data.
148 .ne 2
150 \fB\fBENXIO\fR\fR
152 .RS 10n
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.
158 .ne 2
160 \fB\fBEINVAL\fR\fR
162 .RS 10n
163 Either \fIphys_path\fR is incorrectly formed or the \fIflags\fR argument is
164 invalid.
167 .SH EXAMPLES
169 \fBExample 1 \fRUsing the \fBlibdevinfo\fR Interfaces To Print All Device Tree
170 Node Names
173 The following is an example using the \fBlibdevinfo\fR interfaces to print all
174 device tree device node names:
177 .in +2
180  * Code to print all device tree device node names
181  */
183 #include <stdio.h>
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);
193 main()
195      di_node_t root_node;
196      if((root_node = di_init("/", DINFOSUBTREE)) == DI_NODE_NIL) {
197            fprintf(stderr, "di_init() failed\en");
198            exit(1);
199      }
200      di_walk_node(root_node, DI_WALK_CLDFIRST, NULL, prt_nodename);
201      di_fini(root_node);
204 .in -2
207 \fBExample 2 \fRUsing the \fBlibdevinfo\fR Interfaces To Print The Physical
208 Path Of SCSI Disks
211 The following example uses the \fBlibdevinfo\fR interfaces to print the
212 physical path of SCSI disks:
215 .in +2
218  * Code to print physical path of scsi disks
219  */
221 #include <stdio.h>
222 #include <libdevinfo.h>
223 #define DISK_DRIVER     "sd"    /* driver name */
225 void
226 prt_diskinfo(di_node_t node)
228     int instance;
229         char *phys_path;
231     /*
232      * If the device node exports no minor nodes,
233      * there is no physical disk.
234      */
235      if (di_minor_next(node, DI_MINOR_NIL) == DI_MINOR_NIL) {
236               return;
237          }
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);
245 void
246 walk_disknodes(di_node_t node)
248         node = di_drv_first_node(DISK_DRIVER, node);
249         while (node != DI_NODE_NIL) {
250              prt_diskinfo(node);
251              node = di_drv_next_node(node);
252         }
255 main()
257     di_node_t root_node;
258     if ((root_node = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) {
259         fprintf(stderr, "di_init() failed\en");
260         exit(1);
261     }
262         walk_disknodes(root_node);
263         di_fini(root_node);
266 .in -2
268 .SH ATTRIBUTES
271 See \fBattributes\fR(5)  for descriptions of the following attributes:
276 box;
277 c | c
278 l | l .
279 ATTRIBUTE TYPE  ATTRIBUTE VALUE
281 Interface Stability     Committed
283 MT-Level        Safe
286 .SH SEE ALSO
289 \fBopen\fR(2), \fBioctl\fR(2), \fBmmap\fR(2), \fBlibdevinfo\fR(3LIB),
290 \fBattributes\fR(5)
293 \fIWriting Device Drivers\fR