xref: /freebsd/sys/contrib/libnv/nvpair_impl.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2009-2013 The FreeBSD Foundation
5  * Copyright (c) 2013-2015 Mariusz Zaborski <oshogbo@FreeBSD.org>
6  * All rights reserved.
7  *
8  * This software was developed by Pawel Jakub Dawidek under sponsorship from
9  * the FreeBSD Foundation.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
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.
19  *
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
30  * SUCH DAMAGE.
31  *
32  * $FreeBSD$
33  */
34 
35 #ifndef	_NVPAIR_IMPL_H_
36 #define	_NVPAIR_IMPL_H_
37 
38 #include <sys/nv.h>
39 #include <sys/queue.h>
40 
41 #ifndef _KERNEL
42 #include <stdint.h>
43 #endif
44 
45 TAILQ_HEAD(nvl_head, nvpair);
46 
47 void nvpair_assert(const nvpair_t *nvp);
48 nvlist_t *nvpair_nvlist(const nvpair_t *nvp);
49 nvpair_t *nvpair_next(const nvpair_t *nvp);
50 nvpair_t *nvpair_prev(const nvpair_t *nvp);
51 void nvpair_insert(struct nvl_head *head, nvpair_t *nvp, nvlist_t *nvl);
52 void nvpair_remove(struct nvl_head *head, nvpair_t *nvp, const nvlist_t *nvl);
53 size_t nvpair_header_size(void);
54 size_t nvpair_size(const nvpair_t *nvp);
55 const unsigned char *nvpair_unpack(bool isbe, const unsigned char *ptr,
56     size_t *leftp, nvpair_t **nvpp);
57 void nvpair_free_structure(nvpair_t *nvp);
58 void nvpair_init_datasize(nvpair_t *nvp);
59 const char *nvpair_type_string(int type);
60 
61 /* Pack functions. */
62 unsigned char *nvpair_pack_header(const nvpair_t *nvp, unsigned char *ptr,
63     size_t *leftp);
64 unsigned char *nvpair_pack_null(const nvpair_t *nvp, unsigned char *ptr,
65     size_t *leftp);
66 unsigned char *nvpair_pack_bool(const nvpair_t *nvp, unsigned char *ptr,
67     size_t *leftp);
68 unsigned char *nvpair_pack_number(const nvpair_t *nvp, unsigned char *ptr,
69     size_t *leftp);
70 unsigned char *nvpair_pack_string(const nvpair_t *nvp, unsigned char *ptr,
71     size_t *leftp);
72 unsigned char *nvpair_pack_descriptor(const nvpair_t *nvp, unsigned char *ptr,
73     int64_t *fdidxp, size_t *leftp);
74 unsigned char *nvpair_pack_binary(const nvpair_t *nvp, unsigned char *ptr,
75     size_t *leftp);
76 unsigned char *nvpair_pack_nvlist_up(unsigned char *ptr, size_t *leftp);
77 unsigned char *nvpair_pack_bool_array(const nvpair_t *nvp, unsigned char *ptr,
78     size_t *leftp);
79 unsigned char *nvpair_pack_number_array(const nvpair_t *nvp, unsigned char *ptr,
80     size_t *leftp);
81 unsigned char *nvpair_pack_string_array(const nvpair_t *nvp, unsigned char *ptr,
82     size_t *leftp);
83 unsigned char *nvpair_pack_descriptor_array(const nvpair_t *nvp,
84     unsigned char *ptr, int64_t *fdidxp, size_t *leftp);
85 unsigned char *nvpair_pack_nvlist_array_next(unsigned char *ptr, size_t *leftp);
86 
87 /* Unpack data functions. */
88 const unsigned char *nvpair_unpack_header(bool isbe, nvpair_t *nvp,
89     const unsigned char *ptr, size_t *leftp);
90 const unsigned char *nvpair_unpack_null(bool isbe, nvpair_t *nvp,
91     const unsigned char *ptr, size_t *leftp);
92 const unsigned char *nvpair_unpack_bool(bool isbe, nvpair_t *nvp,
93     const unsigned char *ptr, size_t *leftp);
94 const unsigned char *nvpair_unpack_number(bool isbe, nvpair_t *nvp,
95     const unsigned char *ptr, size_t *leftp);
96 const unsigned char *nvpair_unpack_string(bool isbe, nvpair_t *nvp,
97     const unsigned char *ptr, size_t *leftp);
98 const unsigned char *nvpair_unpack_nvlist(bool isbe, nvpair_t *nvp,
99     const unsigned char *ptr, size_t *leftp, size_t nfds, nvlist_t **child);
100 const unsigned char *nvpair_unpack_descriptor(bool isbe, nvpair_t *nvp,
101     const unsigned char *ptr, size_t *leftp, const int *fds, size_t nfds);
102 const unsigned char *nvpair_unpack_binary(bool isbe, nvpair_t *nvp,
103     const unsigned char *ptr, size_t *leftp);
104 const unsigned char *nvpair_unpack_bool_array(bool isbe, nvpair_t *nvp,
105     const unsigned char *ptr, size_t *leftp);
106 const unsigned char *nvpair_unpack_number_array(bool isbe, nvpair_t *nvp,
107     const unsigned char *ptr, size_t *leftp);
108 const unsigned char *nvpair_unpack_string_array(bool isbe, nvpair_t *nvp,
109     const unsigned char *ptr, size_t *leftp);
110 const unsigned char *nvpair_unpack_descriptor_array(bool isbe, nvpair_t *nvp,
111     const unsigned char *ptr, size_t *leftp, const int *fds, size_t nfds);
112 const unsigned char *nvpair_unpack_nvlist_array(bool isbe, nvpair_t *nvp,
113     const unsigned char *ptr, size_t *leftp, nvlist_t **firstel);
114 
115 #endif	/* !_NVPAIR_IMPL_H_ */
116