Lines Matching refs:nvl

97 #define	NVLIST_MAGIC	0x6e766c	/* "nvl" */
108 #define NVLIST_ASSERT(nvl) do { \
109 PJDLOG_ASSERT((nvl) != NULL); \
110 PJDLOG_ASSERT((nvl)->nvl_magic == NVLIST_MAGIC); \
132 nvlist_t *nvl;
136 nvl = nv_malloc(sizeof(*nvl));
137 if (nvl == NULL)
139 nvl->nvl_error = 0;
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;
147 return (nvl);
151 nvlist_destroy(nvlist_t *nvl)
155 if (nvl == NULL)
160 NVLIST_ASSERT(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;
170 nvl->nvl_magic = 0;
171 nv_free(nvl);
177 nvlist_set_error(nvlist_t *nvl, int error)
186 if (nvl != NULL && error != 0 && nvl->nvl_error == 0)
187 nvl->nvl_error = error;
191 nvlist_error(const nvlist_t *nvl)
194 if (nvl == NULL)
197 NVLIST_ASSERT(nvl);
199 return (nvl->nvl_error);
203 nvlist_get_nvpair_parent(const nvlist_t *nvl)
206 NVLIST_ASSERT(nvl);
208 return (nvl->nvl_parent);
212 nvlist_get_parent(const nvlist_t *nvl, void **cookiep)
216 NVLIST_ASSERT(nvl);
218 nvp = nvl->nvl_parent;
228 nvlist_set_parent(nvlist_t *nvl, nvpair_t *parent)
231 NVLIST_ASSERT(nvl);
233 nvl->nvl_parent = parent;
237 nvlist_set_array_next(nvlist_t *nvl, nvpair_t *ele)
240 NVLIST_ASSERT(nvl);
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)
262 NVLIST_ASSERT(nvl);
288 nvl->nvl_datasize += size;
290 parent = nvl;
298 nvlist_get_array_next_nvpair(nvlist_t *nvl)
301 NVLIST_ASSERT(nvl);
303 return (nvl->nvl_array_next);
307 nvlist_in_array(const nvlist_t *nvl)
310 NVLIST_ASSERT(nvl);
312 return ((nvl->nvl_flags & NV_FLAG_IN_ARRAY) != 0);
316 nvlist_get_array_next(const nvlist_t *nvl)
320 NVLIST_ASSERT(nvl);
322 nvp = nvl->nvl_array_next;
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)
348 NVLIST_ASSERT(nvl);
349 PJDLOG_ASSERT(nvl->nvl_error == 0);
351 return (nvlist_first_nvpair(nvl) == NULL);
355 nvlist_flags(const nvlist_t *nvl)
358 NVLIST_ASSERT(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)
368 NVLIST_ASSERT(nvl);
369 PJDLOG_ASSERT(nvl->nvl_error == 0);
371 nvl->nvl_flags = flags;
383 nvlist_find(const nvlist_t *nvl, int type, const char *name)
387 NVLIST_ASSERT(nvl);
388 PJDLOG_ASSERT(nvl->nvl_error == 0);
392 for (nvp = nvlist_first_nvpair(nvl); nvp != NULL;
393 nvp = nvlist_next_nvpair(nvl, nvp)) {
396 if ((nvl->nvl_flags & NV_FLAG_IGNORE_CASE) != 0) {
413 nvlist_exists_type(const nvlist_t *nvl, const char *name, int type)
416 NVLIST_ASSERT(nvl);
417 PJDLOG_ASSERT(nvl->nvl_error == 0);
421 return (nvlist_find(nvl, type, name) != NULL);
425 nvlist_free_type(nvlist_t *nvl, const char *name, int type)
429 NVLIST_ASSERT(nvl);
430 PJDLOG_ASSERT(nvl->nvl_error == 0);
434 nvp = nvlist_find(nvl, type, name);
436 nvlist_free_nvpair(nvl, nvp);
442 nvlist_clone(const nvlist_t *nvl)
447 NVLIST_ASSERT(nvl);
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)) {
471 nvlist_dump_error_check(const nvlist_t *nvl, int fd, int level)
474 if (nvlist_error(nvl) != 0) {
476 nvlist_error(nvl));
487 nvlist_dump(const nvlist_t *nvl, int fd)
495 if (nvlist_dump_error_check(nvl, fd, level))
498 nvp = nvlist_first_nvpair(nvl);
526 nvl = tmpnvl;
643 nvl = tmpnvl;
654 while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
657 if (nvlist_in_array(nvl))
659 nvl = nvlist_get_pararr(nvl, &cookie);
660 if (nvl == NULL)
662 if (nvlist_in_array(nvl) && cookie == NULL) {
663 nvp = nvlist_first_nvpair(nvl);
669 if (nvlist_in_array(nvl) && cookie == NULL)
676 nvlist_fdump(const nvlist_t *nvl, FILE *fp)
680 nvlist_dump(nvl, fileno(fp));
688 nvlist_size(const nvlist_t *nvl)
691 return (nvl->nvl_datasize);
696 nvlist_xdescriptors(const nvlist_t *nvl, int *descs)
702 NVLIST_ASSERT(nvl);
703 PJDLOG_ASSERT(nvl->nvl_error == 0);
707 while (nvlist_next(nvl, &type, &cookie) != NULL) {
729 nvl = nvpair_get_nvlist(nvp);
741 nvl = value[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);
765 nvlist_xdescriptors(nvl, fds);
774 nvlist_ndescriptors(const nvlist_t *nvl)
782 NVLIST_ASSERT(nvl);
783 PJDLOG_ASSERT(nvl->nvl_error == 0);
788 while (nvlist_next(nvl, &type, &cookie) != NULL) {
795 nvl = nvpair_get_nvlist(nvp);
807 nvl = value[0];
822 } while ((nvl = nvlist_get_pararr(nvl, &cookie)) != NULL);
831 nvlist_pack_header(const nvlist_t *nvl, unsigned char *ptr, size_t *leftp)
835 NVLIST_ASSERT(nvl);
839 nvlhdr.nvlh_flags = nvl->nvl_flags;
843 nvlhdr.nvlh_descriptors = nvlist_ndescriptors(nvl);
854 nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep)
862 NVLIST_ASSERT(nvl);
864 if (nvl->nvl_error != 0) {
865 ERRNO_SET(nvl->nvl_error);
869 size = nvlist_size(nvl);
877 ptr = nvlist_pack_header(nvl, ptr, &left);
879 nvp = nvlist_first_nvpair(nvl);
907 nvl = tmpnvl;
956 nvl = tmpnvl;
967 while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
970 if (nvlist_in_array(nvl)) {
976 nvl = nvlist_get_pararr(nvl, &cookie);
977 if (nvl == NULL)
979 if (nvlist_in_array(nvl) && cookie == NULL) {
980 nvp = nvlist_first_nvpair(nvl);
981 ptr = nvlist_pack_header(nvl, ptr,
995 if (nvlist_in_array(nvl) && cookie == NULL)
1010 nvlist_pack(const nvlist_t *nvl, size_t *sizep)
1013 NVLIST_ASSERT(nvl);
1015 if (nvl->nvl_error != 0) {
1016 ERRNO_SET(nvl->nvl_error);
1020 if (nvlist_ndescriptors(nvl) > 0) {
1025 return (nvlist_xpack(nvl, NULL, sizep));
1055 nvlist_unpack_header(nvlist_t *nvl, const unsigned char *ptr, size_t nfds,
1081 inarrayf = (nvl->nvl_flags & NV_FLAG_IN_ARRAY);
1082 nvl->nvl_flags = (nvlhdr.nvlh_flags & NV_FLAG_PUBLIC_MASK) | inarrayf;
1100 nvlist_t *nvl, *retnvl, *tmpnvl, *array;
1111 nvl = retnvl = nvlist_create(0);
1112 if (nvl == NULL)
1115 ptr = nvlist_unpack_header(nvl, ptr, nfds, &isbe, &left);
1118 if (nvl->nvl_flags != flags) {
1161 if (nvl->nvl_parent == NULL)
1163 nvl = nvpair_nvlist(nvl->nvl_parent);
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,
1210 if (!nvlist_move_nvpair(nvl, nvp))
1213 nvl = tmpnvl;
1233 nvlist_send(int sock, const nvlist_t *nvl)
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);
1278 nvlist_t *nvl, *ret;
1323 nvl = nvlist_xunpack(buf, size, fds, nfds, flags);
1324 if (nvl == NULL) {
1332 ret = nvl;
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);
1356 nvlist_first_nvpair(const nvlist_t *nvl)
1359 NVLIST_ASSERT(nvl);
1361 return (TAILQ_FIRST(&nvl->nvl_head));
1365 nvlist_next_nvpair(const nvlist_t *nvl __unused, const nvpair_t *nvp)
1369 NVLIST_ASSERT(nvl);
1371 PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
1374 PJDLOG_ASSERT(retnvp == NULL || nvpair_nvlist(retnvp) == nvl);
1381 nvlist_prev_nvpair(const nvlist_t *nvl __unused, const nvpair_t *nvp)
1385 NVLIST_ASSERT(nvl);
1387 PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
1390 PJDLOG_ASSERT(nvpair_nvlist(retnvp) == nvl);
1396 nvlist_next(const nvlist_t *nvl, int *typep, void **cookiep)
1400 NVLIST_ASSERT(nvl);
1403 nvp = nvlist_first_nvpair(nvl);
1405 nvp = nvlist_next_nvpair(nvl, *cookiep);
1416 nvlist_exists(const nvlist_t *nvl, const char *name)
1419 return (nvlist_find(nvl, NV_TYPE_NONE, name) != NULL);
1424 nvlist_exists_##type(const nvlist_t *nvl, const char *name) \
1427 return (nvlist_find(nvl, NV_TYPE_##TYPE, name) != NULL); \
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));
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, ...)
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));
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));
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));
1539 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1540 ERRNO_SET(nvl->nvl_error);
1542 (void)nvlist_move_nvpair(nvl, nvp);
1549 nvlist_add_##type(nvlist_t *nvl, const char *name, vtype value) \
1553 if (nvlist_error(nvl) != 0) { \
1554 ERRNO_SET(nvlist_error(nvl)); \
1560 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); \
1561 ERRNO_SET(nvl->nvl_error); \
1563 (void)nvlist_move_nvpair(nvl, nvp); \
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)); \
1591 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); \
1592 ERRNO_SET(nvl->nvl_error); \
1594 (void)nvlist_move_nvpair(nvl, nvp); \
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); \
1620 nvlist_add_##type##_array(nvl, name, &value, 1); \
1623 nvlist_update_size(nvl, nvp, -1); \
1625 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); \
1626 ERRNO_SET(nvl->nvl_error); \
1628 nvlist_update_size(nvl, nvp, 1); \
1642 nvlist_move_nvpair(nvlist_t *nvl, nvpair_t *nvp)
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));
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) {
1695 ERRNO_SET(nvlist_error(nvl));
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));
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));
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));
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) {
1784 ERRNO_SET(nvlist_error(nvl));
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) {
1812 ERRNO_SET(nvlist_error(nvl));
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));
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) {
1861 ERRNO_SET(nvlist_error(nvl));
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));
1884 nvlist_get_##type(const nvlist_t *nvl, const char *name) \
1888 nvp = nvlist_find(nvl, NV_TYPE_##TYPE, name); \
1905 nvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep)
1909 nvp = nvlist_find(nvl, NV_TYPE_BINARY, name);
1918 nvlist_get_##type##_array(const nvlist_t *nvl, const char *name, \
1923 nvp = nvlist_find(nvl, NV_TYPE_##TYPE##_ARRAY, name); \
1941 nvlist_take_##type(nvlist_t *nvl, const char *name) \
1946 nvp = nvlist_find(nvl, NV_TYPE_##TYPE, name); \
1950 nvlist_remove_nvpair(nvl, nvp); \
1966 nvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep)
1971 nvp = nvlist_find(nvl, NV_TYPE_BINARY, name);
1976 nvlist_remove_nvpair(nvl, nvp);
1983 nvlist_take_##type##_array(nvlist_t *nvl, const char *name, \
1989 nvp = nvlist_find(nvl, NV_TYPE_##TYPE##_ARRAY, name); \
1993 nvlist_remove_nvpair(nvl, nvp); \
2007 nvlist_remove_nvpair(nvlist_t *nvl, nvpair_t *nvp)
2010 NVLIST_ASSERT(nvl);
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);
2027 nvlist_free_##type(nvlist_t *nvl, const char *name) \
2030 nvlist_free_type(nvl, name, NV_TYPE_##TYPE); \
2051 nvlist_free_nvpair(nvlist_t *nvl, nvpair_t *nvp)
2054 NVLIST_ASSERT(nvl);
2056 PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
2058 nvlist_remove_nvpair(nvl, nvp);