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.
24 * Copyright (c) 2015, 2016 by Delphix. All rights reserved.
27 #include <sys/stropts.h>
28 #include <sys/debug.h>
29 #include <sys/isa_defs.h>
30 #include <sys/int_limits.h>
31 #include <sys/nvpair.h>
32 #include <sys/nvpair_impl.h>
33 #include <rpc/types.h>
36 #if defined(_KERNEL) && !defined(_BOOT)
37 #include <sys/varargs.h>
39 #include <sys/sunddi.h>
48 #define offsetof(s, m) ((size_t)(&(((s *)0)->m)))
50 #define skip_whitespace(p) while ((*(p) == ' ') || (*(p) == '\t')) p++
53 * nvpair.c - Provides kernel & userland interfaces for manipulating
68 * +--------------+ last i_nvp in list
69 * | nvpriv_t | +--------------------->
71 * +--+- nvp_list | | +------------+
72 * | | nvp_last -+--+ + nv_alloc_t |
73 * | | nvp_curr | |------------|
74 * | | nvp_nva -+----> | nva_ops |
75 * | | nvp_stat | | nva_arg |
76 * | +--------------+ +------------+
80 * +---------------------+ +-------------------+
81 * | i_nvp_t | +-->| i_nvp_t | +-->
82 * |---------------------| | |-------------------| |
83 * | nvi_next -+--+ | nvi_next -+--+
84 * | nvi_prev (NULL) | <----+ nvi_prev |
85 * | . . . . . . . . . . | | . . . . . . . . . |
86 * | nvp (nvpair_t) | | nvp (nvpair_t) |
87 * | - nvp_size | | - nvp_size |
88 * | - nvp_name_sz | | - nvp_name_sz |
89 * | - nvp_value_elem | | - nvp_value_elem |
90 * | - nvp_type | | - nvp_type |
91 * | - data ... | | - data ... |
92 * +---------------------+ +-------------------+
96 * +---------------------+ +---------------------+
97 * | i_nvp_t | +--> +-->| i_nvp_t (last) |
98 * |---------------------| | | |---------------------|
99 * | nvi_next -+--+ ... --+ | nvi_next (NULL) |
100 * <-+- nvi_prev |<-- ... <----+ nvi_prev |
101 * | . . . . . . . . . | | . . . . . . . . . |
102 * | nvp (nvpair_t) | | nvp (nvpair_t) |
103 * | - nvp_size | | - nvp_size |
104 * | - nvp_name_sz | | - nvp_name_sz |
105 * | - nvp_value_elem | | - nvp_value_elem |
106 * | - DATA_TYPE_NVLIST | | - nvp_type |
107 * | - data (embedded) | | - data ... |
108 * | nvlist name | +---------------------+
109 * | +--------------+ |
111 * | |--------------| |
112 * | | nvl_version | |
114 * | | nvl_priv --+---+---->
117 * | +--------------+ |
118 * +---------------------+
121 * N.B. nvpair_t may be aligned on 4 byte boundary, so +4 will
122 * allow value to be aligned on 8 byte boundary
124 * name_len is the length of the name string including the null terminator
127 #define NVP_SIZE_CALC(name_len, data_len) \
128 (NV_ALIGN((sizeof (nvpair_t)) + name_len) + NV_ALIGN(data_len))
130 static int i_get_value_size(data_type_t type
, const void *data
, uint_t nelem
);
131 static int nvlist_add_common(nvlist_t
*nvl
, const char *name
, data_type_t type
,
132 uint_t nelem
, const void *data
);
134 #define NV_STAT_EMBEDDED 0x1
135 #define EMBEDDED_NVL(nvp) ((nvlist_t *)(void *)NVP_VALUE(nvp))
136 #define EMBEDDED_NVL_ARRAY(nvp) ((nvlist_t **)(void *)NVP_VALUE(nvp))
138 #define NVP_VALOFF(nvp) (NV_ALIGN(sizeof (nvpair_t) + (nvp)->nvp_name_sz))
139 #define NVPAIR2I_NVP(nvp) \
140 ((i_nvp_t *)((size_t)(nvp) - offsetof(i_nvp_t, nvi_nvp)))
143 int nvpair_max_recursion
= 20;
145 int nvpair_max_recursion
= 100;
149 nv_alloc_init(nv_alloc_t
*nva
, const nv_alloc_ops_t
*nvo
, /* args */ ...)
157 va_start(valist
, nvo
);
158 if (nva
->nva_ops
->nv_ao_init
!= NULL
)
159 err
= nva
->nva_ops
->nv_ao_init(nva
, valist
);
166 nv_alloc_reset(nv_alloc_t
*nva
)
168 if (nva
->nva_ops
->nv_ao_reset
!= NULL
)
169 nva
->nva_ops
->nv_ao_reset(nva
);
173 nv_alloc_fini(nv_alloc_t
*nva
)
175 if (nva
->nva_ops
->nv_ao_fini
!= NULL
)
176 nva
->nva_ops
->nv_ao_fini(nva
);
180 nvlist_lookup_nv_alloc(nvlist_t
*nvl
)
185 (priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
) == NULL
)
188 return (priv
->nvp_nva
);
192 nv_mem_zalloc(nvpriv_t
*nvp
, size_t size
)
194 nv_alloc_t
*nva
= nvp
->nvp_nva
;
197 if ((buf
= nva
->nva_ops
->nv_ao_alloc(nva
, size
)) != NULL
)
204 nv_mem_free(nvpriv_t
*nvp
, void *buf
, size_t size
)
206 nv_alloc_t
*nva
= nvp
->nvp_nva
;
208 nva
->nva_ops
->nv_ao_free(nva
, buf
, size
);
212 nv_priv_init(nvpriv_t
*priv
, nv_alloc_t
*nva
, uint32_t stat
)
214 bzero(priv
, sizeof (nvpriv_t
));
217 priv
->nvp_stat
= stat
;
221 nv_priv_alloc(nv_alloc_t
*nva
)
226 * nv_mem_alloc() cannot called here because it needs the priv
229 if ((priv
= nva
->nva_ops
->nv_ao_alloc(nva
, sizeof (nvpriv_t
))) == NULL
)
232 nv_priv_init(priv
, nva
, 0);
238 * Embedded lists need their own nvpriv_t's. We create a new
239 * nvpriv_t using the parameters and allocator from the parent
243 nv_priv_alloc_embedded(nvpriv_t
*priv
)
247 if ((emb_priv
= nv_mem_zalloc(priv
, sizeof (nvpriv_t
))) == NULL
)
250 nv_priv_init(emb_priv
, priv
->nvp_nva
, NV_STAT_EMBEDDED
);
256 nvlist_init(nvlist_t
*nvl
, uint32_t nvflag
, nvpriv_t
*priv
)
258 nvl
->nvl_version
= NV_VERSION
;
259 nvl
->nvl_nvflag
= nvflag
& (NV_UNIQUE_NAME
|NV_UNIQUE_NAME_TYPE
);
260 nvl
->nvl_priv
= (uint64_t)(uintptr_t)priv
;
266 nvlist_nvflag(nvlist_t
*nvl
)
268 return (nvl
->nvl_nvflag
);
272 nvlist_nv_alloc(int kmflag
)
274 #if defined(_KERNEL) && !defined(_BOOT)
277 return (nv_alloc_sleep
);
279 return (nv_alloc_pushpage
);
281 return (nv_alloc_nosleep
);
284 return (nv_alloc_nosleep
);
285 #endif /* _KERNEL && !_BOOT */
289 * nvlist_alloc - Allocate nvlist.
292 nvlist_alloc(nvlist_t
**nvlp
, uint_t nvflag
, int kmflag
)
294 return (nvlist_xalloc(nvlp
, nvflag
, nvlist_nv_alloc(kmflag
)));
298 nvlist_xalloc(nvlist_t
**nvlp
, uint_t nvflag
, nv_alloc_t
*nva
)
302 if (nvlp
== NULL
|| nva
== NULL
)
305 if ((priv
= nv_priv_alloc(nva
)) == NULL
)
308 if ((*nvlp
= nv_mem_zalloc(priv
,
309 NV_ALIGN(sizeof (nvlist_t
)))) == NULL
) {
310 nv_mem_free(priv
, priv
, sizeof (nvpriv_t
));
314 nvlist_init(*nvlp
, nvflag
, priv
);
320 * nvp_buf_alloc - Allocate i_nvp_t for storing a new nv pair.
323 nvp_buf_alloc(nvlist_t
*nvl
, size_t len
)
325 nvpriv_t
*priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
;
331 * Allocate the buffer
333 nvsize
= len
+ offsetof(i_nvp_t
, nvi_nvp
);
335 if ((buf
= nv_mem_zalloc(priv
, nvsize
)) == NULL
)
345 * nvp_buf_free - de-Allocate an i_nvp_t.
348 nvp_buf_free(nvlist_t
*nvl
, nvpair_t
*nvp
)
350 nvpriv_t
*priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
;
351 size_t nvsize
= nvp
->nvp_size
+ offsetof(i_nvp_t
, nvi_nvp
);
353 nv_mem_free(priv
, NVPAIR2I_NVP(nvp
), nvsize
);
357 * nvp_buf_link - link a new nv pair into the nvlist.
360 nvp_buf_link(nvlist_t
*nvl
, nvpair_t
*nvp
)
362 nvpriv_t
*priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
;
363 i_nvp_t
*curr
= NVPAIR2I_NVP(nvp
);
365 /* Put element at end of nvlist */
366 if (priv
->nvp_list
== NULL
) {
367 priv
->nvp_list
= priv
->nvp_last
= curr
;
369 curr
->nvi_prev
= priv
->nvp_last
;
370 priv
->nvp_last
->nvi_next
= curr
;
371 priv
->nvp_last
= curr
;
376 * nvp_buf_unlink - unlink an removed nvpair out of the nvlist.
379 nvp_buf_unlink(nvlist_t
*nvl
, nvpair_t
*nvp
)
381 nvpriv_t
*priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
;
382 i_nvp_t
*curr
= NVPAIR2I_NVP(nvp
);
385 * protect nvlist_next_nvpair() against walking on freed memory.
387 if (priv
->nvp_curr
== curr
)
388 priv
->nvp_curr
= curr
->nvi_next
;
390 if (curr
== priv
->nvp_list
)
391 priv
->nvp_list
= curr
->nvi_next
;
393 curr
->nvi_prev
->nvi_next
= curr
->nvi_next
;
395 if (curr
== priv
->nvp_last
)
396 priv
->nvp_last
= curr
->nvi_prev
;
398 curr
->nvi_next
->nvi_prev
= curr
->nvi_prev
;
402 * take a nvpair type and number of elements and make sure the are valid
405 i_validate_type_nelem(data_type_t type
, uint_t nelem
)
408 case DATA_TYPE_BOOLEAN
:
412 case DATA_TYPE_BOOLEAN_VALUE
:
415 case DATA_TYPE_UINT8
:
416 case DATA_TYPE_INT16
:
417 case DATA_TYPE_UINT16
:
418 case DATA_TYPE_INT32
:
419 case DATA_TYPE_UINT32
:
420 case DATA_TYPE_INT64
:
421 case DATA_TYPE_UINT64
:
422 case DATA_TYPE_STRING
:
423 case DATA_TYPE_HRTIME
:
424 case DATA_TYPE_NVLIST
:
425 #if !defined(_KERNEL)
426 case DATA_TYPE_DOUBLE
:
431 case DATA_TYPE_BOOLEAN_ARRAY
:
432 case DATA_TYPE_BYTE_ARRAY
:
433 case DATA_TYPE_INT8_ARRAY
:
434 case DATA_TYPE_UINT8_ARRAY
:
435 case DATA_TYPE_INT16_ARRAY
:
436 case DATA_TYPE_UINT16_ARRAY
:
437 case DATA_TYPE_INT32_ARRAY
:
438 case DATA_TYPE_UINT32_ARRAY
:
439 case DATA_TYPE_INT64_ARRAY
:
440 case DATA_TYPE_UINT64_ARRAY
:
441 case DATA_TYPE_STRING_ARRAY
:
442 case DATA_TYPE_NVLIST_ARRAY
:
443 /* we allow arrays with 0 elements */
452 * Verify nvp_name_sz and check the name string length.
455 i_validate_nvpair_name(nvpair_t
*nvp
)
457 if ((nvp
->nvp_name_sz
<= 0) ||
458 (nvp
->nvp_size
< NVP_SIZE_CALC(nvp
->nvp_name_sz
, 0)))
461 /* verify the name string, make sure its terminated */
462 if (NVP_NAME(nvp
)[nvp
->nvp_name_sz
- 1] != '\0')
465 return (strlen(NVP_NAME(nvp
)) == nvp
->nvp_name_sz
- 1 ? 0 : EFAULT
);
469 i_validate_nvpair_value(data_type_t type
, uint_t nelem
, const void *data
)
472 case DATA_TYPE_BOOLEAN_VALUE
:
473 if (*(boolean_t
*)data
!= B_TRUE
&&
474 *(boolean_t
*)data
!= B_FALSE
)
477 case DATA_TYPE_BOOLEAN_ARRAY
: {
480 for (i
= 0; i
< nelem
; i
++)
481 if (((boolean_t
*)data
)[i
] != B_TRUE
&&
482 ((boolean_t
*)data
)[i
] != B_FALSE
)
494 * This function takes a pointer to what should be a nvpair and it's size
495 * and then verifies that all the nvpair fields make sense and can be
496 * trusted. This function is used when decoding packed nvpairs.
499 i_validate_nvpair(nvpair_t
*nvp
)
501 data_type_t type
= NVP_TYPE(nvp
);
504 /* verify nvp_name_sz, check the name string length */
505 if (i_validate_nvpair_name(nvp
) != 0)
508 if (i_validate_nvpair_value(type
, NVP_NELEM(nvp
), NVP_VALUE(nvp
)) != 0)
512 * verify nvp_type, nvp_value_elem, and also possibly
513 * verify string values and get the value size.
515 size2
= i_get_value_size(type
, NVP_VALUE(nvp
), NVP_NELEM(nvp
));
516 size1
= nvp
->nvp_size
- NVP_VALOFF(nvp
);
517 if (size2
< 0 || size1
!= NV_ALIGN(size2
))
524 nvlist_copy_pairs(nvlist_t
*snvl
, nvlist_t
*dnvl
)
529 if ((priv
= (nvpriv_t
*)(uintptr_t)snvl
->nvl_priv
) == NULL
)
532 for (curr
= priv
->nvp_list
; curr
!= NULL
; curr
= curr
->nvi_next
) {
533 nvpair_t
*nvp
= &curr
->nvi_nvp
;
536 if ((err
= nvlist_add_common(dnvl
, NVP_NAME(nvp
), NVP_TYPE(nvp
),
537 NVP_NELEM(nvp
), NVP_VALUE(nvp
))) != 0)
545 * Frees all memory allocated for an nvpair (like embedded lists) with
546 * the exception of the nvpair buffer itself.
549 nvpair_free(nvpair_t
*nvp
)
551 switch (NVP_TYPE(nvp
)) {
552 case DATA_TYPE_NVLIST
:
553 nvlist_free(EMBEDDED_NVL(nvp
));
555 case DATA_TYPE_NVLIST_ARRAY
: {
556 nvlist_t
**nvlp
= EMBEDDED_NVL_ARRAY(nvp
);
559 for (i
= 0; i
< NVP_NELEM(nvp
); i
++)
561 nvlist_free(nvlp
[i
]);
570 * nvlist_free - free an unpacked nvlist
573 nvlist_free(nvlist_t
*nvl
)
579 (priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
) == NULL
)
583 * Unpacked nvlist are linked through i_nvp_t
585 curr
= priv
->nvp_list
;
586 while (curr
!= NULL
) {
587 nvpair_t
*nvp
= &curr
->nvi_nvp
;
588 curr
= curr
->nvi_next
;
591 nvp_buf_free(nvl
, nvp
);
594 if (!(priv
->nvp_stat
& NV_STAT_EMBEDDED
))
595 nv_mem_free(priv
, nvl
, NV_ALIGN(sizeof (nvlist_t
)));
599 nv_mem_free(priv
, priv
, sizeof (nvpriv_t
));
603 nvlist_contains_nvp(nvlist_t
*nvl
, nvpair_t
*nvp
)
605 nvpriv_t
*priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
;
611 for (curr
= priv
->nvp_list
; curr
!= NULL
; curr
= curr
->nvi_next
)
612 if (&curr
->nvi_nvp
== nvp
)
619 * Make a copy of nvlist
622 nvlist_dup(nvlist_t
*nvl
, nvlist_t
**nvlp
, int kmflag
)
624 return (nvlist_xdup(nvl
, nvlp
, nvlist_nv_alloc(kmflag
)));
628 nvlist_xdup(nvlist_t
*nvl
, nvlist_t
**nvlp
, nv_alloc_t
*nva
)
633 if (nvl
== NULL
|| nvlp
== NULL
)
636 if ((err
= nvlist_xalloc(&ret
, nvl
->nvl_nvflag
, nva
)) != 0)
639 if ((err
= nvlist_copy_pairs(nvl
, ret
)) != 0)
648 * Remove all with matching name
651 nvlist_remove_all(nvlist_t
*nvl
, const char *name
)
657 if (nvl
== NULL
|| name
== NULL
||
658 (priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
) == NULL
)
661 curr
= priv
->nvp_list
;
662 while (curr
!= NULL
) {
663 nvpair_t
*nvp
= &curr
->nvi_nvp
;
665 curr
= curr
->nvi_next
;
666 if (strcmp(name
, NVP_NAME(nvp
)) != 0)
669 nvp_buf_unlink(nvl
, nvp
);
671 nvp_buf_free(nvl
, nvp
);
680 * Remove first one with matching name and type
683 nvlist_remove(nvlist_t
*nvl
, const char *name
, data_type_t type
)
688 if (nvl
== NULL
|| name
== NULL
||
689 (priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
) == NULL
)
692 curr
= priv
->nvp_list
;
693 while (curr
!= NULL
) {
694 nvpair_t
*nvp
= &curr
->nvi_nvp
;
696 if (strcmp(name
, NVP_NAME(nvp
)) == 0 && NVP_TYPE(nvp
) == type
) {
697 nvp_buf_unlink(nvl
, nvp
);
699 nvp_buf_free(nvl
, nvp
);
703 curr
= curr
->nvi_next
;
710 nvlist_remove_nvpair(nvlist_t
*nvl
, nvpair_t
*nvp
)
712 if (nvl
== NULL
|| nvp
== NULL
)
715 nvp_buf_unlink(nvl
, nvp
);
717 nvp_buf_free(nvl
, nvp
);
722 * This function calculates the size of an nvpair value.
724 * The data argument controls the behavior in case of the data types
725 * DATA_TYPE_STRING and
726 * DATA_TYPE_STRING_ARRAY
727 * Is data == NULL then the size of the string(s) is excluded.
730 i_get_value_size(data_type_t type
, const void *data
, uint_t nelem
)
734 if (i_validate_type_nelem(type
, nelem
) != 0)
737 /* Calculate required size for holding value */
739 case DATA_TYPE_BOOLEAN
:
742 case DATA_TYPE_BOOLEAN_VALUE
:
743 value_sz
= sizeof (boolean_t
);
746 value_sz
= sizeof (uchar_t
);
749 value_sz
= sizeof (int8_t);
751 case DATA_TYPE_UINT8
:
752 value_sz
= sizeof (uint8_t);
754 case DATA_TYPE_INT16
:
755 value_sz
= sizeof (int16_t);
757 case DATA_TYPE_UINT16
:
758 value_sz
= sizeof (uint16_t);
760 case DATA_TYPE_INT32
:
761 value_sz
= sizeof (int32_t);
763 case DATA_TYPE_UINT32
:
764 value_sz
= sizeof (uint32_t);
766 case DATA_TYPE_INT64
:
767 value_sz
= sizeof (int64_t);
769 case DATA_TYPE_UINT64
:
770 value_sz
= sizeof (uint64_t);
772 #if !defined(_KERNEL)
773 case DATA_TYPE_DOUBLE
:
774 value_sz
= sizeof (double);
777 case DATA_TYPE_STRING
:
781 value_sz
= strlen(data
) + 1;
783 case DATA_TYPE_BOOLEAN_ARRAY
:
784 value_sz
= (uint64_t)nelem
* sizeof (boolean_t
);
786 case DATA_TYPE_BYTE_ARRAY
:
787 value_sz
= (uint64_t)nelem
* sizeof (uchar_t
);
789 case DATA_TYPE_INT8_ARRAY
:
790 value_sz
= (uint64_t)nelem
* sizeof (int8_t);
792 case DATA_TYPE_UINT8_ARRAY
:
793 value_sz
= (uint64_t)nelem
* sizeof (uint8_t);
795 case DATA_TYPE_INT16_ARRAY
:
796 value_sz
= (uint64_t)nelem
* sizeof (int16_t);
798 case DATA_TYPE_UINT16_ARRAY
:
799 value_sz
= (uint64_t)nelem
* sizeof (uint16_t);
801 case DATA_TYPE_INT32_ARRAY
:
802 value_sz
= (uint64_t)nelem
* sizeof (int32_t);
804 case DATA_TYPE_UINT32_ARRAY
:
805 value_sz
= (uint64_t)nelem
* sizeof (uint32_t);
807 case DATA_TYPE_INT64_ARRAY
:
808 value_sz
= (uint64_t)nelem
* sizeof (int64_t);
810 case DATA_TYPE_UINT64_ARRAY
:
811 value_sz
= (uint64_t)nelem
* sizeof (uint64_t);
813 case DATA_TYPE_STRING_ARRAY
:
814 value_sz
= (uint64_t)nelem
* sizeof (uint64_t);
817 char *const *strs
= data
;
820 /* no alignment requirement for strings */
821 for (i
= 0; i
< nelem
; i
++) {
824 value_sz
+= strlen(strs
[i
]) + 1;
828 case DATA_TYPE_HRTIME
:
829 value_sz
= sizeof (hrtime_t
);
831 case DATA_TYPE_NVLIST
:
832 value_sz
= NV_ALIGN(sizeof (nvlist_t
));
834 case DATA_TYPE_NVLIST_ARRAY
:
835 value_sz
= (uint64_t)nelem
* sizeof (uint64_t) +
836 (uint64_t)nelem
* NV_ALIGN(sizeof (nvlist_t
));
842 return (value_sz
> INT32_MAX
? -1 : (int)value_sz
);
846 nvlist_copy_embedded(nvlist_t
*nvl
, nvlist_t
*onvl
, nvlist_t
*emb_nvl
)
851 if ((priv
= nv_priv_alloc_embedded((nvpriv_t
*)(uintptr_t)
852 nvl
->nvl_priv
)) == NULL
)
855 nvlist_init(emb_nvl
, onvl
->nvl_nvflag
, priv
);
857 if ((err
= nvlist_copy_pairs(onvl
, emb_nvl
)) != 0) {
858 nvlist_free(emb_nvl
);
859 emb_nvl
->nvl_priv
= 0;
866 * nvlist_add_common - Add new <name,value> pair to nvlist
869 nvlist_add_common(nvlist_t
*nvl
, const char *name
,
870 data_type_t type
, uint_t nelem
, const void *data
)
875 int nvp_sz
, name_sz
, value_sz
;
878 if (name
== NULL
|| nvl
== NULL
|| nvl
->nvl_priv
== 0)
881 if (nelem
!= 0 && data
== NULL
)
885 * Verify type and nelem and get the value size.
886 * In case of data types DATA_TYPE_STRING and DATA_TYPE_STRING_ARRAY
887 * is the size of the string(s) included.
889 if ((value_sz
= i_get_value_size(type
, data
, nelem
)) < 0)
892 if (i_validate_nvpair_value(type
, nelem
, data
) != 0)
896 * If we're adding an nvlist or nvlist array, ensure that we are not
897 * adding the input nvlist to itself, which would cause recursion,
898 * and ensure that no NULL nvlist pointers are present.
901 case DATA_TYPE_NVLIST
:
902 if (data
== nvl
|| data
== NULL
)
905 case DATA_TYPE_NVLIST_ARRAY
: {
906 nvlist_t
**onvlp
= (nvlist_t
**)data
;
907 for (i
= 0; i
< nelem
; i
++) {
908 if (onvlp
[i
] == nvl
|| onvlp
[i
] == NULL
)
917 /* calculate sizes of the nvpair elements and the nvpair itself */
918 name_sz
= strlen(name
) + 1;
920 nvp_sz
= NVP_SIZE_CALC(name_sz
, value_sz
);
922 if ((nvp
= nvp_buf_alloc(nvl
, nvp_sz
)) == NULL
)
925 ASSERT(nvp
->nvp_size
== nvp_sz
);
926 nvp
->nvp_name_sz
= name_sz
;
927 nvp
->nvp_value_elem
= nelem
;
928 nvp
->nvp_type
= type
;
929 bcopy(name
, NVP_NAME(nvp
), name_sz
);
932 case DATA_TYPE_BOOLEAN
:
934 case DATA_TYPE_STRING_ARRAY
: {
935 char *const *strs
= data
;
936 char *buf
= NVP_VALUE(nvp
);
937 char **cstrs
= (void *)buf
;
939 /* skip pre-allocated space for pointer array */
940 buf
+= nelem
* sizeof (uint64_t);
941 for (i
= 0; i
< nelem
; i
++) {
942 int slen
= strlen(strs
[i
]) + 1;
943 bcopy(strs
[i
], buf
, slen
);
949 case DATA_TYPE_NVLIST
: {
950 nvlist_t
*nnvl
= EMBEDDED_NVL(nvp
);
951 nvlist_t
*onvl
= (nvlist_t
*)data
;
953 if ((err
= nvlist_copy_embedded(nvl
, onvl
, nnvl
)) != 0) {
954 nvp_buf_free(nvl
, nvp
);
959 case DATA_TYPE_NVLIST_ARRAY
: {
960 nvlist_t
**onvlp
= (nvlist_t
**)data
;
961 nvlist_t
**nvlp
= EMBEDDED_NVL_ARRAY(nvp
);
962 nvlist_t
*embedded
= (nvlist_t
*)
963 ((uintptr_t)nvlp
+ nelem
* sizeof (uint64_t));
965 for (i
= 0; i
< nelem
; i
++) {
966 if ((err
= nvlist_copy_embedded(nvl
,
967 onvlp
[i
], embedded
)) != 0) {
969 * Free any successfully created lists
972 nvp_buf_free(nvl
, nvp
);
976 nvlp
[i
] = embedded
++;
981 bcopy(data
, NVP_VALUE(nvp
), value_sz
);
984 /* if unique name, remove before add */
985 if (nvl
->nvl_nvflag
& NV_UNIQUE_NAME
)
986 (void) nvlist_remove_all(nvl
, name
);
987 else if (nvl
->nvl_nvflag
& NV_UNIQUE_NAME_TYPE
)
988 (void) nvlist_remove(nvl
, name
, type
);
990 nvp_buf_link(nvl
, nvp
);
996 nvlist_add_boolean(nvlist_t
*nvl
, const char *name
)
998 return (nvlist_add_common(nvl
, name
, DATA_TYPE_BOOLEAN
, 0, NULL
));
1002 nvlist_add_boolean_value(nvlist_t
*nvl
, const char *name
, boolean_t val
)
1004 return (nvlist_add_common(nvl
, name
, DATA_TYPE_BOOLEAN_VALUE
, 1, &val
));
1008 nvlist_add_byte(nvlist_t
*nvl
, const char *name
, uchar_t val
)
1010 return (nvlist_add_common(nvl
, name
, DATA_TYPE_BYTE
, 1, &val
));
1014 nvlist_add_int8(nvlist_t
*nvl
, const char *name
, int8_t val
)
1016 return (nvlist_add_common(nvl
, name
, DATA_TYPE_INT8
, 1, &val
));
1020 nvlist_add_uint8(nvlist_t
*nvl
, const char *name
, uint8_t val
)
1022 return (nvlist_add_common(nvl
, name
, DATA_TYPE_UINT8
, 1, &val
));
1026 nvlist_add_int16(nvlist_t
*nvl
, const char *name
, int16_t val
)
1028 return (nvlist_add_common(nvl
, name
, DATA_TYPE_INT16
, 1, &val
));
1032 nvlist_add_uint16(nvlist_t
*nvl
, const char *name
, uint16_t val
)
1034 return (nvlist_add_common(nvl
, name
, DATA_TYPE_UINT16
, 1, &val
));
1038 nvlist_add_int32(nvlist_t
*nvl
, const char *name
, int32_t val
)
1040 return (nvlist_add_common(nvl
, name
, DATA_TYPE_INT32
, 1, &val
));
1044 nvlist_add_uint32(nvlist_t
*nvl
, const char *name
, uint32_t val
)
1046 return (nvlist_add_common(nvl
, name
, DATA_TYPE_UINT32
, 1, &val
));
1050 nvlist_add_int64(nvlist_t
*nvl
, const char *name
, int64_t val
)
1052 return (nvlist_add_common(nvl
, name
, DATA_TYPE_INT64
, 1, &val
));
1056 nvlist_add_uint64(nvlist_t
*nvl
, const char *name
, uint64_t val
)
1058 return (nvlist_add_common(nvl
, name
, DATA_TYPE_UINT64
, 1, &val
));
1061 #if !defined(_KERNEL)
1063 nvlist_add_double(nvlist_t
*nvl
, const char *name
, double val
)
1065 return (nvlist_add_common(nvl
, name
, DATA_TYPE_DOUBLE
, 1, &val
));
1070 nvlist_add_string(nvlist_t
*nvl
, const char *name
, const char *val
)
1072 return (nvlist_add_common(nvl
, name
, DATA_TYPE_STRING
, 1, (void *)val
));
1076 nvlist_add_boolean_array(nvlist_t
*nvl
, const char *name
,
1077 boolean_t
*a
, uint_t n
)
1079 return (nvlist_add_common(nvl
, name
, DATA_TYPE_BOOLEAN_ARRAY
, n
, a
));
1083 nvlist_add_byte_array(nvlist_t
*nvl
, const char *name
, uchar_t
*a
, uint_t n
)
1085 return (nvlist_add_common(nvl
, name
, DATA_TYPE_BYTE_ARRAY
, n
, a
));
1089 nvlist_add_int8_array(nvlist_t
*nvl
, const char *name
, int8_t *a
, uint_t n
)
1091 return (nvlist_add_common(nvl
, name
, DATA_TYPE_INT8_ARRAY
, n
, a
));
1095 nvlist_add_uint8_array(nvlist_t
*nvl
, const char *name
, uint8_t *a
, uint_t n
)
1097 return (nvlist_add_common(nvl
, name
, DATA_TYPE_UINT8_ARRAY
, n
, a
));
1101 nvlist_add_int16_array(nvlist_t
*nvl
, const char *name
, int16_t *a
, uint_t n
)
1103 return (nvlist_add_common(nvl
, name
, DATA_TYPE_INT16_ARRAY
, n
, a
));
1107 nvlist_add_uint16_array(nvlist_t
*nvl
, const char *name
, uint16_t *a
, uint_t n
)
1109 return (nvlist_add_common(nvl
, name
, DATA_TYPE_UINT16_ARRAY
, n
, a
));
1113 nvlist_add_int32_array(nvlist_t
*nvl
, const char *name
, int32_t *a
, uint_t n
)
1115 return (nvlist_add_common(nvl
, name
, DATA_TYPE_INT32_ARRAY
, n
, a
));
1119 nvlist_add_uint32_array(nvlist_t
*nvl
, const char *name
, uint32_t *a
, uint_t n
)
1121 return (nvlist_add_common(nvl
, name
, DATA_TYPE_UINT32_ARRAY
, n
, a
));
1125 nvlist_add_int64_array(nvlist_t
*nvl
, const char *name
, int64_t *a
, uint_t n
)
1127 return (nvlist_add_common(nvl
, name
, DATA_TYPE_INT64_ARRAY
, n
, a
));
1131 nvlist_add_uint64_array(nvlist_t
*nvl
, const char *name
, uint64_t *a
, uint_t n
)
1133 return (nvlist_add_common(nvl
, name
, DATA_TYPE_UINT64_ARRAY
, n
, a
));
1137 nvlist_add_string_array(nvlist_t
*nvl
, const char *name
,
1138 char *const *a
, uint_t n
)
1140 return (nvlist_add_common(nvl
, name
, DATA_TYPE_STRING_ARRAY
, n
, a
));
1144 nvlist_add_hrtime(nvlist_t
*nvl
, const char *name
, hrtime_t val
)
1146 return (nvlist_add_common(nvl
, name
, DATA_TYPE_HRTIME
, 1, &val
));
1150 nvlist_add_nvlist(nvlist_t
*nvl
, const char *name
, nvlist_t
*val
)
1152 return (nvlist_add_common(nvl
, name
, DATA_TYPE_NVLIST
, 1, val
));
1156 nvlist_add_nvlist_array(nvlist_t
*nvl
, const char *name
, nvlist_t
**a
, uint_t n
)
1158 return (nvlist_add_common(nvl
, name
, DATA_TYPE_NVLIST_ARRAY
, n
, a
));
1161 /* reading name-value pairs */
1163 nvlist_next_nvpair(nvlist_t
*nvl
, nvpair_t
*nvp
)
1169 (priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
) == NULL
)
1172 curr
= NVPAIR2I_NVP(nvp
);
1175 * Ensure that nvp is a valid nvpair on this nvlist.
1176 * NB: nvp_curr is used only as a hint so that we don't always
1177 * have to walk the list to determine if nvp is still on the list.
1180 curr
= priv
->nvp_list
;
1181 else if (priv
->nvp_curr
== curr
|| nvlist_contains_nvp(nvl
, nvp
))
1182 curr
= curr
->nvi_next
;
1186 priv
->nvp_curr
= curr
;
1188 return (curr
!= NULL
? &curr
->nvi_nvp
: NULL
);
1192 nvlist_prev_nvpair(nvlist_t
*nvl
, nvpair_t
*nvp
)
1198 (priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
) == NULL
)
1201 curr
= NVPAIR2I_NVP(nvp
);
1204 curr
= priv
->nvp_last
;
1205 else if (priv
->nvp_curr
== curr
|| nvlist_contains_nvp(nvl
, nvp
))
1206 curr
= curr
->nvi_prev
;
1210 priv
->nvp_curr
= curr
;
1212 return (curr
!= NULL
? &curr
->nvi_nvp
: NULL
);
1216 nvlist_empty(nvlist_t
*nvl
)
1221 (priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
) == NULL
)
1224 return (priv
->nvp_list
== NULL
);
1228 nvpair_name(nvpair_t
*nvp
)
1230 return (NVP_NAME(nvp
));
1234 nvpair_type(nvpair_t
*nvp
)
1236 return (NVP_TYPE(nvp
));
1240 nvpair_type_is_array(nvpair_t
*nvp
)
1242 data_type_t type
= NVP_TYPE(nvp
);
1244 if ((type
== DATA_TYPE_BYTE_ARRAY
) ||
1245 (type
== DATA_TYPE_UINT8_ARRAY
) ||
1246 (type
== DATA_TYPE_INT16_ARRAY
) ||
1247 (type
== DATA_TYPE_UINT16_ARRAY
) ||
1248 (type
== DATA_TYPE_INT32_ARRAY
) ||
1249 (type
== DATA_TYPE_UINT32_ARRAY
) ||
1250 (type
== DATA_TYPE_INT64_ARRAY
) ||
1251 (type
== DATA_TYPE_UINT64_ARRAY
) ||
1252 (type
== DATA_TYPE_BOOLEAN_ARRAY
) ||
1253 (type
== DATA_TYPE_STRING_ARRAY
) ||
1254 (type
== DATA_TYPE_NVLIST_ARRAY
))
1261 nvpair_value_common(nvpair_t
*nvp
, data_type_t type
, uint_t
*nelem
, void *data
)
1263 if (nvp
== NULL
|| nvpair_type(nvp
) != type
)
1267 * For non-array types, we copy the data.
1268 * For array types (including string), we set a pointer.
1271 case DATA_TYPE_BOOLEAN
:
1276 case DATA_TYPE_BOOLEAN_VALUE
:
1277 case DATA_TYPE_BYTE
:
1278 case DATA_TYPE_INT8
:
1279 case DATA_TYPE_UINT8
:
1280 case DATA_TYPE_INT16
:
1281 case DATA_TYPE_UINT16
:
1282 case DATA_TYPE_INT32
:
1283 case DATA_TYPE_UINT32
:
1284 case DATA_TYPE_INT64
:
1285 case DATA_TYPE_UINT64
:
1286 case DATA_TYPE_HRTIME
:
1287 #if !defined(_KERNEL)
1288 case DATA_TYPE_DOUBLE
:
1292 bcopy(NVP_VALUE(nvp
), data
,
1293 (size_t)i_get_value_size(type
, NULL
, 1));
1298 case DATA_TYPE_NVLIST
:
1299 case DATA_TYPE_STRING
:
1302 *(void **)data
= (void *)NVP_VALUE(nvp
);
1307 case DATA_TYPE_BOOLEAN_ARRAY
:
1308 case DATA_TYPE_BYTE_ARRAY
:
1309 case DATA_TYPE_INT8_ARRAY
:
1310 case DATA_TYPE_UINT8_ARRAY
:
1311 case DATA_TYPE_INT16_ARRAY
:
1312 case DATA_TYPE_UINT16_ARRAY
:
1313 case DATA_TYPE_INT32_ARRAY
:
1314 case DATA_TYPE_UINT32_ARRAY
:
1315 case DATA_TYPE_INT64_ARRAY
:
1316 case DATA_TYPE_UINT64_ARRAY
:
1317 case DATA_TYPE_STRING_ARRAY
:
1318 case DATA_TYPE_NVLIST_ARRAY
:
1319 if (nelem
== NULL
|| data
== NULL
)
1321 if ((*nelem
= NVP_NELEM(nvp
)) != 0)
1322 *(void **)data
= (void *)NVP_VALUE(nvp
);
1324 *(void **)data
= NULL
;
1335 nvlist_lookup_common(nvlist_t
*nvl
, const char *name
, data_type_t type
,
1336 uint_t
*nelem
, void *data
)
1342 if (name
== NULL
|| nvl
== NULL
||
1343 (priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
) == NULL
)
1346 if (!(nvl
->nvl_nvflag
& (NV_UNIQUE_NAME
| NV_UNIQUE_NAME_TYPE
)))
1349 for (curr
= priv
->nvp_list
; curr
!= NULL
; curr
= curr
->nvi_next
) {
1350 nvp
= &curr
->nvi_nvp
;
1352 if (strcmp(name
, NVP_NAME(nvp
)) == 0 && NVP_TYPE(nvp
) == type
)
1353 return (nvpair_value_common(nvp
, type
, nelem
, data
));
1360 nvlist_lookup_boolean(nvlist_t
*nvl
, const char *name
)
1362 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_BOOLEAN
, NULL
, NULL
));
1366 nvlist_lookup_boolean_value(nvlist_t
*nvl
, const char *name
, boolean_t
*val
)
1368 return (nvlist_lookup_common(nvl
, name
,
1369 DATA_TYPE_BOOLEAN_VALUE
, NULL
, val
));
1373 nvlist_lookup_byte(nvlist_t
*nvl
, const char *name
, uchar_t
*val
)
1375 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_BYTE
, NULL
, val
));
1379 nvlist_lookup_int8(nvlist_t
*nvl
, const char *name
, int8_t *val
)
1381 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_INT8
, NULL
, val
));
1385 nvlist_lookup_uint8(nvlist_t
*nvl
, const char *name
, uint8_t *val
)
1387 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_UINT8
, NULL
, val
));
1391 nvlist_lookup_int16(nvlist_t
*nvl
, const char *name
, int16_t *val
)
1393 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_INT16
, NULL
, val
));
1397 nvlist_lookup_uint16(nvlist_t
*nvl
, const char *name
, uint16_t *val
)
1399 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_UINT16
, NULL
, val
));
1403 nvlist_lookup_int32(nvlist_t
*nvl
, const char *name
, int32_t *val
)
1405 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_INT32
, NULL
, val
));
1409 nvlist_lookup_uint32(nvlist_t
*nvl
, const char *name
, uint32_t *val
)
1411 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_UINT32
, NULL
, val
));
1415 nvlist_lookup_int64(nvlist_t
*nvl
, const char *name
, int64_t *val
)
1417 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_INT64
, NULL
, val
));
1421 nvlist_lookup_uint64(nvlist_t
*nvl
, const char *name
, uint64_t *val
)
1423 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_UINT64
, NULL
, val
));
1426 #if !defined(_KERNEL)
1428 nvlist_lookup_double(nvlist_t
*nvl
, const char *name
, double *val
)
1430 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_DOUBLE
, NULL
, val
));
1435 nvlist_lookup_string(nvlist_t
*nvl
, const char *name
, char **val
)
1437 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_STRING
, NULL
, val
));
1441 nvlist_lookup_nvlist(nvlist_t
*nvl
, const char *name
, nvlist_t
**val
)
1443 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_NVLIST
, NULL
, val
));
1447 nvlist_lookup_boolean_array(nvlist_t
*nvl
, const char *name
,
1448 boolean_t
**a
, uint_t
*n
)
1450 return (nvlist_lookup_common(nvl
, name
,
1451 DATA_TYPE_BOOLEAN_ARRAY
, n
, a
));
1455 nvlist_lookup_byte_array(nvlist_t
*nvl
, const char *name
,
1456 uchar_t
**a
, uint_t
*n
)
1458 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_BYTE_ARRAY
, n
, a
));
1462 nvlist_lookup_int8_array(nvlist_t
*nvl
, const char *name
, int8_t **a
, uint_t
*n
)
1464 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_INT8_ARRAY
, n
, a
));
1468 nvlist_lookup_uint8_array(nvlist_t
*nvl
, const char *name
,
1469 uint8_t **a
, uint_t
*n
)
1471 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_UINT8_ARRAY
, n
, a
));
1475 nvlist_lookup_int16_array(nvlist_t
*nvl
, const char *name
,
1476 int16_t **a
, uint_t
*n
)
1478 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_INT16_ARRAY
, n
, a
));
1482 nvlist_lookup_uint16_array(nvlist_t
*nvl
, const char *name
,
1483 uint16_t **a
, uint_t
*n
)
1485 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_UINT16_ARRAY
, n
, a
));
1489 nvlist_lookup_int32_array(nvlist_t
*nvl
, const char *name
,
1490 int32_t **a
, uint_t
*n
)
1492 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_INT32_ARRAY
, n
, a
));
1496 nvlist_lookup_uint32_array(nvlist_t
*nvl
, const char *name
,
1497 uint32_t **a
, uint_t
*n
)
1499 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_UINT32_ARRAY
, n
, a
));
1503 nvlist_lookup_int64_array(nvlist_t
*nvl
, const char *name
,
1504 int64_t **a
, uint_t
*n
)
1506 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_INT64_ARRAY
, n
, a
));
1510 nvlist_lookup_uint64_array(nvlist_t
*nvl
, const char *name
,
1511 uint64_t **a
, uint_t
*n
)
1513 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_UINT64_ARRAY
, n
, a
));
1517 nvlist_lookup_string_array(nvlist_t
*nvl
, const char *name
,
1518 char ***a
, uint_t
*n
)
1520 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_STRING_ARRAY
, n
, a
));
1524 nvlist_lookup_nvlist_array(nvlist_t
*nvl
, const char *name
,
1525 nvlist_t
***a
, uint_t
*n
)
1527 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_NVLIST_ARRAY
, n
, a
));
1531 nvlist_lookup_hrtime(nvlist_t
*nvl
, const char *name
, hrtime_t
*val
)
1533 return (nvlist_lookup_common(nvl
, name
, DATA_TYPE_HRTIME
, NULL
, val
));
1537 nvlist_lookup_pairs(nvlist_t
*nvl
, int flag
, ...)
1541 int noentok
= (flag
& NV_FLAG_NOENTOK
? 1 : 0);
1545 while (ret
== 0 && (name
= va_arg(ap
, char *)) != NULL
) {
1550 switch (type
= va_arg(ap
, data_type_t
)) {
1551 case DATA_TYPE_BOOLEAN
:
1552 ret
= nvlist_lookup_common(nvl
, name
, type
, NULL
, NULL
);
1555 case DATA_TYPE_BOOLEAN_VALUE
:
1556 case DATA_TYPE_BYTE
:
1557 case DATA_TYPE_INT8
:
1558 case DATA_TYPE_UINT8
:
1559 case DATA_TYPE_INT16
:
1560 case DATA_TYPE_UINT16
:
1561 case DATA_TYPE_INT32
:
1562 case DATA_TYPE_UINT32
:
1563 case DATA_TYPE_INT64
:
1564 case DATA_TYPE_UINT64
:
1565 case DATA_TYPE_HRTIME
:
1566 case DATA_TYPE_STRING
:
1567 case DATA_TYPE_NVLIST
:
1568 #if !defined(_KERNEL)
1569 case DATA_TYPE_DOUBLE
:
1571 val
= va_arg(ap
, void *);
1572 ret
= nvlist_lookup_common(nvl
, name
, type
, NULL
, val
);
1575 case DATA_TYPE_BYTE_ARRAY
:
1576 case DATA_TYPE_BOOLEAN_ARRAY
:
1577 case DATA_TYPE_INT8_ARRAY
:
1578 case DATA_TYPE_UINT8_ARRAY
:
1579 case DATA_TYPE_INT16_ARRAY
:
1580 case DATA_TYPE_UINT16_ARRAY
:
1581 case DATA_TYPE_INT32_ARRAY
:
1582 case DATA_TYPE_UINT32_ARRAY
:
1583 case DATA_TYPE_INT64_ARRAY
:
1584 case DATA_TYPE_UINT64_ARRAY
:
1585 case DATA_TYPE_STRING_ARRAY
:
1586 case DATA_TYPE_NVLIST_ARRAY
:
1587 val
= va_arg(ap
, void *);
1588 nelem
= va_arg(ap
, uint_t
*);
1589 ret
= nvlist_lookup_common(nvl
, name
, type
, nelem
, val
);
1596 if (ret
== ENOENT
&& noentok
)
1605 * Find the 'name'ed nvpair in the nvlist 'nvl'. If 'name' found, the function
1606 * returns zero and a pointer to the matching nvpair is returned in '*ret'
1607 * (given 'ret' is non-NULL). If 'sep' is specified then 'name' will penitrate
1608 * multiple levels of embedded nvlists, with 'sep' as the separator. As an
1609 * example, if sep is '.', name might look like: "a" or "a.b" or "a.c[3]" or
1610 * "a.d[3].e[1]". This matches the C syntax for array embed (for convience,
1611 * code also supports "a.d[3]e[1]" syntax).
1613 * If 'ip' is non-NULL and the last name component is an array, return the
1614 * value of the "...[index]" array index in *ip. For an array reference that
1615 * is not indexed, *ip will be returned as -1. If there is a syntax error in
1616 * 'name', and 'ep' is non-NULL then *ep will be set to point to the location
1617 * inside the 'name' string where the syntax error was detected.
1620 nvlist_lookup_nvpair_ei_sep(nvlist_t
*nvl
, const char *name
, const char sep
,
1621 nvpair_t
**ret
, int *ip
, char **ep
)
1632 *ip
= -1; /* not indexed */
1636 if ((nvl
== NULL
) || (name
== NULL
))
1639 /* step through components of name */
1640 for (np
= name
; np
&& *np
; np
= sepp
) {
1641 /* ensure unique names */
1642 if (!(nvl
->nvl_nvflag
& NV_UNIQUE_NAME
))
1645 /* skip white space */
1646 skip_whitespace(np
);
1650 /* set 'sepp' to end of current component 'np' */
1652 sepp
= strchr(np
, sep
);
1656 /* find start of next "[ index ]..." */
1657 idxp
= strchr(np
, '[');
1659 /* if sepp comes first, set idxp to NULL */
1660 if (sepp
&& idxp
&& (sepp
< idxp
))
1664 * At this point 'idxp' is set if there is an index
1665 * expected for the current component.
1668 /* set 'n' to length of current 'np' name component */
1671 /* keep sepp up to date for *ep use as we advance */
1672 skip_whitespace(idxp
);
1675 /* determine the index value */
1676 #if defined(_KERNEL) && !defined(_BOOT)
1677 if (ddi_strtol(idxp
, &idxep
, 0, &idx
))
1680 idx
= strtol(idxp
, &idxep
, 0);
1685 /* keep sepp up to date for *ep use as we advance */
1688 /* skip white space index value and check for ']' */
1689 skip_whitespace(sepp
);
1693 /* for embedded arrays, support C syntax: "a[1].b" */
1694 skip_whitespace(sepp
);
1695 if (sep
&& (*sepp
== sep
))
1703 /* trim trailing whitespace by reducing length of 'np' */
1706 for (n
--; (np
[n
] == ' ') || (np
[n
] == '\t'); n
--)
1710 /* skip whitespace, and set sepp to NULL if complete */
1712 skip_whitespace(sepp
);
1719 * o 'n' is the length of current 'np' component.
1720 * o 'idxp' is set if there was an index, and value 'idx'.
1721 * o 'sepp' is set to the beginning of the next component,
1722 * and set to NULL if we have no more components.
1724 * Search for nvpair with matching component name.
1726 for (nvp
= nvlist_next_nvpair(nvl
, NULL
); nvp
!= NULL
;
1727 nvp
= nvlist_next_nvpair(nvl
, nvp
)) {
1729 /* continue if no match on name */
1730 if (strncmp(np
, nvpair_name(nvp
), n
) ||
1731 (strlen(nvpair_name(nvp
)) != n
))
1734 /* if indexed, verify type is array oriented */
1735 if (idxp
&& !nvpair_type_is_array(nvp
))
1739 * Full match found, return nvp and idx if this
1740 * was the last component.
1746 *ip
= (int)idx
; /* return index */
1747 return (0); /* found */
1751 * More components: current match must be
1752 * of DATA_TYPE_NVLIST or DATA_TYPE_NVLIST_ARRAY
1753 * to support going deeper.
1755 if (nvpair_type(nvp
) == DATA_TYPE_NVLIST
) {
1756 nvl
= EMBEDDED_NVL(nvp
);
1758 } else if (nvpair_type(nvp
) == DATA_TYPE_NVLIST_ARRAY
) {
1759 (void) nvpair_value_nvlist_array(nvp
,
1760 &nva
, (uint_t
*)&n
);
1761 if ((n
< 0) || (idx
>= n
))
1767 /* type does not support more levels */
1771 goto fail
; /* 'name' not found */
1773 /* search for match of next component in embedded 'nvl' list */
1776 fail
: if (ep
&& sepp
)
1782 * Return pointer to nvpair with specified 'name'.
1785 nvlist_lookup_nvpair(nvlist_t
*nvl
, const char *name
, nvpair_t
**ret
)
1787 return (nvlist_lookup_nvpair_ei_sep(nvl
, name
, 0, ret
, NULL
, NULL
));
1791 * Determine if named nvpair exists in nvlist (use embedded separator of '.'
1792 * and return array index). See nvlist_lookup_nvpair_ei_sep for more detailed
1795 int nvlist_lookup_nvpair_embedded_index(nvlist_t
*nvl
,
1796 const char *name
, nvpair_t
**ret
, int *ip
, char **ep
)
1798 return (nvlist_lookup_nvpair_ei_sep(nvl
, name
, '.', ret
, ip
, ep
));
1802 nvlist_exists(nvlist_t
*nvl
, const char *name
)
1808 if (name
== NULL
|| nvl
== NULL
||
1809 (priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
) == NULL
)
1812 for (curr
= priv
->nvp_list
; curr
!= NULL
; curr
= curr
->nvi_next
) {
1813 nvp
= &curr
->nvi_nvp
;
1815 if (strcmp(name
, NVP_NAME(nvp
)) == 0)
1823 nvpair_value_boolean_value(nvpair_t
*nvp
, boolean_t
*val
)
1825 return (nvpair_value_common(nvp
, DATA_TYPE_BOOLEAN_VALUE
, NULL
, val
));
1829 nvpair_value_byte(nvpair_t
*nvp
, uchar_t
*val
)
1831 return (nvpair_value_common(nvp
, DATA_TYPE_BYTE
, NULL
, val
));
1835 nvpair_value_int8(nvpair_t
*nvp
, int8_t *val
)
1837 return (nvpair_value_common(nvp
, DATA_TYPE_INT8
, NULL
, val
));
1841 nvpair_value_uint8(nvpair_t
*nvp
, uint8_t *val
)
1843 return (nvpair_value_common(nvp
, DATA_TYPE_UINT8
, NULL
, val
));
1847 nvpair_value_int16(nvpair_t
*nvp
, int16_t *val
)
1849 return (nvpair_value_common(nvp
, DATA_TYPE_INT16
, NULL
, val
));
1853 nvpair_value_uint16(nvpair_t
*nvp
, uint16_t *val
)
1855 return (nvpair_value_common(nvp
, DATA_TYPE_UINT16
, NULL
, val
));
1859 nvpair_value_int32(nvpair_t
*nvp
, int32_t *val
)
1861 return (nvpair_value_common(nvp
, DATA_TYPE_INT32
, NULL
, val
));
1865 nvpair_value_uint32(nvpair_t
*nvp
, uint32_t *val
)
1867 return (nvpair_value_common(nvp
, DATA_TYPE_UINT32
, NULL
, val
));
1871 nvpair_value_int64(nvpair_t
*nvp
, int64_t *val
)
1873 return (nvpair_value_common(nvp
, DATA_TYPE_INT64
, NULL
, val
));
1877 nvpair_value_uint64(nvpair_t
*nvp
, uint64_t *val
)
1879 return (nvpair_value_common(nvp
, DATA_TYPE_UINT64
, NULL
, val
));
1882 #if !defined(_KERNEL)
1884 nvpair_value_double(nvpair_t
*nvp
, double *val
)
1886 return (nvpair_value_common(nvp
, DATA_TYPE_DOUBLE
, NULL
, val
));
1891 nvpair_value_string(nvpair_t
*nvp
, char **val
)
1893 return (nvpair_value_common(nvp
, DATA_TYPE_STRING
, NULL
, val
));
1897 nvpair_value_nvlist(nvpair_t
*nvp
, nvlist_t
**val
)
1899 return (nvpair_value_common(nvp
, DATA_TYPE_NVLIST
, NULL
, val
));
1903 nvpair_value_boolean_array(nvpair_t
*nvp
, boolean_t
**val
, uint_t
*nelem
)
1905 return (nvpair_value_common(nvp
, DATA_TYPE_BOOLEAN_ARRAY
, nelem
, val
));
1909 nvpair_value_byte_array(nvpair_t
*nvp
, uchar_t
**val
, uint_t
*nelem
)
1911 return (nvpair_value_common(nvp
, DATA_TYPE_BYTE_ARRAY
, nelem
, val
));
1915 nvpair_value_int8_array(nvpair_t
*nvp
, int8_t **val
, uint_t
*nelem
)
1917 return (nvpair_value_common(nvp
, DATA_TYPE_INT8_ARRAY
, nelem
, val
));
1921 nvpair_value_uint8_array(nvpair_t
*nvp
, uint8_t **val
, uint_t
*nelem
)
1923 return (nvpair_value_common(nvp
, DATA_TYPE_UINT8_ARRAY
, nelem
, val
));
1927 nvpair_value_int16_array(nvpair_t
*nvp
, int16_t **val
, uint_t
*nelem
)
1929 return (nvpair_value_common(nvp
, DATA_TYPE_INT16_ARRAY
, nelem
, val
));
1933 nvpair_value_uint16_array(nvpair_t
*nvp
, uint16_t **val
, uint_t
*nelem
)
1935 return (nvpair_value_common(nvp
, DATA_TYPE_UINT16_ARRAY
, nelem
, val
));
1939 nvpair_value_int32_array(nvpair_t
*nvp
, int32_t **val
, uint_t
*nelem
)
1941 return (nvpair_value_common(nvp
, DATA_TYPE_INT32_ARRAY
, nelem
, val
));
1945 nvpair_value_uint32_array(nvpair_t
*nvp
, uint32_t **val
, uint_t
*nelem
)
1947 return (nvpair_value_common(nvp
, DATA_TYPE_UINT32_ARRAY
, nelem
, val
));
1951 nvpair_value_int64_array(nvpair_t
*nvp
, int64_t **val
, uint_t
*nelem
)
1953 return (nvpair_value_common(nvp
, DATA_TYPE_INT64_ARRAY
, nelem
, val
));
1957 nvpair_value_uint64_array(nvpair_t
*nvp
, uint64_t **val
, uint_t
*nelem
)
1959 return (nvpair_value_common(nvp
, DATA_TYPE_UINT64_ARRAY
, nelem
, val
));
1963 nvpair_value_string_array(nvpair_t
*nvp
, char ***val
, uint_t
*nelem
)
1965 return (nvpair_value_common(nvp
, DATA_TYPE_STRING_ARRAY
, nelem
, val
));
1969 nvpair_value_nvlist_array(nvpair_t
*nvp
, nvlist_t
***val
, uint_t
*nelem
)
1971 return (nvpair_value_common(nvp
, DATA_TYPE_NVLIST_ARRAY
, nelem
, val
));
1975 nvpair_value_hrtime(nvpair_t
*nvp
, hrtime_t
*val
)
1977 return (nvpair_value_common(nvp
, DATA_TYPE_HRTIME
, NULL
, val
));
1981 * Add specified pair to the list.
1984 nvlist_add_nvpair(nvlist_t
*nvl
, nvpair_t
*nvp
)
1986 if (nvl
== NULL
|| nvp
== NULL
)
1989 return (nvlist_add_common(nvl
, NVP_NAME(nvp
), NVP_TYPE(nvp
),
1990 NVP_NELEM(nvp
), NVP_VALUE(nvp
)));
1994 * Merge the supplied nvlists and put the result in dst.
1995 * The merged list will contain all names specified in both lists,
1996 * the values are taken from nvl in the case of duplicates.
1997 * Return 0 on success.
2001 nvlist_merge(nvlist_t
*dst
, nvlist_t
*nvl
, int flag
)
2003 if (nvl
== NULL
|| dst
== NULL
)
2007 return (nvlist_copy_pairs(nvl
, dst
));
2013 * Encoding related routines
2015 #define NVS_OP_ENCODE 0
2016 #define NVS_OP_DECODE 1
2017 #define NVS_OP_GETSIZE 2
2019 typedef struct nvs_ops nvs_ops_t
;
2023 const nvs_ops_t
*nvs_ops
;
2030 * nvs operations are:
2032 * encoding / decoding of a nvlist header (nvlist_t)
2033 * calculates the size used for header and end detection
2036 * responsible for the first part of encoding / decoding of an nvpair
2037 * calculates the decoded size of an nvpair
2040 * second part of encoding / decoding of an nvpair
2043 * calculates the encoding size of an nvpair
2046 * encodes the end detection mark (zeros).
2049 int (*nvs_nvlist
)(nvstream_t
*, nvlist_t
*, size_t *);
2050 int (*nvs_nvpair
)(nvstream_t
*, nvpair_t
*, size_t *);
2051 int (*nvs_nvp_op
)(nvstream_t
*, nvpair_t
*);
2052 int (*nvs_nvp_size
)(nvstream_t
*, nvpair_t
*, size_t *);
2053 int (*nvs_nvl_fini
)(nvstream_t
*);
2057 char nvh_encoding
; /* nvs encoding method */
2058 char nvh_endian
; /* nvs endian */
2059 char nvh_reserved1
; /* reserved for future use */
2060 char nvh_reserved2
; /* reserved for future use */
2064 nvs_encode_pairs(nvstream_t
*nvs
, nvlist_t
*nvl
)
2066 nvpriv_t
*priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
;
2070 * Walk nvpair in list and encode each nvpair
2072 for (curr
= priv
->nvp_list
; curr
!= NULL
; curr
= curr
->nvi_next
)
2073 if (nvs
->nvs_ops
->nvs_nvpair(nvs
, &curr
->nvi_nvp
, NULL
) != 0)
2076 return (nvs
->nvs_ops
->nvs_nvl_fini(nvs
));
2080 nvs_decode_pairs(nvstream_t
*nvs
, nvlist_t
*nvl
)
2087 * Get decoded size of next pair in stream, alloc
2088 * memory for nvpair_t, then decode the nvpair
2090 while ((err
= nvs
->nvs_ops
->nvs_nvpair(nvs
, NULL
, &nvsize
)) == 0) {
2091 if (nvsize
== 0) /* end of list */
2094 /* make sure len makes sense */
2095 if (nvsize
< NVP_SIZE_CALC(1, 0))
2098 if ((nvp
= nvp_buf_alloc(nvl
, nvsize
)) == NULL
)
2101 if ((err
= nvs
->nvs_ops
->nvs_nvp_op(nvs
, nvp
)) != 0) {
2102 nvp_buf_free(nvl
, nvp
);
2106 if (i_validate_nvpair(nvp
) != 0) {
2108 nvp_buf_free(nvl
, nvp
);
2112 nvp_buf_link(nvl
, nvp
);
2118 nvs_getsize_pairs(nvstream_t
*nvs
, nvlist_t
*nvl
, size_t *buflen
)
2120 nvpriv_t
*priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
;
2122 uint64_t nvsize
= *buflen
;
2126 * Get encoded size of nvpairs in nvlist
2128 for (curr
= priv
->nvp_list
; curr
!= NULL
; curr
= curr
->nvi_next
) {
2129 if (nvs
->nvs_ops
->nvs_nvp_size(nvs
, &curr
->nvi_nvp
, &size
) != 0)
2132 if ((nvsize
+= size
) > INT32_MAX
)
2141 nvs_operation(nvstream_t
*nvs
, nvlist_t
*nvl
, size_t *buflen
)
2145 if (nvl
->nvl_priv
== 0)
2149 * Perform the operation, starting with header, then each nvpair
2151 if ((err
= nvs
->nvs_ops
->nvs_nvlist(nvs
, nvl
, buflen
)) != 0)
2154 switch (nvs
->nvs_op
) {
2156 err
= nvs_encode_pairs(nvs
, nvl
);
2160 err
= nvs_decode_pairs(nvs
, nvl
);
2163 case NVS_OP_GETSIZE
:
2164 err
= nvs_getsize_pairs(nvs
, nvl
, buflen
);
2175 nvs_embedded(nvstream_t
*nvs
, nvlist_t
*embedded
)
2177 switch (nvs
->nvs_op
) {
2178 case NVS_OP_ENCODE
: {
2181 if (nvs
->nvs_recursion
>= nvpair_max_recursion
)
2183 nvs
->nvs_recursion
++;
2184 err
= nvs_operation(nvs
, embedded
, NULL
);
2185 nvs
->nvs_recursion
--;
2188 case NVS_OP_DECODE
: {
2192 if (embedded
->nvl_version
!= NV_VERSION
)
2195 if ((priv
= nv_priv_alloc_embedded(nvs
->nvs_priv
)) == NULL
)
2198 nvlist_init(embedded
, embedded
->nvl_nvflag
, priv
);
2200 if (nvs
->nvs_recursion
>= nvpair_max_recursion
)
2202 nvs
->nvs_recursion
++;
2203 if ((err
= nvs_operation(nvs
, embedded
, NULL
)) != 0)
2204 nvlist_free(embedded
);
2205 nvs
->nvs_recursion
--;
2216 nvs_embedded_nvl_array(nvstream_t
*nvs
, nvpair_t
*nvp
, size_t *size
)
2218 size_t nelem
= NVP_NELEM(nvp
);
2219 nvlist_t
**nvlp
= EMBEDDED_NVL_ARRAY(nvp
);
2222 switch (nvs
->nvs_op
) {
2224 for (i
= 0; i
< nelem
; i
++)
2225 if (nvs_embedded(nvs
, nvlp
[i
]) != 0)
2229 case NVS_OP_DECODE
: {
2230 size_t len
= nelem
* sizeof (uint64_t);
2231 nvlist_t
*embedded
= (nvlist_t
*)((uintptr_t)nvlp
+ len
);
2233 bzero(nvlp
, len
); /* don't trust packed data */
2234 for (i
= 0; i
< nelem
; i
++) {
2235 if (nvs_embedded(nvs
, embedded
) != 0) {
2240 nvlp
[i
] = embedded
++;
2244 case NVS_OP_GETSIZE
: {
2245 uint64_t nvsize
= 0;
2247 for (i
= 0; i
< nelem
; i
++) {
2250 if (nvs_operation(nvs
, nvlp
[i
], &nvp_sz
) != 0)
2253 if ((nvsize
+= nvp_sz
) > INT32_MAX
)
2267 static int nvs_native(nvstream_t
*, nvlist_t
*, char *, size_t *);
2268 static int nvs_xdr(nvstream_t
*, nvlist_t
*, char *, size_t *);
2271 * Common routine for nvlist operations:
2272 * encode, decode, getsize (encoded size).
2275 nvlist_common(nvlist_t
*nvl
, char *buf
, size_t *buflen
, int encoding
,
2281 #ifdef _LITTLE_ENDIAN
2282 int host_endian
= 1;
2284 int host_endian
= 0;
2285 #endif /* _LITTLE_ENDIAN */
2286 nvs_header_t
*nvh
= (void *)buf
;
2288 if (buflen
== NULL
|| nvl
== NULL
||
2289 (nvs
.nvs_priv
= (nvpriv_t
*)(uintptr_t)nvl
->nvl_priv
) == NULL
)
2292 nvs
.nvs_op
= nvs_op
;
2293 nvs
.nvs_recursion
= 0;
2296 * For NVS_OP_ENCODE and NVS_OP_DECODE make sure an nvlist and
2297 * a buffer is allocated. The first 4 bytes in the buffer are
2298 * used for encoding method and host endian.
2302 if (buf
== NULL
|| *buflen
< sizeof (nvs_header_t
))
2305 nvh
->nvh_encoding
= encoding
;
2306 nvh
->nvh_endian
= nvl_endian
= host_endian
;
2307 nvh
->nvh_reserved1
= 0;
2308 nvh
->nvh_reserved2
= 0;
2312 if (buf
== NULL
|| *buflen
< sizeof (nvs_header_t
))
2315 /* get method of encoding from first byte */
2316 encoding
= nvh
->nvh_encoding
;
2317 nvl_endian
= nvh
->nvh_endian
;
2320 case NVS_OP_GETSIZE
:
2321 nvl_endian
= host_endian
;
2324 * add the size for encoding
2326 *buflen
= sizeof (nvs_header_t
);
2334 * Create an nvstream with proper encoding method
2337 case NV_ENCODE_NATIVE
:
2339 * check endianness, in case we are unpacking
2342 if (nvl_endian
!= host_endian
)
2344 err
= nvs_native(&nvs
, nvl
, buf
, buflen
);
2347 err
= nvs_xdr(&nvs
, nvl
, buf
, buflen
);
2358 nvlist_size(nvlist_t
*nvl
, size_t *size
, int encoding
)
2360 return (nvlist_common(nvl
, NULL
, size
, encoding
, NVS_OP_GETSIZE
));
2364 * Pack nvlist into contiguous memory
2367 nvlist_pack(nvlist_t
*nvl
, char **bufp
, size_t *buflen
, int encoding
,
2370 return (nvlist_xpack(nvl
, bufp
, buflen
, encoding
,
2371 nvlist_nv_alloc(kmflag
)));
2375 nvlist_xpack(nvlist_t
*nvl
, char **bufp
, size_t *buflen
, int encoding
,
2383 if (nva
== NULL
|| nvl
== NULL
|| bufp
== NULL
|| buflen
== NULL
)
2387 return (nvlist_common(nvl
, *bufp
, buflen
, encoding
,
2391 * Here is a difficult situation:
2392 * 1. The nvlist has fixed allocator properties.
2393 * All other nvlist routines (like nvlist_add_*, ...) use
2395 * 2. When using nvlist_pack() the user can specify his own
2396 * allocator properties (e.g. by using KM_NOSLEEP).
2398 * We use the user specified properties (2). A clearer solution
2399 * will be to remove the kmflag from nvlist_pack(), but we will
2400 * not change the interface.
2402 nv_priv_init(&nvpriv
, nva
, 0);
2404 if ((err
= nvlist_size(nvl
, &alloc_size
, encoding
)))
2407 if ((buf
= nv_mem_zalloc(&nvpriv
, alloc_size
)) == NULL
)
2410 if ((err
= nvlist_common(nvl
, buf
, &alloc_size
, encoding
,
2411 NVS_OP_ENCODE
)) != 0) {
2412 nv_mem_free(&nvpriv
, buf
, alloc_size
);
2414 *buflen
= alloc_size
;
2422 * Unpack buf into an nvlist_t
2425 nvlist_unpack(char *buf
, size_t buflen
, nvlist_t
**nvlp
, int kmflag
)
2427 return (nvlist_xunpack(buf
, buflen
, nvlp
, nvlist_nv_alloc(kmflag
)));
2431 nvlist_xunpack(char *buf
, size_t buflen
, nvlist_t
**nvlp
, nv_alloc_t
*nva
)
2439 if ((err
= nvlist_xalloc(&nvl
, 0, nva
)) != 0)
2442 if ((err
= nvlist_common(nvl
, buf
, &buflen
, 0, NVS_OP_DECODE
)) != 0)
2451 * Native encoding functions
2455 * This structure is used when decoding a packed nvpair in
2456 * the native format. n_base points to a buffer containing the
2457 * packed nvpair. n_end is a pointer to the end of the buffer.
2458 * (n_end actually points to the first byte past the end of the
2459 * buffer.) n_curr is a pointer that lies between n_base and n_end.
2460 * It points to the current data that we are decoding.
2461 * The amount of data left in the buffer is equal to n_end - n_curr.
2462 * n_flag is used to recognize a packed embedded list.
2471 nvs_native_create(nvstream_t
*nvs
, nvs_native_t
*native
, char *buf
,
2474 switch (nvs
->nvs_op
) {
2477 nvs
->nvs_private
= native
;
2478 native
->n_curr
= native
->n_base
= buf
;
2479 native
->n_end
= buf
+ buflen
;
2483 case NVS_OP_GETSIZE
:
2484 nvs
->nvs_private
= native
;
2485 native
->n_curr
= native
->n_base
= native
->n_end
= NULL
;
2495 nvs_native_destroy(nvstream_t
*nvs
)
2500 native_cp(nvstream_t
*nvs
, void *buf
, size_t size
)
2502 nvs_native_t
*native
= (nvs_native_t
*)nvs
->nvs_private
;
2504 if (native
->n_curr
+ size
> native
->n_end
)
2508 * The bcopy() below eliminates alignment requirement
2509 * on the buffer (stream) and is preferred over direct access.
2511 switch (nvs
->nvs_op
) {
2513 bcopy(buf
, native
->n_curr
, size
);
2516 bcopy(native
->n_curr
, buf
, size
);
2522 native
->n_curr
+= size
;
2527 * operate on nvlist_t header
2530 nvs_native_nvlist(nvstream_t
*nvs
, nvlist_t
*nvl
, size_t *size
)
2532 nvs_native_t
*native
= nvs
->nvs_private
;
2534 switch (nvs
->nvs_op
) {
2538 return (0); /* packed embedded list */
2542 /* copy version and nvflag of the nvlist_t */
2543 if (native_cp(nvs
, &nvl
->nvl_version
, sizeof (int32_t)) != 0 ||
2544 native_cp(nvs
, &nvl
->nvl_nvflag
, sizeof (int32_t)) != 0)
2549 case NVS_OP_GETSIZE
:
2551 * if calculate for packed embedded list
2552 * 4 for end of the embedded list
2554 * 2 * sizeof (int32_t) for nvl_version and nvl_nvflag
2555 * and 4 for end of the entire list
2557 if (native
->n_flag
) {
2561 *size
+= 2 * sizeof (int32_t) + 4;
2572 nvs_native_nvl_fini(nvstream_t
*nvs
)
2574 if (nvs
->nvs_op
== NVS_OP_ENCODE
) {
2575 nvs_native_t
*native
= (nvs_native_t
*)nvs
->nvs_private
;
2577 * Add 4 zero bytes at end of nvlist. They are used
2578 * for end detection by the decode routine.
2580 if (native
->n_curr
+ sizeof (int) > native
->n_end
)
2583 bzero(native
->n_curr
, sizeof (int));
2584 native
->n_curr
+= sizeof (int);
2591 nvpair_native_embedded(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 nvlist_t
*packed
= (void *)
2596 (native
->n_curr
- nvp
->nvp_size
+ NVP_VALOFF(nvp
));
2598 * Null out the pointer that is meaningless in the packed
2599 * structure. The address may not be aligned, so we have
2602 bzero((char *)packed
+ offsetof(nvlist_t
, nvl_priv
),
2606 return (nvs_embedded(nvs
, EMBEDDED_NVL(nvp
)));
2610 nvpair_native_embedded_array(nvstream_t
*nvs
, nvpair_t
*nvp
)
2612 if (nvs
->nvs_op
== NVS_OP_ENCODE
) {
2613 nvs_native_t
*native
= (nvs_native_t
*)nvs
->nvs_private
;
2614 char *value
= native
->n_curr
- nvp
->nvp_size
+ NVP_VALOFF(nvp
);
2615 size_t len
= NVP_NELEM(nvp
) * sizeof (uint64_t);
2616 nvlist_t
*packed
= (nvlist_t
*)((uintptr_t)value
+ len
);
2619 * Null out pointers that are meaningless in the packed
2620 * structure. The addresses may not be aligned, so we have
2625 for (i
= 0; i
< NVP_NELEM(nvp
); i
++, packed
++)
2627 * Null out the pointer that is meaningless in the
2628 * packed structure. The address may not be aligned,
2629 * so we have to use bzero.
2631 bzero((char *)packed
+ offsetof(nvlist_t
, nvl_priv
),
2635 return (nvs_embedded_nvl_array(nvs
, nvp
, NULL
));
2639 nvpair_native_string_array(nvstream_t
*nvs
, nvpair_t
*nvp
)
2641 switch (nvs
->nvs_op
) {
2642 case NVS_OP_ENCODE
: {
2643 nvs_native_t
*native
= (nvs_native_t
*)nvs
->nvs_private
;
2644 uint64_t *strp
= (void *)
2645 (native
->n_curr
- nvp
->nvp_size
+ NVP_VALOFF(nvp
));
2647 * Null out pointers that are meaningless in the packed
2648 * structure. The addresses may not be aligned, so we have
2651 bzero(strp
, NVP_NELEM(nvp
) * sizeof (uint64_t));
2654 case NVS_OP_DECODE
: {
2655 char **strp
= (void *)NVP_VALUE(nvp
);
2656 char *buf
= ((char *)strp
+ NVP_NELEM(nvp
) * sizeof (uint64_t));
2659 for (i
= 0; i
< NVP_NELEM(nvp
); i
++) {
2661 buf
+= strlen(buf
) + 1;
2669 nvs_native_nvp_op(nvstream_t
*nvs
, nvpair_t
*nvp
)
2676 * We do the initial bcopy of the data before we look at
2677 * the nvpair type, because when we're decoding, we won't
2678 * have the correct values for the pair until we do the bcopy.
2680 switch (nvs
->nvs_op
) {
2683 if (native_cp(nvs
, nvp
, nvp
->nvp_size
) != 0)
2690 /* verify nvp_name_sz, check the name string length */
2691 if (i_validate_nvpair_name(nvp
) != 0)
2694 type
= NVP_TYPE(nvp
);
2697 * Verify type and nelem and get the value size.
2698 * In case of data types DATA_TYPE_STRING and DATA_TYPE_STRING_ARRAY
2699 * is the size of the string(s) excluded.
2701 if ((value_sz
= i_get_value_size(type
, NULL
, NVP_NELEM(nvp
))) < 0)
2704 if (NVP_SIZE_CALC(nvp
->nvp_name_sz
, value_sz
) > nvp
->nvp_size
)
2708 case DATA_TYPE_NVLIST
:
2709 ret
= nvpair_native_embedded(nvs
, nvp
);
2711 case DATA_TYPE_NVLIST_ARRAY
:
2712 ret
= nvpair_native_embedded_array(nvs
, nvp
);
2714 case DATA_TYPE_STRING_ARRAY
:
2715 nvpair_native_string_array(nvs
, nvp
);
2725 nvs_native_nvp_size(nvstream_t
*nvs
, nvpair_t
*nvp
, size_t *size
)
2727 uint64_t nvp_sz
= nvp
->nvp_size
;
2729 switch (NVP_TYPE(nvp
)) {
2730 case DATA_TYPE_NVLIST
: {
2733 if (nvs_operation(nvs
, EMBEDDED_NVL(nvp
), &nvsize
) != 0)
2739 case DATA_TYPE_NVLIST_ARRAY
: {
2742 if (nvs_embedded_nvl_array(nvs
, nvp
, &nvsize
) != 0)
2752 if (nvp_sz
> INT32_MAX
)
2761 nvs_native_nvpair(nvstream_t
*nvs
, nvpair_t
*nvp
, size_t *size
)
2763 switch (nvs
->nvs_op
) {
2765 return (nvs_native_nvp_op(nvs
, nvp
));
2767 case NVS_OP_DECODE
: {
2768 nvs_native_t
*native
= (nvs_native_t
*)nvs
->nvs_private
;
2771 /* try to read the size value from the stream */
2772 if (native
->n_curr
+ sizeof (int32_t) > native
->n_end
)
2774 bcopy(native
->n_curr
, &decode_len
, sizeof (int32_t));
2776 /* sanity check the size value */
2777 if (decode_len
< 0 ||
2778 decode_len
> native
->n_end
- native
->n_curr
)
2784 * If at the end of the stream then move the cursor
2785 * forward, otherwise nvpair_native_op() will read
2786 * the entire nvpair at the same cursor position.
2789 native
->n_curr
+= sizeof (int32_t);
2800 static const nvs_ops_t nvs_native_ops
= {
2804 nvs_native_nvp_size
,
2809 nvs_native(nvstream_t
*nvs
, nvlist_t
*nvl
, char *buf
, size_t *buflen
)
2811 nvs_native_t native
;
2814 nvs
->nvs_ops
= &nvs_native_ops
;
2816 if ((err
= nvs_native_create(nvs
, &native
, buf
+ sizeof (nvs_header_t
),
2817 *buflen
- sizeof (nvs_header_t
))) != 0)
2820 err
= nvs_operation(nvs
, nvl
, buflen
);
2822 nvs_native_destroy(nvs
);
2828 * XDR encoding functions
2830 * An xdr packed nvlist is encoded as:
2832 * - encoding methode and host endian (4 bytes)
2833 * - nvl_version (4 bytes)
2834 * - nvl_nvflag (4 bytes)
2836 * - encoded nvpairs, the format of one xdr encoded nvpair is:
2837 * - encoded size of the nvpair (4 bytes)
2838 * - decoded size of the nvpair (4 bytes)
2839 * - name string, (4 + sizeof(NV_ALIGN4(string))
2840 * a string is coded as size (4 bytes) and data
2841 * - data type (4 bytes)
2842 * - number of elements in the nvpair (4 bytes)
2845 * - 2 zero's for end of the entire list (8 bytes)
2848 nvs_xdr_create(nvstream_t
*nvs
, XDR
*xdr
, char *buf
, size_t buflen
)
2850 /* xdr data must be 4 byte aligned */
2851 if ((ulong_t
)buf
% 4 != 0)
2854 switch (nvs
->nvs_op
) {
2856 xdrmem_create(xdr
, buf
, (uint_t
)buflen
, XDR_ENCODE
);
2857 nvs
->nvs_private
= xdr
;
2860 xdrmem_create(xdr
, buf
, (uint_t
)buflen
, XDR_DECODE
);
2861 nvs
->nvs_private
= xdr
;
2863 case NVS_OP_GETSIZE
:
2864 nvs
->nvs_private
= NULL
;
2872 nvs_xdr_destroy(nvstream_t
*nvs
)
2874 switch (nvs
->nvs_op
) {
2877 xdr_destroy((XDR
*)nvs
->nvs_private
);
2885 nvs_xdr_nvlist(nvstream_t
*nvs
, nvlist_t
*nvl
, size_t *size
)
2887 switch (nvs
->nvs_op
) {
2889 case NVS_OP_DECODE
: {
2890 XDR
*xdr
= nvs
->nvs_private
;
2892 if (!xdr_int(xdr
, &nvl
->nvl_version
) ||
2893 !xdr_u_int(xdr
, &nvl
->nvl_nvflag
))
2897 case NVS_OP_GETSIZE
: {
2899 * 2 * 4 for nvl_version + nvl_nvflag
2900 * and 8 for end of the entire list
2912 nvs_xdr_nvl_fini(nvstream_t
*nvs
)
2914 if (nvs
->nvs_op
== NVS_OP_ENCODE
) {
2915 XDR
*xdr
= nvs
->nvs_private
;
2918 if (!xdr_int(xdr
, &zero
) || !xdr_int(xdr
, &zero
))
2926 * The format of xdr encoded nvpair is:
2927 * encode_size, decode_size, name string, data type, nelem, data
2930 nvs_xdr_nvp_op(nvstream_t
*nvs
, nvpair_t
*nvp
)
2934 char *buf_end
= (char *)nvp
+ nvp
->nvp_size
;
2936 uint_t nelem
, buflen
;
2938 XDR
*xdr
= nvs
->nvs_private
;
2940 ASSERT(xdr
!= NULL
&& nvp
!= NULL
);
2943 if ((buf
= NVP_NAME(nvp
)) >= buf_end
)
2945 buflen
= buf_end
- buf
;
2947 if (!xdr_string(xdr
, &buf
, buflen
- 1))
2949 nvp
->nvp_name_sz
= strlen(buf
) + 1;
2951 /* type and nelem */
2952 if (!xdr_int(xdr
, (int *)&nvp
->nvp_type
) ||
2953 !xdr_int(xdr
, &nvp
->nvp_value_elem
))
2956 type
= NVP_TYPE(nvp
);
2957 nelem
= nvp
->nvp_value_elem
;
2960 * Verify type and nelem and get the value size.
2961 * In case of data types DATA_TYPE_STRING and DATA_TYPE_STRING_ARRAY
2962 * is the size of the string(s) excluded.
2964 if ((value_sz
= i_get_value_size(type
, NULL
, nelem
)) < 0)
2967 /* if there is no data to extract then return */
2972 if ((buf
= NVP_VALUE(nvp
)) >= buf_end
)
2974 buflen
= buf_end
- buf
;
2976 if (buflen
< value_sz
)
2980 case DATA_TYPE_NVLIST
:
2981 if (nvs_embedded(nvs
, (void *)buf
) == 0)
2985 case DATA_TYPE_NVLIST_ARRAY
:
2986 if (nvs_embedded_nvl_array(nvs
, nvp
, NULL
) == 0)
2990 case DATA_TYPE_BOOLEAN
:
2994 case DATA_TYPE_BYTE
:
2995 case DATA_TYPE_INT8
:
2996 case DATA_TYPE_UINT8
:
2997 ret
= xdr_char(xdr
, buf
);
3000 case DATA_TYPE_INT16
:
3001 ret
= xdr_short(xdr
, (void *)buf
);
3004 case DATA_TYPE_UINT16
:
3005 ret
= xdr_u_short(xdr
, (void *)buf
);
3008 case DATA_TYPE_BOOLEAN_VALUE
:
3009 case DATA_TYPE_INT32
:
3010 ret
= xdr_int(xdr
, (void *)buf
);
3013 case DATA_TYPE_UINT32
:
3014 ret
= xdr_u_int(xdr
, (void *)buf
);
3017 case DATA_TYPE_INT64
:
3018 ret
= xdr_longlong_t(xdr
, (void *)buf
);
3021 case DATA_TYPE_UINT64
:
3022 ret
= xdr_u_longlong_t(xdr
, (void *)buf
);
3025 case DATA_TYPE_HRTIME
:
3027 * NOTE: must expose the definition of hrtime_t here
3029 ret
= xdr_longlong_t(xdr
, (void *)buf
);
3031 #if !defined(_KERNEL)
3032 case DATA_TYPE_DOUBLE
:
3033 ret
= xdr_double(xdr
, (void *)buf
);
3036 case DATA_TYPE_STRING
:
3037 ret
= xdr_string(xdr
, &buf
, buflen
- 1);
3040 case DATA_TYPE_BYTE_ARRAY
:
3041 ret
= xdr_opaque(xdr
, buf
, nelem
);
3044 case DATA_TYPE_INT8_ARRAY
:
3045 case DATA_TYPE_UINT8_ARRAY
:
3046 ret
= xdr_array(xdr
, &buf
, &nelem
, buflen
, sizeof (int8_t),
3047 (xdrproc_t
)xdr_char
);
3050 case DATA_TYPE_INT16_ARRAY
:
3051 ret
= xdr_array(xdr
, &buf
, &nelem
, buflen
/ sizeof (int16_t),
3052 sizeof (int16_t), (xdrproc_t
)xdr_short
);
3055 case DATA_TYPE_UINT16_ARRAY
:
3056 ret
= xdr_array(xdr
, &buf
, &nelem
, buflen
/ sizeof (uint16_t),
3057 sizeof (uint16_t), (xdrproc_t
)xdr_u_short
);
3060 case DATA_TYPE_BOOLEAN_ARRAY
:
3061 case DATA_TYPE_INT32_ARRAY
:
3062 ret
= xdr_array(xdr
, &buf
, &nelem
, buflen
/ sizeof (int32_t),
3063 sizeof (int32_t), (xdrproc_t
)xdr_int
);
3066 case DATA_TYPE_UINT32_ARRAY
:
3067 ret
= xdr_array(xdr
, &buf
, &nelem
, buflen
/ sizeof (uint32_t),
3068 sizeof (uint32_t), (xdrproc_t
)xdr_u_int
);
3071 case DATA_TYPE_INT64_ARRAY
:
3072 ret
= xdr_array(xdr
, &buf
, &nelem
, buflen
/ sizeof (int64_t),
3073 sizeof (int64_t), (xdrproc_t
)xdr_longlong_t
);
3076 case DATA_TYPE_UINT64_ARRAY
:
3077 ret
= xdr_array(xdr
, &buf
, &nelem
, buflen
/ sizeof (uint64_t),
3078 sizeof (uint64_t), (xdrproc_t
)xdr_u_longlong_t
);
3081 case DATA_TYPE_STRING_ARRAY
: {
3082 size_t len
= nelem
* sizeof (uint64_t);
3083 char **strp
= (void *)buf
;
3086 if (nvs
->nvs_op
== NVS_OP_DECODE
)
3087 bzero(buf
, len
); /* don't trust packed data */
3089 for (i
= 0; i
< nelem
; i
++) {
3096 if (xdr_string(xdr
, &buf
, buflen
- 1) != TRUE
)
3099 if (nvs
->nvs_op
== NVS_OP_DECODE
)
3101 len
= strlen(buf
) + 1;
3110 return (ret
== TRUE
? 0 : EFAULT
);
3114 nvs_xdr_nvp_size(nvstream_t
*nvs
, nvpair_t
*nvp
, size_t *size
)
3116 data_type_t type
= NVP_TYPE(nvp
);
3118 * encode_size + decode_size + name string size + data type + nelem
3119 * where name string size = 4 + NV_ALIGN4(strlen(NVP_NAME(nvp)))
3121 uint64_t nvp_sz
= 4 + 4 + 4 + NV_ALIGN4(strlen(NVP_NAME(nvp
))) + 4 + 4;
3124 case DATA_TYPE_BOOLEAN
:
3127 case DATA_TYPE_BOOLEAN_VALUE
:
3128 case DATA_TYPE_BYTE
:
3129 case DATA_TYPE_INT8
:
3130 case DATA_TYPE_UINT8
:
3131 case DATA_TYPE_INT16
:
3132 case DATA_TYPE_UINT16
:
3133 case DATA_TYPE_INT32
:
3134 case DATA_TYPE_UINT32
:
3135 nvp_sz
+= 4; /* 4 is the minimum xdr unit */
3138 case DATA_TYPE_INT64
:
3139 case DATA_TYPE_UINT64
:
3140 case DATA_TYPE_HRTIME
:
3141 #if !defined(_KERNEL)
3142 case DATA_TYPE_DOUBLE
:
3147 case DATA_TYPE_STRING
:
3148 nvp_sz
+= 4 + NV_ALIGN4(strlen((char *)NVP_VALUE(nvp
)));
3151 case DATA_TYPE_BYTE_ARRAY
:
3152 nvp_sz
+= NV_ALIGN4(NVP_NELEM(nvp
));
3155 case DATA_TYPE_BOOLEAN_ARRAY
:
3156 case DATA_TYPE_INT8_ARRAY
:
3157 case DATA_TYPE_UINT8_ARRAY
:
3158 case DATA_TYPE_INT16_ARRAY
:
3159 case DATA_TYPE_UINT16_ARRAY
:
3160 case DATA_TYPE_INT32_ARRAY
:
3161 case DATA_TYPE_UINT32_ARRAY
:
3162 nvp_sz
+= 4 + 4 * (uint64_t)NVP_NELEM(nvp
);
3165 case DATA_TYPE_INT64_ARRAY
:
3166 case DATA_TYPE_UINT64_ARRAY
:
3167 nvp_sz
+= 4 + 8 * (uint64_t)NVP_NELEM(nvp
);
3170 case DATA_TYPE_STRING_ARRAY
: {
3172 char **strs
= (void *)NVP_VALUE(nvp
);
3174 for (i
= 0; i
< NVP_NELEM(nvp
); i
++)
3175 nvp_sz
+= 4 + NV_ALIGN4(strlen(strs
[i
]));
3180 case DATA_TYPE_NVLIST
:
3181 case DATA_TYPE_NVLIST_ARRAY
: {
3183 int old_nvs_op
= nvs
->nvs_op
;
3186 nvs
->nvs_op
= NVS_OP_GETSIZE
;
3187 if (type
== DATA_TYPE_NVLIST
)
3188 err
= nvs_operation(nvs
, EMBEDDED_NVL(nvp
), &nvsize
);
3190 err
= nvs_embedded_nvl_array(nvs
, nvp
, &nvsize
);
3191 nvs
->nvs_op
= old_nvs_op
;
3204 if (nvp_sz
> INT32_MAX
)
3214 * The NVS_XDR_MAX_LEN macro takes a packed xdr buffer of size x and estimates
3215 * the largest nvpair that could be encoded in the buffer.
3217 * See comments above nvpair_xdr_op() for the format of xdr encoding.
3218 * The size of a xdr packed nvpair without any data is 5 words.
3220 * Using the size of the data directly as an estimate would be ok
3221 * in all cases except one. If the data type is of DATA_TYPE_STRING_ARRAY
3222 * then the actual nvpair has space for an array of pointers to index
3223 * the strings. These pointers are not encoded into the packed xdr buffer.
3225 * If the data is of type DATA_TYPE_STRING_ARRAY and all the strings are
3226 * of length 0, then each string is endcoded in xdr format as a single word.
3227 * Therefore when expanded to an nvpair there will be 2.25 word used for
3228 * each string. (a int64_t allocated for pointer usage, and a single char
3229 * for the null termination.)
3231 * This is the calculation performed by the NVS_XDR_MAX_LEN macro.
3233 #define NVS_XDR_HDR_LEN ((size_t)(5 * 4))
3234 #define NVS_XDR_DATA_LEN(y) (((size_t)(y) <= NVS_XDR_HDR_LEN) ? \
3235 0 : ((size_t)(y) - NVS_XDR_HDR_LEN))
3236 #define NVS_XDR_MAX_LEN(x) (NVP_SIZE_CALC(1, 0) + \
3237 (NVS_XDR_DATA_LEN(x) * 2) + \
3238 NV_ALIGN4((NVS_XDR_DATA_LEN(x) / 4)))
3241 nvs_xdr_nvpair(nvstream_t
*nvs
, nvpair_t
*nvp
, size_t *size
)
3243 XDR
*xdr
= nvs
->nvs_private
;
3244 int32_t encode_len
, decode_len
;
3246 switch (nvs
->nvs_op
) {
3247 case NVS_OP_ENCODE
: {
3250 if (nvs_xdr_nvp_size(nvs
, nvp
, &nvsize
) != 0)
3253 decode_len
= nvp
->nvp_size
;
3254 encode_len
= nvsize
;
3255 if (!xdr_int(xdr
, &encode_len
) || !xdr_int(xdr
, &decode_len
))
3258 return (nvs_xdr_nvp_op(nvs
, nvp
));
3260 case NVS_OP_DECODE
: {
3261 struct xdr_bytesrec bytesrec
;
3263 /* get the encode and decode size */
3264 if (!xdr_int(xdr
, &encode_len
) || !xdr_int(xdr
, &decode_len
))
3268 /* are we at the end of the stream? */
3272 /* sanity check the size parameter */
3273 if (!xdr_control(xdr
, XDR_GET_BYTES_AVAIL
, &bytesrec
))
3276 if (*size
> NVS_XDR_MAX_LEN(bytesrec
.xc_num_avail
))
3287 static const struct nvs_ops nvs_xdr_ops
= {
3296 nvs_xdr(nvstream_t
*nvs
, nvlist_t
*nvl
, char *buf
, size_t *buflen
)
3301 nvs
->nvs_ops
= &nvs_xdr_ops
;
3303 if ((err
= nvs_xdr_create(nvs
, &xdr
, buf
+ sizeof (nvs_header_t
),
3304 *buflen
- sizeof (nvs_header_t
))) != 0)
3307 err
= nvs_operation(nvs
, nvl
, buflen
);
3309 nvs_xdr_destroy(nvs
);
3314 #if defined(_KERNEL) && defined(HAVE_SPL)
3326 module_init(nvpair_init
);
3327 module_exit(nvpair_fini
);
3329 MODULE_DESCRIPTION("Generic name/value pair implementation");
3330 MODULE_AUTHOR(ZFS_META_AUTHOR
);
3331 MODULE_LICENSE(ZFS_META_LICENSE
);
3332 MODULE_VERSION(ZFS_META_VERSION
"-" ZFS_META_RELEASE
);
3334 EXPORT_SYMBOL(nv_alloc_init
);
3335 EXPORT_SYMBOL(nv_alloc_reset
);
3336 EXPORT_SYMBOL(nv_alloc_fini
);
3338 /* list management */
3339 EXPORT_SYMBOL(nvlist_alloc
);
3340 EXPORT_SYMBOL(nvlist_free
);
3341 EXPORT_SYMBOL(nvlist_size
);
3342 EXPORT_SYMBOL(nvlist_pack
);
3343 EXPORT_SYMBOL(nvlist_unpack
);
3344 EXPORT_SYMBOL(nvlist_dup
);
3345 EXPORT_SYMBOL(nvlist_merge
);
3347 EXPORT_SYMBOL(nvlist_xalloc
);
3348 EXPORT_SYMBOL(nvlist_xpack
);
3349 EXPORT_SYMBOL(nvlist_xunpack
);
3350 EXPORT_SYMBOL(nvlist_xdup
);
3351 EXPORT_SYMBOL(nvlist_lookup_nv_alloc
);
3353 EXPORT_SYMBOL(nvlist_add_nvpair
);
3354 EXPORT_SYMBOL(nvlist_add_boolean
);
3355 EXPORT_SYMBOL(nvlist_add_boolean_value
);
3356 EXPORT_SYMBOL(nvlist_add_byte
);
3357 EXPORT_SYMBOL(nvlist_add_int8
);
3358 EXPORT_SYMBOL(nvlist_add_uint8
);
3359 EXPORT_SYMBOL(nvlist_add_int16
);
3360 EXPORT_SYMBOL(nvlist_add_uint16
);
3361 EXPORT_SYMBOL(nvlist_add_int32
);
3362 EXPORT_SYMBOL(nvlist_add_uint32
);
3363 EXPORT_SYMBOL(nvlist_add_int64
);
3364 EXPORT_SYMBOL(nvlist_add_uint64
);
3365 EXPORT_SYMBOL(nvlist_add_string
);
3366 EXPORT_SYMBOL(nvlist_add_nvlist
);
3367 EXPORT_SYMBOL(nvlist_add_boolean_array
);
3368 EXPORT_SYMBOL(nvlist_add_byte_array
);
3369 EXPORT_SYMBOL(nvlist_add_int8_array
);
3370 EXPORT_SYMBOL(nvlist_add_uint8_array
);
3371 EXPORT_SYMBOL(nvlist_add_int16_array
);
3372 EXPORT_SYMBOL(nvlist_add_uint16_array
);
3373 EXPORT_SYMBOL(nvlist_add_int32_array
);
3374 EXPORT_SYMBOL(nvlist_add_uint32_array
);
3375 EXPORT_SYMBOL(nvlist_add_int64_array
);
3376 EXPORT_SYMBOL(nvlist_add_uint64_array
);
3377 EXPORT_SYMBOL(nvlist_add_string_array
);
3378 EXPORT_SYMBOL(nvlist_add_nvlist_array
);
3379 EXPORT_SYMBOL(nvlist_next_nvpair
);
3380 EXPORT_SYMBOL(nvlist_prev_nvpair
);
3381 EXPORT_SYMBOL(nvlist_empty
);
3382 EXPORT_SYMBOL(nvlist_add_hrtime
);
3384 EXPORT_SYMBOL(nvlist_remove
);
3385 EXPORT_SYMBOL(nvlist_remove_nvpair
);
3386 EXPORT_SYMBOL(nvlist_remove_all
);
3388 EXPORT_SYMBOL(nvlist_lookup_boolean
);
3389 EXPORT_SYMBOL(nvlist_lookup_boolean_value
);
3390 EXPORT_SYMBOL(nvlist_lookup_byte
);
3391 EXPORT_SYMBOL(nvlist_lookup_int8
);
3392 EXPORT_SYMBOL(nvlist_lookup_uint8
);
3393 EXPORT_SYMBOL(nvlist_lookup_int16
);
3394 EXPORT_SYMBOL(nvlist_lookup_uint16
);
3395 EXPORT_SYMBOL(nvlist_lookup_int32
);
3396 EXPORT_SYMBOL(nvlist_lookup_uint32
);
3397 EXPORT_SYMBOL(nvlist_lookup_int64
);
3398 EXPORT_SYMBOL(nvlist_lookup_uint64
);
3399 EXPORT_SYMBOL(nvlist_lookup_string
);
3400 EXPORT_SYMBOL(nvlist_lookup_nvlist
);
3401 EXPORT_SYMBOL(nvlist_lookup_boolean_array
);
3402 EXPORT_SYMBOL(nvlist_lookup_byte_array
);
3403 EXPORT_SYMBOL(nvlist_lookup_int8_array
);
3404 EXPORT_SYMBOL(nvlist_lookup_uint8_array
);
3405 EXPORT_SYMBOL(nvlist_lookup_int16_array
);
3406 EXPORT_SYMBOL(nvlist_lookup_uint16_array
);
3407 EXPORT_SYMBOL(nvlist_lookup_int32_array
);
3408 EXPORT_SYMBOL(nvlist_lookup_uint32_array
);
3409 EXPORT_SYMBOL(nvlist_lookup_int64_array
);
3410 EXPORT_SYMBOL(nvlist_lookup_uint64_array
);
3411 EXPORT_SYMBOL(nvlist_lookup_string_array
);
3412 EXPORT_SYMBOL(nvlist_lookup_nvlist_array
);
3413 EXPORT_SYMBOL(nvlist_lookup_hrtime
);
3414 EXPORT_SYMBOL(nvlist_lookup_pairs
);
3416 EXPORT_SYMBOL(nvlist_lookup_nvpair
);
3417 EXPORT_SYMBOL(nvlist_exists
);
3419 /* processing nvpair */
3420 EXPORT_SYMBOL(nvpair_name
);
3421 EXPORT_SYMBOL(nvpair_type
);
3422 EXPORT_SYMBOL(nvpair_value_boolean_value
);
3423 EXPORT_SYMBOL(nvpair_value_byte
);
3424 EXPORT_SYMBOL(nvpair_value_int8
);
3425 EXPORT_SYMBOL(nvpair_value_uint8
);
3426 EXPORT_SYMBOL(nvpair_value_int16
);
3427 EXPORT_SYMBOL(nvpair_value_uint16
);
3428 EXPORT_SYMBOL(nvpair_value_int32
);
3429 EXPORT_SYMBOL(nvpair_value_uint32
);
3430 EXPORT_SYMBOL(nvpair_value_int64
);
3431 EXPORT_SYMBOL(nvpair_value_uint64
);
3432 EXPORT_SYMBOL(nvpair_value_string
);
3433 EXPORT_SYMBOL(nvpair_value_nvlist
);
3434 EXPORT_SYMBOL(nvpair_value_boolean_array
);
3435 EXPORT_SYMBOL(nvpair_value_byte_array
);
3436 EXPORT_SYMBOL(nvpair_value_int8_array
);
3437 EXPORT_SYMBOL(nvpair_value_uint8_array
);
3438 EXPORT_SYMBOL(nvpair_value_int16_array
);
3439 EXPORT_SYMBOL(nvpair_value_uint16_array
);
3440 EXPORT_SYMBOL(nvpair_value_int32_array
);
3441 EXPORT_SYMBOL(nvpair_value_uint32_array
);
3442 EXPORT_SYMBOL(nvpair_value_int64_array
);
3443 EXPORT_SYMBOL(nvpair_value_uint64_array
);
3444 EXPORT_SYMBOL(nvpair_value_string_array
);
3445 EXPORT_SYMBOL(nvpair_value_nvlist_array
);
3446 EXPORT_SYMBOL(nvpair_value_hrtime
);