2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2009-2013 The FreeBSD Foundation
5 * Copyright (c) 2013-2015 Mariusz Zaborski <oshogbo@FreeBSD.org>
8 * This software was developed by Pawel Jakub Dawidek under sponsorship from
9 * the FreeBSD Foundation.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <sys/param.h>
37 #include <sys/endian.h>
38 #include <sys/queue.h>
42 #include <sys/errno.h>
43 #include <sys/kernel.h>
45 #include <sys/malloc.h>
46 #include <sys/systm.h>
48 #include <machine/stdarg.h>
51 #include <sys/socket.h>
72 #include "nvlist_impl.h"
73 #include "nvpair_impl.h"
77 #define PJDLOG_ASSERT(...) MPASS(__VA_ARGS__)
78 #define PJDLOG_RASSERT(expr, ...) KASSERT(expr, (__VA_ARGS__))
79 #define PJDLOG_ABORT(...) panic(__VA_ARGS__)
82 #define PJDLOG_ASSERT(...) assert(__VA_ARGS__)
83 #define PJDLOG_RASSERT(expr, ...) assert(expr)
84 #define PJDLOG_ABORT(...) do { \
85 fprintf(stderr, "%s:%u: ", __FILE__, __LINE__); \
86 fprintf(stderr, __VA_ARGS__); \
87 fprintf(stderr, "\n"); \
93 #define NV_FLAG_PRIVATE_MASK (NV_FLAG_BIG_ENDIAN | NV_FLAG_IN_ARRAY)
94 #define NV_FLAG_PUBLIC_MASK (NV_FLAG_IGNORE_CASE | NV_FLAG_NO_UNIQUE)
95 #define NV_FLAG_ALL_MASK (NV_FLAG_PRIVATE_MASK | NV_FLAG_PUBLIC_MASK)
97 #define NVLIST_MAGIC 0x6e766c /* "nvl" */
103 nvpair_t *nvl_parent;
104 nvpair_t *nvl_array_next;
105 struct nvl_head nvl_head;
108 #define NVLIST_ASSERT(nvl) do { \
109 PJDLOG_ASSERT((nvl) != NULL); \
110 PJDLOG_ASSERT((nvl)->nvl_magic == NVLIST_MAGIC); \
114 MALLOC_DEFINE(M_NVLIST, "nvlist", "kernel nvlist");
117 #define NVPAIR_ASSERT(nvp) nvpair_assert(nvp)
119 #define NVLIST_HEADER_MAGIC 0x6c
120 #define NVLIST_HEADER_VERSION 0x00
121 struct nvlist_header {
123 uint8_t nvlh_version;
125 uint64_t nvlh_descriptors;
130 nvlist_create(int flags)
134 PJDLOG_ASSERT((flags & ~(NV_FLAG_PUBLIC_MASK)) == 0);
136 nvl = nv_malloc(sizeof(*nvl));
140 nvl->nvl_flags = flags;
141 nvl->nvl_parent = NULL;
142 nvl->nvl_array_next = NULL;
143 nvl->nvl_datasize = sizeof(struct nvlist_header);
144 TAILQ_INIT(&nvl->nvl_head);
145 nvl->nvl_magic = NVLIST_MAGIC;
151 nvlist_destroy(nvlist_t *nvl)
162 while ((nvp = nvlist_first_nvpair(nvl)) != NULL) {
163 nvlist_remove_nvpair(nvl, nvp);
166 if (nvl->nvl_array_next != NULL)
167 nvpair_free_structure(nvl->nvl_array_next);
168 nvl->nvl_array_next = NULL;
169 nvl->nvl_parent = NULL;
177 nvlist_set_error(nvlist_t *nvl, int error)
180 PJDLOG_ASSERT(error != 0);
183 * Check for error != 0 so that we don't do the wrong thing if somebody
184 * tries to abuse this API when asserts are disabled.
186 if (nvl != NULL && error != 0 && nvl->nvl_error == 0)
187 nvl->nvl_error = error;
191 nvlist_error(const nvlist_t *nvl)
199 return (nvl->nvl_error);
203 nvlist_get_nvpair_parent(const nvlist_t *nvl)
208 return (nvl->nvl_parent);
212 nvlist_get_parent(const nvlist_t *nvl, void **cookiep)
218 nvp = nvl->nvl_parent;
224 return (nvpair_nvlist(nvp));
228 nvlist_set_parent(nvlist_t *nvl, nvpair_t *parent)
233 nvl->nvl_parent = parent;
237 nvlist_set_array_next(nvlist_t *nvl, nvpair_t *ele)
243 nvl->nvl_flags |= NV_FLAG_IN_ARRAY;
245 nvl->nvl_flags &= ~NV_FLAG_IN_ARRAY;
246 nv_free(nvl->nvl_array_next);
249 nvl->nvl_array_next = ele;
253 nvlist_update_size(nvlist_t *nvl, nvpair_t *new, ssize_t mul)
257 const nvlist_t *nvlistnew;
258 const nvlist_t * const *nvlarray;
264 PJDLOG_ASSERT(mul == 1 || mul == -1);
266 size = nvpair_header_size();
267 size += strlen(nvpair_name(new)) + 1;
269 if (nvpair_type(new) == NV_TYPE_NVLIST) {
270 nvlistnew = nvpair_get_nvlist(new);
271 size += nvlistnew->nvl_datasize;
272 size += nvpair_header_size() + 1;
273 } else if (nvpair_type(new) == NV_TYPE_NVLIST_ARRAY) {
274 nvlarray = nvpair_get_nvlist_array(new, &nitems);
275 PJDLOG_ASSERT(nitems > 0);
277 size += (nvpair_header_size() + 1) * nitems;
278 for (ii = 0; ii < nitems; ii++) {
279 PJDLOG_ASSERT(nvlarray[ii]->nvl_error == 0);
280 size += nvlarray[ii]->nvl_datasize;
283 size += nvpair_size(new);
288 nvl->nvl_datasize += size;
291 while ((parent = __DECONST(nvlist_t *,
292 nvlist_get_parent(parent, NULL))) != NULL) {
293 parent->nvl_datasize += size;
298 nvlist_get_array_next_nvpair(nvlist_t *nvl)
303 return (nvl->nvl_array_next);
307 nvlist_in_array(const nvlist_t *nvl)
312 return ((nvl->nvl_flags & NV_FLAG_IN_ARRAY) != 0);
316 nvlist_get_array_next(const nvlist_t *nvl)
322 nvp = nvl->nvl_array_next;
326 return (nvpair_get_nvlist(nvp));
330 nvlist_get_pararr(const nvlist_t *nvl, void **cookiep)
334 ret = nvlist_get_array_next(nvl);
341 return (nvlist_get_parent(nvl, cookiep));
345 nvlist_empty(const nvlist_t *nvl)
349 PJDLOG_ASSERT(nvl->nvl_error == 0);
351 return (nvlist_first_nvpair(nvl) == NULL);
355 nvlist_flags(const nvlist_t *nvl)
359 PJDLOG_ASSERT(nvl->nvl_error == 0);
361 return (nvl->nvl_flags & NV_FLAG_PUBLIC_MASK);
365 nvlist_set_flags(nvlist_t *nvl, int flags)
369 PJDLOG_ASSERT(nvl->nvl_error == 0);
371 nvl->nvl_flags = flags;
375 nvlist_report_missing(int type, const char *name)
378 PJDLOG_ABORT("Element '%s' of type %s doesn't exist.",
379 name, nvpair_type_string(type));
383 nvlist_find(const nvlist_t *nvl, int type, const char *name)
388 PJDLOG_ASSERT(nvl->nvl_error == 0);
389 PJDLOG_ASSERT(type == NV_TYPE_NONE ||
390 (type >= NV_TYPE_FIRST && type <= NV_TYPE_LAST));
392 for (nvp = nvlist_first_nvpair(nvl); nvp != NULL;
393 nvp = nvlist_next_nvpair(nvl, nvp)) {
394 if (type != NV_TYPE_NONE && nvpair_type(nvp) != type)
396 if ((nvl->nvl_flags & NV_FLAG_IGNORE_CASE) != 0) {
397 if (strcasecmp(nvpair_name(nvp), name) != 0)
400 if (strcmp(nvpair_name(nvp), name) != 0)
413 nvlist_exists_type(const nvlist_t *nvl, const char *name, int type)
417 PJDLOG_ASSERT(nvl->nvl_error == 0);
418 PJDLOG_ASSERT(type == NV_TYPE_NONE ||
419 (type >= NV_TYPE_FIRST && type <= NV_TYPE_LAST));
421 return (nvlist_find(nvl, type, name) != NULL);
425 nvlist_free_type(nvlist_t *nvl, const char *name, int type)
430 PJDLOG_ASSERT(nvl->nvl_error == 0);
431 PJDLOG_ASSERT(type == NV_TYPE_NONE ||
432 (type >= NV_TYPE_FIRST && type <= NV_TYPE_LAST));
434 nvp = nvlist_find(nvl, type, name);
436 nvlist_free_nvpair(nvl, nvp);
438 nvlist_report_missing(type, name);
442 nvlist_clone(const nvlist_t *nvl)
445 nvpair_t *nvp, *newnvp;
449 if (nvl->nvl_error != 0) {
450 ERRNO_SET(nvl->nvl_error);
454 newnvl = nvlist_create(nvl->nvl_flags & NV_FLAG_PUBLIC_MASK);
455 for (nvp = nvlist_first_nvpair(nvl); nvp != NULL;
456 nvp = nvlist_next_nvpair(nvl, nvp)) {
457 newnvp = nvpair_clone(nvp);
460 (void)nvlist_move_nvpair(newnvl, newnvp);
463 nvlist_destroy(newnvl);
471 nvlist_dump_error_check(const nvlist_t *nvl, int fd, int level)
474 if (nvlist_error(nvl) != 0) {
475 dprintf(fd, "%*serror: %d\n", level * 4, "",
484 * Dump content of nvlist.
487 nvlist_dump(const nvlist_t *nvl, int fd)
489 const nvlist_t *tmpnvl;
490 nvpair_t *nvp, *tmpnvp;
495 if (nvlist_dump_error_check(nvl, fd, level))
498 nvp = nvlist_first_nvpair(nvl);
499 while (nvp != NULL) {
500 dprintf(fd, "%*s%s (%s):", level * 4, "", nvpair_name(nvp),
501 nvpair_type_string(nvpair_type(nvp)));
502 switch (nvpair_type(nvp)) {
504 dprintf(fd, " null\n");
507 dprintf(fd, " %s\n", nvpair_get_bool(nvp) ?
511 dprintf(fd, " %ju (%jd) (0x%jx)\n",
512 (uintmax_t)nvpair_get_number(nvp),
513 (intmax_t)nvpair_get_number(nvp),
514 (uintmax_t)nvpair_get_number(nvp));
517 dprintf(fd, " [%s]\n", nvpair_get_string(nvp));
521 tmpnvl = nvpair_get_nvlist(nvp);
522 if (nvlist_dump_error_check(tmpnvl, fd, level + 1))
524 tmpnvp = nvlist_first_nvpair(tmpnvl);
525 if (tmpnvp != NULL) {
532 case NV_TYPE_DESCRIPTOR:
533 dprintf(fd, " %d\n", nvpair_get_descriptor(nvp));
537 const unsigned char *binary;
541 binary = nvpair_get_binary(nvp, &size);
542 dprintf(fd, " %zu ", size);
543 for (ii = 0; ii < size; ii++)
544 dprintf(fd, "%02hhx", binary[ii]);
548 case NV_TYPE_BOOL_ARRAY:
554 value = nvpair_get_bool_array(nvp, &nitems);
556 for (ii = 0; ii < nitems; ii++) {
557 dprintf(fd, "%s", value[ii] ? "TRUE" : "FALSE");
558 if (ii != nitems - 1)
564 case NV_TYPE_STRING_ARRAY:
566 const char * const *value;
570 value = nvpair_get_string_array(nvp, &nitems);
572 for (ii = 0; ii < nitems; ii++) {
573 if (value[ii] == NULL)
576 dprintf(fd, "\"%s\"", value[ii]);
577 if (ii != nitems - 1)
583 case NV_TYPE_NUMBER_ARRAY:
585 const uint64_t *value;
589 value = nvpair_get_number_array(nvp, &nitems);
591 for (ii = 0; ii < nitems; ii++) {
592 dprintf(fd, "%ju (%jd) (0x%jx)",
593 value[ii], value[ii], value[ii]);
594 if (ii != nitems - 1)
600 case NV_TYPE_DESCRIPTOR_ARRAY:
606 value = nvpair_get_descriptor_array(nvp, &nitems);
608 for (ii = 0; ii < nitems; ii++) {
609 dprintf(fd, "%d", value[ii]);
610 if (ii != nitems - 1)
616 case NV_TYPE_NVLIST_ARRAY:
618 const nvlist_t * const *value;
622 value = nvpair_get_nvlist_array(nvp, &nitems);
623 dprintf(fd, " %zu\n", nitems);
626 for (ii = 0; ii < nitems; ii++) {
627 if (nvlist_dump_error_check(value[ii], fd,
632 if (tmpnvl == NULL) {
633 tmpnvp = nvlist_first_nvpair(value[ii]);
634 if (tmpnvp != NULL) {
637 dprintf(fd, "%*s,\n",
638 (level + 1) * 4, "");
642 if (tmpnvp != NULL) {
651 PJDLOG_ABORT("Unknown type: %d.", nvpair_type(nvp));
654 while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
657 if (nvlist_in_array(nvl))
658 dprintf(fd, "%*s,\n", level * 4, "");
659 nvl = nvlist_get_pararr(nvl, &cookie);
662 if (nvlist_in_array(nvl) && cookie == NULL) {
663 nvp = nvlist_first_nvpair(nvl);
668 } while (nvp == NULL);
669 if (nvlist_in_array(nvl) && cookie == NULL)
676 nvlist_fdump(const nvlist_t *nvl, FILE *fp)
680 nvlist_dump(nvl, fileno(fp));
685 * The function obtains size of the nvlist after nvlist_pack().
688 nvlist_size(const nvlist_t *nvl)
691 return (nvl->nvl_datasize);
696 nvlist_xdescriptors(const nvlist_t *nvl, int *descs)
703 PJDLOG_ASSERT(nvl->nvl_error == 0);
707 while (nvlist_next(nvl, &type, &cookie) != NULL) {
710 case NV_TYPE_DESCRIPTOR:
711 *descs = nvpair_get_descriptor(nvp);
714 case NV_TYPE_DESCRIPTOR_ARRAY:
720 value = nvpair_get_descriptor_array(nvp,
722 for (ii = 0; ii < nitems; ii++) {
729 nvl = nvpair_get_nvlist(nvp);
732 case NV_TYPE_NVLIST_ARRAY:
734 const nvlist_t * const *value;
737 value = nvpair_get_nvlist_array(nvp, &nitems);
738 PJDLOG_ASSERT(value != NULL);
739 PJDLOG_ASSERT(nitems > 0);
747 } while ((nvl = nvlist_get_pararr(nvl, &cookie)) != NULL);
755 nvlist_descriptors(const nvlist_t *nvl, size_t *nitemsp)
760 nitems = nvlist_ndescriptors(nvl);
761 fds = nv_malloc(sizeof(fds[0]) * (nitems + 1));
765 nvlist_xdescriptors(nvl, fds);
774 nvlist_ndescriptors(const nvlist_t *nvl)
783 PJDLOG_ASSERT(nvl->nvl_error == 0);
788 while (nvlist_next(nvl, &type, &cookie) != NULL) {
791 case NV_TYPE_DESCRIPTOR:
795 nvl = nvpair_get_nvlist(nvp);
798 case NV_TYPE_NVLIST_ARRAY:
800 const nvlist_t * const *value;
803 value = nvpair_get_nvlist_array(nvp, &nitems);
804 PJDLOG_ASSERT(value != NULL);
805 PJDLOG_ASSERT(nitems > 0);
811 case NV_TYPE_DESCRIPTOR_ARRAY:
815 (void)nvpair_get_descriptor_array(nvp,
822 } while ((nvl = nvlist_get_pararr(nvl, &cookie)) != NULL);
830 static unsigned char *
831 nvlist_pack_header(const nvlist_t *nvl, unsigned char *ptr, size_t *leftp)
833 struct nvlist_header nvlhdr;
837 nvlhdr.nvlh_magic = NVLIST_HEADER_MAGIC;
838 nvlhdr.nvlh_version = NVLIST_HEADER_VERSION;
839 nvlhdr.nvlh_flags = nvl->nvl_flags;
840 #if BYTE_ORDER == BIG_ENDIAN
841 nvlhdr.nvlh_flags |= NV_FLAG_BIG_ENDIAN;
843 nvlhdr.nvlh_descriptors = nvlist_ndescriptors(nvl);
844 nvlhdr.nvlh_size = *leftp - sizeof(nvlhdr);
845 PJDLOG_ASSERT(*leftp >= sizeof(nvlhdr));
846 memcpy(ptr, &nvlhdr, sizeof(nvlhdr));
847 ptr += sizeof(nvlhdr);
848 *leftp -= sizeof(nvlhdr);
854 nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep)
856 unsigned char *buf, *ptr;
858 const nvlist_t *tmpnvl;
859 nvpair_t *nvp, *tmpnvp;
864 if (nvl->nvl_error != 0) {
865 ERRNO_SET(nvl->nvl_error);
869 size = nvlist_size(nvl);
870 buf = nv_malloc(size);
877 ptr = nvlist_pack_header(nvl, ptr, &left);
879 nvp = nvlist_first_nvpair(nvl);
880 while (nvp != NULL) {
883 nvpair_init_datasize(nvp);
884 ptr = nvpair_pack_header(nvp, ptr, &left);
887 switch (nvpair_type(nvp)) {
889 ptr = nvpair_pack_null(nvp, ptr, &left);
892 ptr = nvpair_pack_bool(nvp, ptr, &left);
895 ptr = nvpair_pack_number(nvp, ptr, &left);
898 ptr = nvpair_pack_string(nvp, ptr, &left);
901 tmpnvl = nvpair_get_nvlist(nvp);
902 ptr = nvlist_pack_header(tmpnvl, ptr, &left);
905 tmpnvp = nvlist_first_nvpair(tmpnvl);
906 if (tmpnvp != NULL) {
911 ptr = nvpair_pack_nvlist_up(ptr, &left);
914 case NV_TYPE_DESCRIPTOR:
915 ptr = nvpair_pack_descriptor(nvp, ptr, fdidxp, &left);
917 case NV_TYPE_DESCRIPTOR_ARRAY:
918 ptr = nvpair_pack_descriptor_array(nvp, ptr, fdidxp,
923 ptr = nvpair_pack_binary(nvp, ptr, &left);
925 case NV_TYPE_BOOL_ARRAY:
926 ptr = nvpair_pack_bool_array(nvp, ptr, &left);
928 case NV_TYPE_NUMBER_ARRAY:
929 ptr = nvpair_pack_number_array(nvp, ptr, &left);
931 case NV_TYPE_STRING_ARRAY:
932 ptr = nvpair_pack_string_array(nvp, ptr, &left);
934 case NV_TYPE_NVLIST_ARRAY:
936 const nvlist_t * const * value;
941 value = nvpair_get_nvlist_array(nvp, &nitems);
942 for (ii = 0; ii < nitems; ii++) {
943 ptr = nvlist_pack_header(value[ii], ptr, &left);
946 tmpnvp = nvlist_first_nvpair(value[ii]);
947 if (tmpnvp != NULL) {
951 ptr = nvpair_pack_nvlist_array_next(ptr, &left);
955 if (tmpnvl != NULL) {
963 PJDLOG_ABORT("Invalid type (%d).", nvpair_type(nvp));
967 while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
970 if (nvlist_in_array(nvl)) {
971 ptr = nvpair_pack_nvlist_array_next(ptr,
976 nvl = nvlist_get_pararr(nvl, &cookie);
979 if (nvlist_in_array(nvl) && cookie == NULL) {
980 nvp = nvlist_first_nvpair(nvl);
981 ptr = nvlist_pack_header(nvl, ptr,
985 } else if (nvpair_type((nvpair_t *)cookie) !=
986 NV_TYPE_NVLIST_ARRAY) {
987 ptr = nvpair_pack_nvlist_up(ptr, &left);
994 } while (nvp == NULL);
995 if (nvlist_in_array(nvl) && cookie == NULL)
1010 nvlist_pack(const nvlist_t *nvl, size_t *sizep)
1015 if (nvl->nvl_error != 0) {
1016 ERRNO_SET(nvl->nvl_error);
1020 if (nvlist_ndescriptors(nvl) > 0) {
1021 ERRNO_SET(EOPNOTSUPP);
1025 return (nvlist_xpack(nvl, NULL, sizep));
1029 nvlist_check_header(struct nvlist_header *nvlhdrp)
1032 if (nvlhdrp->nvlh_magic != NVLIST_HEADER_MAGIC) {
1036 if ((nvlhdrp->nvlh_flags & ~NV_FLAG_ALL_MASK) != 0) {
1040 #if BYTE_ORDER == BIG_ENDIAN
1041 if ((nvlhdrp->nvlh_flags & NV_FLAG_BIG_ENDIAN) == 0) {
1042 nvlhdrp->nvlh_size = le64toh(nvlhdrp->nvlh_size);
1043 nvlhdrp->nvlh_descriptors = le64toh(nvlhdrp->nvlh_descriptors);
1046 if ((nvlhdrp->nvlh_flags & NV_FLAG_BIG_ENDIAN) != 0) {
1047 nvlhdrp->nvlh_size = be64toh(nvlhdrp->nvlh_size);
1048 nvlhdrp->nvlh_descriptors = be64toh(nvlhdrp->nvlh_descriptors);
1054 const unsigned char *
1055 nvlist_unpack_header(nvlist_t *nvl, const unsigned char *ptr, size_t nfds,
1056 bool *isbep, size_t *leftp)
1058 struct nvlist_header nvlhdr;
1061 if (*leftp < sizeof(nvlhdr))
1064 memcpy(&nvlhdr, ptr, sizeof(nvlhdr));
1066 if (!nvlist_check_header(&nvlhdr))
1069 if (nvlhdr.nvlh_size != *leftp - sizeof(nvlhdr))
1073 * nvlh_descriptors might be smaller than nfds in embedded nvlists.
1075 if (nvlhdr.nvlh_descriptors > nfds)
1078 if ((nvlhdr.nvlh_flags & ~NV_FLAG_ALL_MASK) != 0)
1081 inarrayf = (nvl->nvl_flags & NV_FLAG_IN_ARRAY);
1082 nvl->nvl_flags = (nvlhdr.nvlh_flags & NV_FLAG_PUBLIC_MASK) | inarrayf;
1084 ptr += sizeof(nvlhdr);
1086 *isbep = (((int)nvlhdr.nvlh_flags & NV_FLAG_BIG_ENDIAN) != 0);
1087 *leftp -= sizeof(nvlhdr);
1096 nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds,
1099 const unsigned char *ptr;
1100 nvlist_t *nvl, *retnvl, *tmpnvl, *array;
1105 PJDLOG_ASSERT((flags & ~(NV_FLAG_PUBLIC_MASK)) == 0);
1110 tmpnvl = array = NULL;
1111 nvl = retnvl = nvlist_create(0);
1115 ptr = nvlist_unpack_header(nvl, ptr, nfds, &isbe, &left);
1118 if (nvl->nvl_flags != flags) {
1124 ptr = nvpair_unpack(isbe, ptr, &left, &nvp);
1127 switch (nvpair_type(nvp)) {
1129 ptr = nvpair_unpack_null(isbe, nvp, ptr, &left);
1132 ptr = nvpair_unpack_bool(isbe, nvp, ptr, &left);
1134 case NV_TYPE_NUMBER:
1135 ptr = nvpair_unpack_number(isbe, nvp, ptr, &left);
1137 case NV_TYPE_STRING:
1138 ptr = nvpair_unpack_string(isbe, nvp, ptr, &left);
1140 case NV_TYPE_NVLIST:
1141 ptr = nvpair_unpack_nvlist(isbe, nvp, ptr, &left, nfds,
1143 if (tmpnvl == NULL || ptr == NULL)
1145 nvlist_set_parent(tmpnvl, nvp);
1148 case NV_TYPE_DESCRIPTOR:
1149 ptr = nvpair_unpack_descriptor(isbe, nvp, ptr, &left,
1152 case NV_TYPE_DESCRIPTOR_ARRAY:
1153 ptr = nvpair_unpack_descriptor_array(isbe, nvp, ptr,
1157 case NV_TYPE_BINARY:
1158 ptr = nvpair_unpack_binary(isbe, nvp, ptr, &left);
1160 case NV_TYPE_NVLIST_UP:
1161 if (nvl->nvl_parent == NULL)
1163 nvl = nvpair_nvlist(nvl->nvl_parent);
1164 nvpair_free_structure(nvp);
1166 case NV_TYPE_NVLIST_ARRAY_NEXT:
1167 if (nvl->nvl_array_next == NULL) {
1168 if (nvl->nvl_parent == NULL)
1170 nvl = nvpair_nvlist(nvl->nvl_parent);
1172 nvl = __DECONST(nvlist_t *,
1173 nvlist_get_array_next(nvl));
1174 ptr = nvlist_unpack_header(nvl, ptr, nfds,
1179 nvpair_free_structure(nvp);
1181 case NV_TYPE_BOOL_ARRAY:
1182 ptr = nvpair_unpack_bool_array(isbe, nvp, ptr, &left);
1184 case NV_TYPE_NUMBER_ARRAY:
1185 ptr = nvpair_unpack_number_array(isbe, nvp, ptr, &left);
1187 case NV_TYPE_STRING_ARRAY:
1188 ptr = nvpair_unpack_string_array(isbe, nvp, ptr, &left);
1190 case NV_TYPE_NVLIST_ARRAY:
1191 ptr = nvpair_unpack_nvlist_array(isbe, nvp, ptr, &left,
1195 PJDLOG_ASSERT(array != NULL);
1198 nvlist_set_parent(array, nvp);
1199 array = __DECONST(nvlist_t *,
1200 nvlist_get_array_next(array));
1201 } while (array != NULL);
1202 ptr = nvlist_unpack_header(tmpnvl, ptr, nfds, &isbe,
1206 PJDLOG_ABORT("Invalid type (%d).", nvpair_type(nvp));
1210 if (!nvlist_move_nvpair(nvl, nvp))
1212 if (tmpnvl != NULL) {
1220 nvlist_destroy(retnvl);
1225 nvlist_unpack(const void *buf, size_t size, int flags)
1228 return (nvlist_xunpack(buf, size, NULL, 0, flags));
1233 nvlist_send(int sock, const nvlist_t *nvl)
1235 size_t datasize, nfds;
1241 if (nvlist_error(nvl) != 0) {
1242 ERRNO_SET(nvlist_error(nvl));
1246 fds = nvlist_descriptors(nvl, &nfds);
1253 data = nvlist_xpack(nvl, &fdidx, &datasize);
1257 if (buf_send(sock, data, datasize) == -1)
1261 if (fd_send(sock, fds, nfds) == -1)
1275 nvlist_recv(int sock, int flags)
1277 struct nvlist_header nvlhdr;
1278 nvlist_t *nvl, *ret;
1280 size_t nfds, size, i, offset;
1281 int *fds, soflags, sotype;
1284 solen = sizeof(sotype);
1285 if (getsockopt(sock, SOL_SOCKET, SO_TYPE, &sotype, &solen) != 0)
1288 soflags = sotype == SOCK_DGRAM ? MSG_PEEK : 0;
1289 if (buf_recv(sock, &nvlhdr, sizeof(nvlhdr), soflags) == -1)
1292 if (!nvlist_check_header(&nvlhdr))
1295 nfds = (size_t)nvlhdr.nvlh_descriptors;
1296 size = sizeof(nvlhdr) + (size_t)nvlhdr.nvlh_size;
1298 buf = nv_malloc(size);
1305 if (sotype == SOCK_DGRAM)
1308 memcpy(buf, &nvlhdr, sizeof(nvlhdr));
1309 offset = sizeof(nvlhdr);
1312 if (buf_recv(sock, buf + offset, size - offset, 0) == -1)
1316 fds = nv_malloc(nfds * sizeof(fds[0]));
1319 if (fd_recv(sock, fds, nfds) == -1)
1323 nvl = nvlist_xunpack(buf, size, fds, nfds, flags);
1326 for (i = 0; i < nfds; i++)
1343 nvlist_xfer(int sock, nvlist_t *nvl, int flags)
1346 if (nvlist_send(sock, nvl) < 0) {
1347 nvlist_destroy(nvl);
1350 nvlist_destroy(nvl);
1351 return (nvlist_recv(sock, flags));
1356 nvlist_first_nvpair(const nvlist_t *nvl)
1361 return (TAILQ_FIRST(&nvl->nvl_head));
1365 nvlist_next_nvpair(const nvlist_t *nvl __unused, const nvpair_t *nvp)
1371 PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
1373 retnvp = nvpair_next(nvp);
1374 PJDLOG_ASSERT(retnvp == NULL || nvpair_nvlist(retnvp) == nvl);
1381 nvlist_prev_nvpair(const nvlist_t *nvl __unused, const nvpair_t *nvp)
1387 PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
1389 retnvp = nvpair_prev(nvp);
1390 PJDLOG_ASSERT(nvpair_nvlist(retnvp) == nvl);
1396 nvlist_next(const nvlist_t *nvl, int *typep, void **cookiep)
1402 if (cookiep == NULL || *cookiep == NULL)
1403 nvp = nvlist_first_nvpair(nvl);
1405 nvp = nvlist_next_nvpair(nvl, *cookiep);
1409 *typep = nvpair_type(nvp);
1410 if (cookiep != NULL)
1412 return (nvpair_name(nvp));
1416 nvlist_exists(const nvlist_t *nvl, const char *name)
1419 return (nvlist_find(nvl, NV_TYPE_NONE, name) != NULL);
1422 #define NVLIST_EXISTS(type, TYPE) \
1424 nvlist_exists_##type(const nvlist_t *nvl, const char *name) \
1427 return (nvlist_find(nvl, NV_TYPE_##TYPE, name) != NULL); \
1430 NVLIST_EXISTS(null, NULL)
1431 NVLIST_EXISTS(bool, BOOL)
1432 NVLIST_EXISTS(number, NUMBER)
1433 NVLIST_EXISTS(string, STRING)
1434 NVLIST_EXISTS(nvlist, NVLIST)
1435 NVLIST_EXISTS(binary, BINARY)
1436 NVLIST_EXISTS(bool_array, BOOL_ARRAY)
1437 NVLIST_EXISTS(number_array, NUMBER_ARRAY)
1438 NVLIST_EXISTS(string_array, STRING_ARRAY)
1439 NVLIST_EXISTS(nvlist_array, NVLIST_ARRAY)
1441 NVLIST_EXISTS(descriptor, DESCRIPTOR)
1442 NVLIST_EXISTS(descriptor_array, DESCRIPTOR_ARRAY)
1445 #undef NVLIST_EXISTS
1448 nvlist_add_nvpair(nvlist_t *nvl, const nvpair_t *nvp)
1454 if (nvlist_error(nvl) != 0) {
1455 ERRNO_SET(nvlist_error(nvl));
1458 if ((nvl->nvl_flags & NV_FLAG_NO_UNIQUE) == 0) {
1459 if (nvlist_exists(nvl, nvpair_name(nvp))) {
1460 nvl->nvl_error = EEXIST;
1461 ERRNO_SET(nvlist_error(nvl));
1466 newnvp = nvpair_clone(nvp);
1467 if (newnvp == NULL) {
1468 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1469 ERRNO_SET(nvlist_error(nvl));
1473 nvpair_insert(&nvl->nvl_head, newnvp, nvl);
1474 nvlist_update_size(nvl, newnvp, 1);
1478 nvlist_add_stringf(nvlist_t *nvl, const char *name, const char *valuefmt, ...)
1482 va_start(valueap, valuefmt);
1483 nvlist_add_stringv(nvl, name, valuefmt, valueap);
1488 nvlist_add_stringv(nvlist_t *nvl, const char *name, const char *valuefmt,
1493 if (nvlist_error(nvl) != 0) {
1494 ERRNO_SET(nvlist_error(nvl));
1498 nvp = nvpair_create_stringv(name, valuefmt, valueap);
1500 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1501 ERRNO_SET(nvl->nvl_error);
1503 (void)nvlist_move_nvpair(nvl, nvp);
1508 nvlist_add_null(nvlist_t *nvl, const char *name)
1512 if (nvlist_error(nvl) != 0) {
1513 ERRNO_SET(nvlist_error(nvl));
1517 nvp = nvpair_create_null(name);
1519 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1520 ERRNO_SET(nvl->nvl_error);
1522 (void)nvlist_move_nvpair(nvl, nvp);
1527 nvlist_add_binary(nvlist_t *nvl, const char *name, const void *value,
1532 if (nvlist_error(nvl) != 0) {
1533 ERRNO_SET(nvlist_error(nvl));
1537 nvp = nvpair_create_binary(name, value, size);
1539 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1540 ERRNO_SET(nvl->nvl_error);
1542 (void)nvlist_move_nvpair(nvl, nvp);
1547 #define NVLIST_ADD(vtype, type) \
1549 nvlist_add_##type(nvlist_t *nvl, const char *name, vtype value) \
1553 if (nvlist_error(nvl) != 0) { \
1554 ERRNO_SET(nvlist_error(nvl)); \
1558 nvp = nvpair_create_##type(name, value); \
1559 if (nvp == NULL) { \
1560 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); \
1561 ERRNO_SET(nvl->nvl_error); \
1563 (void)nvlist_move_nvpair(nvl, nvp); \
1567 NVLIST_ADD(bool, bool)
1568 NVLIST_ADD(uint64_t, number)
1569 NVLIST_ADD(const char *, string)
1570 NVLIST_ADD(const nvlist_t *, nvlist)
1572 NVLIST_ADD(int, descriptor);
1577 #define NVLIST_ADD_ARRAY(vtype, type) \
1579 nvlist_add_##type##_array(nvlist_t *nvl, const char *name, vtype value, \
1584 if (nvlist_error(nvl) != 0) { \
1585 ERRNO_SET(nvlist_error(nvl)); \
1589 nvp = nvpair_create_##type##_array(name, value, nitems); \
1590 if (nvp == NULL) { \
1591 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); \
1592 ERRNO_SET(nvl->nvl_error); \
1594 (void)nvlist_move_nvpair(nvl, nvp); \
1598 NVLIST_ADD_ARRAY(const bool *, bool)
1599 NVLIST_ADD_ARRAY(const uint64_t *, number)
1600 NVLIST_ADD_ARRAY(const char * const *, string)
1601 NVLIST_ADD_ARRAY(const nvlist_t * const *, nvlist)
1603 NVLIST_ADD_ARRAY(const int *, descriptor)
1606 #undef NVLIST_ADD_ARRAY
1608 #define NVLIST_APPEND_ARRAY(vtype, type, TYPE) \
1610 nvlist_append_##type##_array(nvlist_t *nvl, const char *name, vtype value)\
1614 if (nvlist_error(nvl) != 0) { \
1615 ERRNO_SET(nvlist_error(nvl)); \
1618 nvp = nvlist_find(nvl, NV_TYPE_##TYPE##_ARRAY, name); \
1619 if (nvp == NULL) { \
1620 nvlist_add_##type##_array(nvl, name, &value, 1); \
1623 nvlist_update_size(nvl, nvp, -1); \
1624 if (nvpair_append_##type##_array(nvp, value) == -1) { \
1625 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); \
1626 ERRNO_SET(nvl->nvl_error); \
1628 nvlist_update_size(nvl, nvp, 1); \
1631 NVLIST_APPEND_ARRAY(const bool, bool, BOOL)
1632 NVLIST_APPEND_ARRAY(const uint64_t, number, NUMBER)
1633 NVLIST_APPEND_ARRAY(const char *, string, STRING)
1634 NVLIST_APPEND_ARRAY(const nvlist_t *, nvlist, NVLIST)
1636 NVLIST_APPEND_ARRAY(const int, descriptor, DESCRIPTOR)
1639 #undef NVLIST_APPEND_ARRAY
1642 nvlist_move_nvpair(nvlist_t *nvl, nvpair_t *nvp)
1646 PJDLOG_ASSERT(nvpair_nvlist(nvp) == NULL);
1648 if (nvlist_error(nvl) != 0) {
1650 ERRNO_SET(nvlist_error(nvl));
1653 if ((nvl->nvl_flags & NV_FLAG_NO_UNIQUE) == 0) {
1654 if (nvlist_exists(nvl, nvpair_name(nvp))) {
1656 nvl->nvl_error = EEXIST;
1657 ERRNO_SET(nvl->nvl_error);
1662 nvpair_insert(&nvl->nvl_head, nvp, nvl);
1663 nvlist_update_size(nvl, nvp, 1);
1668 nvlist_move_string(nvlist_t *nvl, const char *name, char *value)
1672 if (nvlist_error(nvl) != 0) {
1674 ERRNO_SET(nvlist_error(nvl));
1678 nvp = nvpair_move_string(name, value);
1680 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1681 ERRNO_SET(nvl->nvl_error);
1683 (void)nvlist_move_nvpair(nvl, nvp);
1688 nvlist_move_nvlist(nvlist_t *nvl, const char *name, nvlist_t *value)
1692 if (nvlist_error(nvl) != 0) {
1693 if (value != NULL && nvlist_get_nvpair_parent(value) != NULL)
1694 nvlist_destroy(value);
1695 ERRNO_SET(nvlist_error(nvl));
1699 nvp = nvpair_move_nvlist(name, value);
1701 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1702 ERRNO_SET(nvl->nvl_error);
1704 (void)nvlist_move_nvpair(nvl, nvp);
1710 nvlist_move_descriptor(nvlist_t *nvl, const char *name, int value)
1714 if (nvlist_error(nvl) != 0) {
1716 ERRNO_SET(nvlist_error(nvl));
1720 nvp = nvpair_move_descriptor(name, value);
1722 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1723 ERRNO_SET(nvl->nvl_error);
1725 (void)nvlist_move_nvpair(nvl, nvp);
1731 nvlist_move_binary(nvlist_t *nvl, const char *name, void *value, size_t size)
1735 if (nvlist_error(nvl) != 0) {
1737 ERRNO_SET(nvlist_error(nvl));
1741 nvp = nvpair_move_binary(name, value, size);
1743 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1744 ERRNO_SET(nvl->nvl_error);
1746 (void)nvlist_move_nvpair(nvl, nvp);
1751 nvlist_move_bool_array(nvlist_t *nvl, const char *name, bool *value,
1756 if (nvlist_error(nvl) != 0) {
1758 ERRNO_SET(nvlist_error(nvl));
1762 nvp = nvpair_move_bool_array(name, value, nitems);
1764 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1765 ERRNO_SET(nvl->nvl_error);
1767 (void)nvlist_move_nvpair(nvl, nvp);
1772 nvlist_move_string_array(nvlist_t *nvl, const char *name, char **value,
1778 if (nvlist_error(nvl) != 0) {
1779 if (value != NULL) {
1780 for (i = 0; i < nitems; i++)
1784 ERRNO_SET(nvlist_error(nvl));
1788 nvp = nvpair_move_string_array(name, value, nitems);
1790 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1791 ERRNO_SET(nvl->nvl_error);
1793 (void)nvlist_move_nvpair(nvl, nvp);
1798 nvlist_move_nvlist_array(nvlist_t *nvl, const char *name, nvlist_t **value,
1804 if (nvlist_error(nvl) != 0) {
1805 if (value != NULL) {
1806 for (i = 0; i < nitems; i++) {
1807 if (nvlist_get_pararr(value[i], NULL) == NULL)
1808 nvlist_destroy(value[i]);
1812 ERRNO_SET(nvlist_error(nvl));
1816 nvp = nvpair_move_nvlist_array(name, value, nitems);
1818 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1819 ERRNO_SET(nvl->nvl_error);
1821 (void)nvlist_move_nvpair(nvl, nvp);
1826 nvlist_move_number_array(nvlist_t *nvl, const char *name, uint64_t *value,
1831 if (nvlist_error(nvl) != 0) {
1833 ERRNO_SET(nvlist_error(nvl));
1837 nvp = nvpair_move_number_array(name, value, nitems);
1839 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1840 ERRNO_SET(nvl->nvl_error);
1842 (void)nvlist_move_nvpair(nvl, nvp);
1848 nvlist_move_descriptor_array(nvlist_t *nvl, const char *name, int *value,
1854 if (nvlist_error(nvl) != 0) {
1856 for (i = 0; i < nitems; i++)
1861 ERRNO_SET(nvlist_error(nvl));
1865 nvp = nvpair_move_descriptor_array(name, value, nitems);
1867 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1868 ERRNO_SET(nvl->nvl_error);
1870 (void)nvlist_move_nvpair(nvl, nvp);
1876 nvlist_get_nvpair(const nvlist_t *nvl, const char *name)
1879 return (nvlist_find(nvl, NV_TYPE_NONE, name));
1882 #define NVLIST_GET(ftype, type, TYPE) \
1884 nvlist_get_##type(const nvlist_t *nvl, const char *name) \
1886 const nvpair_t *nvp; \
1888 nvp = nvlist_find(nvl, NV_TYPE_##TYPE, name); \
1890 nvlist_report_missing(NV_TYPE_##TYPE, name); \
1891 return (nvpair_get_##type(nvp)); \
1894 NVLIST_GET(bool, bool, BOOL)
1895 NVLIST_GET(uint64_t, number, NUMBER)
1896 NVLIST_GET(const char *, string, STRING)
1897 NVLIST_GET(const nvlist_t *, nvlist, NVLIST)
1899 NVLIST_GET(int, descriptor, DESCRIPTOR)
1905 nvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep)
1909 nvp = nvlist_find(nvl, NV_TYPE_BINARY, name);
1911 nvlist_report_missing(NV_TYPE_BINARY, name);
1913 return (nvpair_get_binary(nvp, sizep));
1916 #define NVLIST_GET_ARRAY(ftype, type, TYPE) \
1918 nvlist_get_##type##_array(const nvlist_t *nvl, const char *name, \
1921 const nvpair_t *nvp; \
1923 nvp = nvlist_find(nvl, NV_TYPE_##TYPE##_ARRAY, name); \
1925 nvlist_report_missing(NV_TYPE_##TYPE##_ARRAY, name); \
1926 return (nvpair_get_##type##_array(nvp, nitems)); \
1929 NVLIST_GET_ARRAY(const bool *, bool, BOOL)
1930 NVLIST_GET_ARRAY(const uint64_t *, number, NUMBER)
1931 NVLIST_GET_ARRAY(const char * const *, string, STRING)
1932 NVLIST_GET_ARRAY(const nvlist_t * const *, nvlist, NVLIST)
1934 NVLIST_GET_ARRAY(const int *, descriptor, DESCRIPTOR)
1937 #undef NVLIST_GET_ARRAY
1939 #define NVLIST_TAKE(ftype, type, TYPE) \
1941 nvlist_take_##type(nvlist_t *nvl, const char *name) \
1946 nvp = nvlist_find(nvl, NV_TYPE_##TYPE, name); \
1948 nvlist_report_missing(NV_TYPE_##TYPE, name); \
1949 value = (ftype)(intptr_t)nvpair_get_##type(nvp); \
1950 nvlist_remove_nvpair(nvl, nvp); \
1951 nvpair_free_structure(nvp); \
1955 NVLIST_TAKE(bool, bool, BOOL)
1956 NVLIST_TAKE(uint64_t, number, NUMBER)
1957 NVLIST_TAKE(char *, string, STRING)
1958 NVLIST_TAKE(nvlist_t *, nvlist, NVLIST)
1960 NVLIST_TAKE(int, descriptor, DESCRIPTOR)
1966 nvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep)
1971 nvp = nvlist_find(nvl, NV_TYPE_BINARY, name);
1973 nvlist_report_missing(NV_TYPE_BINARY, name);
1975 value = (void *)(intptr_t)nvpair_get_binary(nvp, sizep);
1976 nvlist_remove_nvpair(nvl, nvp);
1977 nvpair_free_structure(nvp);
1981 #define NVLIST_TAKE_ARRAY(ftype, type, TYPE) \
1983 nvlist_take_##type##_array(nvlist_t *nvl, const char *name, \
1989 nvp = nvlist_find(nvl, NV_TYPE_##TYPE##_ARRAY, name); \
1991 nvlist_report_missing(NV_TYPE_##TYPE##_ARRAY, name); \
1992 value = (ftype)(intptr_t)nvpair_get_##type##_array(nvp, nitems);\
1993 nvlist_remove_nvpair(nvl, nvp); \
1994 nvpair_free_structure(nvp); \
1998 NVLIST_TAKE_ARRAY(bool *, bool, BOOL)
1999 NVLIST_TAKE_ARRAY(uint64_t *, number, NUMBER)
2000 NVLIST_TAKE_ARRAY(char **, string, STRING)
2001 NVLIST_TAKE_ARRAY(nvlist_t **, nvlist, NVLIST)
2003 NVLIST_TAKE_ARRAY(int *, descriptor, DESCRIPTOR)
2007 nvlist_remove_nvpair(nvlist_t *nvl, nvpair_t *nvp)
2012 PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
2014 nvpair_remove(&nvl->nvl_head, nvp, nvl);
2015 nvlist_update_size(nvl, nvp, -1);
2019 nvlist_free(nvlist_t *nvl, const char *name)
2022 nvlist_free_type(nvl, name, NV_TYPE_NONE);
2025 #define NVLIST_FREE(type, TYPE) \
2027 nvlist_free_##type(nvlist_t *nvl, const char *name) \
2030 nvlist_free_type(nvl, name, NV_TYPE_##TYPE); \
2033 NVLIST_FREE(null, NULL)
2034 NVLIST_FREE(bool, BOOL)
2035 NVLIST_FREE(number, NUMBER)
2036 NVLIST_FREE(string, STRING)
2037 NVLIST_FREE(nvlist, NVLIST)
2038 NVLIST_FREE(binary, BINARY)
2039 NVLIST_FREE(bool_array, BOOL_ARRAY)
2040 NVLIST_FREE(number_array, NUMBER_ARRAY)
2041 NVLIST_FREE(string_array, STRING_ARRAY)
2042 NVLIST_FREE(nvlist_array, NVLIST_ARRAY)
2044 NVLIST_FREE(descriptor, DESCRIPTOR)
2045 NVLIST_FREE(descriptor_array, DESCRIPTOR_ARRAY)
2051 nvlist_free_nvpair(nvlist_t *nvl, nvpair_t *nvp)
2056 PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
2058 nvlist_remove_nvpair(nvl, nvp);