4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
31 #include "libnvpair.h"
34 * libnvpair - A tools library for manipulating <name, value> pairs.
36 * This library provides routines packing an unpacking nv pairs
37 * for transporting data across process boundaries, transporting
38 * between kernel and userland, and possibly saving onto disk files.
42 indent(FILE *fp, int depth)
45 (void) fprintf(fp, "\t");
49 * nvlist_print - Prints elements in an event buffer
53 nvlist_print_with_indent(FILE *fp, nvlist_t *nvl, int depth)
64 (void) fprintf(fp, "nvlist version: %d\n", NVL_VERSION(nvl));
66 nvp = nvlist_next_nvpair(nvl, NULL);
69 data_type_t type = nvpair_type(nvp);
72 name = nvpair_name(nvp);
73 (void) fprintf(fp, "\t%s =", name);
76 case DATA_TYPE_BOOLEAN: {
77 (void) fprintf(fp, " 1");
80 case DATA_TYPE_BOOLEAN_VALUE: {
82 (void) nvpair_value_boolean_value(nvp, &val);
83 (void) fprintf(fp, " %d", val);
86 case DATA_TYPE_BYTE: {
88 (void) nvpair_value_byte(nvp, &val);
89 (void) fprintf(fp, " 0x%2.2x", val);
92 case DATA_TYPE_INT8: {
94 (void) nvpair_value_int8(nvp, &val);
95 (void) fprintf(fp, " %d", val);
98 case DATA_TYPE_UINT8: {
100 (void) nvpair_value_uint8(nvp, &val);
101 (void) fprintf(fp, " 0x%x", val);
104 case DATA_TYPE_INT16: {
106 (void) nvpair_value_int16(nvp, &val);
107 (void) fprintf(fp, " %d", val);
110 case DATA_TYPE_UINT16: {
112 (void) nvpair_value_uint16(nvp, &val);
113 (void) fprintf(fp, " 0x%x", val);
116 case DATA_TYPE_INT32: {
118 (void) nvpair_value_int32(nvp, &val);
119 (void) fprintf(fp, " %d", val);
122 case DATA_TYPE_UINT32: {
124 (void) nvpair_value_uint32(nvp, &val);
125 (void) fprintf(fp, " 0x%x", val);
128 case DATA_TYPE_INT64: {
130 (void) nvpair_value_int64(nvp, &val);
131 (void) fprintf(fp, " %lld", (longlong_t)val);
134 case DATA_TYPE_UINT64: {
136 (void) nvpair_value_uint64(nvp, &val);
137 (void) fprintf(fp, " 0x%llx", (u_longlong_t)val);
140 case DATA_TYPE_STRING: {
142 (void) nvpair_value_string(nvp, &val);
143 (void) fprintf(fp, " %s", val);
146 case DATA_TYPE_BOOLEAN_ARRAY: {
148 (void) nvpair_value_boolean_array(nvp, &val, &nelem);
149 for (i = 0; i < nelem; i++)
150 (void) fprintf(fp, " %d", val[i]);
153 case DATA_TYPE_BYTE_ARRAY: {
155 (void) nvpair_value_byte_array(nvp, &val, &nelem);
156 for (i = 0; i < nelem; i++)
157 (void) fprintf(fp, " 0x%2.2x", val[i]);
160 case DATA_TYPE_INT8_ARRAY: {
162 (void) nvpair_value_int8_array(nvp, &val, &nelem);
163 for (i = 0; i < nelem; i++)
164 (void) fprintf(fp, " %d", val[i]);
167 case DATA_TYPE_UINT8_ARRAY: {
169 (void) nvpair_value_uint8_array(nvp, &val, &nelem);
170 for (i = 0; i < nelem; i++)
171 (void) fprintf(fp, " 0x%x", val[i]);
174 case DATA_TYPE_INT16_ARRAY: {
176 (void) nvpair_value_int16_array(nvp, &val, &nelem);
177 for (i = 0; i < nelem; i++)
178 (void) fprintf(fp, " %d", val[i]);
181 case DATA_TYPE_UINT16_ARRAY: {
183 (void) nvpair_value_uint16_array(nvp, &val, &nelem);
184 for (i = 0; i < nelem; i++)
185 (void) fprintf(fp, " 0x%x", val[i]);
188 case DATA_TYPE_INT32_ARRAY: {
190 (void) nvpair_value_int32_array(nvp, &val, &nelem);
191 for (i = 0; i < nelem; i++)
192 (void) fprintf(fp, " %d", val[i]);
195 case DATA_TYPE_UINT32_ARRAY: {
197 (void) nvpair_value_uint32_array(nvp, &val, &nelem);
198 for (i = 0; i < nelem; i++)
199 (void) fprintf(fp, " 0x%x", val[i]);
202 case DATA_TYPE_INT64_ARRAY: {
204 (void) nvpair_value_int64_array(nvp, &val, &nelem);
205 for (i = 0; i < nelem; i++)
206 (void) fprintf(fp, " %lld", (longlong_t)val[i]);
209 case DATA_TYPE_UINT64_ARRAY: {
211 (void) nvpair_value_uint64_array(nvp, &val, &nelem);
212 for (i = 0; i < nelem; i++)
213 (void) fprintf(fp, " 0x%llx",
214 (u_longlong_t)val[i]);
217 case DATA_TYPE_STRING_ARRAY: {
219 (void) nvpair_value_string_array(nvp, &val, &nelem);
220 for (i = 0; i < nelem; i++)
221 (void) fprintf(fp, " %s", val[i]);
224 case DATA_TYPE_HRTIME: {
226 (void) nvpair_value_hrtime(nvp, &val);
227 (void) fprintf(fp, " 0x%llx", val);
230 case DATA_TYPE_NVLIST: {
232 (void) nvpair_value_nvlist(nvp, &val);
233 (void) fprintf(fp, " (embedded nvlist)\n");
234 nvlist_print_with_indent(fp, val, depth + 1);
235 indent(fp, depth + 1);
236 (void) fprintf(fp, "(end %s)\n", name);
239 case DATA_TYPE_NVLIST_ARRAY: {
241 (void) nvpair_value_nvlist_array(nvp, &val, &nelem);
242 (void) fprintf(fp, " (array of embedded nvlists)\n");
243 for (i = 0; i < nelem; i++) {
244 indent(fp, depth + 1);
246 "(start %s[%d])\n", name, i);
247 nvlist_print_with_indent(fp, val[i], depth + 1);
248 indent(fp, depth + 1);
249 (void) fprintf(fp, "(end %s[%d])\n", name, i);
254 (void) fprintf(fp, " unknown data type (%d)", type);
257 (void) fprintf(fp, "\n");
258 nvp = nvlist_next_nvpair(nvl, nvp);
263 nvlist_print(FILE *fp, nvlist_t *nvl)
265 nvlist_print_with_indent(fp, nvl, 0);