4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
26 #include <sys/stropts.h>
27 #include <sys/debug.h>
28 #include <sys/isa_defs.h>
29 #include <sys/int_limits.h>
30 #include <sys/nvpair.h>
31 #include <sys/nvpair_impl.h>
32 #include <rpc/types.h>
35 #if defined(_KERNEL) && !defined(_BOOT)
36 #include <sys/varargs.h>
38 #include <sys/sunddi.h>
47 #define offsetof(s, m) ((size_t)(&(((s *)0)->m)))
49 #define skip_whitespace(p) while ((*(p) == ' ') || (*(p) == '\t')) p++
52 * nvpair.c - Provides kernel & userland interfaces for manipulating
67 * +--------------+ last i_nvp in list
68 * | nvpriv_t | +--------------------->
70 * +--+- nvp_list | | +------------+
71 * | | nvp_last -+--+ + nv_alloc_t |
72 * | | nvp_curr | |------------|
73 * | | nvp_nva -+----> | nva_ops |
74 * | | nvp_stat | | nva_arg |
75 * | +--------------+ +------------+
79 * +---------------------+ +-------------------+
80 * | i_nvp_t | +-->| i_nvp_t | +-->
81 * |---------------------| | |-------------------| |
82 * | nvi_next -+--+ | nvi_next -+--+
83 * | nvi_prev (NULL) | <----+ nvi_prev |
84 * | . . . . . . . . . . | | . . . . . . . . . |
85 * | nvp (nvpair_t) | | nvp (nvpair_t) |
86 * | - nvp_size | | - nvp_size |
87 * | - nvp_name_sz | | - nvp_name_sz |
88 * | - nvp_value_elem | | - nvp_value_elem |
89 * | - nvp_type | | - nvp_type |
90 * | - data ... | | - data ... |
91 * +---------------------+ +-------------------+
95 * +---------------------+ +---------------------+
96 * | i_nvp_t | +--> +-->| i_nvp_t (last) |
97 * |---------------------| | | |---------------------|
98 * | nvi_next -+--+ ... --+ | nvi_next (NULL) |
99 * <-+- nvi_prev |<-- ... <----+ nvi_prev |
100 * | . . . . . . . . . | | . . . . . . . . . |
101 * | nvp (nvpair_t) | | nvp (nvpair_t) |
102 * | - nvp_size | | - nvp_size |
103 * | - nvp_name_sz | | - nvp_name_sz |
104 * | - nvp_value_elem | | - nvp_value_elem |
105 * | - DATA_TYPE_NVLIST | | - nvp_type |
106 * | - data (embedded) | | - data ... |
107 * | nvlist name | +---------------------+
108 * | +--------------+ |
110 * | |--------------| |
111 * | | nvl_version | |
113 * | | nvl_priv --+---+---->
116 * | +--------------+ |
117 * +---------------------+
120 * N.B. nvpair_t may be aligned on 4 byte boundary, so +4 will
121 * allow value to be aligned on 8 byte boundary
123 * name_len is the length of the name string including the null terminator
126 #define NVP_SIZE_CALC(name_len, data_len) \
127 (NV_ALIGN((sizeof (nvpair_t)) + name_len) + NV_ALIGN(data_len))
129 static int i_get_value_size(data_type_t type
, const void *data
, uint_t nelem
);
130 static int nvlist_add_common(nvlist_t
*nvl
, const char *name
, data_type_t type
,
131 uint_t nelem
, const void *data
);
133 #define NV_STAT_EMBEDDED 0x1
134 #define EMBEDDED_NVL(nvp) ((nvlist_t *)(void *)NVP_VALUE(nvp))
135 #define EMBEDDED_NVL_ARRAY(nvp) ((nvlist_t **)(void *)NVP_VALUE(nvp))
137 #define NVP_VALOFF(nvp) (NV_ALIGN(sizeof (nvpair_t) + (nvp)->nvp_name_sz))
138 #define NVPAIR2I_NVP(nvp) \
139 ((i_nvp_t *)((size_t)(nvp) - offsetof(i_nvp_t, nvi_nvp)))
143 nv_alloc_init(nv_alloc_t
*nva
, const nv_alloc_ops_t
*nvo
, /* args */ ...)
151 va_start(valist
, nvo
);
152 if (nva
->nva_ops
->nv_ao_init
!= NULL
)
153 err
= nva
->nva_ops
->nv_ao_init(nva
, valist
);
160 nv_alloc_reset(nv_alloc_t
*nva
)
162 if (nva
->nva_ops
->nv_ao_reset
!= NULL
)
163 nva
->nva_ops
->nv_ao_reset(nva
);
167 nv_alloc_fini(nv_alloc_t
*nva
)
169 if (nva
->nva_ops
->nv_ao_fini
!= NULL
)
170 nva
->nva_ops
->nv_ao_fini(nva
);
174 nvlist_lookup_nv_alloc(nvlist_t
*nvl
)
179 (priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
) == NULL
)
182 return (priv
->nvp_nva
);
186 nv_mem_zalloc(nvpriv_t
*nvp
, size_t size
)
188 nv_alloc_t
*nva
= nvp
->nvp_nva
;
191 if ((buf
= nva
->nva_ops
->nv_ao_alloc(nva
, size
)) != NULL
)
198 nv_mem_free(nvpriv_t
*nvp
, void *buf
, size_t size
)
200 nv_alloc_t
*nva
= nvp
->nvp_nva
;
202 nva
->nva_ops
->nv_ao_free(nva
, buf
, size
);
206 nv_priv_init(nvpriv_t
*priv
, nv_alloc_t
*nva
, uint32_t stat
)
208 bzero(priv
, sizeof (nvpriv_t
));
211 priv
->nvp_stat
= stat
;
215 nv_priv_alloc(nv_alloc_t
*nva
)
220 * nv_mem_alloc() cannot called here because it needs the priv
223 if ((priv
= nva
->nva_ops
->nv_ao_alloc(nva
, sizeof (nvpriv_t
))) == NULL
)
226 nv_priv_init(priv
, nva
, 0);
232 * Embedded lists need their own nvpriv_t's. We create a new
233 * nvpriv_t using the parameters and allocator from the parent
237 nv_priv_alloc_embedded(nvpriv_t
*priv
)
241 if ((emb_priv
= nv_mem_zalloc(priv
, sizeof (nvpriv_t
))) == NULL
)
244 nv_priv_init(emb_priv
, priv
->nvp_nva
, NV_STAT_EMBEDDED
);
250 nvlist_init(nvlist_t
*nvl
, uint32_t nvflag
, nvpriv_t
*priv
)
252 nvl
->nvl_version
= NV_VERSION
;
253 nvl
->nvl_nvflag
= nvflag
& (NV_UNIQUE_NAME
|NV_UNIQUE_NAME_TYPE
);
254 nvl
->nvl_priv
= (uint64_t)(uintptr_t)priv
;
260 nvlist_nvflag(nvlist_t
*nvl
)
262 return (nvl
->nvl_nvflag
);
266 nvlist_nv_alloc(int kmflag
)
268 #if defined(_KERNEL) && !defined(_BOOT)
271 return (nv_alloc_sleep
);
273 return (nv_alloc_pushpage
);
275 return (nv_alloc_nosleep
);
278 return (nv_alloc_nosleep
);
279 #endif /* _KERNEL && !_BOOT */
283 * nvlist_alloc - Allocate nvlist.
286 nvlist_alloc(nvlist_t
**nvlp
, uint_t nvflag
, int kmflag
)
288 return (nvlist_xalloc(nvlp
, nvflag
, nvlist_nv_alloc(kmflag
)));
292 nvlist_xalloc(nvlist_t
**nvlp
, uint_t nvflag
, nv_alloc_t
*nva
)
296 if (nvlp
== NULL
|| nva
== NULL
)
299 if ((priv
= nv_priv_alloc(nva
)) == NULL
)
302 if ((*nvlp
= nv_mem_zalloc(priv
,
303 NV_ALIGN(sizeof (nvlist_t
)))) == NULL
) {
304 nv_mem_free(priv
, priv
, sizeof (nvpriv_t
));
308 nvlist_init(*nvlp
, nvflag
, priv
);
314 * nvp_buf_alloc - Allocate i_nvp_t for storing a new nv pair.
317 nvp_buf_alloc(nvlist_t
*nvl
, size_t len
)
319 nvpriv_t
*priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
;
325 * Allocate the buffer
327 nvsize
= len
+ offsetof(i_nvp_t
, nvi_nvp
);
329 if ((buf
= nv_mem_zalloc(priv
, nvsize
)) == NULL
)
339 * nvp_buf_free - de-Allocate an i_nvp_t.
342 nvp_buf_free(nvlist_t
*nvl
, nvpair_t
*nvp
)
344 nvpriv_t
*priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
;
345 size_t nvsize
= nvp
->nvp_size
+ offsetof(i_nvp_t
, nvi_nvp
);
347 nv_mem_free(priv
, NVPAIR2I_NVP(nvp
), nvsize
);
351 * nvp_buf_link - link a new nv pair into the nvlist.
354 nvp_buf_link(nvlist_t
*nvl
, nvpair_t
*nvp
)
356 nvpriv_t
*priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
;
357 i_nvp_t
*curr
= NVPAIR2I_NVP(nvp
);
359 /* Put element at end of nvlist */
360 if (priv
->nvp_list
== NULL
) {
361 priv
->nvp_list
= priv
->nvp_last
= curr
;
363 curr
->nvi_prev
= priv
->nvp_last
;
364 priv
->nvp_last
->nvi_next
= curr
;
365 priv
->nvp_last
= curr
;
370 * nvp_buf_unlink - unlink an removed nvpair out of the nvlist.
373 nvp_buf_unlink(nvlist_t
*nvl
, nvpair_t
*nvp
)
375 nvpriv_t
*priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
;
376 i_nvp_t
*curr
= NVPAIR2I_NVP(nvp
);
379 * protect nvlist_next_nvpair() against walking on freed memory.
381 if (priv
->nvp_curr
== curr
)
382 priv
->nvp_curr
= curr
->nvi_next
;
384 if (curr
== priv
->nvp_list
)
385 priv
->nvp_list
= curr
->nvi_next
;
387 curr
->nvi_prev
->nvi_next
= curr
->nvi_next
;
389 if (curr
== priv
->nvp_last
)
390 priv
->nvp_last
= curr
->nvi_prev
;
392 curr
->nvi_next
->nvi_prev
= curr
->nvi_prev
;
396 * take a nvpair type and number of elements and make sure the are valid
399 i_validate_type_nelem(data_type_t type
, uint_t nelem
)
402 case DATA_TYPE_BOOLEAN
:
406 case DATA_TYPE_BOOLEAN_VALUE
:
409 case DATA_TYPE_UINT8
:
410 case DATA_TYPE_INT16
:
411 case DATA_TYPE_UINT16
:
412 case DATA_TYPE_INT32
:
413 case DATA_TYPE_UINT32
:
414 case DATA_TYPE_INT64
:
415 case DATA_TYPE_UINT64
:
416 case DATA_TYPE_STRING
:
417 case DATA_TYPE_HRTIME
:
418 case DATA_TYPE_NVLIST
:
419 #if !defined(_KERNEL)
420 case DATA_TYPE_DOUBLE
:
425 case DATA_TYPE_BOOLEAN_ARRAY
:
426 case DATA_TYPE_BYTE_ARRAY
:
427 case DATA_TYPE_INT8_ARRAY
:
428 case DATA_TYPE_UINT8_ARRAY
:
429 case DATA_TYPE_INT16_ARRAY
:
430 case DATA_TYPE_UINT16_ARRAY
:
431 case DATA_TYPE_INT32_ARRAY
:
432 case DATA_TYPE_UINT32_ARRAY
:
433 case DATA_TYPE_INT64_ARRAY
:
434 case DATA_TYPE_UINT64_ARRAY
:
435 case DATA_TYPE_STRING_ARRAY
:
436 case DATA_TYPE_NVLIST_ARRAY
:
437 /* we allow arrays with 0 elements */
446 * Verify nvp_name_sz and check the name string length.
449 i_validate_nvpair_name(nvpair_t
*nvp
)
451 if ((nvp
->nvp_name_sz
<= 0) ||
452 (nvp
->nvp_size
< NVP_SIZE_CALC(nvp
->nvp_name_sz
, 0)))
455 /* verify the name string, make sure its terminated */
456 if (NVP_NAME(nvp
)[nvp
->nvp_name_sz
- 1] != '\0')
459 return (strlen(NVP_NAME(nvp
)) == nvp
->nvp_name_sz
- 1 ? 0 : EFAULT
);
463 i_validate_nvpair_value(data_type_t type
, uint_t nelem
, const void *data
)
466 case DATA_TYPE_BOOLEAN_VALUE
:
467 if (*(boolean_t
*)data
!= B_TRUE
&&
468 *(boolean_t
*)data
!= B_FALSE
)
471 case DATA_TYPE_BOOLEAN_ARRAY
: {
474 for (i
= 0; i
< nelem
; i
++)
475 if (((boolean_t
*)data
)[i
] != B_TRUE
&&
476 ((boolean_t
*)data
)[i
] != B_FALSE
)
488 * This function takes a pointer to what should be a nvpair and it's size
489 * and then verifies that all the nvpair fields make sense and can be
490 * trusted. This function is used when decoding packed nvpairs.
493 i_validate_nvpair(nvpair_t
*nvp
)
495 data_type_t type
= NVP_TYPE(nvp
);
498 /* verify nvp_name_sz, check the name string length */
499 if (i_validate_nvpair_name(nvp
) != 0)
502 if (i_validate_nvpair_value(type
, NVP_NELEM(nvp
), NVP_VALUE(nvp
)) != 0)
506 * verify nvp_type, nvp_value_elem, and also possibly
507 * verify string values and get the value size.
509 size2
= i_get_value_size(type
, NVP_VALUE(nvp
), NVP_NELEM(nvp
));
510 size1
= nvp
->nvp_size
- NVP_VALOFF(nvp
);
511 if (size2
< 0 || size1
!= NV_ALIGN(size2
))
518 nvlist_copy_pairs(nvlist_t
*snvl
, nvlist_t
*dnvl
)
523 if ((priv
= (nvpriv_t
*)(uintptr_t)snvl
->nvl_priv
) == NULL
)
526 for (curr
= priv
->nvp_list
; curr
!= NULL
; curr
= curr
->nvi_next
) {
527 nvpair_t
*nvp
= &curr
->nvi_nvp
;
530 if ((err
= nvlist_add_common(dnvl
, NVP_NAME(nvp
), NVP_TYPE(nvp
),
531 NVP_NELEM(nvp
), NVP_VALUE(nvp
))) != 0)
539 * Frees all memory allocated for an nvpair (like embedded lists) with
540 * the exception of the nvpair buffer itself.
543 nvpair_free(nvpair_t
*nvp
)
545 switch (NVP_TYPE(nvp
)) {
546 case DATA_TYPE_NVLIST
:
547 nvlist_free(EMBEDDED_NVL(nvp
));
549 case DATA_TYPE_NVLIST_ARRAY
: {
550 nvlist_t
**nvlp
= EMBEDDED_NVL_ARRAY(nvp
);
553 for (i
= 0; i
< NVP_NELEM(nvp
); i
++)
555 nvlist_free(nvlp
[i
]);
564 * nvlist_free - free an unpacked nvlist
567 nvlist_free(nvlist_t
*nvl
)
573 (priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
) == NULL
)
577 * Unpacked nvlist are linked through i_nvp_t
579 curr
= priv
->nvp_list
;
580 while (curr
!= NULL
) {
581 nvpair_t
*nvp
= &curr
->nvi_nvp
;
582 curr
= curr
->nvi_next
;
585 nvp_buf_free(nvl
, nvp
);
588 if (!(priv
->nvp_stat
& NV_STAT_EMBEDDED
))
589 nv_mem_free(priv
, nvl
, NV_ALIGN(sizeof (nvlist_t
)));
593 nv_mem_free(priv
, priv
, sizeof (nvpriv_t
));
597 nvlist_contains_nvp(nvlist_t
*nvl
, nvpair_t
*nvp
)
599 nvpriv_t
*priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
;
605 for (curr
= priv
->nvp_list
; curr
!= NULL
; curr
= curr
->nvi_next
)
606 if (&curr
->nvi_nvp
== nvp
)
613 * Make a copy of nvlist
616 nvlist_dup(nvlist_t
*nvl
, nvlist_t
**nvlp
, int kmflag
)
618 return (nvlist_xdup(nvl
, nvlp
, nvlist_nv_alloc(kmflag
)));
622 nvlist_xdup(nvlist_t
*nvl
, nvlist_t
**nvlp
, nv_alloc_t
*nva
)
627 if (nvl
== NULL
|| nvlp
== NULL
)
630 if ((err
= nvlist_xalloc(&ret
, nvl
->nvl_nvflag
, nva
)) != 0)
633 if ((err
= nvlist_copy_pairs(nvl
, ret
)) != 0)
642 * Remove all with matching name
645 nvlist_remove_all(nvlist_t
*nvl
, const char *name
)
651 if (nvl
== NULL
|| name
== NULL
||
652 (priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
) == NULL
)
655 curr
= priv
->nvp_list
;
656 while (curr
!= NULL
) {
657 nvpair_t
*nvp
= &curr
->nvi_nvp
;
659 curr
= curr
->nvi_next
;
660 if (strcmp(name
, NVP_NAME(nvp
)) != 0)
663 nvp_buf_unlink(nvl
, nvp
);
665 nvp_buf_free(nvl
, nvp
);
674 * Remove first one with matching name and type
677 nvlist_remove(nvlist_t
*nvl
, const char *name
, data_type_t type
)
682 if (nvl
== NULL
|| name
== NULL
||
683 (priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
) == NULL
)
686 curr
= priv
->nvp_list
;
687 while (curr
!= NULL
) {
688 nvpair_t
*nvp
= &curr
->nvi_nvp
;
690 if (strcmp(name
, NVP_NAME(nvp
)) == 0 && NVP_TYPE(nvp
) == type
) {
691 nvp_buf_unlink(nvl
, nvp
);
693 nvp_buf_free(nvl
, nvp
);
697 curr
= curr
->nvi_next
;
704 nvlist_remove_nvpair(nvlist_t
*nvl
, nvpair_t
*nvp
)
706 if (nvl
== NULL
|| nvp
== NULL
)
709 nvp_buf_unlink(nvl
, nvp
);
711 nvp_buf_free(nvl
, nvp
);
716 * This function calculates the size of an nvpair value.
718 * The data argument controls the behavior in case of the data types
719 * DATA_TYPE_STRING and
720 * DATA_TYPE_STRING_ARRAY
721 * Is data == NULL then the size of the string(s) is excluded.
724 i_get_value_size(data_type_t type
, const void *data
, uint_t nelem
)
728 if (i_validate_type_nelem(type
, nelem
) != 0)
731 /* Calculate required size for holding value */
733 case DATA_TYPE_BOOLEAN
:
736 case DATA_TYPE_BOOLEAN_VALUE
:
737 value_sz
= sizeof (boolean_t
);
740 value_sz
= sizeof (uchar_t
);
743 value_sz
= sizeof (int8_t);
745 case DATA_TYPE_UINT8
:
746 value_sz
= sizeof (uint8_t);
748 case DATA_TYPE_INT16
:
749 value_sz
= sizeof (int16_t);
751 case DATA_TYPE_UINT16
:
752 value_sz
= sizeof (uint16_t);
754 case DATA_TYPE_INT32
:
755 value_sz
= sizeof (int32_t);
757 case DATA_TYPE_UINT32
:
758 value_sz
= sizeof (uint32_t);
760 case DATA_TYPE_INT64
:
761 value_sz
= sizeof (int64_t);
763 case DATA_TYPE_UINT64
:
764 value_sz
= sizeof (uint64_t);
766 #if !defined(_KERNEL)
767 case DATA_TYPE_DOUBLE
:
768 value_sz
= sizeof (double);
771 case DATA_TYPE_STRING
:
775 value_sz
= strlen(data
) + 1;
777 case DATA_TYPE_BOOLEAN_ARRAY
:
778 value_sz
= (uint64_t)nelem
* sizeof (boolean_t
);
780 case DATA_TYPE_BYTE_ARRAY
:
781 value_sz
= (uint64_t)nelem
* sizeof (uchar_t
);
783 case DATA_TYPE_INT8_ARRAY
:
784 value_sz
= (uint64_t)nelem
* sizeof (int8_t);
786 case DATA_TYPE_UINT8_ARRAY
:
787 value_sz
= (uint64_t)nelem
* sizeof (uint8_t);
789 case DATA_TYPE_INT16_ARRAY
:
790 value_sz
= (uint64_t)nelem
* sizeof (int16_t);
792 case DATA_TYPE_UINT16_ARRAY
:
793 value_sz
= (uint64_t)nelem
* sizeof (uint16_t);
795 case DATA_TYPE_INT32_ARRAY
:
796 value_sz
= (uint64_t)nelem
* sizeof (int32_t);
798 case DATA_TYPE_UINT32_ARRAY
:
799 value_sz
= (uint64_t)nelem
* sizeof (uint32_t);
801 case DATA_TYPE_INT64_ARRAY
:
802 value_sz
= (uint64_t)nelem
* sizeof (int64_t);
804 case DATA_TYPE_UINT64_ARRAY
:
805 value_sz
= (uint64_t)nelem
* sizeof (uint64_t);
807 case DATA_TYPE_STRING_ARRAY
:
808 value_sz
= (uint64_t)nelem
* sizeof (uint64_t);
811 char *const *strs
= data
;
814 /* no alignment requirement for strings */
815 for (i
= 0; i
< nelem
; i
++) {
818 value_sz
+= strlen(strs
[i
]) + 1;
822 case DATA_TYPE_HRTIME
:
823 value_sz
= sizeof (hrtime_t
);
825 case DATA_TYPE_NVLIST
:
826 value_sz
= NV_ALIGN(sizeof (nvlist_t
));
828 case DATA_TYPE_NVLIST_ARRAY
:
829 value_sz
= (uint64_t)nelem
* sizeof (uint64_t) +
830 (uint64_t)nelem
* NV_ALIGN(sizeof (nvlist_t
));
836 return (value_sz
> INT32_MAX
? -1 : (int)value_sz
);
840 nvlist_copy_embedded(nvlist_t
*nvl
, nvlist_t
*onvl
, nvlist_t
*emb_nvl
)
845 if ((priv
= nv_priv_alloc_embedded((nvpriv_t
*)(uintptr_t)
846 nvl
->nvl_priv
)) == NULL
)
849 nvlist_init(emb_nvl
, onvl
->nvl_nvflag
, priv
);
851 if ((err
= nvlist_copy_pairs(onvl
, emb_nvl
)) != 0) {
852 nvlist_free(emb_nvl
);
853 emb_nvl
->nvl_priv
= 0;
860 * nvlist_add_common - Add new <name,value> pair to nvlist
863 nvlist_add_common(nvlist_t
*nvl
, const char *name
,
864 data_type_t type
, uint_t nelem
, const void *data
)
869 int nvp_sz
, name_sz
, value_sz
;
872 if (name
== NULL
|| nvl
== NULL
|| nvl
->nvl_priv
== 0)
875 if (nelem
!= 0 && data
== NULL
)
879 * Verify type and nelem and get the value size.
880 * In case of data types DATA_TYPE_STRING and DATA_TYPE_STRING_ARRAY
881 * is the size of the string(s) included.
883 if ((value_sz
= i_get_value_size(type
, data
, nelem
)) < 0)
886 if (i_validate_nvpair_value(type
, nelem
, data
) != 0)
890 * If we're adding an nvlist or nvlist array, ensure that we are not
891 * adding the input nvlist to itself, which would cause recursion,
892 * and ensure that no NULL nvlist pointers are present.
895 case DATA_TYPE_NVLIST
:
896 if (data
== nvl
|| data
== NULL
)
899 case DATA_TYPE_NVLIST_ARRAY
: {
900 nvlist_t
**onvlp
= (nvlist_t
**)data
;
901 for (i
= 0; i
< nelem
; i
++) {
902 if (onvlp
[i
] == nvl
|| onvlp
[i
] == NULL
)
911 /* calculate sizes of the nvpair elements and the nvpair itself */
912 name_sz
= strlen(name
) + 1;
914 nvp_sz
= NVP_SIZE_CALC(name_sz
, value_sz
);
916 if ((nvp
= nvp_buf_alloc(nvl
, nvp_sz
)) == NULL
)
919 ASSERT(nvp
->nvp_size
== nvp_sz
);
920 nvp
->nvp_name_sz
= name_sz
;
921 nvp
->nvp_value_elem
= nelem
;
922 nvp
->nvp_type
= type
;
923 bcopy(name
, NVP_NAME(nvp
), name_sz
);
926 case DATA_TYPE_BOOLEAN
:
928 case DATA_TYPE_STRING_ARRAY
: {
929 char *const *strs
= data
;
930 char *buf
= NVP_VALUE(nvp
);
931 char **cstrs
= (void *)buf
;
933 /* skip pre-allocated space for pointer array */
934 buf
+= nelem
* sizeof (uint64_t);
935 for (i
= 0; i
< nelem
; i
++) {
936 int slen
= strlen(strs
[i
]) + 1;
937 bcopy(strs
[i
], buf
, slen
);
943 case DATA_TYPE_NVLIST
: {
944 nvlist_t
*nnvl
= EMBEDDED_NVL(nvp
);
945 nvlist_t
*onvl
= (nvlist_t
*)data
;
947 if ((err
= nvlist_copy_embedded(nvl
, onvl
, nnvl
)) != 0) {
948 nvp_buf_free(nvl
, nvp
);
953 case DATA_TYPE_NVLIST_ARRAY
: {
954 nvlist_t
**onvlp
= (nvlist_t
**)data
;
955 nvlist_t
**nvlp
= EMBEDDED_NVL_ARRAY(nvp
);
956 nvlist_t
*embedded
= (nvlist_t
*)
957 ((uintptr_t)nvlp
+ nelem
* sizeof (uint64_t));
959 for (i
= 0; i
< nelem
; i
++) {
960 if ((err
= nvlist_copy_embedded(nvl
,
961 onvlp
[i
], embedded
)) != 0) {
963 * Free any successfully created lists
966 nvp_buf_free(nvl
, nvp
);
970 nvlp
[i
] = embedded
++;
975 bcopy(data
, NVP_VALUE(nvp
), value_sz
);
978 /* if unique name, remove before add */
979 if (nvl
->nvl_nvflag
& NV_UNIQUE_NAME
)
980 (void) nvlist_remove_all(nvl
, name
);
981 else if (nvl
->nvl_nvflag
& NV_UNIQUE_NAME_TYPE
)
982 (void) nvlist_remove(nvl
, name
, type
);
984 nvp_buf_link(nvl
, nvp
);
990 nvlist_add_boolean(nvlist_t
*nvl
, const char *name
)
992 return (nvlist_add_common(nvl
, name
, DATA_TYPE_BOOLEAN
, 0, NULL
));
996 nvlist_add_boolean_value(nvlist_t
*nvl
, const char *name
, boolean_t val
)
998 return (nvlist_add_common(nvl
, name
, DATA_TYPE_BOOLEAN_VALUE
, 1, &val
));
1002 nvlist_add_byte(nvlist_t
*nvl
, const char *name
, uchar_t val
)
1004 return (nvlist_add_common(nvl
, name
, DATA_TYPE_BYTE
, 1, &val
));
1008 nvlist_add_int8(nvlist_t
*nvl
, const char *name
, int8_t val
)
1010 return (nvlist_add_common(nvl
, name
, DATA_TYPE_INT8
, 1, &val
));
1014 nvlist_add_uint8(nvlist_t
*nvl
, const char *name
, uint8_t val
)
1016 return (nvlist_add_common(nvl
, name
, DATA_TYPE_UINT8
, 1, &val
));
1020 nvlist_add_int16(nvlist_t
*nvl
, const char *name
, int16_t val
)
1022 return (nvlist_add_common(nvl
, name
, DATA_TYPE_INT16
, 1, &val
));
1026 nvlist_add_uint16(nvlist_t
*nvl
, const char *name
, uint16_t val
)
1028 return (nvlist_add_common(nvl
, name
, DATA_TYPE_UINT16
, 1, &val
));
1032 nvlist_add_int32(nvlist_t
*nvl
, const char *name
, int32_t val
)
1034 return (nvlist_add_common(nvl
, name
, DATA_TYPE_INT32
, 1, &val
));
1038 nvlist_add_uint32(nvlist_t
*nvl
, const char *name
, uint32_t val
)
1040 return (nvlist_add_common(nvl
, name
, DATA_TYPE_UINT32
, 1, &val
));
1044 nvlist_add_int64(nvlist_t
*nvl
, const char *name
, int64_t val
)
1046 return (nvlist_add_common(nvl
, name
, DATA_TYPE_INT64
, 1, &val
));
1050 nvlist_add_uint64(nvlist_t
*nvl
, const char *name
, uint64_t val
)
1052 return (nvlist_add_common(nvl
, name
, DATA_TYPE_UINT64
, 1, &val
));
1055 #if !defined(_KERNEL)
1057 nvlist_add_double(nvlist_t
*nvl
, const char *name
, double val
)
1059 return (nvlist_add_common(nvl
, name
, DATA_TYPE_DOUBLE
, 1, &val
));
1064 nvlist_add_string(nvlist_t
*nvl
, const char *name
, const char *val
)
1066 return (nvlist_add_common(nvl
, name
, DATA_TYPE_STRING
, 1, (void *)val
));
1070 nvlist_add_boolean_array(nvlist_t
*nvl
, const char *name
,
1071 boolean_t
*a
, uint_t n
)
1073 return (nvlist_add_common(nvl
, name
, DATA_TYPE_BOOLEAN_ARRAY
, n
, a
));
1077 nvlist_add_byte_array(nvlist_t
*nvl
, const char *name
, uchar_t
*a
, uint_t n
)
1079 return (nvlist_add_common(nvl
, name
, DATA_TYPE_BYTE_ARRAY
, n
, a
));
1083 nvlist_add_int8_array(nvlist_t
*nvl
, const char *name
, int8_t *a
, uint_t n
)
1085 return (nvlist_add_common(nvl
, name
, DATA_TYPE_INT8_ARRAY
, n
, a
));
1089 nvlist_add_uint8_array(nvlist_t
*nvl
, const char *name
, uint8_t *a
, uint_t n
)
1091 return (nvlist_add_common(nvl
, name
, DATA_TYPE_UINT8_ARRAY
, n
, a
));
1095 nvlist_add_int16_array(nvlist_t
*nvl
, const char *name
, int16_t *a
, uint_t n
)
1097 return (nvlist_add_common(nvl
, name
, DATA_TYPE_INT16_ARRAY
, n
, a
));
1101 nvlist_add_uint16_array(nvlist_t
*nvl
, const char *name
, uint16_t *a
, uint_t n
)
1103 return (nvlist_add_common(nvl
, name
, DATA_TYPE_UINT16_ARRAY
, n
, a
));
1107 nvlist_add_int32_array(nvlist_t
*nvl
, const char *name
, int32_t *a
, uint_t n
)
1109 return (nvlist_add_common(nvl
, name
, DATA_TYPE_INT32_ARRAY
, n
, a
));
1113 nvlist_add_uint32_array(nvlist_t
*nvl
, const char *name
, uint32_t *a
, uint_t n
)
1115 return (nvlist_add_common(nvl
, name
, DATA_TYPE_UINT32_ARRAY
, n
, a
));
1119 nvlist_add_int64_array(nvlist_t
*nvl
, const char *name
, int64_t *a
, uint_t n
)
1121 return (nvlist_add_common(nvl
, name
, DATA_TYPE_INT64_ARRAY
, n
, a
));
1125 nvlist_add_uint64_array(nvlist_t
*nvl
, const char *name
, uint64_t *a
, uint_t n
)
1127 return (nvlist_add_common(nvl
, name
, DATA_TYPE_UINT64_ARRAY
, n
, a
));
1131 nvlist_add_string_array(nvlist_t
*nvl
, const char *name
,
1132 char *const *a
, uint_t n
)
1134 return (nvlist_add_common(nvl
, name
, DATA_TYPE_STRING_ARRAY
, n
, a
));
1138 nvlist_add_hrtime(nvlist_t
*nvl
, const char *name
, hrtime_t val
)
1140 return (nvlist_add_common(nvl
, name
, DATA_TYPE_HRTIME
, 1, &val
));
1144 nvlist_add_nvlist(nvlist_t
*nvl
, const char *name
, nvlist_t
*val
)
1146 return (nvlist_add_common(nvl
, name
, DATA_TYPE_NVLIST
, 1, val
));
1150 nvlist_add_nvlist_array(nvlist_t
*nvl
, const char *name
, nvlist_t
**a
, uint_t n
)
1152 return (nvlist_add_common(nvl
, name
, DATA_TYPE_NVLIST_ARRAY
, n
, a
));
1155 /* reading name-value pairs */
1157 nvlist_next_nvpair(nvlist_t
*nvl
, nvpair_t
*nvp
)
1163 (priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
) == NULL
)
1166 curr
= NVPAIR2I_NVP(nvp
);
1169 * Ensure that nvp is a valid nvpair on this nvlist.
1170 * NB: nvp_curr is used only as a hint so that we don't always
1171 * have to walk the list to determine if nvp is still on the list.
1174 curr
= priv
->nvp_list
;
1175 else if (priv
->nvp_curr
== curr
|| nvlist_contains_nvp(nvl
, nvp
))
1176 curr
= curr
->nvi_next
;
1180 priv
->nvp_curr
= curr
;
1182 return (curr
!= NULL
? &curr
->nvi_nvp
: NULL
);
1186 nvlist_prev_nvpair(nvlist_t
*nvl
, nvpair_t
*nvp
)
1192 (priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
) == NULL
)
1195 curr
= NVPAIR2I_NVP(nvp
);
1198 curr
= priv
->nvp_last
;
1199 else if (priv
->nvp_curr
== curr
|| nvlist_contains_nvp(nvl
, nvp
))
1200 curr
= curr
->nvi_prev
;
1204 priv
->nvp_curr
= curr
;
1206 return (curr
!= NULL
? &curr
->nvi_nvp
: NULL
);
1210 nvlist_empty(nvlist_t
*nvl
)
1215 (priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
) == NULL
)
1218 return (priv
->nvp_list
== NULL
);
1222 nvpair_name(nvpair_t
*nvp
)
1224 return (NVP_NAME(nvp
));
1228 nvpair_type(nvpair_t
*nvp
)
1230 return (NVP_TYPE(nvp
));
1234 nvpair_type_is_array(nvpair_t
*nvp
)
1236 data_type_t type
= NVP_TYPE(nvp
);
1238 if ((type
== DATA_TYPE_BYTE_ARRAY
) ||
1239 (type
== DATA_TYPE_UINT8_ARRAY
) ||
1240 (type
== DATA_TYPE_INT16_ARRAY
) ||
1241 (type
== DATA_TYPE_UINT16_ARRAY
) ||
1242 (type
== DATA_TYPE_INT32_ARRAY
) ||
1243 (type
== DATA_TYPE_UINT32_ARRAY
) ||
1244 (type
== DATA_TYPE_INT64_ARRAY
) ||
1245 (type
== DATA_TYPE_UINT64_ARRAY
) ||
1246 (type
== DATA_TYPE_BOOLEAN_ARRAY
) ||
1247 (type
== DATA_TYPE_STRING_ARRAY
) ||
1248 (type
== DATA_TYPE_NVLIST_ARRAY
))
1255 nvpair_value_common(nvpair_t
*nvp
, data_type_t type
, uint_t
*nelem
, void *data
)
1257 if (nvp
== NULL
|| nvpair_type(nvp
) != type
)
1261 * For non-array types, we copy the data.
1262 * For array types (including string), we set a pointer.
1265 case DATA_TYPE_BOOLEAN
:
1270 case DATA_TYPE_BOOLEAN_VALUE
:
1271 case DATA_TYPE_BYTE
:
1272 case DATA_TYPE_INT8
:
1273 case DATA_TYPE_UINT8
:
1274 case DATA_TYPE_INT16
:
1275 case DATA_TYPE_UINT16
:
1276 case DATA_TYPE_INT32
:
1277 case DATA_TYPE_UINT32
:
1278 case DATA_TYPE_INT64
:
1279 case DATA_TYPE_UINT64
:
1280 case DATA_TYPE_HRTIME
:
1281 #if !defined(_KERNEL)
1282 case DATA_TYPE_DOUBLE
:
1286 bcopy(NVP_VALUE(nvp
), data
,
1287 (size_t)i_get_value_size(type
, NULL
, 1));
1292 case DATA_TYPE_NVLIST
:
1293 case DATA_TYPE_STRING
:
1296 *(void **)data
= (void *)NVP_VALUE(nvp
);
1301 case DATA_TYPE_BOOLEAN_ARRAY
:
1302 case DATA_TYPE_BYTE_ARRAY
:
1303 case DATA_TYPE_INT8_ARRAY
:
1304 case DATA_TYPE_UINT8_ARRAY
:
1305 case DATA_TYPE_INT16_ARRAY
:
1306 case DATA_TYPE_UINT16_ARRAY
:
1307 case DATA_TYPE_INT32_ARRAY
:
1308 case DATA_TYPE_UINT32_ARRAY
:
1309 case DATA_TYPE_INT64_ARRAY
:
1310 case DATA_TYPE_UINT64_ARRAY
:
1311 case DATA_TYPE_STRING_ARRAY
:
1312 case DATA_TYPE_NVLIST_ARRAY
:
1313 if (nelem
== NULL
|| data
== NULL
)
1315 if ((*nelem
= NVP_NELEM(nvp
)) != 0)
1316 *(void **)data
= (void *)NVP_VALUE(nvp
);
1318 *(void **)data
= NULL
;
1329 nvlist_lookup_common(nvlist_t
*nvl
, const char *name
, data_type_t type
,
1330 uint_t
*nelem
, void *data
)
1336 if (name
== NULL
|| nvl
== NULL
||
1337 (priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
) == NULL
)
1340 if (!(nvl
->nvl_nvflag
& (NV_UNIQUE_NAME
| NV_UNIQUE_NAME_TYPE
)))
1343 for (curr
= priv
->nvp_list
; curr
!= NULL
; curr
= curr
->nvi_next
) {
1344 nvp
= &curr
->nvi_nvp
;
1346 if (strcmp(name
, NVP_NAME(nvp
)) == 0 && NVP_TYPE(nvp
) == type
)
1347 return (nvpair_value_common(nvp
, type
, nelem
, data
));
1354 nvlist_lookup_boolean(nvlist_t
*nvl
, const char *name
)
1356 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_BOOLEAN
, NULL
, NULL
));
1360 nvlist_lookup_boolean_value(nvlist_t
*nvl
, const char *name
, boolean_t
*val
)
1362 return (nvlist_lookup_common(nvl
, name
,
1363 DATA_TYPE_BOOLEAN_VALUE
, NULL
, val
));
1367 nvlist_lookup_byte(nvlist_t
*nvl
, const char *name
, uchar_t
*val
)
1369 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_BYTE
, NULL
, val
));
1373 nvlist_lookup_int8(nvlist_t
*nvl
, const char *name
, int8_t *val
)
1375 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_INT8
, NULL
, val
));
1379 nvlist_lookup_uint8(nvlist_t
*nvl
, const char *name
, uint8_t *val
)
1381 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_UINT8
, NULL
, val
));
1385 nvlist_lookup_int16(nvlist_t
*nvl
, const char *name
, int16_t *val
)
1387 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_INT16
, NULL
, val
));
1391 nvlist_lookup_uint16(nvlist_t
*nvl
, const char *name
, uint16_t *val
)
1393 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_UINT16
, NULL
, val
));
1397 nvlist_lookup_int32(nvlist_t
*nvl
, const char *name
, int32_t *val
)
1399 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_INT32
, NULL
, val
));
1403 nvlist_lookup_uint32(nvlist_t
*nvl
, const char *name
, uint32_t *val
)
1405 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_UINT32
, NULL
, val
));
1409 nvlist_lookup_int64(nvlist_t
*nvl
, const char *name
, int64_t *val
)
1411 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_INT64
, NULL
, val
));
1415 nvlist_lookup_uint64(nvlist_t
*nvl
, const char *name
, uint64_t *val
)
1417 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_UINT64
, NULL
, val
));
1420 #if !defined(_KERNEL)
1422 nvlist_lookup_double(nvlist_t
*nvl
, const char *name
, double *val
)
1424 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_DOUBLE
, NULL
, val
));
1429 nvlist_lookup_string(nvlist_t
*nvl
, const char *name
, char **val
)
1431 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_STRING
, NULL
, val
));
1435 nvlist_lookup_nvlist(nvlist_t
*nvl
, const char *name
, nvlist_t
**val
)
1437 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_NVLIST
, NULL
, val
));
1441 nvlist_lookup_boolean_array(nvlist_t
*nvl
, const char *name
,
1442 boolean_t
**a
, uint_t
*n
)
1444 return (nvlist_lookup_common(nvl
, name
,
1445 DATA_TYPE_BOOLEAN_ARRAY
, n
, a
));
1449 nvlist_lookup_byte_array(nvlist_t
*nvl
, const char *name
,
1450 uchar_t
**a
, uint_t
*n
)
1452 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_BYTE_ARRAY
, n
, a
));
1456 nvlist_lookup_int8_array(nvlist_t
*nvl
, const char *name
, int8_t **a
, uint_t
*n
)
1458 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_INT8_ARRAY
, n
, a
));
1462 nvlist_lookup_uint8_array(nvlist_t
*nvl
, const char *name
,
1463 uint8_t **a
, uint_t
*n
)
1465 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_UINT8_ARRAY
, n
, a
));
1469 nvlist_lookup_int16_array(nvlist_t
*nvl
, const char *name
,
1470 int16_t **a
, uint_t
*n
)
1472 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_INT16_ARRAY
, n
, a
));
1476 nvlist_lookup_uint16_array(nvlist_t
*nvl
, const char *name
,
1477 uint16_t **a
, uint_t
*n
)
1479 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_UINT16_ARRAY
, n
, a
));
1483 nvlist_lookup_int32_array(nvlist_t
*nvl
, const char *name
,
1484 int32_t **a
, uint_t
*n
)
1486 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_INT32_ARRAY
, n
, a
));
1490 nvlist_lookup_uint32_array(nvlist_t
*nvl
, const char *name
,
1491 uint32_t **a
, uint_t
*n
)
1493 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_UINT32_ARRAY
, n
, a
));
1497 nvlist_lookup_int64_array(nvlist_t
*nvl
, const char *name
,
1498 int64_t **a
, uint_t
*n
)
1500 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_INT64_ARRAY
, n
, a
));
1504 nvlist_lookup_uint64_array(nvlist_t
*nvl
, const char *name
,
1505 uint64_t **a
, uint_t
*n
)
1507 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_UINT64_ARRAY
, n
, a
));
1511 nvlist_lookup_string_array(nvlist_t
*nvl
, const char *name
,
1512 char ***a
, uint_t
*n
)
1514 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_STRING_ARRAY
, n
, a
));
1518 nvlist_lookup_nvlist_array(nvlist_t
*nvl
, const char *name
,
1519 nvlist_t
***a
, uint_t
*n
)
1521 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_NVLIST_ARRAY
, n
, a
));
1525 nvlist_lookup_hrtime(nvlist_t
*nvl
, const char *name
, hrtime_t
*val
)
1527 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_HRTIME
, NULL
, val
));
1531 nvlist_lookup_pairs(nvlist_t
*nvl
, int flag
, ...)
1535 int noentok
= (flag
& NV_FLAG_NOENTOK
? 1 : 0);
1539 while (ret
== 0 && (name
= va_arg(ap
, char *)) != NULL
) {
1544 switch (type
= va_arg(ap
, data_type_t
)) {
1545 case DATA_TYPE_BOOLEAN
:
1546 ret
= nvlist_lookup_common(nvl
, name
, type
, NULL
, NULL
);
1549 case DATA_TYPE_BOOLEAN_VALUE
:
1550 case DATA_TYPE_BYTE
:
1551 case DATA_TYPE_INT8
:
1552 case DATA_TYPE_UINT8
:
1553 case DATA_TYPE_INT16
:
1554 case DATA_TYPE_UINT16
:
1555 case DATA_TYPE_INT32
:
1556 case DATA_TYPE_UINT32
:
1557 case DATA_TYPE_INT64
:
1558 case DATA_TYPE_UINT64
:
1559 case DATA_TYPE_HRTIME
:
1560 case DATA_TYPE_STRING
:
1561 case DATA_TYPE_NVLIST
:
1562 #if !defined(_KERNEL)
1563 case DATA_TYPE_DOUBLE
:
1565 val
= va_arg(ap
, void *);
1566 ret
= nvlist_lookup_common(nvl
, name
, type
, NULL
, val
);
1569 case DATA_TYPE_BYTE_ARRAY
:
1570 case DATA_TYPE_BOOLEAN_ARRAY
:
1571 case DATA_TYPE_INT8_ARRAY
:
1572 case DATA_TYPE_UINT8_ARRAY
:
1573 case DATA_TYPE_INT16_ARRAY
:
1574 case DATA_TYPE_UINT16_ARRAY
:
1575 case DATA_TYPE_INT32_ARRAY
:
1576 case DATA_TYPE_UINT32_ARRAY
:
1577 case DATA_TYPE_INT64_ARRAY
:
1578 case DATA_TYPE_UINT64_ARRAY
:
1579 case DATA_TYPE_STRING_ARRAY
:
1580 case DATA_TYPE_NVLIST_ARRAY
:
1581 val
= va_arg(ap
, void *);
1582 nelem
= va_arg(ap
, uint_t
*);
1583 ret
= nvlist_lookup_common(nvl
, name
, type
, nelem
, val
);
1590 if (ret
== ENOENT
&& noentok
)
1599 * Find the 'name'ed nvpair in the nvlist 'nvl'. If 'name' found, the function
1600 * returns zero and a pointer to the matching nvpair is returned in '*ret'
1601 * (given 'ret' is non-NULL). If 'sep' is specified then 'name' will penitrate
1602 * multiple levels of embedded nvlists, with 'sep' as the separator. As an
1603 * example, if sep is '.', name might look like: "a" or "a.b" or "a.c[3]" or
1604 * "a.d[3].e[1]". This matches the C syntax for array embed (for convience,
1605 * code also supports "a.d[3]e[1]" syntax).
1607 * If 'ip' is non-NULL and the last name component is an array, return the
1608 * value of the "...[index]" array index in *ip. For an array reference that
1609 * is not indexed, *ip will be returned as -1. If there is a syntax error in
1610 * 'name', and 'ep' is non-NULL then *ep will be set to point to the location
1611 * inside the 'name' string where the syntax error was detected.
1614 nvlist_lookup_nvpair_ei_sep(nvlist_t
*nvl
, const char *name
, const char sep
,
1615 nvpair_t
**ret
, int *ip
, char **ep
)
1626 *ip
= -1; /* not indexed */
1630 if ((nvl
== NULL
) || (name
== NULL
))
1633 /* step through components of name */
1634 for (np
= name
; np
&& *np
; np
= sepp
) {
1635 /* ensure unique names */
1636 if (!(nvl
->nvl_nvflag
& NV_UNIQUE_NAME
))
1639 /* skip white space */
1640 skip_whitespace(np
);
1644 /* set 'sepp' to end of current component 'np' */
1646 sepp
= strchr(np
, sep
);
1650 /* find start of next "[ index ]..." */
1651 idxp
= strchr(np
, '[');
1653 /* if sepp comes first, set idxp to NULL */
1654 if (sepp
&& idxp
&& (sepp
< idxp
))
1658 * At this point 'idxp' is set if there is an index
1659 * expected for the current component.
1662 /* set 'n' to length of current 'np' name component */
1665 /* keep sepp up to date for *ep use as we advance */
1666 skip_whitespace(idxp
);
1669 /* determine the index value */
1670 #if defined(_KERNEL) && !defined(_BOOT)
1671 if (ddi_strtol(idxp
, &idxep
, 0, &idx
))
1674 idx
= strtol(idxp
, &idxep
, 0);
1679 /* keep sepp up to date for *ep use as we advance */
1682 /* skip white space index value and check for ']' */
1683 skip_whitespace(sepp
);
1687 /* for embedded arrays, support C syntax: "a[1].b" */
1688 skip_whitespace(sepp
);
1689 if (sep
&& (*sepp
== sep
))
1697 /* trim trailing whitespace by reducing length of 'np' */
1700 for (n
--; (np
[n
] == ' ') || (np
[n
] == '\t'); n
--)
1704 /* skip whitespace, and set sepp to NULL if complete */
1706 skip_whitespace(sepp
);
1713 * o 'n' is the length of current 'np' component.
1714 * o 'idxp' is set if there was an index, and value 'idx'.
1715 * o 'sepp' is set to the beginning of the next component,
1716 * and set to NULL if we have no more components.
1718 * Search for nvpair with matching component name.
1720 for (nvp
= nvlist_next_nvpair(nvl
, NULL
); nvp
!= NULL
;
1721 nvp
= nvlist_next_nvpair(nvl
, nvp
)) {
1723 /* continue if no match on name */
1724 if (strncmp(np
, nvpair_name(nvp
), n
) ||
1725 (strlen(nvpair_name(nvp
)) != n
))
1728 /* if indexed, verify type is array oriented */
1729 if (idxp
&& !nvpair_type_is_array(nvp
))
1733 * Full match found, return nvp and idx if this
1734 * was the last component.
1740 *ip
= (int)idx
; /* return index */
1741 return (0); /* found */
1745 * More components: current match must be
1746 * of DATA_TYPE_NVLIST or DATA_TYPE_NVLIST_ARRAY
1747 * to support going deeper.
1749 if (nvpair_type(nvp
) == DATA_TYPE_NVLIST
) {
1750 nvl
= EMBEDDED_NVL(nvp
);
1752 } else if (nvpair_type(nvp
) == DATA_TYPE_NVLIST_ARRAY
) {
1753 (void) nvpair_value_nvlist_array(nvp
,
1754 &nva
, (uint_t
*)&n
);
1755 if ((n
< 0) || (idx
>= n
))
1761 /* type does not support more levels */
1765 goto fail
; /* 'name' not found */
1767 /* search for match of next component in embedded 'nvl' list */
1770 fail
: if (ep
&& sepp
)
1776 * Return pointer to nvpair with specified 'name'.
1779 nvlist_lookup_nvpair(nvlist_t
*nvl
, const char *name
, nvpair_t
**ret
)
1781 return (nvlist_lookup_nvpair_ei_sep(nvl
, name
, 0, ret
, NULL
, NULL
));
1785 * Determine if named nvpair exists in nvlist (use embedded separator of '.'
1786 * and return array index). See nvlist_lookup_nvpair_ei_sep for more detailed
1789 int nvlist_lookup_nvpair_embedded_index(nvlist_t
*nvl
,
1790 const char *name
, nvpair_t
**ret
, int *ip
, char **ep
)
1792 return (nvlist_lookup_nvpair_ei_sep(nvl
, name
, '.', ret
, ip
, ep
));
1796 nvlist_exists(nvlist_t
*nvl
, const char *name
)
1802 if (name
== NULL
|| nvl
== NULL
||
1803 (priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
) == NULL
)
1806 for (curr
= priv
->nvp_list
; curr
!= NULL
; curr
= curr
->nvi_next
) {
1807 nvp
= &curr
->nvi_nvp
;
1809 if (strcmp(name
, NVP_NAME(nvp
)) == 0)
1817 nvpair_value_boolean_value(nvpair_t
*nvp
, boolean_t
*val
)
1819 return (nvpair_value_common(nvp
, DATA_TYPE_BOOLEAN_VALUE
, NULL
, val
));
1823 nvpair_value_byte(nvpair_t
*nvp
, uchar_t
*val
)
1825 return (nvpair_value_common(nvp
, DATA_TYPE_BYTE
, NULL
, val
));
1829 nvpair_value_int8(nvpair_t
*nvp
, int8_t *val
)
1831 return (nvpair_value_common(nvp
, DATA_TYPE_INT8
, NULL
, val
));
1835 nvpair_value_uint8(nvpair_t
*nvp
, uint8_t *val
)
1837 return (nvpair_value_common(nvp
, DATA_TYPE_UINT8
, NULL
, val
));
1841 nvpair_value_int16(nvpair_t
*nvp
, int16_t *val
)
1843 return (nvpair_value_common(nvp
, DATA_TYPE_INT16
, NULL
, val
));
1847 nvpair_value_uint16(nvpair_t
*nvp
, uint16_t *val
)
1849 return (nvpair_value_common(nvp
, DATA_TYPE_UINT16
, NULL
, val
));
1853 nvpair_value_int32(nvpair_t
*nvp
, int32_t *val
)
1855 return (nvpair_value_common(nvp
, DATA_TYPE_INT32
, NULL
, val
));
1859 nvpair_value_uint32(nvpair_t
*nvp
, uint32_t *val
)
1861 return (nvpair_value_common(nvp
, DATA_TYPE_UINT32
, NULL
, val
));
1865 nvpair_value_int64(nvpair_t
*nvp
, int64_t *val
)
1867 return (nvpair_value_common(nvp
, DATA_TYPE_INT64
, NULL
, val
));
1871 nvpair_value_uint64(nvpair_t
*nvp
, uint64_t *val
)
1873 return (nvpair_value_common(nvp
, DATA_TYPE_UINT64
, NULL
, val
));
1876 #if !defined(_KERNEL)
1878 nvpair_value_double(nvpair_t
*nvp
, double *val
)
1880 return (nvpair_value_common(nvp
, DATA_TYPE_DOUBLE
, NULL
, val
));
1885 nvpair_value_string(nvpair_t
*nvp
, char **val
)
1887 return (nvpair_value_common(nvp
, DATA_TYPE_STRING
, NULL
, val
));
1891 nvpair_value_nvlist(nvpair_t
*nvp
, nvlist_t
**val
)
1893 return (nvpair_value_common(nvp
, DATA_TYPE_NVLIST
, NULL
, val
));
1897 nvpair_value_boolean_array(nvpair_t
*nvp
, boolean_t
**val
, uint_t
*nelem
)
1899 return (nvpair_value_common(nvp
, DATA_TYPE_BOOLEAN_ARRAY
, nelem
, val
));
1903 nvpair_value_byte_array(nvpair_t
*nvp
, uchar_t
**val
, uint_t
*nelem
)
1905 return (nvpair_value_common(nvp
, DATA_TYPE_BYTE_ARRAY
, nelem
, val
));
1909 nvpair_value_int8_array(nvpair_t
*nvp
, int8_t **val
, uint_t
*nelem
)
1911 return (nvpair_value_common(nvp
, DATA_TYPE_INT8_ARRAY
, nelem
, val
));
1915 nvpair_value_uint8_array(nvpair_t
*nvp
, uint8_t **val
, uint_t
*nelem
)
1917 return (nvpair_value_common(nvp
, DATA_TYPE_UINT8_ARRAY
, nelem
, val
));
1921 nvpair_value_int16_array(nvpair_t
*nvp
, int16_t **val
, uint_t
*nelem
)
1923 return (nvpair_value_common(nvp
, DATA_TYPE_INT16_ARRAY
, nelem
, val
));
1927 nvpair_value_uint16_array(nvpair_t
*nvp
, uint16_t **val
, uint_t
*nelem
)
1929 return (nvpair_value_common(nvp
, DATA_TYPE_UINT16_ARRAY
, nelem
, val
));
1933 nvpair_value_int32_array(nvpair_t
*nvp
, int32_t **val
, uint_t
*nelem
)
1935 return (nvpair_value_common(nvp
, DATA_TYPE_INT32_ARRAY
, nelem
, val
));
1939 nvpair_value_uint32_array(nvpair_t
*nvp
, uint32_t **val
, uint_t
*nelem
)
1941 return (nvpair_value_common(nvp
, DATA_TYPE_UINT32_ARRAY
, nelem
, val
));
1945 nvpair_value_int64_array(nvpair_t
*nvp
, int64_t **val
, uint_t
*nelem
)
1947 return (nvpair_value_common(nvp
, DATA_TYPE_INT64_ARRAY
, nelem
, val
));
1951 nvpair_value_uint64_array(nvpair_t
*nvp
, uint64_t **val
, uint_t
*nelem
)
1953 return (nvpair_value_common(nvp
, DATA_TYPE_UINT64_ARRAY
, nelem
, val
));
1957 nvpair_value_string_array(nvpair_t
*nvp
, char ***val
, uint_t
*nelem
)
1959 return (nvpair_value_common(nvp
, DATA_TYPE_STRING_ARRAY
, nelem
, val
));
1963 nvpair_value_nvlist_array(nvpair_t
*nvp
, nvlist_t
***val
, uint_t
*nelem
)
1965 return (nvpair_value_common(nvp
, DATA_TYPE_NVLIST_ARRAY
, nelem
, val
));
1969 nvpair_value_hrtime(nvpair_t
*nvp
, hrtime_t
*val
)
1971 return (nvpair_value_common(nvp
, DATA_TYPE_HRTIME
, NULL
, val
));
1975 * Add specified pair to the list.
1978 nvlist_add_nvpair(nvlist_t
*nvl
, nvpair_t
*nvp
)
1980 if (nvl
== NULL
|| nvp
== NULL
)
1983 return (nvlist_add_common(nvl
, NVP_NAME(nvp
), NVP_TYPE(nvp
),
1984 NVP_NELEM(nvp
), NVP_VALUE(nvp
)));
1988 * Merge the supplied nvlists and put the result in dst.
1989 * The merged list will contain all names specified in both lists,
1990 * the values are taken from nvl in the case of duplicates.
1991 * Return 0 on success.
1995 nvlist_merge(nvlist_t
*dst
, nvlist_t
*nvl
, int flag
)
1997 if (nvl
== NULL
|| dst
== NULL
)
2001 return (nvlist_copy_pairs(nvl
, dst
));
2007 * Encoding related routines
2009 #define NVS_OP_ENCODE 0
2010 #define NVS_OP_DECODE 1
2011 #define NVS_OP_GETSIZE 2
2013 typedef struct nvs_ops nvs_ops_t
;
2017 const nvs_ops_t
*nvs_ops
;
2023 * nvs operations are:
2025 * encoding / decoding of a nvlist header (nvlist_t)
2026 * calculates the size used for header and end detection
2029 * responsible for the first part of encoding / decoding of an nvpair
2030 * calculates the decoded size of an nvpair
2033 * second part of encoding / decoding of an nvpair
2036 * calculates the encoding size of an nvpair
2039 * encodes the end detection mark (zeros).
2042 int (*nvs_nvlist
)(nvstream_t
*, nvlist_t
*, size_t *);
2043 int (*nvs_nvpair
)(nvstream_t
*, nvpair_t
*, size_t *);
2044 int (*nvs_nvp_op
)(nvstream_t
*, nvpair_t
*);
2045 int (*nvs_nvp_size
)(nvstream_t
*, nvpair_t
*, size_t *);
2046 int (*nvs_nvl_fini
)(nvstream_t
*);
2050 char nvh_encoding
; /* nvs encoding method */
2051 char nvh_endian
; /* nvs endian */
2052 char nvh_reserved1
; /* reserved for future use */
2053 char nvh_reserved2
; /* reserved for future use */
2057 nvs_encode_pairs(nvstream_t
*nvs
, nvlist_t
*nvl
)
2059 nvpriv_t
*priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
;
2063 * Walk nvpair in list and encode each nvpair
2065 for (curr
= priv
->nvp_list
; curr
!= NULL
; curr
= curr
->nvi_next
)
2066 if (nvs
->nvs_ops
->nvs_nvpair(nvs
, &curr
->nvi_nvp
, NULL
) != 0)
2069 return (nvs
->nvs_ops
->nvs_nvl_fini(nvs
));
2073 nvs_decode_pairs(nvstream_t
*nvs
, nvlist_t
*nvl
)
2080 * Get decoded size of next pair in stream, alloc
2081 * memory for nvpair_t, then decode the nvpair
2083 while ((err
= nvs
->nvs_ops
->nvs_nvpair(nvs
, NULL
, &nvsize
)) == 0) {
2084 if (nvsize
== 0) /* end of list */
2087 /* make sure len makes sense */
2088 if (nvsize
< NVP_SIZE_CALC(1, 0))
2091 if ((nvp
= nvp_buf_alloc(nvl
, nvsize
)) == NULL
)
2094 if ((err
= nvs
->nvs_ops
->nvs_nvp_op(nvs
, nvp
)) != 0) {
2095 nvp_buf_free(nvl
, nvp
);
2099 if (i_validate_nvpair(nvp
) != 0) {
2101 nvp_buf_free(nvl
, nvp
);
2105 nvp_buf_link(nvl
, nvp
);
2111 nvs_getsize_pairs(nvstream_t
*nvs
, nvlist_t
*nvl
, size_t *buflen
)
2113 nvpriv_t
*priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
;
2115 uint64_t nvsize
= *buflen
;
2119 * Get encoded size of nvpairs in nvlist
2121 for (curr
= priv
->nvp_list
; curr
!= NULL
; curr
= curr
->nvi_next
) {
2122 if (nvs
->nvs_ops
->nvs_nvp_size(nvs
, &curr
->nvi_nvp
, &size
) != 0)
2125 if ((nvsize
+= size
) > INT32_MAX
)
2134 nvs_operation(nvstream_t
*nvs
, nvlist_t
*nvl
, size_t *buflen
)
2138 if (nvl
->nvl_priv
== 0)
2142 * Perform the operation, starting with header, then each nvpair
2144 if ((err
= nvs
->nvs_ops
->nvs_nvlist(nvs
, nvl
, buflen
)) != 0)
2147 switch (nvs
->nvs_op
) {
2149 err
= nvs_encode_pairs(nvs
, nvl
);
2153 err
= nvs_decode_pairs(nvs
, nvl
);
2156 case NVS_OP_GETSIZE
:
2157 err
= nvs_getsize_pairs(nvs
, nvl
, buflen
);
2168 nvs_embedded(nvstream_t
*nvs
, nvlist_t
*embedded
)
2170 switch (nvs
->nvs_op
) {
2172 return (nvs_operation(nvs
, embedded
, NULL
));
2174 case NVS_OP_DECODE
: {
2178 if (embedded
->nvl_version
!= NV_VERSION
)
2181 if ((priv
= nv_priv_alloc_embedded(nvs
->nvs_priv
)) == NULL
)
2184 nvlist_init(embedded
, embedded
->nvl_nvflag
, priv
);
2186 if ((err
= nvs_operation(nvs
, embedded
, NULL
)) != 0)
2187 nvlist_free(embedded
);
2198 nvs_embedded_nvl_array(nvstream_t
*nvs
, nvpair_t
*nvp
, size_t *size
)
2200 size_t nelem
= NVP_NELEM(nvp
);
2201 nvlist_t
**nvlp
= EMBEDDED_NVL_ARRAY(nvp
);
2204 switch (nvs
->nvs_op
) {
2206 for (i
= 0; i
< nelem
; i
++)
2207 if (nvs_embedded(nvs
, nvlp
[i
]) != 0)
2211 case NVS_OP_DECODE
: {
2212 size_t len
= nelem
* sizeof (uint64_t);
2213 nvlist_t
*embedded
= (nvlist_t
*)((uintptr_t)nvlp
+ len
);
2215 bzero(nvlp
, len
); /* don't trust packed data */
2216 for (i
= 0; i
< nelem
; i
++) {
2217 if (nvs_embedded(nvs
, embedded
) != 0) {
2222 nvlp
[i
] = embedded
++;
2226 case NVS_OP_GETSIZE
: {
2227 uint64_t nvsize
= 0;
2229 for (i
= 0; i
< nelem
; i
++) {
2232 if (nvs_operation(nvs
, nvlp
[i
], &nvp_sz
) != 0)
2235 if ((nvsize
+= nvp_sz
) > INT32_MAX
)
2249 static int nvs_native(nvstream_t
*, nvlist_t
*, char *, size_t *);
2250 static int nvs_xdr(nvstream_t
*, nvlist_t
*, char *, size_t *);
2253 * Common routine for nvlist operations:
2254 * encode, decode, getsize (encoded size).
2257 nvlist_common(nvlist_t
*nvl
, char *buf
, size_t *buflen
, int encoding
,
2263 #ifdef _LITTLE_ENDIAN
2264 int host_endian
= 1;
2266 int host_endian
= 0;
2267 #endif /* _LITTLE_ENDIAN */
2268 nvs_header_t
*nvh
= (void *)buf
;
2270 if (buflen
== NULL
|| nvl
== NULL
||
2271 (nvs
.nvs_priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
) == NULL
)
2274 nvs
.nvs_op
= nvs_op
;
2277 * For NVS_OP_ENCODE and NVS_OP_DECODE make sure an nvlist and
2278 * a buffer is allocated. The first 4 bytes in the buffer are
2279 * used for encoding method and host endian.
2283 if (buf
== NULL
|| *buflen
< sizeof (nvs_header_t
))
2286 nvh
->nvh_encoding
= encoding
;
2287 nvh
->nvh_endian
= nvl_endian
= host_endian
;
2288 nvh
->nvh_reserved1
= 0;
2289 nvh
->nvh_reserved2
= 0;
2293 if (buf
== NULL
|| *buflen
< sizeof (nvs_header_t
))
2296 /* get method of encoding from first byte */
2297 encoding
= nvh
->nvh_encoding
;
2298 nvl_endian
= nvh
->nvh_endian
;
2301 case NVS_OP_GETSIZE
:
2302 nvl_endian
= host_endian
;
2305 * add the size for encoding
2307 *buflen
= sizeof (nvs_header_t
);
2315 * Create an nvstream with proper encoding method
2318 case NV_ENCODE_NATIVE
:
2320 * check endianness, in case we are unpacking
2323 if (nvl_endian
!= host_endian
)
2325 err
= nvs_native(&nvs
, nvl
, buf
, buflen
);
2328 err
= nvs_xdr(&nvs
, nvl
, buf
, buflen
);
2339 nvlist_size(nvlist_t
*nvl
, size_t *size
, int encoding
)
2341 return (nvlist_common(nvl
, NULL
, size
, encoding
, NVS_OP_GETSIZE
));
2345 * Pack nvlist into contiguous memory
2348 nvlist_pack(nvlist_t
*nvl
, char **bufp
, size_t *buflen
, int encoding
,
2351 return (nvlist_xpack(nvl
, bufp
, buflen
, encoding
,
2352 nvlist_nv_alloc(kmflag
)));
2356 nvlist_xpack(nvlist_t
*nvl
, char **bufp
, size_t *buflen
, int encoding
,
2364 if (nva
== NULL
|| nvl
== NULL
|| bufp
== NULL
|| buflen
== NULL
)
2368 return (nvlist_common(nvl
, *bufp
, buflen
, encoding
,
2372 * Here is a difficult situation:
2373 * 1. The nvlist has fixed allocator properties.
2374 * All other nvlist routines (like nvlist_add_*, ...) use
2376 * 2. When using nvlist_pack() the user can specify his own
2377 * allocator properties (e.g. by using KM_NOSLEEP).
2379 * We use the user specified properties (2). A clearer solution
2380 * will be to remove the kmflag from nvlist_pack(), but we will
2381 * not change the interface.
2383 nv_priv_init(&nvpriv
, nva
, 0);
2385 if ((err
= nvlist_size(nvl
, &alloc_size
, encoding
)))
2388 if ((buf
= nv_mem_zalloc(&nvpriv
, alloc_size
)) == NULL
)
2391 if ((err
= nvlist_common(nvl
, buf
, &alloc_size
, encoding
,
2392 NVS_OP_ENCODE
)) != 0) {
2393 nv_mem_free(&nvpriv
, buf
, alloc_size
);
2395 *buflen
= alloc_size
;
2403 * Unpack buf into an nvlist_t
2406 nvlist_unpack(char *buf
, size_t buflen
, nvlist_t
**nvlp
, int kmflag
)
2408 return (nvlist_xunpack(buf
, buflen
, nvlp
, nvlist_nv_alloc(kmflag
)));
2412 nvlist_xunpack(char *buf
, size_t buflen
, nvlist_t
**nvlp
, nv_alloc_t
*nva
)
2420 if ((err
= nvlist_xalloc(&nvl
, 0, nva
)) != 0)
2423 if ((err
= nvlist_common(nvl
, buf
, &buflen
, 0, NVS_OP_DECODE
)) != 0)
2432 * Native encoding functions
2436 * This structure is used when decoding a packed nvpair in
2437 * the native format. n_base points to a buffer containing the
2438 * packed nvpair. n_end is a pointer to the end of the buffer.
2439 * (n_end actually points to the first byte past the end of the
2440 * buffer.) n_curr is a pointer that lies between n_base and n_end.
2441 * It points to the current data that we are decoding.
2442 * The amount of data left in the buffer is equal to n_end - n_curr.
2443 * n_flag is used to recognize a packed embedded list.
2452 nvs_native_create(nvstream_t
*nvs
, nvs_native_t
*native
, char *buf
,
2455 switch (nvs
->nvs_op
) {
2458 nvs
->nvs_private
= native
;
2459 native
->n_curr
= native
->n_base
= buf
;
2460 native
->n_end
= buf
+ buflen
;
2464 case NVS_OP_GETSIZE
:
2465 nvs
->nvs_private
= native
;
2466 native
->n_curr
= native
->n_base
= native
->n_end
= NULL
;
2476 nvs_native_destroy(nvstream_t
*nvs
)
2481 native_cp(nvstream_t
*nvs
, void *buf
, size_t size
)
2483 nvs_native_t
*native
= (nvs_native_t
*)nvs
->nvs_private
;
2485 if (native
->n_curr
+ size
> native
->n_end
)
2489 * The bcopy() below eliminates alignment requirement
2490 * on the buffer (stream) and is preferred over direct access.
2492 switch (nvs
->nvs_op
) {
2494 bcopy(buf
, native
->n_curr
, size
);
2497 bcopy(native
->n_curr
, buf
, size
);
2503 native
->n_curr
+= size
;
2508 * operate on nvlist_t header
2511 nvs_native_nvlist(nvstream_t
*nvs
, nvlist_t
*nvl
, size_t *size
)
2513 nvs_native_t
*native
= nvs
->nvs_private
;
2515 switch (nvs
->nvs_op
) {
2519 return (0); /* packed embedded list */
2523 /* copy version and nvflag of the nvlist_t */
2524 if (native_cp(nvs
, &nvl
->nvl_version
, sizeof (int32_t)) != 0 ||
2525 native_cp(nvs
, &nvl
->nvl_nvflag
, sizeof (int32_t)) != 0)
2530 case NVS_OP_GETSIZE
:
2532 * if calculate for packed embedded list
2533 * 4 for end of the embedded list
2535 * 2 * sizeof (int32_t) for nvl_version and nvl_nvflag
2536 * and 4 for end of the entire list
2538 if (native
->n_flag
) {
2542 *size
+= 2 * sizeof (int32_t) + 4;
2553 nvs_native_nvl_fini(nvstream_t
*nvs
)
2555 if (nvs
->nvs_op
== NVS_OP_ENCODE
) {
2556 nvs_native_t
*native
= (nvs_native_t
*)nvs
->nvs_private
;
2558 * Add 4 zero bytes at end of nvlist. They are used
2559 * for end detection by the decode routine.
2561 if (native
->n_curr
+ sizeof (int) > native
->n_end
)
2564 bzero(native
->n_curr
, sizeof (int));
2565 native
->n_curr
+= sizeof (int);
2572 nvpair_native_embedded(nvstream_t
*nvs
, nvpair_t
*nvp
)
2574 if (nvs
->nvs_op
== NVS_OP_ENCODE
) {
2575 nvs_native_t
*native
= (nvs_native_t
*)nvs
->nvs_private
;
2576 nvlist_t
*packed
= (void *)
2577 (native
->n_curr
- nvp
->nvp_size
+ NVP_VALOFF(nvp
));
2579 * Null out the pointer that is meaningless in the packed
2580 * structure. The address may not be aligned, so we have
2583 bzero((char *)packed
+ offsetof(nvlist_t
, nvl_priv
),
2587 return (nvs_embedded(nvs
, EMBEDDED_NVL(nvp
)));
2591 nvpair_native_embedded_array(nvstream_t
*nvs
, nvpair_t
*nvp
)
2593 if (nvs
->nvs_op
== NVS_OP_ENCODE
) {
2594 nvs_native_t
*native
= (nvs_native_t
*)nvs
->nvs_private
;
2595 char *value
= native
->n_curr
- nvp
->nvp_size
+ NVP_VALOFF(nvp
);
2596 size_t len
= NVP_NELEM(nvp
) * sizeof (uint64_t);
2597 nvlist_t
*packed
= (nvlist_t
*)((uintptr_t)value
+ len
);
2600 * Null out pointers that are meaningless in the packed
2601 * structure. The addresses may not be aligned, so we have
2606 for (i
= 0; i
< NVP_NELEM(nvp
); i
++, packed
++)
2608 * Null out the pointer that is meaningless in the
2609 * packed structure. The address may not be aligned,
2610 * so we have to use bzero.
2612 bzero((char *)packed
+ offsetof(nvlist_t
, nvl_priv
),
2616 return (nvs_embedded_nvl_array(nvs
, nvp
, NULL
));
2620 nvpair_native_string_array(nvstream_t
*nvs
, nvpair_t
*nvp
)
2622 switch (nvs
->nvs_op
) {
2623 case NVS_OP_ENCODE
: {
2624 nvs_native_t
*native
= (nvs_native_t
*)nvs
->nvs_private
;
2625 uint64_t *strp
= (void *)
2626 (native
->n_curr
- nvp
->nvp_size
+ NVP_VALOFF(nvp
));
2628 * Null out pointers that are meaningless in the packed
2629 * structure. The addresses may not be aligned, so we have
2632 bzero(strp
, NVP_NELEM(nvp
) * sizeof (uint64_t));
2635 case NVS_OP_DECODE
: {
2636 char **strp
= (void *)NVP_VALUE(nvp
);
2637 char *buf
= ((char *)strp
+ NVP_NELEM(nvp
) * sizeof (uint64_t));
2640 for (i
= 0; i
< NVP_NELEM(nvp
); i
++) {
2642 buf
+= strlen(buf
) + 1;
2650 nvs_native_nvp_op(nvstream_t
*nvs
, nvpair_t
*nvp
)
2657 * We do the initial bcopy of the data before we look at
2658 * the nvpair type, because when we're decoding, we won't
2659 * have the correct values for the pair until we do the bcopy.
2661 switch (nvs
->nvs_op
) {
2664 if (native_cp(nvs
, nvp
, nvp
->nvp_size
) != 0)
2671 /* verify nvp_name_sz, check the name string length */
2672 if (i_validate_nvpair_name(nvp
) != 0)
2675 type
= NVP_TYPE(nvp
);
2678 * Verify type and nelem and get the value size.
2679 * In case of data types DATA_TYPE_STRING and DATA_TYPE_STRING_ARRAY
2680 * is the size of the string(s) excluded.
2682 if ((value_sz
= i_get_value_size(type
, NULL
, NVP_NELEM(nvp
))) < 0)
2685 if (NVP_SIZE_CALC(nvp
->nvp_name_sz
, value_sz
) > nvp
->nvp_size
)
2689 case DATA_TYPE_NVLIST
:
2690 ret
= nvpair_native_embedded(nvs
, nvp
);
2692 case DATA_TYPE_NVLIST_ARRAY
:
2693 ret
= nvpair_native_embedded_array(nvs
, nvp
);
2695 case DATA_TYPE_STRING_ARRAY
:
2696 nvpair_native_string_array(nvs
, nvp
);
2706 nvs_native_nvp_size(nvstream_t
*nvs
, nvpair_t
*nvp
, size_t *size
)
2708 uint64_t nvp_sz
= nvp
->nvp_size
;
2710 switch (NVP_TYPE(nvp
)) {
2711 case DATA_TYPE_NVLIST
: {
2714 if (nvs_operation(nvs
, EMBEDDED_NVL(nvp
), &nvsize
) != 0)
2720 case DATA_TYPE_NVLIST_ARRAY
: {
2723 if (nvs_embedded_nvl_array(nvs
, nvp
, &nvsize
) != 0)
2733 if (nvp_sz
> INT32_MAX
)
2742 nvs_native_nvpair(nvstream_t
*nvs
, nvpair_t
*nvp
, size_t *size
)
2744 switch (nvs
->nvs_op
) {
2746 return (nvs_native_nvp_op(nvs
, nvp
));
2748 case NVS_OP_DECODE
: {
2749 nvs_native_t
*native
= (nvs_native_t
*)nvs
->nvs_private
;
2752 /* try to read the size value from the stream */
2753 if (native
->n_curr
+ sizeof (int32_t) > native
->n_end
)
2755 bcopy(native
->n_curr
, &decode_len
, sizeof (int32_t));
2757 /* sanity check the size value */
2758 if (decode_len
< 0 ||
2759 decode_len
> native
->n_end
- native
->n_curr
)
2765 * If at the end of the stream then move the cursor
2766 * forward, otherwise nvpair_native_op() will read
2767 * the entire nvpair at the same cursor position.
2770 native
->n_curr
+= sizeof (int32_t);
2781 static const nvs_ops_t nvs_native_ops
= {
2785 nvs_native_nvp_size
,
2790 nvs_native(nvstream_t
*nvs
, nvlist_t
*nvl
, char *buf
, size_t *buflen
)
2792 nvs_native_t native
;
2795 nvs
->nvs_ops
= &nvs_native_ops
;
2797 if ((err
= nvs_native_create(nvs
, &native
, buf
+ sizeof (nvs_header_t
),
2798 *buflen
- sizeof (nvs_header_t
))) != 0)
2801 err
= nvs_operation(nvs
, nvl
, buflen
);
2803 nvs_native_destroy(nvs
);
2809 * XDR encoding functions
2811 * An xdr packed nvlist is encoded as:
2813 * - encoding methode and host endian (4 bytes)
2814 * - nvl_version (4 bytes)
2815 * - nvl_nvflag (4 bytes)
2817 * - encoded nvpairs, the format of one xdr encoded nvpair is:
2818 * - encoded size of the nvpair (4 bytes)
2819 * - decoded size of the nvpair (4 bytes)
2820 * - name string, (4 + sizeof(NV_ALIGN4(string))
2821 * a string is coded as size (4 bytes) and data
2822 * - data type (4 bytes)
2823 * - number of elements in the nvpair (4 bytes)
2826 * - 2 zero's for end of the entire list (8 bytes)
2829 nvs_xdr_create(nvstream_t
*nvs
, XDR
*xdr
, char *buf
, size_t buflen
)
2831 /* xdr data must be 4 byte aligned */
2832 if ((ulong_t
)buf
% 4 != 0)
2835 switch (nvs
->nvs_op
) {
2837 xdrmem_create(xdr
, buf
, (uint_t
)buflen
, XDR_ENCODE
);
2838 nvs
->nvs_private
= xdr
;
2841 xdrmem_create(xdr
, buf
, (uint_t
)buflen
, XDR_DECODE
);
2842 nvs
->nvs_private
= xdr
;
2844 case NVS_OP_GETSIZE
:
2845 nvs
->nvs_private
= NULL
;
2853 nvs_xdr_destroy(nvstream_t
*nvs
)
2855 switch (nvs
->nvs_op
) {
2858 xdr_destroy((XDR
*)nvs
->nvs_private
);
2866 nvs_xdr_nvlist(nvstream_t
*nvs
, nvlist_t
*nvl
, size_t *size
)
2868 switch (nvs
->nvs_op
) {
2870 case NVS_OP_DECODE
: {
2871 XDR
*xdr
= nvs
->nvs_private
;
2873 if (!xdr_int(xdr
, &nvl
->nvl_version
) ||
2874 !xdr_u_int(xdr
, &nvl
->nvl_nvflag
))
2878 case NVS_OP_GETSIZE
: {
2880 * 2 * 4 for nvl_version + nvl_nvflag
2881 * and 8 for end of the entire list
2893 nvs_xdr_nvl_fini(nvstream_t
*nvs
)
2895 if (nvs
->nvs_op
== NVS_OP_ENCODE
) {
2896 XDR
*xdr
= nvs
->nvs_private
;
2899 if (!xdr_int(xdr
, &zero
) || !xdr_int(xdr
, &zero
))
2907 * The format of xdr encoded nvpair is:
2908 * encode_size, decode_size, name string, data type, nelem, data
2911 nvs_xdr_nvp_op(nvstream_t
*nvs
, nvpair_t
*nvp
)
2915 char *buf_end
= (char *)nvp
+ nvp
->nvp_size
;
2917 uint_t nelem
, buflen
;
2919 XDR
*xdr
= nvs
->nvs_private
;
2921 ASSERT(xdr
!= NULL
&& nvp
!= NULL
);
2924 if ((buf
= NVP_NAME(nvp
)) >= buf_end
)
2926 buflen
= buf_end
- buf
;
2928 if (!xdr_string(xdr
, &buf
, buflen
- 1))
2930 nvp
->nvp_name_sz
= strlen(buf
) + 1;
2932 /* type and nelem */
2933 if (!xdr_int(xdr
, (int *)&nvp
->nvp_type
) ||
2934 !xdr_int(xdr
, &nvp
->nvp_value_elem
))
2937 type
= NVP_TYPE(nvp
);
2938 nelem
= nvp
->nvp_value_elem
;
2941 * Verify type and nelem and get the value size.
2942 * In case of data types DATA_TYPE_STRING and DATA_TYPE_STRING_ARRAY
2943 * is the size of the string(s) excluded.
2945 if ((value_sz
= i_get_value_size(type
, NULL
, nelem
)) < 0)
2948 /* if there is no data to extract then return */
2953 if ((buf
= NVP_VALUE(nvp
)) >= buf_end
)
2955 buflen
= buf_end
- buf
;
2957 if (buflen
< value_sz
)
2961 case DATA_TYPE_NVLIST
:
2962 if (nvs_embedded(nvs
, (void *)buf
) == 0)
2966 case DATA_TYPE_NVLIST_ARRAY
:
2967 if (nvs_embedded_nvl_array(nvs
, nvp
, NULL
) == 0)
2971 case DATA_TYPE_BOOLEAN
:
2975 case DATA_TYPE_BYTE
:
2976 case DATA_TYPE_INT8
:
2977 case DATA_TYPE_UINT8
:
2978 ret
= xdr_char(xdr
, buf
);
2981 case DATA_TYPE_INT16
:
2982 ret
= xdr_short(xdr
, (void *)buf
);
2985 case DATA_TYPE_UINT16
:
2986 ret
= xdr_u_short(xdr
, (void *)buf
);
2989 case DATA_TYPE_BOOLEAN_VALUE
:
2990 case DATA_TYPE_INT32
:
2991 ret
= xdr_int(xdr
, (void *)buf
);
2994 case DATA_TYPE_UINT32
:
2995 ret
= xdr_u_int(xdr
, (void *)buf
);
2998 case DATA_TYPE_INT64
:
2999 ret
= xdr_longlong_t(xdr
, (void *)buf
);
3002 case DATA_TYPE_UINT64
:
3003 ret
= xdr_u_longlong_t(xdr
, (void *)buf
);
3006 case DATA_TYPE_HRTIME
:
3008 * NOTE: must expose the definition of hrtime_t here
3010 ret
= xdr_longlong_t(xdr
, (void *)buf
);
3012 #if !defined(_KERNEL)
3013 case DATA_TYPE_DOUBLE
:
3014 ret
= xdr_double(xdr
, (void *)buf
);
3017 case DATA_TYPE_STRING
:
3018 ret
= xdr_string(xdr
, &buf
, buflen
- 1);
3021 case DATA_TYPE_BYTE_ARRAY
:
3022 ret
= xdr_opaque(xdr
, buf
, nelem
);
3025 case DATA_TYPE_INT8_ARRAY
:
3026 case DATA_TYPE_UINT8_ARRAY
:
3027 ret
= xdr_array(xdr
, &buf
, &nelem
, buflen
, sizeof (int8_t),
3028 (xdrproc_t
)xdr_char
);
3031 case DATA_TYPE_INT16_ARRAY
:
3032 ret
= xdr_array(xdr
, &buf
, &nelem
, buflen
/ sizeof (int16_t),
3033 sizeof (int16_t), (xdrproc_t
)xdr_short
);
3036 case DATA_TYPE_UINT16_ARRAY
:
3037 ret
= xdr_array(xdr
, &buf
, &nelem
, buflen
/ sizeof (uint16_t),
3038 sizeof (uint16_t), (xdrproc_t
)xdr_u_short
);
3041 case DATA_TYPE_BOOLEAN_ARRAY
:
3042 case DATA_TYPE_INT32_ARRAY
:
3043 ret
= xdr_array(xdr
, &buf
, &nelem
, buflen
/ sizeof (int32_t),
3044 sizeof (int32_t), (xdrproc_t
)xdr_int
);
3047 case DATA_TYPE_UINT32_ARRAY
:
3048 ret
= xdr_array(xdr
, &buf
, &nelem
, buflen
/ sizeof (uint32_t),
3049 sizeof (uint32_t), (xdrproc_t
)xdr_u_int
);
3052 case DATA_TYPE_INT64_ARRAY
:
3053 ret
= xdr_array(xdr
, &buf
, &nelem
, buflen
/ sizeof (int64_t),
3054 sizeof (int64_t), (xdrproc_t
)xdr_longlong_t
);
3057 case DATA_TYPE_UINT64_ARRAY
:
3058 ret
= xdr_array(xdr
, &buf
, &nelem
, buflen
/ sizeof (uint64_t),
3059 sizeof (uint64_t), (xdrproc_t
)xdr_u_longlong_t
);
3062 case DATA_TYPE_STRING_ARRAY
: {
3063 size_t len
= nelem
* sizeof (uint64_t);
3064 char **strp
= (void *)buf
;
3067 if (nvs
->nvs_op
== NVS_OP_DECODE
)
3068 bzero(buf
, len
); /* don't trust packed data */
3070 for (i
= 0; i
< nelem
; i
++) {
3077 if (xdr_string(xdr
, &buf
, buflen
- 1) != TRUE
)
3080 if (nvs
->nvs_op
== NVS_OP_DECODE
)
3082 len
= strlen(buf
) + 1;
3091 return (ret
== TRUE
? 0 : EFAULT
);
3095 nvs_xdr_nvp_size(nvstream_t
*nvs
, nvpair_t
*nvp
, size_t *size
)
3097 data_type_t type
= NVP_TYPE(nvp
);
3099 * encode_size + decode_size + name string size + data type + nelem
3100 * where name string size = 4 + NV_ALIGN4(strlen(NVP_NAME(nvp)))
3102 uint64_t nvp_sz
= 4 + 4 + 4 + NV_ALIGN4(strlen(NVP_NAME(nvp
))) + 4 + 4;
3105 case DATA_TYPE_BOOLEAN
:
3108 case DATA_TYPE_BOOLEAN_VALUE
:
3109 case DATA_TYPE_BYTE
:
3110 case DATA_TYPE_INT8
:
3111 case DATA_TYPE_UINT8
:
3112 case DATA_TYPE_INT16
:
3113 case DATA_TYPE_UINT16
:
3114 case DATA_TYPE_INT32
:
3115 case DATA_TYPE_UINT32
:
3116 nvp_sz
+= 4; /* 4 is the minimum xdr unit */
3119 case DATA_TYPE_INT64
:
3120 case DATA_TYPE_UINT64
:
3121 case DATA_TYPE_HRTIME
:
3122 #if !defined(_KERNEL)
3123 case DATA_TYPE_DOUBLE
:
3128 case DATA_TYPE_STRING
:
3129 nvp_sz
+= 4 + NV_ALIGN4(strlen((char *)NVP_VALUE(nvp
)));
3132 case DATA_TYPE_BYTE_ARRAY
:
3133 nvp_sz
+= NV_ALIGN4(NVP_NELEM(nvp
));
3136 case DATA_TYPE_BOOLEAN_ARRAY
:
3137 case DATA_TYPE_INT8_ARRAY
:
3138 case DATA_TYPE_UINT8_ARRAY
:
3139 case DATA_TYPE_INT16_ARRAY
:
3140 case DATA_TYPE_UINT16_ARRAY
:
3141 case DATA_TYPE_INT32_ARRAY
:
3142 case DATA_TYPE_UINT32_ARRAY
:
3143 nvp_sz
+= 4 + 4 * (uint64_t)NVP_NELEM(nvp
);
3146 case DATA_TYPE_INT64_ARRAY
:
3147 case DATA_TYPE_UINT64_ARRAY
:
3148 nvp_sz
+= 4 + 8 * (uint64_t)NVP_NELEM(nvp
);
3151 case DATA_TYPE_STRING_ARRAY
: {
3153 char **strs
= (void *)NVP_VALUE(nvp
);
3155 for (i
= 0; i
< NVP_NELEM(nvp
); i
++)
3156 nvp_sz
+= 4 + NV_ALIGN4(strlen(strs
[i
]));
3161 case DATA_TYPE_NVLIST
:
3162 case DATA_TYPE_NVLIST_ARRAY
: {
3164 int old_nvs_op
= nvs
->nvs_op
;
3167 nvs
->nvs_op
= NVS_OP_GETSIZE
;
3168 if (type
== DATA_TYPE_NVLIST
)
3169 err
= nvs_operation(nvs
, EMBEDDED_NVL(nvp
), &nvsize
);
3171 err
= nvs_embedded_nvl_array(nvs
, nvp
, &nvsize
);
3172 nvs
->nvs_op
= old_nvs_op
;
3185 if (nvp_sz
> INT32_MAX
)
3195 * The NVS_XDR_MAX_LEN macro takes a packed xdr buffer of size x and estimates
3196 * the largest nvpair that could be encoded in the buffer.
3198 * See comments above nvpair_xdr_op() for the format of xdr encoding.
3199 * The size of a xdr packed nvpair without any data is 5 words.
3201 * Using the size of the data directly as an estimate would be ok
3202 * in all cases except one. If the data type is of DATA_TYPE_STRING_ARRAY
3203 * then the actual nvpair has space for an array of pointers to index
3204 * the strings. These pointers are not encoded into the packed xdr buffer.
3206 * If the data is of type DATA_TYPE_STRING_ARRAY and all the strings are
3207 * of length 0, then each string is endcoded in xdr format as a single word.
3208 * Therefore when expanded to an nvpair there will be 2.25 word used for
3209 * each string. (a int64_t allocated for pointer usage, and a single char
3210 * for the null termination.)
3212 * This is the calculation performed by the NVS_XDR_MAX_LEN macro.
3214 #define NVS_XDR_HDR_LEN ((size_t)(5 * 4))
3215 #define NVS_XDR_DATA_LEN(y) (((size_t)(y) <= NVS_XDR_HDR_LEN) ? \
3216 0 : ((size_t)(y) - NVS_XDR_HDR_LEN))
3217 #define NVS_XDR_MAX_LEN(x) (NVP_SIZE_CALC(1, 0) + \
3218 (NVS_XDR_DATA_LEN(x) * 2) + \
3219 NV_ALIGN4((NVS_XDR_DATA_LEN(x) / 4)))
3222 nvs_xdr_nvpair(nvstream_t
*nvs
, nvpair_t
*nvp
, size_t *size
)
3224 XDR
*xdr
= nvs
->nvs_private
;
3225 int32_t encode_len
, decode_len
;
3227 switch (nvs
->nvs_op
) {
3228 case NVS_OP_ENCODE
: {
3231 if (nvs_xdr_nvp_size(nvs
, nvp
, &nvsize
) != 0)
3234 decode_len
= nvp
->nvp_size
;
3235 encode_len
= nvsize
;
3236 if (!xdr_int(xdr
, &encode_len
) || !xdr_int(xdr
, &decode_len
))
3239 return (nvs_xdr_nvp_op(nvs
, nvp
));
3241 case NVS_OP_DECODE
: {
3242 struct xdr_bytesrec bytesrec
;
3244 /* get the encode and decode size */
3245 if (!xdr_int(xdr
, &encode_len
) || !xdr_int(xdr
, &decode_len
))
3249 /* are we at the end of the stream? */
3253 /* sanity check the size parameter */
3254 if (!xdr_control(xdr
, XDR_GET_BYTES_AVAIL
, &bytesrec
))
3257 if (*size
> NVS_XDR_MAX_LEN(bytesrec
.xc_num_avail
))
3268 static const struct nvs_ops nvs_xdr_ops
= {
3277 nvs_xdr(nvstream_t
*nvs
, nvlist_t
*nvl
, char *buf
, size_t *buflen
)
3282 nvs
->nvs_ops
= &nvs_xdr_ops
;
3284 if ((err
= nvs_xdr_create(nvs
, &xdr
, buf
+ sizeof (nvs_header_t
),
3285 *buflen
- sizeof (nvs_header_t
))) != 0)
3288 err
= nvs_operation(nvs
, nvl
, buflen
);
3290 nvs_xdr_destroy(nvs
);
3295 #if defined(_KERNEL) && defined(HAVE_SPL)
3307 module_init(nvpair_init
);
3308 module_exit(nvpair_fini
);
3310 MODULE_DESCRIPTION("Generic name/value pair implementation");
3311 MODULE_AUTHOR(ZFS_META_AUTHOR
);
3312 MODULE_LICENSE(ZFS_META_LICENSE
);
3313 MODULE_VERSION(ZFS_META_VERSION
"-" ZFS_META_RELEASE
);
3315 EXPORT_SYMBOL(nv_alloc_init
);
3316 EXPORT_SYMBOL(nv_alloc_reset
);
3317 EXPORT_SYMBOL(nv_alloc_fini
);
3319 /* list management */
3320 EXPORT_SYMBOL(nvlist_alloc
);
3321 EXPORT_SYMBOL(nvlist_free
);
3322 EXPORT_SYMBOL(nvlist_size
);
3323 EXPORT_SYMBOL(nvlist_pack
);
3324 EXPORT_SYMBOL(nvlist_unpack
);
3325 EXPORT_SYMBOL(nvlist_dup
);
3326 EXPORT_SYMBOL(nvlist_merge
);
3328 EXPORT_SYMBOL(nvlist_xalloc
);
3329 EXPORT_SYMBOL(nvlist_xpack
);
3330 EXPORT_SYMBOL(nvlist_xunpack
);
3331 EXPORT_SYMBOL(nvlist_xdup
);
3332 EXPORT_SYMBOL(nvlist_lookup_nv_alloc
);
3334 EXPORT_SYMBOL(nvlist_add_nvpair
);
3335 EXPORT_SYMBOL(nvlist_add_boolean
);
3336 EXPORT_SYMBOL(nvlist_add_boolean_value
);
3337 EXPORT_SYMBOL(nvlist_add_byte
);
3338 EXPORT_SYMBOL(nvlist_add_int8
);
3339 EXPORT_SYMBOL(nvlist_add_uint8
);
3340 EXPORT_SYMBOL(nvlist_add_int16
);
3341 EXPORT_SYMBOL(nvlist_add_uint16
);
3342 EXPORT_SYMBOL(nvlist_add_int32
);
3343 EXPORT_SYMBOL(nvlist_add_uint32
);
3344 EXPORT_SYMBOL(nvlist_add_int64
);
3345 EXPORT_SYMBOL(nvlist_add_uint64
);
3346 EXPORT_SYMBOL(nvlist_add_string
);
3347 EXPORT_SYMBOL(nvlist_add_nvlist
);
3348 EXPORT_SYMBOL(nvlist_add_boolean_array
);
3349 EXPORT_SYMBOL(nvlist_add_byte_array
);
3350 EXPORT_SYMBOL(nvlist_add_int8_array
);
3351 EXPORT_SYMBOL(nvlist_add_uint8_array
);
3352 EXPORT_SYMBOL(nvlist_add_int16_array
);
3353 EXPORT_SYMBOL(nvlist_add_uint16_array
);
3354 EXPORT_SYMBOL(nvlist_add_int32_array
);
3355 EXPORT_SYMBOL(nvlist_add_uint32_array
);
3356 EXPORT_SYMBOL(nvlist_add_int64_array
);
3357 EXPORT_SYMBOL(nvlist_add_uint64_array
);
3358 EXPORT_SYMBOL(nvlist_add_string_array
);
3359 EXPORT_SYMBOL(nvlist_add_nvlist_array
);
3360 EXPORT_SYMBOL(nvlist_next_nvpair
);
3361 EXPORT_SYMBOL(nvlist_prev_nvpair
);
3362 EXPORT_SYMBOL(nvlist_empty
);
3363 EXPORT_SYMBOL(nvlist_add_hrtime
);
3365 EXPORT_SYMBOL(nvlist_remove
);
3366 EXPORT_SYMBOL(nvlist_remove_nvpair
);
3367 EXPORT_SYMBOL(nvlist_remove_all
);
3369 EXPORT_SYMBOL(nvlist_lookup_boolean
);
3370 EXPORT_SYMBOL(nvlist_lookup_boolean_value
);
3371 EXPORT_SYMBOL(nvlist_lookup_byte
);
3372 EXPORT_SYMBOL(nvlist_lookup_int8
);
3373 EXPORT_SYMBOL(nvlist_lookup_uint8
);
3374 EXPORT_SYMBOL(nvlist_lookup_int16
);
3375 EXPORT_SYMBOL(nvlist_lookup_uint16
);
3376 EXPORT_SYMBOL(nvlist_lookup_int32
);
3377 EXPORT_SYMBOL(nvlist_lookup_uint32
);
3378 EXPORT_SYMBOL(nvlist_lookup_int64
);
3379 EXPORT_SYMBOL(nvlist_lookup_uint64
);
3380 EXPORT_SYMBOL(nvlist_lookup_string
);
3381 EXPORT_SYMBOL(nvlist_lookup_nvlist
);
3382 EXPORT_SYMBOL(nvlist_lookup_boolean_array
);
3383 EXPORT_SYMBOL(nvlist_lookup_byte_array
);
3384 EXPORT_SYMBOL(nvlist_lookup_int8_array
);
3385 EXPORT_SYMBOL(nvlist_lookup_uint8_array
);
3386 EXPORT_SYMBOL(nvlist_lookup_int16_array
);
3387 EXPORT_SYMBOL(nvlist_lookup_uint16_array
);
3388 EXPORT_SYMBOL(nvlist_lookup_int32_array
);
3389 EXPORT_SYMBOL(nvlist_lookup_uint32_array
);
3390 EXPORT_SYMBOL(nvlist_lookup_int64_array
);
3391 EXPORT_SYMBOL(nvlist_lookup_uint64_array
);
3392 EXPORT_SYMBOL(nvlist_lookup_string_array
);
3393 EXPORT_SYMBOL(nvlist_lookup_nvlist_array
);
3394 EXPORT_SYMBOL(nvlist_lookup_hrtime
);
3395 EXPORT_SYMBOL(nvlist_lookup_pairs
);
3397 EXPORT_SYMBOL(nvlist_lookup_nvpair
);
3398 EXPORT_SYMBOL(nvlist_exists
);
3400 /* processing nvpair */
3401 EXPORT_SYMBOL(nvpair_name
);
3402 EXPORT_SYMBOL(nvpair_type
);
3403 EXPORT_SYMBOL(nvpair_value_boolean_value
);
3404 EXPORT_SYMBOL(nvpair_value_byte
);
3405 EXPORT_SYMBOL(nvpair_value_int8
);
3406 EXPORT_SYMBOL(nvpair_value_uint8
);
3407 EXPORT_SYMBOL(nvpair_value_int16
);
3408 EXPORT_SYMBOL(nvpair_value_uint16
);
3409 EXPORT_SYMBOL(nvpair_value_int32
);
3410 EXPORT_SYMBOL(nvpair_value_uint32
);
3411 EXPORT_SYMBOL(nvpair_value_int64
);
3412 EXPORT_SYMBOL(nvpair_value_uint64
);
3413 EXPORT_SYMBOL(nvpair_value_string
);
3414 EXPORT_SYMBOL(nvpair_value_nvlist
);
3415 EXPORT_SYMBOL(nvpair_value_boolean_array
);
3416 EXPORT_SYMBOL(nvpair_value_byte_array
);
3417 EXPORT_SYMBOL(nvpair_value_int8_array
);
3418 EXPORT_SYMBOL(nvpair_value_uint8_array
);
3419 EXPORT_SYMBOL(nvpair_value_int16_array
);
3420 EXPORT_SYMBOL(nvpair_value_uint16_array
);
3421 EXPORT_SYMBOL(nvpair_value_int32_array
);
3422 EXPORT_SYMBOL(nvpair_value_uint32_array
);
3423 EXPORT_SYMBOL(nvpair_value_int64_array
);
3424 EXPORT_SYMBOL(nvpair_value_uint64_array
);
3425 EXPORT_SYMBOL(nvpair_value_string_array
);
3426 EXPORT_SYMBOL(nvpair_value_nvlist_array
);
3427 EXPORT_SYMBOL(nvpair_value_hrtime
);