FreeBSD/Linux Kernel Cross Reference
sys/sys/nv.h
1 /*-
2 * Copyright (c) 2009-2013 The FreeBSD Foundation
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:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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 * $FreeBSD$
30 */
31
32 #ifndef _NV_H_
33 #define _NV_H_
34
35 #include <sys/cdefs.h>
36
37 #ifndef _KERNEL
38 #include <stdarg.h>
39 #include <stdbool.h>
40 #include <stdint.h>
41 #include <stdio.h>
42 #endif
43
44 #ifndef _NVLIST_T_DECLARED
45 #define _NVLIST_T_DECLARED
46 struct nvlist;
47
48 typedef struct nvlist nvlist_t;
49 #endif
50
51 #define NV_NAME_MAX 2048
52
53 #define NV_TYPE_NONE 0
54
55 #define NV_TYPE_NULL 1
56 #define NV_TYPE_BOOL 2
57 #define NV_TYPE_NUMBER 3
58 #define NV_TYPE_STRING 4
59 #define NV_TYPE_NVLIST 5
60 #define NV_TYPE_DESCRIPTOR 6
61 #define NV_TYPE_BINARY 7
62
63 /*
64 * Perform case-insensitive lookups of provided names.
65 */
66 #define NV_FLAG_IGNORE_CASE 0x01
67
68 #if defined(_KERNEL) && defined(MALLOC_DECLARE)
69 MALLOC_DECLARE(M_NVLIST);
70 #endif
71
72 __BEGIN_DECLS
73
74 nvlist_t *nvlist_create(int flags);
75 void nvlist_destroy(nvlist_t *nvl);
76 int nvlist_error(const nvlist_t *nvl);
77 bool nvlist_empty(const nvlist_t *nvl);
78 int nvlist_flags(const nvlist_t *nvl);
79 void nvlist_set_error(nvlist_t *nvl, int error);
80
81 nvlist_t *nvlist_clone(const nvlist_t *nvl);
82
83 #ifndef _KERNEL
84 void nvlist_dump(const nvlist_t *nvl, int fd);
85 void nvlist_fdump(const nvlist_t *nvl, FILE *fp);
86 #endif
87
88 size_t nvlist_size(const nvlist_t *nvl);
89 void *nvlist_pack(const nvlist_t *nvl, size_t *sizep);
90 nvlist_t *nvlist_unpack(const void *buf, size_t size);
91
92 int nvlist_send(int sock, const nvlist_t *nvl);
93 nvlist_t *nvlist_recv(int sock);
94 nvlist_t *nvlist_xfer(int sock, nvlist_t *nvl);
95
96 const char *nvlist_next(const nvlist_t *nvl, int *typep, void **cookiep);
97
98 const nvlist_t *nvlist_get_parent(const nvlist_t *nvl, void **cookiep);
99
100 /*
101 * The nvlist_exists functions check if the given name (optionally of the given
102 * type) exists on nvlist.
103 */
104
105 bool nvlist_exists(const nvlist_t *nvl, const char *name);
106 bool nvlist_exists_type(const nvlist_t *nvl, const char *name, int type);
107
108 bool nvlist_exists_null(const nvlist_t *nvl, const char *name);
109 bool nvlist_exists_bool(const nvlist_t *nvl, const char *name);
110 bool nvlist_exists_number(const nvlist_t *nvl, const char *name);
111 bool nvlist_exists_string(const nvlist_t *nvl, const char *name);
112 bool nvlist_exists_nvlist(const nvlist_t *nvl, const char *name);
113 #ifndef _KERNEL
114 bool nvlist_exists_descriptor(const nvlist_t *nvl, const char *name);
115 #endif
116 bool nvlist_exists_binary(const nvlist_t *nvl, const char *name);
117
118 /*
119 * The nvlist_add functions add the given name/value pair.
120 * If a pointer is provided, nvlist_add will internally allocate memory for the
121 * given data (in other words it won't consume provided buffer).
122 */
123
124 void nvlist_add_null(nvlist_t *nvl, const char *name);
125 void nvlist_add_bool(nvlist_t *nvl, const char *name, bool value);
126 void nvlist_add_number(nvlist_t *nvl, const char *name, uint64_t value);
127 void nvlist_add_string(nvlist_t *nvl, const char *name, const char *value);
128 void nvlist_add_stringf(nvlist_t *nvl, const char *name, const char *valuefmt, ...) __printflike(3, 4);
129 #ifdef _VA_LIST_DECLARED
130 void nvlist_add_stringv(nvlist_t *nvl, const char *name, const char *valuefmt, va_list valueap) __printflike(3, 0);
131 #endif
132 void nvlist_add_nvlist(nvlist_t *nvl, const char *name, const nvlist_t *value);
133 #ifndef _KERNEL
134 void nvlist_add_descriptor(nvlist_t *nvl, const char *name, int value);
135 #endif
136 void nvlist_add_binary(nvlist_t *nvl, const char *name, const void *value, size_t size);
137
138 /*
139 * The nvlist_move functions add the given name/value pair.
140 * The functions consumes provided buffer.
141 */
142
143 void nvlist_move_string(nvlist_t *nvl, const char *name, char *value);
144 void nvlist_move_nvlist(nvlist_t *nvl, const char *name, nvlist_t *value);
145 #ifndef _KERNEL
146 void nvlist_move_descriptor(nvlist_t *nvl, const char *name, int value);
147 #endif
148 void nvlist_move_binary(nvlist_t *nvl, const char *name, void *value, size_t size);
149
150 /*
151 * The nvlist_get functions returns value associated with the given name.
152 * If it returns a pointer, the pointer represents internal buffer and should
153 * not be freed by the caller.
154 */
155
156 bool nvlist_get_bool(const nvlist_t *nvl, const char *name);
157 uint64_t nvlist_get_number(const nvlist_t *nvl, const char *name);
158 const char *nvlist_get_string(const nvlist_t *nvl, const char *name);
159 const nvlist_t *nvlist_get_nvlist(const nvlist_t *nvl, const char *name);
160 #ifndef _KERNEL
161 int nvlist_get_descriptor(const nvlist_t *nvl, const char *name);
162 #endif
163 const void *nvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep);
164
165 /*
166 * The nvlist_take functions returns value associated with the given name and
167 * remove the given entry from the nvlist.
168 * The caller is responsible for freeing received data.
169 */
170
171 bool nvlist_take_bool(nvlist_t *nvl, const char *name);
172 uint64_t nvlist_take_number(nvlist_t *nvl, const char *name);
173 char *nvlist_take_string(nvlist_t *nvl, const char *name);
174 nvlist_t *nvlist_take_nvlist(nvlist_t *nvl, const char *name);
175 #ifndef _KERNEL
176 int nvlist_take_descriptor(nvlist_t *nvl, const char *name);
177 #endif
178 void *nvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep);
179
180 /*
181 * The nvlist_free functions removes the given name/value pair from the nvlist
182 * and frees memory associated with it.
183 */
184
185 void nvlist_free(nvlist_t *nvl, const char *name);
186 void nvlist_free_type(nvlist_t *nvl, const char *name, int type);
187
188 void nvlist_free_null(nvlist_t *nvl, const char *name);
189 void nvlist_free_bool(nvlist_t *nvl, const char *name);
190 void nvlist_free_number(nvlist_t *nvl, const char *name);
191 void nvlist_free_string(nvlist_t *nvl, const char *name);
192 void nvlist_free_nvlist(nvlist_t *nvl, const char *name);
193 #ifndef _KERNEL
194 void nvlist_free_descriptor(nvlist_t *nvl, const char *name);
195 #endif
196 void nvlist_free_binary(nvlist_t *nvl, const char *name);
197
198 __END_DECLS
199
200 #endif /* !_NV_H_ */
Cache object: ff5e56fd1e4063623e19180cb07bce3a
|