Deleted Added
full compact
nvlist.c (286646) nvlist.c (286796)
1/*-
2 * Copyright (c) 2009-2013 The FreeBSD Foundation
1/*-
2 * Copyright (c) 2009-2013 The FreeBSD Foundation
3 * Copyright (c) 2013-2015 Mariusz Zaborski <oshogbo@FreeBSD.org>
3 * All rights reserved.
4 *
5 * This software was developed by Pawel Jakub Dawidek under sponsorship from
6 * the FreeBSD Foundation.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:

--- 12 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
4 * All rights reserved.
5 *
6 * This software was developed by Pawel Jakub Dawidek under sponsorship from
7 * the FreeBSD Foundation.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:

--- 12 unchanged lines hidden (view full) ---

24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/sys/contrib/libnv/nvlist.c 286646 2015-08-11 18:17:31Z oshogbo $");
32__FBSDID("$FreeBSD: head/sys/contrib/libnv/nvlist.c 286796 2015-08-15 06:34:49Z oshogbo $");
32
33#include <sys/param.h>
34#include <sys/endian.h>
35#include <sys/queue.h>
36
37#ifdef _KERNEL
38
39#include <sys/errno.h>

--- 43 unchanged lines hidden (view full) ---

83 fprintf(stderr, "%s:%u: ", __FILE__, __LINE__); \
84 fprintf(stderr, __VA_ARGS__); \
85 fprintf(stderr, "\n"); \
86 abort(); \
87} while (0)
88#endif
89#endif
90
33
34#include <sys/param.h>
35#include <sys/endian.h>
36#include <sys/queue.h>
37
38#ifdef _KERNEL
39
40#include <sys/errno.h>

--- 43 unchanged lines hidden (view full) ---

84 fprintf(stderr, "%s:%u: ", __FILE__, __LINE__); \
85 fprintf(stderr, __VA_ARGS__); \
86 fprintf(stderr, "\n"); \
87 abort(); \
88} while (0)
89#endif
90#endif
91
91#define NV_FLAG_PRIVATE_MASK (NV_FLAG_BIG_ENDIAN)
92#define NV_FLAG_PRIVATE_MASK (NV_FLAG_BIG_ENDIAN | NV_FLAG_IN_ARRAY)
92#define NV_FLAG_PUBLIC_MASK (NV_FLAG_IGNORE_CASE | NV_FLAG_NO_UNIQUE)
93#define NV_FLAG_ALL_MASK (NV_FLAG_PRIVATE_MASK | NV_FLAG_PUBLIC_MASK)
94
95#define NVLIST_MAGIC 0x6e766c /* "nvl" */
96struct nvlist {
97 int nvl_magic;
98 int nvl_error;
99 int nvl_flags;
100 nvpair_t *nvl_parent;
93#define NV_FLAG_PUBLIC_MASK (NV_FLAG_IGNORE_CASE | NV_FLAG_NO_UNIQUE)
94#define NV_FLAG_ALL_MASK (NV_FLAG_PRIVATE_MASK | NV_FLAG_PUBLIC_MASK)
95
96#define NVLIST_MAGIC 0x6e766c /* "nvl" */
97struct nvlist {
98 int nvl_magic;
99 int nvl_error;
100 int nvl_flags;
101 nvpair_t *nvl_parent;
102 nvpair_t *nvl_array_next;
101 struct nvl_head nvl_head;
102};
103
104#define NVLIST_ASSERT(nvl) do { \
105 PJDLOG_ASSERT((nvl) != NULL); \
106 PJDLOG_ASSERT((nvl)->nvl_magic == NVLIST_MAGIC); \
107} while (0)
108

--- 21 unchanged lines hidden (view full) ---

130 PJDLOG_ASSERT((flags & ~(NV_FLAG_PUBLIC_MASK)) == 0);
131
132 nvl = nv_malloc(sizeof(*nvl));
133 if (nvl == NULL)
134 return (NULL);
135 nvl->nvl_error = 0;
136 nvl->nvl_flags = flags;
137 nvl->nvl_parent = NULL;
103 struct nvl_head nvl_head;
104};
105
106#define NVLIST_ASSERT(nvl) do { \
107 PJDLOG_ASSERT((nvl) != NULL); \
108 PJDLOG_ASSERT((nvl)->nvl_magic == NVLIST_MAGIC); \
109} while (0)
110

--- 21 unchanged lines hidden (view full) ---

132 PJDLOG_ASSERT((flags & ~(NV_FLAG_PUBLIC_MASK)) == 0);
133
134 nvl = nv_malloc(sizeof(*nvl));
135 if (nvl == NULL)
136 return (NULL);
137 nvl->nvl_error = 0;
138 nvl->nvl_flags = flags;
139 nvl->nvl_parent = NULL;
140 nvl->nvl_array_next = NULL;
138 TAILQ_INIT(&nvl->nvl_head);
139 nvl->nvl_magic = NVLIST_MAGIC;
140
141 return (nvl);
142}
143
144void
145nvlist_destroy(nvlist_t *nvl)

--- 6 unchanged lines hidden (view full) ---

152 ERRNO_SAVE();
153
154 NVLIST_ASSERT(nvl);
155
156 while ((nvp = nvlist_first_nvpair(nvl)) != NULL) {
157 nvlist_remove_nvpair(nvl, nvp);
158 nvpair_free(nvp);
159 }
141 TAILQ_INIT(&nvl->nvl_head);
142 nvl->nvl_magic = NVLIST_MAGIC;
143
144 return (nvl);
145}
146
147void
148nvlist_destroy(nvlist_t *nvl)

--- 6 unchanged lines hidden (view full) ---

155 ERRNO_SAVE();
156
157 NVLIST_ASSERT(nvl);
158
159 while ((nvp = nvlist_first_nvpair(nvl)) != NULL) {
160 nvlist_remove_nvpair(nvl, nvp);
161 nvpair_free(nvp);
162 }
163 if (nvl->nvl_array_next != NULL)
164 nvpair_free_structure(nvl->nvl_array_next);
165 nvl->nvl_array_next = NULL;
166 nvl->nvl_parent = NULL;
160 nvl->nvl_magic = 0;
161 nv_free(nvl);
162
163 ERRNO_RESTORE();
164}
165
166void
167nvlist_set_error(nvlist_t *nvl, int error)

--- 50 unchanged lines hidden (view full) ---

218nvlist_set_parent(nvlist_t *nvl, nvpair_t *parent)
219{
220
221 NVLIST_ASSERT(nvl);
222
223 nvl->nvl_parent = parent;
224}
225
167 nvl->nvl_magic = 0;
168 nv_free(nvl);
169
170 ERRNO_RESTORE();
171}
172
173void
174nvlist_set_error(nvlist_t *nvl, int error)

--- 50 unchanged lines hidden (view full) ---

225nvlist_set_parent(nvlist_t *nvl, nvpair_t *parent)
226{
227
228 NVLIST_ASSERT(nvl);
229
230 nvl->nvl_parent = parent;
231}
232
233void
234nvlist_set_array_next(nvlist_t *nvl, nvpair_t *ele)
235{
236
237 NVLIST_ASSERT(nvl);
238
239 if (ele != NULL)
240 nvl->nvl_flags |= NV_FLAG_IN_ARRAY;
241 else
242 nvl->nvl_flags &= ~NV_FLAG_IN_ARRAY;
243
244 nvl->nvl_array_next = ele;
245}
246
226bool
247bool
248nvlist_in_array(const nvlist_t *nvl)
249{
250
251 NVLIST_ASSERT(nvl);
252
253 return ((nvl->nvl_flags & NV_FLAG_IN_ARRAY) != 0);
254}
255
256const nvlist_t *
257nvlist_get_array_next(const nvlist_t *nvl)
258{
259 nvpair_t *nvp;
260
261 NVLIST_ASSERT(nvl);
262
263 nvp = nvl->nvl_array_next;
264 if (nvp == NULL)
265 return (NULL);
266
267 return (nvpair_get_nvlist(nvp));
268}
269
270const nvlist_t *
271nvlist_get_pararr(const nvlist_t *nvl, void **cookiep)
272{
273 const nvlist_t *ret;
274
275 ret = nvlist_get_array_next(nvl);
276 if (ret != NULL) {
277 if (cookiep != NULL)
278 *cookiep = NULL;
279 return (ret);
280 }
281
282 ret = nvlist_get_parent(nvl, cookiep);
283 return (ret);
284}
285
286bool
227nvlist_empty(const nvlist_t *nvl)
228{
229
230 NVLIST_ASSERT(nvl);
231 PJDLOG_ASSERT(nvl->nvl_error == 0);
232
233 return (nvlist_first_nvpair(nvl) == NULL);
234}
235
236int
237nvlist_flags(const nvlist_t *nvl)
238{
239
240 NVLIST_ASSERT(nvl);
241 PJDLOG_ASSERT(nvl->nvl_error == 0);
287nvlist_empty(const nvlist_t *nvl)
288{
289
290 NVLIST_ASSERT(nvl);
291 PJDLOG_ASSERT(nvl->nvl_error == 0);
292
293 return (nvlist_first_nvpair(nvl) == NULL);
294}
295
296int
297nvlist_flags(const nvlist_t *nvl)
298{
299
300 NVLIST_ASSERT(nvl);
301 PJDLOG_ASSERT(nvl->nvl_error == 0);
242 PJDLOG_ASSERT((nvl->nvl_flags & ~(NV_FLAG_PUBLIC_MASK)) == 0);
243
302
244 return (nvl->nvl_flags);
303 return (nvl->nvl_flags & NV_FLAG_PUBLIC_MASK);
245}
246
304}
305
306void
307nvlist_set_flags(nvlist_t *nvl, int flags)
308{
309
310 NVLIST_ASSERT(nvl);
311 PJDLOG_ASSERT(nvl->nvl_error == 0);
312
313 nvl->nvl_flags = flags;
314}
315
247static void
248nvlist_report_missing(int type, const char *name)
249{
250
251 PJDLOG_ABORT("Element '%s' of type %s doesn't exist.",
252 name, nvpair_type_string(type));
253}
254

--- 158 unchanged lines hidden (view full) ---

413
414 binary = nvpair_get_binary(nvp, &size);
415 dprintf(fd, " %zu ", size);
416 for (ii = 0; ii < size; ii++)
417 dprintf(fd, "%02hhx", binary[ii]);
418 dprintf(fd, "\n");
419 break;
420 }
316static void
317nvlist_report_missing(int type, const char *name)
318{
319
320 PJDLOG_ABORT("Element '%s' of type %s doesn't exist.",
321 name, nvpair_type_string(type));
322}
323

--- 158 unchanged lines hidden (view full) ---

482
483 binary = nvpair_get_binary(nvp, &size);
484 dprintf(fd, " %zu ", size);
485 for (ii = 0; ii < size; ii++)
486 dprintf(fd, "%02hhx", binary[ii]);
487 dprintf(fd, "\n");
488 break;
489 }
490 case NV_TYPE_BOOL_ARRAY:
491 {
492 const bool *value;
493 unsigned int ii;
494 size_t nitems;
495
496 value = nvpair_get_bool_array(nvp, &nitems);
497 dprintf(fd, " [ ");
498 for (ii = 0; ii < nitems; ii++) {
499 dprintf(fd, "%s", value[ii] ? "TRUE" : "FALSE");
500 if (ii != nitems - 1)
501 dprintf(fd, ", ");
502 }
503 dprintf(fd, " ]\n");
504 break;
505 }
506 case NV_TYPE_STRING_ARRAY:
507 {
508 const char * const *value;
509 unsigned int ii;
510 size_t nitems;
511
512 value = nvpair_get_string_array(nvp, &nitems);
513 dprintf(fd, " [ ");
514 for (ii = 0; ii < nitems; ii++) {
515 if (value[ii] == NULL)
516 dprintf(fd, "NULL");
517 else
518 dprintf(fd, "\"%s\"", value[ii]);
519 if (ii != nitems - 1)
520 dprintf(fd, ", ");
521 }
522 dprintf(fd, " ]\n");
523 break;
524 }
525 case NV_TYPE_NUMBER_ARRAY:
526 {
527 const uint64_t *value;
528 unsigned int ii;
529 size_t nitems;
530
531 value = nvpair_get_number_array(nvp, &nitems);
532 dprintf(fd, " [ ");
533 for (ii = 0; ii < nitems; ii++) {
534 dprintf(fd, "%ju (%jd) (0x%jx)",
535 value[ii], value[ii], value[ii]);
536 if (ii != nitems - 1)
537 dprintf(fd, ", ");
538 }
539 dprintf(fd, " ]\n");
540 break;
541 }
542 case NV_TYPE_DESCRIPTOR_ARRAY:
543 {
544 const int *value;
545 unsigned int ii;
546 size_t nitems;
547
548 value = nvpair_get_descriptor_array(nvp, &nitems);
549 dprintf(fd, " [ ");
550 for (ii = 0; ii < nitems; ii++) {
551 dprintf(fd, "%d", value[ii]);
552 if (ii != nitems - 1)
553 dprintf(fd, ", ");
554 }
555 dprintf(fd, " ]\n");
556 break;
557 }
558 case NV_TYPE_NVLIST_ARRAY:
559 {
560 const nvlist_t * const *value;
561 unsigned int ii;
562 size_t nitems;
563
564 value = nvpair_get_nvlist_array(nvp, &nitems);
565 dprintf(fd, " %zu\n", nitems);
566 tmpnvl = NULL;
567 tmpnvp = NULL;
568 for (ii = 0; ii < nitems; ii++) {
569 if (nvlist_dump_error_check(value[ii], fd,
570 level + 1)) {
571 break;
572 }
573
574 if (tmpnvl == NULL) {
575 tmpnvp = nvlist_first_nvpair(value[ii]);
576 if (tmpnvp != NULL) {
577 tmpnvl = value[ii];
578 } else {
579 dprintf(fd, "%*s,\n",
580 (level + 1) * 4, "");
581 }
582 }
583 }
584 if (tmpnvp != NULL) {
585 nvl = tmpnvl;
586 nvp = tmpnvp;
587 level++;
588 continue;
589 }
590 break;
591 }
421 default:
422 PJDLOG_ABORT("Unknown type: %d.", nvpair_type(nvp));
423 }
424
425 while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
592 default:
593 PJDLOG_ABORT("Unknown type: %d.", nvpair_type(nvp));
594 }
595
596 while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
426 cookie = NULL;
427 nvl = nvlist_get_parent(nvl, &cookie);
428 if (nvl == NULL)
429 return;
430 nvp = cookie;
431 level--;
597 do {
598 cookie = NULL;
599 if (nvlist_in_array(nvl))
600 dprintf(fd, "%*s,\n", level * 4, "");
601 nvl = nvlist_get_pararr(nvl, &cookie);
602 if (nvl == NULL)
603 return;
604 if (nvlist_in_array(nvl) && cookie == NULL) {
605 nvp = nvlist_first_nvpair(nvl);
606 } else {
607 nvp = cookie;
608 level--;
609 }
610 } while (nvp == NULL);
611 if (nvlist_in_array(nvl) && cookie == NULL)
612 break;
432 }
433 }
434}
435
436void
437nvlist_fdump(const nvlist_t *nvl, FILE *fp)
438{
439

--- 4 unchanged lines hidden (view full) ---

444
445/*
446 * The function obtains size of the nvlist after nvlist_pack().
447 */
448size_t
449nvlist_size(const nvlist_t *nvl)
450{
451 const nvlist_t *tmpnvl;
613 }
614 }
615}
616
617void
618nvlist_fdump(const nvlist_t *nvl, FILE *fp)
619{
620

--- 4 unchanged lines hidden (view full) ---

625
626/*
627 * The function obtains size of the nvlist after nvlist_pack().
628 */
629size_t
630nvlist_size(const nvlist_t *nvl)
631{
632 const nvlist_t *tmpnvl;
633 const nvlist_t * const *nvlarray;
452 const nvpair_t *nvp, *tmpnvp;
453 void *cookie;
634 const nvpair_t *nvp, *tmpnvp;
635 void *cookie;
454 size_t size;
636 size_t size, nitems;
637 unsigned int ii;
455
456 NVLIST_ASSERT(nvl);
457 PJDLOG_ASSERT(nvl->nvl_error == 0);
458
459 size = sizeof(struct nvlist_header);
460 nvp = nvlist_first_nvpair(nvl);
461 while (nvp != NULL) {
462 size += nvpair_header_size();

--- 4 unchanged lines hidden (view full) ---

467 tmpnvl = nvpair_get_nvlist(nvp);
468 PJDLOG_ASSERT(tmpnvl->nvl_error == 0);
469 tmpnvp = nvlist_first_nvpair(tmpnvl);
470 if (tmpnvp != NULL) {
471 nvl = tmpnvl;
472 nvp = tmpnvp;
473 continue;
474 }
638
639 NVLIST_ASSERT(nvl);
640 PJDLOG_ASSERT(nvl->nvl_error == 0);
641
642 size = sizeof(struct nvlist_header);
643 nvp = nvlist_first_nvpair(nvl);
644 while (nvp != NULL) {
645 size += nvpair_header_size();

--- 4 unchanged lines hidden (view full) ---

650 tmpnvl = nvpair_get_nvlist(nvp);
651 PJDLOG_ASSERT(tmpnvl->nvl_error == 0);
652 tmpnvp = nvlist_first_nvpair(tmpnvl);
653 if (tmpnvp != NULL) {
654 nvl = tmpnvl;
655 nvp = tmpnvp;
656 continue;
657 }
658 } else if (nvpair_type(nvp) == NV_TYPE_NVLIST_ARRAY) {
659 nvlarray = nvpair_get_nvlist_array(nvp, &nitems);
660 PJDLOG_ASSERT(nitems > 0);
661
662 size += (nvpair_header_size() + 1) * nitems;
663 size += sizeof(struct nvlist_header) * nitems;
664
665 tmpnvl = NULL;
666 tmpnvp = NULL;
667 for (ii = 0; ii < nitems; ii++) {
668 PJDLOG_ASSERT(nvlarray[ii]->nvl_error == 0);
669 tmpnvp = nvlist_first_nvpair(nvlarray[ii]);
670 if (tmpnvp != NULL) {
671 tmpnvl = nvlarray[ii];
672 break;
673 }
674 }
675 if (tmpnvp != NULL) {
676 nvp = tmpnvp;
677 nvl = tmpnvl;
678 continue;
679 }
680
475 } else {
476 size += nvpair_size(nvp);
477 }
478
479 while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
681 } else {
682 size += nvpair_size(nvp);
683 }
684
685 while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
480 cookie = NULL;
481 nvl = nvlist_get_parent(nvl, &cookie);
482 if (nvl == NULL)
483 goto out;
484 nvp = cookie;
686 do {
687 cookie = NULL;
688 nvl = nvlist_get_pararr(nvl, &cookie);
689 if (nvl == NULL)
690 goto out;
691 if (nvlist_in_array(nvl) && cookie == NULL) {
692 nvp = nvlist_first_nvpair(nvl);
693 } else {
694 nvp = cookie;
695 }
696 } while (nvp == NULL);
697 if (nvlist_in_array(nvl) && cookie == NULL)
698 break;
485 }
486 }
487
488out:
489 return (size);
490}
491
492#ifndef _KERNEL

--- 10 unchanged lines hidden (view full) ---

503 nvp = NULL;
504 do {
505 while ((name = nvlist_next(nvl, &type, (void**)&nvp)) != NULL) {
506 switch (type) {
507 case NV_TYPE_DESCRIPTOR:
508 *descs = nvpair_get_descriptor(nvp);
509 descs++;
510 break;
699 }
700 }
701
702out:
703 return (size);
704}
705
706#ifndef _KERNEL

--- 10 unchanged lines hidden (view full) ---

717 nvp = NULL;
718 do {
719 while ((name = nvlist_next(nvl, &type, (void**)&nvp)) != NULL) {
720 switch (type) {
721 case NV_TYPE_DESCRIPTOR:
722 *descs = nvpair_get_descriptor(nvp);
723 descs++;
724 break;
725 case NV_TYPE_DESCRIPTOR_ARRAY:
726 {
727 const int *value;
728 size_t nitems;
729 unsigned int ii;
730
731 value = nvpair_get_descriptor_array(nvp,
732 &nitems);
733 for (ii = 0; ii < nitems; ii++) {
734 *descs = value[ii];
735 descs++;
736 }
737 break;
738 }
511 case NV_TYPE_NVLIST:
512 nvl = nvpair_get_nvlist(nvp);
513 nvp = NULL;
514 break;
739 case NV_TYPE_NVLIST:
740 nvl = nvpair_get_nvlist(nvp);
741 nvp = NULL;
742 break;
743 case NV_TYPE_NVLIST_ARRAY:
744 {
745 const nvlist_t * const *value;
746 size_t nitems;
747
748 value = nvpair_get_nvlist_array(nvp, &nitems);
749 PJDLOG_ASSERT(value != NULL);
750 PJDLOG_ASSERT(nitems > 0);
751
752 nvl = value[0];
753 nvp = NULL;
754 break;
755 }
515 }
516 }
756 }
757 }
517 } while ((nvl = nvlist_get_parent(nvl, (void**)&nvp)) != NULL);
758 } while ((nvl = nvlist_get_pararr(nvl, (void**)&nvp)) != NULL);
518
519 return (descs);
520}
521#endif
522
523#ifndef _KERNEL
524int *
525nvlist_descriptors(const nvlist_t *nvl, size_t *nitemsp)

--- 33 unchanged lines hidden (view full) ---

559 switch (type) {
560 case NV_TYPE_DESCRIPTOR:
561 ndescs++;
562 break;
563 case NV_TYPE_NVLIST:
564 nvl = nvpair_get_nvlist(nvp);
565 nvp = NULL;
566 break;
759
760 return (descs);
761}
762#endif
763
764#ifndef _KERNEL
765int *
766nvlist_descriptors(const nvlist_t *nvl, size_t *nitemsp)

--- 33 unchanged lines hidden (view full) ---

800 switch (type) {
801 case NV_TYPE_DESCRIPTOR:
802 ndescs++;
803 break;
804 case NV_TYPE_NVLIST:
805 nvl = nvpair_get_nvlist(nvp);
806 nvp = NULL;
807 break;
808 case NV_TYPE_NVLIST_ARRAY:
809 {
810 const nvlist_t * const *value;
811 size_t nitems;
812
813 value = nvpair_get_nvlist_array(nvp, &nitems);
814 PJDLOG_ASSERT(value != NULL);
815 PJDLOG_ASSERT(nitems > 0);
816
817 nvl = value[0];
818 nvp = NULL;
819 break;
820 }
821 case NV_TYPE_DESCRIPTOR_ARRAY:
822 {
823 size_t nitems;
824
825 (void)nvpair_get_descriptor_array(nvp,
826 &nitems);
827 ndescs += nitems;
828 break;
829 }
567 }
568 }
830 }
831 }
569 } while ((nvl = nvlist_get_parent(nvl, (void**)&nvp)) != NULL);
832 } while ((nvl = nvlist_get_pararr(nvl, (void**)&nvp)) != NULL);
570
571 return (ndescs);
572#else
573 return (0);
574#endif
575}
576
577static unsigned char *

--- 78 unchanged lines hidden (view full) ---

656 continue;
657 }
658 ptr = nvpair_pack_nvlist_up(ptr, &left);
659 break;
660#ifndef _KERNEL
661 case NV_TYPE_DESCRIPTOR:
662 ptr = nvpair_pack_descriptor(nvp, ptr, fdidxp, &left);
663 break;
833
834 return (ndescs);
835#else
836 return (0);
837#endif
838}
839
840static unsigned char *

--- 78 unchanged lines hidden (view full) ---

919 continue;
920 }
921 ptr = nvpair_pack_nvlist_up(ptr, &left);
922 break;
923#ifndef _KERNEL
924 case NV_TYPE_DESCRIPTOR:
925 ptr = nvpair_pack_descriptor(nvp, ptr, fdidxp, &left);
926 break;
927 case NV_TYPE_DESCRIPTOR_ARRAY:
928 ptr = nvpair_pack_descriptor_array(nvp, ptr, fdidxp,
929 &left);
930 break;
664#endif
665 case NV_TYPE_BINARY:
666 ptr = nvpair_pack_binary(nvp, ptr, &left);
667 break;
931#endif
932 case NV_TYPE_BINARY:
933 ptr = nvpair_pack_binary(nvp, ptr, &left);
934 break;
935 case NV_TYPE_BOOL_ARRAY:
936 ptr = nvpair_pack_bool_array(nvp, ptr, &left);
937 break;
938 case NV_TYPE_NUMBER_ARRAY:
939 ptr = nvpair_pack_number_array(nvp, ptr, &left);
940 break;
941 case NV_TYPE_STRING_ARRAY:
942 ptr = nvpair_pack_string_array(nvp, ptr, &left);
943 break;
944 case NV_TYPE_NVLIST_ARRAY:
945 {
946 const nvlist_t * const * value;
947 size_t nitems;
948 unsigned int ii;
949
950 tmpnvl = NULL;
951 value = nvpair_get_nvlist_array(nvp, &nitems);
952 for (ii = 0; ii < nitems; ii++) {
953 ptr = nvlist_pack_header(value[ii], ptr, &left);
954 if (ptr == NULL)
955 goto out;
956 tmpnvp = nvlist_first_nvpair(value[ii]);
957 if (tmpnvp != NULL) {
958 tmpnvl = value[ii];
959 break;
960 }
961 ptr = nvpair_pack_nvlist_array_next(ptr, &left);
962 if (ptr == NULL)
963 goto out;
964 }
965 if (tmpnvl != NULL) {
966 nvl = tmpnvl;
967 nvp = tmpnvp;
968 continue;
969 }
970 break;
971 }
668 default:
669 PJDLOG_ABORT("Invalid type (%d).", nvpair_type(nvp));
670 }
671 if (ptr == NULL)
672 goto fail;
673 while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
972 default:
973 PJDLOG_ABORT("Invalid type (%d).", nvpair_type(nvp));
974 }
975 if (ptr == NULL)
976 goto fail;
977 while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
674 cookie = NULL;
675 nvl = nvlist_get_parent(nvl, &cookie);
676 if (nvl == NULL)
677 goto out;
678 nvp = cookie;
679 ptr = nvpair_pack_nvlist_up(ptr, &left);
680 if (ptr == NULL)
681 goto fail;
978 do {
979 cookie = NULL;
980 if (nvlist_in_array(nvl)) {
981 ptr = nvpair_pack_nvlist_array_next(ptr,
982 &left);
983 if (ptr == NULL)
984 goto fail;
985 }
986 nvl = nvlist_get_pararr(nvl, &cookie);
987 if (nvl == NULL)
988 goto out;
989 if (nvlist_in_array(nvl) && cookie == NULL) {
990 nvp = nvlist_first_nvpair(nvl);
991 ptr = nvlist_pack_header(nvl, ptr,
992 &left);
993 if (ptr == NULL)
994 goto fail;
995 } else if (nvpair_type((nvpair_t *)cookie) !=
996 NV_TYPE_NVLIST_ARRAY) {
997 ptr = nvpair_pack_nvlist_up(ptr, &left);
998 if (ptr == NULL)
999 goto fail;
1000 nvp = cookie;
1001 } else {
1002 nvp = cookie;
1003 }
1004 } while (nvp == NULL);
1005 if (nvlist_in_array(nvl) && cookie == NULL)
1006 break;
682 }
683 }
684
685out:
686 if (sizep != NULL)
687 *sizep = size;
688 return (buf);
689fail:

--- 46 unchanged lines hidden (view full) ---

736 return (true);
737}
738
739const unsigned char *
740nvlist_unpack_header(nvlist_t *nvl, const unsigned char *ptr, size_t nfds,
741 bool *isbep, size_t *leftp)
742{
743 struct nvlist_header nvlhdr;
1007 }
1008 }
1009
1010out:
1011 if (sizep != NULL)
1012 *sizep = size;
1013 return (buf);
1014fail:

--- 46 unchanged lines hidden (view full) ---

1061 return (true);
1062}
1063
1064const unsigned char *
1065nvlist_unpack_header(nvlist_t *nvl, const unsigned char *ptr, size_t nfds,
1066 bool *isbep, size_t *leftp)
1067{
1068 struct nvlist_header nvlhdr;
1069 int inarrayf;
744
745 if (*leftp < sizeof(nvlhdr))
746 goto failed;
747
748 memcpy(&nvlhdr, ptr, sizeof(nvlhdr));
749
750 if (!nvlist_check_header(&nvlhdr))
751 goto failed;

--- 5 unchanged lines hidden (view full) ---

757 * nvlh_descriptors might be smaller than nfds in embedded nvlists.
758 */
759 if (nvlhdr.nvlh_descriptors > nfds)
760 goto failed;
761
762 if ((nvlhdr.nvlh_flags & ~NV_FLAG_ALL_MASK) != 0)
763 goto failed;
764
1070
1071 if (*leftp < sizeof(nvlhdr))
1072 goto failed;
1073
1074 memcpy(&nvlhdr, ptr, sizeof(nvlhdr));
1075
1076 if (!nvlist_check_header(&nvlhdr))
1077 goto failed;

--- 5 unchanged lines hidden (view full) ---

1083 * nvlh_descriptors might be smaller than nfds in embedded nvlists.
1084 */
1085 if (nvlhdr.nvlh_descriptors > nfds)
1086 goto failed;
1087
1088 if ((nvlhdr.nvlh_flags & ~NV_FLAG_ALL_MASK) != 0)
1089 goto failed;
1090
765 nvl->nvl_flags = (nvlhdr.nvlh_flags & NV_FLAG_PUBLIC_MASK);
1091 inarrayf = (nvl->nvl_flags & NV_FLAG_IN_ARRAY);
1092 nvl->nvl_flags = (nvlhdr.nvlh_flags & NV_FLAG_PUBLIC_MASK) | inarrayf;
766
767 ptr += sizeof(nvlhdr);
768 if (isbep != NULL)
769 *isbep = (((int)nvlhdr.nvlh_flags & NV_FLAG_BIG_ENDIAN) != 0);
770 *leftp -= sizeof(nvlhdr);
771
772 return (ptr);
773failed:
774 ERRNO_SET(EINVAL);
775 return (NULL);
776}
777
778static nvlist_t *
779nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds,
780 int flags)
781{
782 const unsigned char *ptr;
1093
1094 ptr += sizeof(nvlhdr);
1095 if (isbep != NULL)
1096 *isbep = (((int)nvlhdr.nvlh_flags & NV_FLAG_BIG_ENDIAN) != 0);
1097 *leftp -= sizeof(nvlhdr);
1098
1099 return (ptr);
1100failed:
1101 ERRNO_SET(EINVAL);
1102 return (NULL);
1103}
1104
1105static nvlist_t *
1106nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds,
1107 int flags)
1108{
1109 const unsigned char *ptr;
783 nvlist_t *nvl, *retnvl, *tmpnvl;
1110 nvlist_t *nvl, *retnvl, *tmpnvl, *array;
784 nvpair_t *nvp;
785 size_t left;
786 bool isbe;
787
788 PJDLOG_ASSERT((flags & ~(NV_FLAG_PUBLIC_MASK)) == 0);
789
790 left = size;
791 ptr = buf;
792
1111 nvpair_t *nvp;
1112 size_t left;
1113 bool isbe;
1114
1115 PJDLOG_ASSERT((flags & ~(NV_FLAG_PUBLIC_MASK)) == 0);
1116
1117 left = size;
1118 ptr = buf;
1119
793 tmpnvl = NULL;
1120 tmpnvl = array = NULL;
794 nvl = retnvl = nvlist_create(0);
795 if (nvl == NULL)
796 goto failed;
797
798 ptr = nvlist_unpack_header(nvl, ptr, nfds, &isbe, &left);
799 if (ptr == NULL)
800 goto failed;
801 if (nvl->nvl_flags != flags) {

--- 25 unchanged lines hidden (view full) ---

827 goto failed;
828 nvlist_set_parent(tmpnvl, nvp);
829 break;
830#ifndef _KERNEL
831 case NV_TYPE_DESCRIPTOR:
832 ptr = nvpair_unpack_descriptor(isbe, nvp, ptr, &left,
833 fds, nfds);
834 break;
1121 nvl = retnvl = nvlist_create(0);
1122 if (nvl == NULL)
1123 goto failed;
1124
1125 ptr = nvlist_unpack_header(nvl, ptr, nfds, &isbe, &left);
1126 if (ptr == NULL)
1127 goto failed;
1128 if (nvl->nvl_flags != flags) {

--- 25 unchanged lines hidden (view full) ---

1154 goto failed;
1155 nvlist_set_parent(tmpnvl, nvp);
1156 break;
1157#ifndef _KERNEL
1158 case NV_TYPE_DESCRIPTOR:
1159 ptr = nvpair_unpack_descriptor(isbe, nvp, ptr, &left,
1160 fds, nfds);
1161 break;
1162 case NV_TYPE_DESCRIPTOR_ARRAY:
1163 ptr = nvpair_unpack_descriptor_array(isbe, nvp, ptr,
1164 &left, fds, nfds);
1165 break;
835#endif
836 case NV_TYPE_BINARY:
837 ptr = nvpair_unpack_binary(isbe, nvp, ptr, &left);
838 break;
839 case NV_TYPE_NVLIST_UP:
840 if (nvl->nvl_parent == NULL)
841 goto failed;
842 nvl = nvpair_nvlist(nvl->nvl_parent);
843 nvpair_free_structure(nvp);
844 continue;
1166#endif
1167 case NV_TYPE_BINARY:
1168 ptr = nvpair_unpack_binary(isbe, nvp, ptr, &left);
1169 break;
1170 case NV_TYPE_NVLIST_UP:
1171 if (nvl->nvl_parent == NULL)
1172 goto failed;
1173 nvl = nvpair_nvlist(nvl->nvl_parent);
1174 nvpair_free_structure(nvp);
1175 continue;
1176 case NV_TYPE_NVLIST_ARRAY_NEXT:
1177 if (nvl->nvl_array_next == NULL) {
1178 if (nvl->nvl_parent == NULL)
1179 goto failed;
1180 nvl = nvpair_nvlist(nvl->nvl_parent);
1181 } else {
1182 nvl = __DECONST(nvlist_t *,
1183 nvlist_get_array_next(nvl));
1184 ptr = nvlist_unpack_header(nvl, ptr, nfds,
1185 &isbe, &left);
1186 if (ptr == NULL)
1187 goto failed;
1188 }
1189 nvpair_free_structure(nvp);
1190 continue;
1191 case NV_TYPE_BOOL_ARRAY:
1192 ptr = nvpair_unpack_bool_array(isbe, nvp, ptr, &left);
1193 break;
1194 case NV_TYPE_NUMBER_ARRAY:
1195 ptr = nvpair_unpack_number_array(isbe, nvp, ptr, &left);
1196 break;
1197 case NV_TYPE_STRING_ARRAY:
1198 ptr = nvpair_unpack_string_array(isbe, nvp, ptr, &left);
1199 break;
1200 case NV_TYPE_NVLIST_ARRAY:
1201 ptr = nvpair_unpack_nvlist_array(isbe, nvp, ptr, &left,
1202 &array);
1203 if (ptr == NULL)
1204 goto failed;
1205 tmpnvl = array;
1206 while (array != NULL) {
1207 nvlist_set_parent(array, nvp);
1208 array = __DECONST(nvlist_t *,
1209 nvlist_get_array_next(array));
1210 }
1211 ptr = nvlist_unpack_header(tmpnvl, ptr, nfds, &isbe,
1212 &left);
1213 break;
845 default:
846 PJDLOG_ABORT("Invalid type (%d).", nvpair_type(nvp));
847 }
848 if (ptr == NULL)
849 goto failed;
850 if (!nvlist_move_nvpair(nvl, nvp))
851 goto failed;
852 if (tmpnvl != NULL) {

--- 204 unchanged lines hidden (view full) ---

1057 return (nvlist_find(nvl, NV_TYPE_##TYPE, name) != NULL); \
1058}
1059
1060NVLIST_EXISTS(null, NULL)
1061NVLIST_EXISTS(bool, BOOL)
1062NVLIST_EXISTS(number, NUMBER)
1063NVLIST_EXISTS(string, STRING)
1064NVLIST_EXISTS(nvlist, NVLIST)
1214 default:
1215 PJDLOG_ABORT("Invalid type (%d).", nvpair_type(nvp));
1216 }
1217 if (ptr == NULL)
1218 goto failed;
1219 if (!nvlist_move_nvpair(nvl, nvp))
1220 goto failed;
1221 if (tmpnvl != NULL) {

--- 204 unchanged lines hidden (view full) ---

1426 return (nvlist_find(nvl, NV_TYPE_##TYPE, name) != NULL); \
1427}
1428
1429NVLIST_EXISTS(null, NULL)
1430NVLIST_EXISTS(bool, BOOL)
1431NVLIST_EXISTS(number, NUMBER)
1432NVLIST_EXISTS(string, STRING)
1433NVLIST_EXISTS(nvlist, NVLIST)
1434NVLIST_EXISTS(binary, BINARY)
1435NVLIST_EXISTS(bool_array, BOOL_ARRAY)
1436NVLIST_EXISTS(number_array, NUMBER_ARRAY)
1437NVLIST_EXISTS(string_array, STRING_ARRAY)
1438NVLIST_EXISTS(nvlist_array, NVLIST_ARRAY)
1065#ifndef _KERNEL
1066NVLIST_EXISTS(descriptor, DESCRIPTOR)
1439#ifndef _KERNEL
1440NVLIST_EXISTS(descriptor, DESCRIPTOR)
1441NVLIST_EXISTS(descriptor_array, DESCRIPTOR_ARRAY)
1067#endif
1442#endif
1068NVLIST_EXISTS(binary, BINARY)
1069
1070#undef NVLIST_EXISTS
1071
1072void
1073nvlist_add_nvpair(nvlist_t *nvl, const nvpair_t *nvp)
1074{
1075 nvpair_t *newnvp;
1076

--- 116 unchanged lines hidden (view full) ---

1193NVLIST_ADD(const char *, string)
1194NVLIST_ADD(const nvlist_t *, nvlist)
1195#ifndef _KERNEL
1196NVLIST_ADD(int, descriptor);
1197#endif
1198
1199#undef NVLIST_ADD
1200
1443
1444#undef NVLIST_EXISTS
1445
1446void
1447nvlist_add_nvpair(nvlist_t *nvl, const nvpair_t *nvp)
1448{
1449 nvpair_t *newnvp;
1450

--- 116 unchanged lines hidden (view full) ---

1567NVLIST_ADD(const char *, string)
1568NVLIST_ADD(const nvlist_t *, nvlist)
1569#ifndef _KERNEL
1570NVLIST_ADD(int, descriptor);
1571#endif
1572
1573#undef NVLIST_ADD
1574
1575#define NVLIST_ADD_ARRAY(vtype, type) \
1576void \
1577nvlist_add_##type##_array(nvlist_t *nvl, const char *name, vtype value, \
1578 size_t nitems) \
1579{ \
1580 nvpair_t *nvp; \
1581 \
1582 if (nvlist_error(nvl) != 0) { \
1583 ERRNO_SET(nvlist_error(nvl)); \
1584 return; \
1585 } \
1586 \
1587 nvp = nvpair_create_##type##_array(name, value, nitems); \
1588 if (nvp == NULL) { \
1589 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); \
1590 ERRNO_SET(nvl->nvl_error); \
1591 } else { \
1592 (void)nvlist_move_nvpair(nvl, nvp); \
1593 } \
1594}
1595
1596NVLIST_ADD_ARRAY(const bool *, bool)
1597NVLIST_ADD_ARRAY(const uint64_t *, number)
1598NVLIST_ADD_ARRAY(const char * const *, string)
1599NVLIST_ADD_ARRAY(const nvlist_t * const *, nvlist)
1600#ifndef _KERNEL
1601NVLIST_ADD_ARRAY(const int *, descriptor)
1602#endif
1603
1604#undef NVLIST_ADD_ARRAY
1605
1201bool
1202nvlist_move_nvpair(nvlist_t *nvl, nvpair_t *nvp)
1203{
1204
1205 NVPAIR_ASSERT(nvp);
1206 PJDLOG_ASSERT(nvpair_nvlist(nvp) == NULL);
1207
1208 if (nvlist_error(nvl) != 0) {

--- 92 unchanged lines hidden (view full) ---

1301 if (nvp == NULL) {
1302 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1303 ERRNO_SET(nvl->nvl_error);
1304 } else {
1305 (void)nvlist_move_nvpair(nvl, nvp);
1306 }
1307}
1308
1606bool
1607nvlist_move_nvpair(nvlist_t *nvl, nvpair_t *nvp)
1608{
1609
1610 NVPAIR_ASSERT(nvp);
1611 PJDLOG_ASSERT(nvpair_nvlist(nvp) == NULL);
1612
1613 if (nvlist_error(nvl) != 0) {

--- 92 unchanged lines hidden (view full) ---

1706 if (nvp == NULL) {
1707 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1708 ERRNO_SET(nvl->nvl_error);
1709 } else {
1710 (void)nvlist_move_nvpair(nvl, nvp);
1711 }
1712}
1713
1714void
1715nvlist_move_bool_array(nvlist_t *nvl, const char *name, bool *value,
1716 size_t nitems)
1717{
1718 nvpair_t *nvp;
1719
1720 if (nvlist_error(nvl) != 0) {
1721 nv_free(value);
1722 ERRNO_SET(nvlist_error(nvl));
1723 return;
1724 }
1725
1726 nvp = nvpair_move_bool_array(name, value, nitems);
1727 if (nvp == NULL) {
1728 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1729 ERRNO_SET(nvl->nvl_error);
1730 } else {
1731 (void)nvlist_move_nvpair(nvl, nvp);
1732 }
1733}
1734
1735void
1736nvlist_move_string_array(nvlist_t *nvl, const char *name, char **value,
1737 size_t nitems)
1738{
1739 nvpair_t *nvp;
1740 size_t i;
1741
1742 if (nvlist_error(nvl) != 0) {
1743 if (value != NULL) {
1744 for (i = 0; i < nitems; i++)
1745 nv_free(value[i]);
1746 nv_free(value);
1747 }
1748 ERRNO_SET(nvlist_error(nvl));
1749 return;
1750 }
1751
1752 nvp = nvpair_move_string_array(name, value, nitems);
1753 if (nvp == NULL) {
1754 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1755 ERRNO_SET(nvl->nvl_error);
1756 } else {
1757 (void)nvlist_move_nvpair(nvl, nvp);
1758 }
1759}
1760
1761void
1762nvlist_move_nvlist_array(nvlist_t *nvl, const char *name, nvlist_t **value,
1763 size_t nitems)
1764{
1765 nvpair_t *nvp;
1766 size_t i;
1767
1768 if (nvlist_error(nvl) != 0) {
1769 if (value != NULL) {
1770 for (i = 0; i < nitems; i++) {
1771 if (nvlist_get_pararr(value[i], NULL) == NULL)
1772 nvlist_destroy(value[i]);
1773 }
1774 }
1775 nv_free(value);
1776 ERRNO_SET(nvlist_error(nvl));
1777 return;
1778 }
1779
1780 nvp = nvpair_move_nvlist_array(name, value, nitems);
1781 if (nvp == NULL) {
1782 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1783 ERRNO_SET(nvl->nvl_error);
1784 } else {
1785 (void)nvlist_move_nvpair(nvl, nvp);
1786 }
1787}
1788
1789void
1790nvlist_move_number_array(nvlist_t *nvl, const char *name, uint64_t *value,
1791 size_t nitems)
1792{
1793 nvpair_t *nvp;
1794
1795 if (nvlist_error(nvl) != 0) {
1796 nv_free(value);
1797 ERRNO_SET(nvlist_error(nvl));
1798 return;
1799 }
1800
1801 nvp = nvpair_move_number_array(name, value, nitems);
1802 if (nvp == NULL) {
1803 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1804 ERRNO_SET(nvl->nvl_error);
1805 } else {
1806 (void)nvlist_move_nvpair(nvl, nvp);
1807 }
1808}
1809
1810#ifndef _KERNEL
1811void
1812nvlist_move_descriptor_array(nvlist_t *nvl, const char *name, int *value,
1813 size_t nitems)
1814{
1815 nvpair_t *nvp;
1816 size_t i;
1817
1818 if (nvlist_error(nvl) != 0) {
1819 if (value != 0) {
1820 for (i = 0; i < nitems; i++)
1821 close(value[i]);
1822 nv_free(value);
1823 }
1824
1825 ERRNO_SET(nvlist_error(nvl));
1826 return;
1827 }
1828
1829 nvp = nvpair_move_descriptor_array(name, value, nitems);
1830 if (nvp == NULL) {
1831 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1832 ERRNO_SET(nvl->nvl_error);
1833 } else {
1834 (void)nvlist_move_nvpair(nvl, nvp);
1835 }
1836}
1837#endif
1838
1309const nvpair_t *
1310nvlist_get_nvpair(const nvlist_t *nvl, const char *name)
1311{
1312
1313 return (nvlist_find(nvl, NV_TYPE_NONE, name));
1314}
1315
1316#define NVLIST_GET(ftype, type, TYPE) \

--- 25 unchanged lines hidden (view full) ---

1342
1343 nvp = nvlist_find(nvl, NV_TYPE_BINARY, name);
1344 if (nvp == NULL)
1345 nvlist_report_missing(NV_TYPE_BINARY, name);
1346
1347 return (nvpair_get_binary(nvp, sizep));
1348}
1349
1839const nvpair_t *
1840nvlist_get_nvpair(const nvlist_t *nvl, const char *name)
1841{
1842
1843 return (nvlist_find(nvl, NV_TYPE_NONE, name));
1844}
1845
1846#define NVLIST_GET(ftype, type, TYPE) \

--- 25 unchanged lines hidden (view full) ---

1872
1873 nvp = nvlist_find(nvl, NV_TYPE_BINARY, name);
1874 if (nvp == NULL)
1875 nvlist_report_missing(NV_TYPE_BINARY, name);
1876
1877 return (nvpair_get_binary(nvp, sizep));
1878}
1879
1880#define NVLIST_GET_ARRAY(ftype, type, TYPE) \
1881ftype \
1882nvlist_get_##type##_array(const nvlist_t *nvl, const char *name, \
1883 size_t *nitems) \
1884{ \
1885 const nvpair_t *nvp; \
1886 \
1887 nvp = nvlist_find(nvl, NV_TYPE_##TYPE##_ARRAY, name); \
1888 if (nvp == NULL) \
1889 nvlist_report_missing(NV_TYPE_##TYPE##_ARRAY, name); \
1890 return (nvpair_get_##type##_array(nvp, nitems)); \
1891}
1892
1893NVLIST_GET_ARRAY(const bool *, bool, BOOL)
1894NVLIST_GET_ARRAY(const uint64_t *, number, NUMBER)
1895NVLIST_GET_ARRAY(const char * const *, string, STRING)
1896NVLIST_GET_ARRAY(const nvlist_t * const *, nvlist, NVLIST)
1897#ifndef _KERNEL
1898NVLIST_GET_ARRAY(const int *, descriptor, DESCRIPTOR)
1899#endif
1900
1901#undef NVLIST_GET_ARRAY
1902
1350#define NVLIST_TAKE(ftype, type, TYPE) \
1351ftype \
1352nvlist_take_##type(nvlist_t *nvl, const char *name) \
1353{ \
1354 nvpair_t *nvp; \
1355 ftype value; \
1356 \
1357 nvp = nvlist_find(nvl, NV_TYPE_##TYPE, name); \

--- 26 unchanged lines hidden (view full) ---

1384 nvlist_report_missing(NV_TYPE_BINARY, name);
1385
1386 value = (void *)(intptr_t)nvpair_get_binary(nvp, sizep);
1387 nvlist_remove_nvpair(nvl, nvp);
1388 nvpair_free_structure(nvp);
1389 return (value);
1390}
1391
1903#define NVLIST_TAKE(ftype, type, TYPE) \
1904ftype \
1905nvlist_take_##type(nvlist_t *nvl, const char *name) \
1906{ \
1907 nvpair_t *nvp; \
1908 ftype value; \
1909 \
1910 nvp = nvlist_find(nvl, NV_TYPE_##TYPE, name); \

--- 26 unchanged lines hidden (view full) ---

1937 nvlist_report_missing(NV_TYPE_BINARY, name);
1938
1939 value = (void *)(intptr_t)nvpair_get_binary(nvp, sizep);
1940 nvlist_remove_nvpair(nvl, nvp);
1941 nvpair_free_structure(nvp);
1942 return (value);
1943}
1944
1945#define NVLIST_TAKE_ARRAY(ftype, type, TYPE) \
1946ftype \
1947nvlist_take_##type##_array(nvlist_t *nvl, const char *name, \
1948 size_t *nitems) \
1949{ \
1950 nvpair_t *nvp; \
1951 ftype value; \
1952 \
1953 nvp = nvlist_find(nvl, NV_TYPE_##TYPE##_ARRAY, name); \
1954 if (nvp == NULL) \
1955 nvlist_report_missing(NV_TYPE_##TYPE##_ARRAY, name); \
1956 value = (ftype)(intptr_t)nvpair_get_##type##_array(nvp, nitems);\
1957 nvlist_remove_nvpair(nvl, nvp); \
1958 nvpair_free_structure(nvp); \
1959 return (value); \
1960}
1961
1962NVLIST_TAKE_ARRAY(bool *, bool, BOOL)
1963NVLIST_TAKE_ARRAY(uint64_t *, number, NUMBER)
1964NVLIST_TAKE_ARRAY(char **, string, STRING)
1965NVLIST_TAKE_ARRAY(nvlist_t **, nvlist, NVLIST)
1966#ifndef _KERNEL
1967NVLIST_TAKE_ARRAY(int *, descriptor, DESCRIPTOR)
1968#endif
1969
1392void
1393nvlist_remove_nvpair(nvlist_t *nvl, nvpair_t *nvp)
1394{
1395
1396 NVLIST_ASSERT(nvl);
1397 NVPAIR_ASSERT(nvp);
1398 PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
1399

--- 15 unchanged lines hidden (view full) ---

1415 nvlist_free_type(nvl, name, NV_TYPE_##TYPE); \
1416}
1417
1418NVLIST_FREE(null, NULL)
1419NVLIST_FREE(bool, BOOL)
1420NVLIST_FREE(number, NUMBER)
1421NVLIST_FREE(string, STRING)
1422NVLIST_FREE(nvlist, NVLIST)
1970void
1971nvlist_remove_nvpair(nvlist_t *nvl, nvpair_t *nvp)
1972{
1973
1974 NVLIST_ASSERT(nvl);
1975 NVPAIR_ASSERT(nvp);
1976 PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
1977

--- 15 unchanged lines hidden (view full) ---

1993 nvlist_free_type(nvl, name, NV_TYPE_##TYPE); \
1994}
1995
1996NVLIST_FREE(null, NULL)
1997NVLIST_FREE(bool, BOOL)
1998NVLIST_FREE(number, NUMBER)
1999NVLIST_FREE(string, STRING)
2000NVLIST_FREE(nvlist, NVLIST)
2001NVLIST_FREE(binary, BINARY)
2002NVLIST_FREE(bool_array, BOOL_ARRAY)
2003NVLIST_FREE(number_array, NUMBER_ARRAY)
2004NVLIST_FREE(string_array, STRING_ARRAY)
2005NVLIST_FREE(nvlist_array, NVLIST_ARRAY)
1423#ifndef _KERNEL
1424NVLIST_FREE(descriptor, DESCRIPTOR)
2006#ifndef _KERNEL
2007NVLIST_FREE(descriptor, DESCRIPTOR)
2008NVLIST_FREE(descriptor_array, DESCRIPTOR_ARRAY)
1425#endif
2009#endif
1426NVLIST_FREE(binary, BINARY)
1427
1428#undef NVLIST_FREE
1429
1430void
1431nvlist_free_nvpair(nvlist_t *nvl, nvpair_t *nvp)
1432{
1433
1434 NVLIST_ASSERT(nvl);
1435 NVPAIR_ASSERT(nvp);
1436 PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
1437
1438 nvlist_remove_nvpair(nvl, nvp);
1439 nvpair_free(nvp);
1440}
1441
2010
2011#undef NVLIST_FREE
2012
2013void
2014nvlist_free_nvpair(nvlist_t *nvl, nvpair_t *nvp)
2015{
2016
2017 NVLIST_ASSERT(nvl);
2018 NVPAIR_ASSERT(nvp);
2019 PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
2020
2021 nvlist_remove_nvpair(nvl, nvp);
2022 nvpair_free(nvp);
2023}
2024