2 .\" Copyright (c) 2009, 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. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
4 .\" See the License for the specific language governing permissions and limitations under the License. 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
5 .\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .\" Copyright (c) 2016 Delphix. All Rights Reserved.
7 .TH NVLIST_ADD_BOOLEAN 3NVPAIR "Sep 15, 2009"
9 nvlist_add_boolean, nvlist_add_boolean_value, nvlist_add_byte, nvlist_add_int8,
10 nvlist_add_uint8, nvlist_add_int16, nvlist_add_uint16, nvlist_add_int32,
11 nvlist_add_uint32, nvlist_add_int64, nvlist_add_uint64, nvlist_add_double,
12 nvlist_add_string, nvlist_add_nvlist, nvlist_add_nvpair,
13 nvlist_add_boolean_array, nvlist_add_byte_array, nvlist_add_int8_array,
14 nvlist_add_uint8_array, nvlist_add_int16_array, nvlist_add_uint16_array,
15 nvlist_add_int32_array, nvlist_add_uint32_array, nvlist_add_int64_array,
16 nvlist_add_uint64_array, nvlist_add_string_array, nvlist_add_nvlist_array \-
17 add new name-value pair to nvlist_t
21 \fBcc\fR [ \fIflag\fR... ] \fIfile\fR... \fB-lnvpair\fR [ \fIlibrary\fR... ]
22 #include <libnvpair.h>
24 \fBint\fR \fBnvlist_add_boolean\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR);
29 \fBint\fR \fBnvlist_add_boolean_value\fR(\fBnvlist_t *\fR\fInvl\fR,
30 \fBconst char *\fR\fIname\fR, \fBboolean_t\fR \fIval\fR);
35 \fBint\fR \fBnvlist_add_byte\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
36 \fBuchar_t\fR \fIval\fR);
41 \fBint\fR \fBnvlist_add_int8\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
42 \fBint8_t\fR \fIval\fR);
47 \fBint\fR \fBnvlist_add_uint8\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
48 \fBuint8_t\fR \fIval\fR);
53 \fBint\fR \fBnvlist_add_int16\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
54 \fBint16_t\fR \fIval\fR);
59 \fBint\fR \fBnvlist_add_uint16\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
60 \fBuint16_t\fR \fIval\fR);
65 \fBint\fR \fBnvlist_add_int32\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
66 \fBint32_t\fR \fIval\fR);
71 \fBint\fR \fBnvlist_add_uint32\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
72 \fBuint32_t\fR \fIval\fR);
77 \fBint\fR \fBnvlist_add_int64\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
78 \fBint64_t\fR \fIval\fR);
83 \fBint\fR \fBnvlist_add_uint64\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
84 \fBuint64_t\fR \fIval\fR);
89 \fBint\fR \fBnvlist_add_double\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
90 \fBdouble\fR \fIval\fR);
95 \fBint\fR \fBnvlist_add_string\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
96 \fBconst char *\fR\fIval\fR);
101 \fBint\fR \fBnvlist_add_nvlist\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
102 \fBnvlist_t *\fR\fIval\fR);
107 \fBint\fR \fBnvlist_add_nvpair\fR(\fBnvlist_t *\fR\fInvl\fR, \fBnvpair_t *\fR\fInvp\fR);
112 \fBint\fR \fBnvlist_add_boolean_array\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
113 \fBboolean_t *\fR\fIval\fR, \fBuint_t\fR \fInelem\fR);
118 \fBint\fR \fBnvlist_add_byte_array\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
119 \fBuchar_t *\fR\fIval\fR, \fBuint_t\fR \fInelem\fR);
124 \fBint\fR \fBnvlist_add_int8_array\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
125 \fBint8_t *\fR\fIval\fR, \fBuint_t\fR \fInelem\fR);
130 \fBint\fR \fBnvlist_add_uint8_array\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
131 \fBuint8_t *\fR\fIval\fR, \fBuint_t\fR \fInelem\fR);
136 \fBint\fR \fBnvlist_add_int16_array\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
137 \fBint16_t *\fR\fIval\fR, \fBuint_t\fR \fInelem\fR);
142 \fBint\fR \fBnvlist_add_uint16_array\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
143 \fBuint16_t *\fR\fIval\fR, \fBuint_t\fR \fInelem\fR);
148 \fBint\fR \fBnvlist_add_int32_array\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
149 \fBint32_t *\fR\fIval\fR, \fBuint_t\fR \fInelem\fR);
154 \fBint\fR \fBnvlist_add_uint32_array\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
155 \fBuint32_t *\fR\fIval\fR, \fBuint_t\fR \fInelem\fR);
160 \fBint\fR \fBnvlist_add_int64_array\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
161 \fBint64_t *\fR\fIval\fR, \fBuint_t\fR \fInelem\fR);
166 \fBint\fR \fBnvlist_add_uint64_array\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
167 \fBuint64_t *\fR\fIval\fR, \fBuint_t\fR \fInelem\fR);
172 \fBint\fR \fBnvlist_add_string_array\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
173 \fBchar *const *\fR\fIval\fR, \fBuint_t\fR \fInelem\fR);
178 \fBint\fR \fBnvlist_add_nvlist_array\fR(\fBnvlist_t *\fR\fInvl\fR, \fBconst char *\fR\fIname\fR,
179 \fBnvlist_t **\fR\fIval\fR, \fBuint_t\fR \fInelem\fR);
188 The \fBnvlist_t\fR (name-value pair list) to be processed.
197 The \fBnvpair_t\fR (name-value pair) to be processed.
206 Name of the \fBnvpair\fR (name-value pair).
215 Number of elements in value (that is, array size).
224 Value or starting address of the array value.
229 These functions add a new name-value pair to an \fBnvlist_t\fR. The uniqueness
230 of \fBnvpair\fR name and data types follows the \fInvflag\fR argument specified
231 for \fBnvlist_alloc()\fR. See \fBnvlist_alloc\fR(3NVPAIR).
234 If \fBNV_UNIQUE_NAME\fR was specified for \fInvflag\fR, existing \fBnvpair\fRs
235 with matching names are removed before the new \fBnvpair\fR is added.
238 If \fBNV_UNIQUE_NAME_TYPE\fR was specified for \fInvflag\fR, existing
239 \fBnvpair\fRs with matching names and data types are removed before the new
240 \fBnvpair\fR is added.
243 If neither was specified for \fInvflag\fR, the new \fBnvpair\fR is
244 unconditionally added at the end of the list. The library preserves the order
245 of the name-value pairs across packing, unpacking, and duplication.
248 Multiple threads can simultaneously read the same \fBnvlist_t\fR, but only one
249 thread can actively change a given \fBnvlist_t\fR at a time. The caller is
250 responsible for the synchronization.
253 The name used for any name-value pair, including the terminating null
254 byte, can be no more than
262 The list that is added to the parent \fBnvlist_t\fR by calling
263 \fBnvlist_add_nvlist()\fR is copied and thus is not freed when
264 \fBnvlist_free()\fR is called on the parent list. To prevent memory leaks, your
265 code needs to look like the following (error handling elided for clarity):
269 nvlist_t *parent_nvl;
272 /* create parent list, add an entry */
273 (void) nvlist_alloc(&parent_nvl, NV_UNIQUE_NAME, KM_SLEEP);
274 (void) nvlist_add_boolean(parent_nvl, "parent_bool", 0);
276 /* create child list, add an entry */
277 (void) nvlist_alloc(&child_nvl, NV_UNIQUE_NAME, KM_SLEEP);
278 (void) nvlist_add_boolean(child_nvl, "child_bool", 0);
280 /* add the child to the parent */
281 (void) nvlist_add_nvlist(parent_nvl, "child_nvlist", child_nvl);
286 (void) nvlist_free(child_nvl); /* required, but not obvious */
287 (void) nvlist_free(parent_nvl);
293 The \fBnvlist_add_boolean()\fR function is deprecated. The
294 \fBnvlist_add_boolean_value()\fR function should be used instead.
297 These functions return 0 on success and an error value on failure.
300 These functions will fail if:
307 There is an invalid argument.
316 There is insufficient memory.
321 See \fBattributes\fR(5) for descriptions of the following attributes:
329 ATTRIBUTE TYPE ATTRIBUTE VALUE
331 Interface Stability Committed
338 \fBlibnvpair\fR(3LIB), \fBnvlist_alloc\fR(3NVPAIR), \fBattributes\fR(5)