libdm_ioctl.c revision 1.1.2.2 1 1.1.2.2 bouyer /*
2 1.1.2.2 bouyer * Copyright (c) 2010 The NetBSD Foundation, Inc.
3 1.1.2.2 bouyer * All rights reserved.
4 1.1.2.2 bouyer *
5 1.1.2.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
6 1.1.2.2 bouyer * by Adam Hamsik.
7 1.1.2.2 bouyer *
8 1.1.2.2 bouyer * Redistribution and use in source and binary forms, with or without
9 1.1.2.2 bouyer * modification, are permitted provided that the following conditions
10 1.1.2.2 bouyer * are met:
11 1.1.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
12 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer.
13 1.1.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
14 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
15 1.1.2.2 bouyer * documentation and/or other materials provided with the distribution.
16 1.1.2.2 bouyer *
17 1.1.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18 1.1.2.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 1.1.2.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 1.1.2.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21 1.1.2.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 1.1.2.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 1.1.2.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 1.1.2.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 1.1.2.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 1.1.2.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 1.1.2.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
28 1.1.2.2 bouyer */
29 1.1.2.2 bouyer
30 1.1.2.2 bouyer #include <sys/types.h>
31 1.1.2.2 bouyer #include <sys/param.h>
32 1.1.2.2 bouyer #include <sys/ioctl.h>
33 1.1.2.2 bouyer
34 1.1.2.2 bouyer #include <errno.h>
35 1.1.2.2 bouyer #include <fcntl.h>
36 1.1.2.2 bouyer #include <stdio.h>
37 1.1.2.2 bouyer #include <stdlib.h>
38 1.1.2.2 bouyer #include <string.h>
39 1.1.2.2 bouyer #include <unistd.h>
40 1.1.2.2 bouyer
41 1.1.2.2 bouyer #include <prop/proplib.h>
42 1.1.2.2 bouyer
43 1.1.2.2 bouyer #include <dev/dm/netbsd-dm.h>
44 1.1.2.2 bouyer
45 1.1.2.2 bouyer #include "dm.h"
46 1.1.2.2 bouyer
47 1.1.2.2 bouyer /*
48 1.1.2.2 bouyer * Libdm library works like interface between device-mapper driver and
49 1.1.2.2 bouyer * NetBSD userspace. For start it uses same set of commands like linux
50 1.1.2.2 bouyer * libdevmapper, but in later stage if we introduce NetBSD device-mapper
51 1.1.2.2 bouyer * extensions we don't need to change libdevmapper.
52 1.1.2.2 bouyer *
53 1.1.2.2 bouyer * LIBDM basically creates one proplib dictionary with everything what is
54 1.1.2.2 bouyer * needed to work with device-mapper devices.
55 1.1.2.2 bouyer *
56 1.1.2.2 bouyer * Basic element of libdm is libdm_task which contains version and command
57 1.1.2.2 bouyer * string with another dictionary cmd.
58 1.1.2.2 bouyer */
59 1.1.2.2 bouyer
60 1.1.2.2 bouyer struct libdm_cmd {
61 1.1.2.2 bouyer prop_array_t ldm_cmd;
62 1.1.2.2 bouyer };
63 1.1.2.2 bouyer
64 1.1.2.2 bouyer struct libdm_iter {
65 1.1.2.2 bouyer prop_object_iterator_t ldm_obji;
66 1.1.2.2 bouyer };
67 1.1.2.2 bouyer
68 1.1.2.2 bouyer struct libdm_task {
69 1.1.2.2 bouyer prop_dictionary_t ldm_task;
70 1.1.2.2 bouyer };
71 1.1.2.2 bouyer
72 1.1.2.2 bouyer struct libdm_table {
73 1.1.2.2 bouyer prop_dictionary_t ldm_tbl;
74 1.1.2.2 bouyer };
75 1.1.2.2 bouyer
76 1.1.2.2 bouyer struct libdm_target {
77 1.1.2.2 bouyer prop_dictionary_t ldm_trgt;
78 1.1.2.2 bouyer };
79 1.1.2.2 bouyer
80 1.1.2.2 bouyer struct libdm_dev {
81 1.1.2.2 bouyer prop_dictionary_t ldm_dev;
82 1.1.2.2 bouyer };
83 1.1.2.2 bouyer
84 1.1.2.2 bouyer struct cmd_version cmd_ver[] = {
85 1.1.2.2 bouyer {"version", {4, 0, 0}},
86 1.1.2.2 bouyer {"targets", {4, 0, 0}},
87 1.1.2.2 bouyer {"create", {4, 0, 0}},
88 1.1.2.2 bouyer {"info", {4, 0, 0}},
89 1.1.2.2 bouyer {"mknodes",{4, 0, 0}},
90 1.1.2.2 bouyer {"names", {4, 0, 0}},
91 1.1.2.2 bouyer {"suspend",{4, 0, 0}},
92 1.1.2.2 bouyer {"remove", {4, 0, 0}},
93 1.1.2.2 bouyer {"rename", {4, 0, 0}},
94 1.1.2.2 bouyer {"resume", {4, 0, 0}},
95 1.1.2.2 bouyer {"clear", {4, 0, 0}},
96 1.1.2.2 bouyer {"deps", {4, 0, 0}},
97 1.1.2.2 bouyer {"reload", {4, 0, 0}},
98 1.1.2.2 bouyer {"status", {4, 0, 0}},
99 1.1.2.2 bouyer {"table", {4, 0, 0}},
100 1.1.2.2 bouyer /* NetBSD device-mapper command extension goes here */
101 1.1.2.2 bouyer {NULL, {0, 0, 0}}
102 1.1.2.2 bouyer };
103 1.1.2.2 bouyer
104 1.1.2.2 bouyer /* /dev/mapper/control managing routines */
105 1.1.2.2 bouyer static int libdm_control_open(const char *);
106 1.1.2.2 bouyer static int libdm_control_close(int);
107 1.1.2.2 bouyer
108 1.1.2.2 bouyer static int
109 1.1.2.2 bouyer libdm_control_open(const char *path)
110 1.1.2.2 bouyer {
111 1.1.2.2 bouyer int fd;
112 1.1.2.2 bouyer #ifdef RUMP_ACTION
113 1.1.2.2 bouyer if ((fd = rump_sys_open(path, O_RDWR)) < 0)
114 1.1.2.2 bouyer return -1;
115 1.1.2.2 bouyer #else
116 1.1.2.2 bouyer if ((fd = open(path, O_RDWR)) < 0)
117 1.1.2.2 bouyer return -1;
118 1.1.2.2 bouyer #endif
119 1.1.2.2 bouyer return fd;
120 1.1.2.2 bouyer }
121 1.1.2.2 bouyer
122 1.1.2.2 bouyer static int
123 1.1.2.2 bouyer libdm_control_close(int fd)
124 1.1.2.2 bouyer {
125 1.1.2.2 bouyer
126 1.1.2.2 bouyer #ifdef RUMP_ACTION
127 1.1.2.2 bouyer return rump_sys_close(fd);
128 1.1.2.2 bouyer #else
129 1.1.2.2 bouyer return close(fd);
130 1.1.2.2 bouyer #endif
131 1.1.2.2 bouyer }
132 1.1.2.2 bouyer
133 1.1.2.2 bouyer /* Destroy iterator for arrays such as version strings, cmd_data. */
134 1.1.2.2 bouyer void
135 1.1.2.2 bouyer libdm_iter_destroy(libdm_iter_t libdm_iter)
136 1.1.2.2 bouyer {
137 1.1.2.2 bouyer
138 1.1.2.2 bouyer prop_object_iterator_release(libdm_iter->ldm_obji);
139 1.1.2.2 bouyer free(libdm_iter);
140 1.1.2.2 bouyer }
141 1.1.2.2 bouyer
142 1.1.2.2 bouyer /*
143 1.1.2.2 bouyer * Issue ioctl call to kernel, releasing both dictionaries is
144 1.1.2.2 bouyer * left on callers.
145 1.1.2.2 bouyer */
146 1.1.2.2 bouyer int
147 1.1.2.2 bouyer libdm_task_run(libdm_task_t libdm_task)
148 1.1.2.2 bouyer {
149 1.1.2.2 bouyer prop_dictionary_t dict;
150 1.1.2.2 bouyer int libdm_control_fd = -1;
151 1.1.2.2 bouyer int error;
152 1.1.2.2 bouyer #ifdef RUMP_ACTION
153 1.1.2.2 bouyer struct plistref prefp;
154 1.1.2.2 bouyer #endif
155 1.1.2.2 bouyer error = 0;
156 1.1.2.2 bouyer
157 1.1.2.2 bouyer if (libdm_task == NULL)
158 1.1.2.2 bouyer return ENOENT;
159 1.1.2.2 bouyer
160 1.1.2.2 bouyer if ((libdm_control_fd = libdm_control_open(DM_DEVICE_PATH)) < 0)
161 1.1.2.2 bouyer return errno;
162 1.1.2.2 bouyer #ifdef RUMP_ACTION
163 1.1.2.2 bouyer prop_dictionary_externalize_to_pref(libdm_task->ldm_task,
164 1.1.2.2 bouyer &prefp);
165 1.1.2.2 bouyer
166 1.1.2.2 bouyer error = rump_sys_ioctl(libdm_control_fd, NETBSD_DM_IOCTL, &prefp);
167 1.1.2.2 bouyer if (error < 0) {
168 1.1.2.2 bouyer libdm_task_destroy(libdm_task);
169 1.1.2.2 bouyer libdm_task = NULL;
170 1.1.2.2 bouyer libdm_control_close(libdm_control_fd);
171 1.1.2.2 bouyer
172 1.1.2.2 bouyer return error;
173 1.1.2.2 bouyer }
174 1.1.2.2 bouyer dict = prop_dictionary_internalize(prefp.pref_plist);
175 1.1.2.2 bouyer #else
176 1.1.2.2 bouyer prop_dictionary_externalize_to_file(libdm_task->ldm_task, "/tmp/libdm_in");
177 1.1.2.2 bouyer error = prop_dictionary_sendrecv_ioctl(libdm_task->ldm_task,
178 1.1.2.2 bouyer libdm_control_fd, NETBSD_DM_IOCTL, &dict);
179 1.1.2.2 bouyer if ( error != 0) {
180 1.1.2.2 bouyer libdm_task_destroy(libdm_task);
181 1.1.2.2 bouyer libdm_task = NULL;
182 1.1.2.2 bouyer libdm_control_close(libdm_control_fd);
183 1.1.2.2 bouyer return error;
184 1.1.2.2 bouyer }
185 1.1.2.2 bouyer prop_dictionary_externalize_to_file(dict, "/tmp/libdm_out");
186 1.1.2.2 bouyer #endif
187 1.1.2.2 bouyer
188 1.1.2.2 bouyer libdm_control_close(libdm_control_fd);
189 1.1.2.2 bouyer prop_object_retain(dict);
190 1.1.2.2 bouyer prop_object_release(libdm_task->ldm_task);
191 1.1.2.2 bouyer libdm_task->ldm_task = dict;
192 1.1.2.2 bouyer
193 1.1.2.2 bouyer return EXIT_SUCCESS;
194 1.1.2.2 bouyer }
195 1.1.2.2 bouyer
196 1.1.2.2 bouyer
197 1.1.2.2 bouyer /* Create libdm General task structure */
198 1.1.2.2 bouyer libdm_task_t
199 1.1.2.2 bouyer libdm_task_create(const char *command)
200 1.1.2.2 bouyer {
201 1.1.2.2 bouyer libdm_task_t task;
202 1.1.2.2 bouyer size_t i,len,slen;
203 1.1.2.2 bouyer prop_array_t ver;
204 1.1.2.2 bouyer
205 1.1.2.2 bouyer task = NULL;
206 1.1.2.2 bouyer
207 1.1.2.2 bouyer task = malloc(sizeof(*task));
208 1.1.2.2 bouyer if (task == NULL)
209 1.1.2.2 bouyer return NULL;
210 1.1.2.2 bouyer
211 1.1.2.2 bouyer if ((task->ldm_task = prop_dictionary_create()) == NULL) {
212 1.1.2.2 bouyer free(task);
213 1.1.2.2 bouyer return NULL;
214 1.1.2.2 bouyer }
215 1.1.2.2 bouyer
216 1.1.2.2 bouyer if ((prop_dictionary_set_cstring(task->ldm_task, DM_IOCTL_COMMAND,
217 1.1.2.2 bouyer command)) == false) {
218 1.1.2.2 bouyer prop_object_release(task->ldm_task);
219 1.1.2.2 bouyer free(task);
220 1.1.2.2 bouyer return NULL;
221 1.1.2.2 bouyer }
222 1.1.2.2 bouyer
223 1.1.2.2 bouyer len = strlen(command);
224 1.1.2.2 bouyer
225 1.1.2.2 bouyer for (i = 0; cmd_ver[i].cmd != NULL; i++) {
226 1.1.2.2 bouyer slen = strlen(cmd_ver[i].cmd);
227 1.1.2.2 bouyer
228 1.1.2.2 bouyer if (len != slen)
229 1.1.2.2 bouyer continue;
230 1.1.2.2 bouyer
231 1.1.2.2 bouyer if ((strncmp(command, cmd_ver[i].cmd, slen)) == 0) {
232 1.1.2.2 bouyer ver = prop_array_create();
233 1.1.2.2 bouyer prop_array_add_uint32(ver, cmd_ver[i].version[0]);
234 1.1.2.2 bouyer prop_array_add_uint32(ver, cmd_ver[i].version[1]);
235 1.1.2.2 bouyer prop_array_add_uint32(ver, cmd_ver[i].version[2]);
236 1.1.2.2 bouyer
237 1.1.2.2 bouyer prop_dictionary_set(task->ldm_task, DM_IOCTL_VERSION,
238 1.1.2.2 bouyer ver);
239 1.1.2.2 bouyer
240 1.1.2.2 bouyer prop_object_release(ver);
241 1.1.2.2 bouyer break;
242 1.1.2.2 bouyer }
243 1.1.2.2 bouyer }
244 1.1.2.2 bouyer
245 1.1.2.2 bouyer return task;
246 1.1.2.2 bouyer }
247 1.1.2.2 bouyer
248 1.1.2.2 bouyer void
249 1.1.2.2 bouyer libdm_task_destroy(libdm_task_t libdm_task)
250 1.1.2.2 bouyer {
251 1.1.2.2 bouyer
252 1.1.2.2 bouyer if (libdm_task != NULL)
253 1.1.2.2 bouyer prop_object_release(libdm_task->ldm_task);
254 1.1.2.2 bouyer free(libdm_task);
255 1.1.2.2 bouyer }
256 1.1.2.2 bouyer
257 1.1.2.2 bouyer /* Set device name */
258 1.1.2.2 bouyer int
259 1.1.2.2 bouyer libdm_task_set_name(const char *name, libdm_task_t libdm_task)
260 1.1.2.2 bouyer {
261 1.1.2.2 bouyer
262 1.1.2.2 bouyer if ((prop_dictionary_set_cstring(libdm_task->ldm_task,
263 1.1.2.2 bouyer DM_IOCTL_NAME, name)) == false)
264 1.1.2.2 bouyer return ENOENT;
265 1.1.2.2 bouyer
266 1.1.2.2 bouyer return 0;
267 1.1.2.2 bouyer }
268 1.1.2.2 bouyer
269 1.1.2.2 bouyer /* Set device name */
270 1.1.2.2 bouyer char *
271 1.1.2.2 bouyer libdm_task_get_name(libdm_task_t libdm_task)
272 1.1.2.2 bouyer {
273 1.1.2.2 bouyer char *name;
274 1.1.2.2 bouyer
275 1.1.2.2 bouyer if (!prop_dictionary_get_cstring_nocopy(libdm_task->ldm_task,
276 1.1.2.2 bouyer DM_IOCTL_NAME, (const char **)&name))
277 1.1.2.2 bouyer return NULL;
278 1.1.2.2 bouyer
279 1.1.2.2 bouyer return name;
280 1.1.2.2 bouyer }
281 1.1.2.2 bouyer
282 1.1.2.2 bouyer /* Set device uuid */
283 1.1.2.2 bouyer int
284 1.1.2.2 bouyer libdm_task_set_uuid(const char *uuid, libdm_task_t libdm_task)
285 1.1.2.2 bouyer {
286 1.1.2.2 bouyer
287 1.1.2.2 bouyer if ((prop_dictionary_set_cstring(libdm_task->ldm_task,
288 1.1.2.2 bouyer DM_IOCTL_NAME, uuid)) == false)
289 1.1.2.2 bouyer return ENOENT;
290 1.1.2.2 bouyer
291 1.1.2.2 bouyer return 0;
292 1.1.2.2 bouyer }
293 1.1.2.2 bouyer
294 1.1.2.2 bouyer /* Set device name */
295 1.1.2.2 bouyer char *
296 1.1.2.2 bouyer libdm_task_get_uuid(libdm_task_t libdm_task)
297 1.1.2.2 bouyer {
298 1.1.2.2 bouyer char *uuid;
299 1.1.2.2 bouyer
300 1.1.2.2 bouyer if (!prop_dictionary_get_cstring_nocopy(libdm_task->ldm_task,
301 1.1.2.2 bouyer DM_IOCTL_UUID, (const char **)&uuid))
302 1.1.2.2 bouyer return NULL;
303 1.1.2.2 bouyer
304 1.1.2.2 bouyer return uuid;
305 1.1.2.2 bouyer }
306 1.1.2.2 bouyer
307 1.1.2.2 bouyer /* Get command name */
308 1.1.2.2 bouyer char *
309 1.1.2.2 bouyer libdm_task_get_command(libdm_task_t libdm_task)
310 1.1.2.2 bouyer {
311 1.1.2.2 bouyer char *command;
312 1.1.2.2 bouyer
313 1.1.2.2 bouyer if (!prop_dictionary_get_cstring_nocopy(libdm_task->ldm_task,
314 1.1.2.2 bouyer DM_IOCTL_COMMAND, (const char **)&command))
315 1.1.2.2 bouyer return NULL;
316 1.1.2.2 bouyer
317 1.1.2.2 bouyer return command;
318 1.1.2.2 bouyer }
319 1.1.2.2 bouyer
320 1.1.2.2 bouyer int32_t
321 1.1.2.2 bouyer libdm_task_get_cmd_version(libdm_task_t libdm_task, uint32_t *ver, size_t size)
322 1.1.2.2 bouyer {
323 1.1.2.2 bouyer prop_array_t prop_ver;
324 1.1.2.2 bouyer size_t i;
325 1.1.2.2 bouyer
326 1.1.2.2 bouyer prop_ver = prop_dictionary_get(libdm_task->ldm_task,
327 1.1.2.2 bouyer DM_IOCTL_VERSION);
328 1.1.2.2 bouyer
329 1.1.2.2 bouyer i = prop_array_count(prop_ver);
330 1.1.2.2 bouyer
331 1.1.2.2 bouyer if (i > size)
332 1.1.2.2 bouyer return -i;
333 1.1.2.2 bouyer
334 1.1.2.2 bouyer for (i = 0; i < size; i++)
335 1.1.2.2 bouyer prop_array_get_uint32(prop_ver, i, &ver[i]);
336 1.1.2.2 bouyer
337 1.1.2.2 bouyer return i;
338 1.1.2.2 bouyer }
339 1.1.2.2 bouyer
340 1.1.2.2 bouyer /* Select device minor number. */
341 1.1.2.2 bouyer int
342 1.1.2.2 bouyer libdm_task_set_minor(uint32_t minor, libdm_task_t libdm_task)
343 1.1.2.2 bouyer {
344 1.1.2.2 bouyer
345 1.1.2.2 bouyer if ((prop_dictionary_set_uint32(libdm_task->ldm_task,
346 1.1.2.2 bouyer DM_IOCTL_MINOR, minor)) == false)
347 1.1.2.2 bouyer return ENOENT;
348 1.1.2.2 bouyer
349 1.1.2.2 bouyer return 0;
350 1.1.2.2 bouyer }
351 1.1.2.2 bouyer
352 1.1.2.2 bouyer /* Select device minor number. */
353 1.1.2.2 bouyer uint32_t
354 1.1.2.2 bouyer libdm_task_get_minor(libdm_task_t libdm_task)
355 1.1.2.2 bouyer {
356 1.1.2.2 bouyer uint32_t minor;
357 1.1.2.2 bouyer
358 1.1.2.2 bouyer minor = 0;
359 1.1.2.2 bouyer
360 1.1.2.2 bouyer (void)prop_dictionary_get_uint32(libdm_task->ldm_task,
361 1.1.2.2 bouyer DM_IOCTL_MINOR, &minor);
362 1.1.2.2 bouyer
363 1.1.2.2 bouyer return minor;
364 1.1.2.2 bouyer }
365 1.1.2.2 bouyer
366 1.1.2.2 bouyer /* Set/Del DM_SUSPEND_FLAG for caller. */
367 1.1.2.2 bouyer void
368 1.1.2.2 bouyer libdm_task_set_suspend_flag(libdm_task_t libdm_task)
369 1.1.2.2 bouyer {
370 1.1.2.2 bouyer uint32_t flags;
371 1.1.2.2 bouyer
372 1.1.2.2 bouyer flags = 0;
373 1.1.2.2 bouyer
374 1.1.2.2 bouyer (void)prop_dictionary_get_uint32(libdm_task->ldm_task,
375 1.1.2.2 bouyer DM_IOCTL_FLAGS, &flags);
376 1.1.2.2 bouyer
377 1.1.2.2 bouyer flags |= DM_SUSPEND_FLAG;
378 1.1.2.2 bouyer
379 1.1.2.2 bouyer (void)prop_dictionary_set_uint32(libdm_task->ldm_task,
380 1.1.2.2 bouyer DM_IOCTL_FLAGS, flags);
381 1.1.2.2 bouyer }
382 1.1.2.2 bouyer
383 1.1.2.2 bouyer void
384 1.1.2.2 bouyer libdm_task_del_suspend_flag(libdm_task_t libdm_task)
385 1.1.2.2 bouyer {
386 1.1.2.2 bouyer uint32_t flags;
387 1.1.2.2 bouyer
388 1.1.2.2 bouyer (void)prop_dictionary_get_uint32(libdm_task->ldm_task,
389 1.1.2.2 bouyer DM_IOCTL_FLAGS, &flags);
390 1.1.2.2 bouyer
391 1.1.2.2 bouyer flags &= ~DM_SUSPEND_FLAG;
392 1.1.2.2 bouyer
393 1.1.2.2 bouyer (void)prop_dictionary_set_uint32(libdm_task->ldm_task,
394 1.1.2.2 bouyer DM_IOCTL_FLAGS, flags);
395 1.1.2.2 bouyer }
396 1.1.2.2 bouyer
397 1.1.2.2 bouyer /* Set/Del DM_STATUS_FLAG for caller. */
398 1.1.2.2 bouyer void
399 1.1.2.2 bouyer libdm_task_set_status_flag(libdm_task_t libdm_task)
400 1.1.2.2 bouyer {
401 1.1.2.2 bouyer uint32_t flags;
402 1.1.2.2 bouyer
403 1.1.2.2 bouyer flags = 0;
404 1.1.2.2 bouyer
405 1.1.2.2 bouyer (void)prop_dictionary_get_uint32(libdm_task->ldm_task,
406 1.1.2.2 bouyer DM_IOCTL_FLAGS, &flags);
407 1.1.2.2 bouyer
408 1.1.2.2 bouyer flags |= DM_STATUS_TABLE_FLAG;
409 1.1.2.2 bouyer
410 1.1.2.2 bouyer (void)prop_dictionary_set_uint32(libdm_task->ldm_task,
411 1.1.2.2 bouyer DM_IOCTL_FLAGS, flags);
412 1.1.2.2 bouyer }
413 1.1.2.2 bouyer
414 1.1.2.2 bouyer void
415 1.1.2.2 bouyer libdm_task_del_status_flag(libdm_task_t libdm_task)
416 1.1.2.2 bouyer {
417 1.1.2.2 bouyer uint32_t flags;
418 1.1.2.2 bouyer
419 1.1.2.2 bouyer (void)prop_dictionary_get_uint32(libdm_task->ldm_task,
420 1.1.2.2 bouyer DM_IOCTL_FLAGS, &flags);
421 1.1.2.2 bouyer
422 1.1.2.2 bouyer flags &= ~DM_STATUS_TABLE_FLAG;
423 1.1.2.2 bouyer
424 1.1.2.2 bouyer (void)prop_dictionary_set_uint32(libdm_task->ldm_task,
425 1.1.2.2 bouyer DM_IOCTL_FLAGS, flags);
426 1.1.2.2 bouyer }
427 1.1.2.2 bouyer
428 1.1.2.2 bouyer /* Set/Del DM_EXISTS_FLAG for caller. */
429 1.1.2.2 bouyer void
430 1.1.2.2 bouyer libdm_task_set_exists_flag(libdm_task_t libdm_task)
431 1.1.2.2 bouyer {
432 1.1.2.2 bouyer uint32_t flags;
433 1.1.2.2 bouyer
434 1.1.2.2 bouyer flags = 0;
435 1.1.2.2 bouyer
436 1.1.2.2 bouyer (void)prop_dictionary_get_uint32(libdm_task->ldm_task,
437 1.1.2.2 bouyer DM_IOCTL_FLAGS, &flags);
438 1.1.2.2 bouyer
439 1.1.2.2 bouyer flags |= DM_EXISTS_FLAG;
440 1.1.2.2 bouyer
441 1.1.2.2 bouyer (void)prop_dictionary_set_uint32(libdm_task->ldm_task,
442 1.1.2.2 bouyer DM_IOCTL_FLAGS, flags);
443 1.1.2.2 bouyer }
444 1.1.2.2 bouyer
445 1.1.2.2 bouyer void
446 1.1.2.2 bouyer libdm_task_del_exists_flag(libdm_task_t libdm_task)
447 1.1.2.2 bouyer {
448 1.1.2.2 bouyer uint32_t flags;
449 1.1.2.2 bouyer
450 1.1.2.2 bouyer (void)prop_dictionary_get_uint32(libdm_task->ldm_task,
451 1.1.2.2 bouyer DM_IOCTL_FLAGS, &flags);
452 1.1.2.2 bouyer
453 1.1.2.2 bouyer flags &= ~DM_EXISTS_FLAG;
454 1.1.2.2 bouyer
455 1.1.2.2 bouyer (void)prop_dictionary_set_uint32(libdm_task->ldm_task,
456 1.1.2.2 bouyer DM_IOCTL_FLAGS, flags);
457 1.1.2.2 bouyer }
458 1.1.2.2 bouyer
459 1.1.2.2 bouyer /* Set flags used by LVM this is shortcut and should not be used
460 1.1.2.2 bouyer by anyone else. */
461 1.1.2.2 bouyer void
462 1.1.2.2 bouyer libdm_task_set_flags(libdm_task_t libdm_task, uint32_t flags)
463 1.1.2.2 bouyer {
464 1.1.2.2 bouyer
465 1.1.2.2 bouyer (void)prop_dictionary_set_uint32(libdm_task->ldm_task,
466 1.1.2.2 bouyer DM_IOCTL_FLAGS, flags);
467 1.1.2.2 bouyer }
468 1.1.2.2 bouyer
469 1.1.2.2 bouyer /* Get ioctl protocol status flags. */
470 1.1.2.2 bouyer uint32_t
471 1.1.2.2 bouyer libdm_task_get_flags(libdm_task_t libdm_task)
472 1.1.2.2 bouyer {
473 1.1.2.2 bouyer uint32_t flags;
474 1.1.2.2 bouyer
475 1.1.2.2 bouyer (void)prop_dictionary_get_uint32(libdm_task->ldm_task,
476 1.1.2.2 bouyer DM_IOCTL_FLAGS, &flags);
477 1.1.2.2 bouyer
478 1.1.2.2 bouyer return flags;
479 1.1.2.2 bouyer }
480 1.1.2.2 bouyer
481 1.1.2.2 bouyer /* Set ioctl protocol status flags. */
482 1.1.2.2 bouyer uint32_t
483 1.1.2.2 bouyer libdm_task_get_target_num(libdm_task_t libdm_task)
484 1.1.2.2 bouyer {
485 1.1.2.2 bouyer uint32_t count;
486 1.1.2.2 bouyer
487 1.1.2.2 bouyer (void)prop_dictionary_get_uint32(libdm_task->ldm_task,
488 1.1.2.2 bouyer DM_IOCTL_TARGET_COUNT, &count);
489 1.1.2.2 bouyer
490 1.1.2.2 bouyer return count;
491 1.1.2.2 bouyer }
492 1.1.2.2 bouyer
493 1.1.2.2 bouyer int32_t
494 1.1.2.2 bouyer libdm_task_get_open_num(libdm_task_t libdm_task)
495 1.1.2.2 bouyer {
496 1.1.2.2 bouyer int32_t count;
497 1.1.2.2 bouyer
498 1.1.2.2 bouyer (void)prop_dictionary_get_int32(libdm_task->ldm_task,
499 1.1.2.2 bouyer DM_IOCTL_OPEN, &count);
500 1.1.2.2 bouyer
501 1.1.2.2 bouyer return count;
502 1.1.2.2 bouyer }
503 1.1.2.2 bouyer
504 1.1.2.2 bouyer uint32_t
505 1.1.2.2 bouyer libdm_task_get_event_num(libdm_task_t libdm_task)
506 1.1.2.2 bouyer {
507 1.1.2.2 bouyer uint32_t event;
508 1.1.2.2 bouyer
509 1.1.2.2 bouyer (void)prop_dictionary_get_uint32(libdm_task->ldm_task,
510 1.1.2.2 bouyer DM_IOCTL_EVENT, &event);
511 1.1.2.2 bouyer
512 1.1.2.2 bouyer return event;
513 1.1.2.2 bouyer }
514 1.1.2.2 bouyer
515 1.1.2.2 bouyer /* Set cmd_data dictionary entry to task struct. */
516 1.1.2.2 bouyer int
517 1.1.2.2 bouyer libdm_task_set_cmd(libdm_cmd_t libdm_cmd, libdm_task_t libdm_task)
518 1.1.2.2 bouyer {
519 1.1.2.2 bouyer
520 1.1.2.2 bouyer if ((prop_dictionary_set(libdm_task->ldm_task,
521 1.1.2.2 bouyer DM_IOCTL_CMD_DATA, libdm_cmd->ldm_cmd)) == false)
522 1.1.2.2 bouyer return ENOENT;
523 1.1.2.2 bouyer
524 1.1.2.2 bouyer return 0;
525 1.1.2.2 bouyer }
526 1.1.2.2 bouyer
527 1.1.2.2 bouyer /* Get cmd_data dictionary entry from task struct */
528 1.1.2.2 bouyer libdm_cmd_t
529 1.1.2.2 bouyer libdm_task_get_cmd(libdm_task_t libdm_task)
530 1.1.2.2 bouyer {
531 1.1.2.2 bouyer libdm_cmd_t cmd;
532 1.1.2.2 bouyer
533 1.1.2.2 bouyer cmd = malloc(sizeof(*cmd));
534 1.1.2.2 bouyer
535 1.1.2.2 bouyer cmd->ldm_cmd = prop_dictionary_get(libdm_task->ldm_task,
536 1.1.2.2 bouyer DM_IOCTL_CMD_DATA);
537 1.1.2.2 bouyer
538 1.1.2.2 bouyer if (cmd->ldm_cmd == NULL) {
539 1.1.2.2 bouyer free(cmd);
540 1.1.2.2 bouyer return NULL;
541 1.1.2.2 bouyer }
542 1.1.2.2 bouyer
543 1.1.2.2 bouyer /* Get a reference prop_dictionary_get will not get it */
544 1.1.2.2 bouyer prop_object_retain(cmd->ldm_cmd);
545 1.1.2.2 bouyer
546 1.1.2.2 bouyer return cmd;
547 1.1.2.2 bouyer }
548 1.1.2.2 bouyer
549 1.1.2.2 bouyer /* Command functions
550 1.1.2.2 bouyer *
551 1.1.2.2 bouyer * Functions for creation, destroing, set, get of command area of
552 1.1.2.2 bouyer * ioctl dictionary.
553 1.1.2.2 bouyer */
554 1.1.2.2 bouyer libdm_cmd_t
555 1.1.2.2 bouyer libdm_cmd_create(void)
556 1.1.2.2 bouyer {
557 1.1.2.2 bouyer libdm_cmd_t cmd;
558 1.1.2.2 bouyer
559 1.1.2.2 bouyer cmd = malloc(sizeof(*cmd));
560 1.1.2.2 bouyer if (cmd == NULL)
561 1.1.2.2 bouyer return NULL;
562 1.1.2.2 bouyer
563 1.1.2.2 bouyer cmd->ldm_cmd = prop_array_create();
564 1.1.2.2 bouyer
565 1.1.2.2 bouyer return cmd;
566 1.1.2.2 bouyer }
567 1.1.2.2 bouyer
568 1.1.2.2 bouyer void
569 1.1.2.2 bouyer libdm_cmd_destroy(libdm_cmd_t libdm_cmd)
570 1.1.2.2 bouyer {
571 1.1.2.2 bouyer
572 1.1.2.2 bouyer prop_object_release(libdm_cmd->ldm_cmd);
573 1.1.2.2 bouyer free(libdm_cmd);
574 1.1.2.2 bouyer }
575 1.1.2.2 bouyer
576 1.1.2.2 bouyer /* Create iterator object for caller this can be used to
577 1.1.2.2 bouyer iterate through all members of cmd array. */
578 1.1.2.2 bouyer libdm_iter_t
579 1.1.2.2 bouyer libdm_cmd_iter_create(libdm_cmd_t libdm_cmd)
580 1.1.2.2 bouyer {
581 1.1.2.2 bouyer
582 1.1.2.2 bouyer libdm_iter_t iter;
583 1.1.2.2 bouyer
584 1.1.2.2 bouyer iter = malloc(sizeof(*iter));
585 1.1.2.2 bouyer if (iter == NULL)
586 1.1.2.2 bouyer return NULL;
587 1.1.2.2 bouyer
588 1.1.2.2 bouyer iter->ldm_obji = prop_array_iterator(libdm_cmd->ldm_cmd);
589 1.1.2.2 bouyer
590 1.1.2.2 bouyer return iter;
591 1.1.2.2 bouyer }
592 1.1.2.2 bouyer
593 1.1.2.2 bouyer int
594 1.1.2.2 bouyer libdm_cmd_set_table(libdm_table_t libdm_table, libdm_cmd_t libdm_cmd)
595 1.1.2.2 bouyer {
596 1.1.2.2 bouyer
597 1.1.2.2 bouyer return prop_array_add(libdm_cmd->ldm_cmd,
598 1.1.2.2 bouyer libdm_table->ldm_tbl);
599 1.1.2.2 bouyer }
600 1.1.2.2 bouyer
601 1.1.2.2 bouyer
602 1.1.2.2 bouyer libdm_target_t
603 1.1.2.2 bouyer libdm_cmd_get_target(libdm_iter_t iter)
604 1.1.2.2 bouyer {
605 1.1.2.2 bouyer libdm_target_t trgt;
606 1.1.2.2 bouyer
607 1.1.2.2 bouyer trgt = malloc(sizeof(*trgt));
608 1.1.2.2 bouyer if (trgt == NULL)
609 1.1.2.2 bouyer return NULL;
610 1.1.2.2 bouyer
611 1.1.2.2 bouyer trgt->ldm_trgt = prop_object_iterator_next(iter->ldm_obji);
612 1.1.2.2 bouyer if (trgt->ldm_trgt == NULL) {
613 1.1.2.2 bouyer free(trgt);
614 1.1.2.2 bouyer return NULL;
615 1.1.2.2 bouyer }
616 1.1.2.2 bouyer
617 1.1.2.2 bouyer return trgt;
618 1.1.2.2 bouyer }
619 1.1.2.2 bouyer
620 1.1.2.2 bouyer libdm_table_t
621 1.1.2.2 bouyer libdm_cmd_get_table(libdm_iter_t iter)
622 1.1.2.2 bouyer {
623 1.1.2.2 bouyer libdm_table_t tbl;
624 1.1.2.2 bouyer
625 1.1.2.2 bouyer tbl = malloc(sizeof(*tbl));
626 1.1.2.2 bouyer if (tbl == NULL)
627 1.1.2.2 bouyer return NULL;
628 1.1.2.2 bouyer
629 1.1.2.2 bouyer tbl->ldm_tbl = prop_object_iterator_next(iter->ldm_obji);
630 1.1.2.2 bouyer if (tbl->ldm_tbl == NULL) {
631 1.1.2.2 bouyer free(tbl);
632 1.1.2.2 bouyer return NULL;
633 1.1.2.2 bouyer }
634 1.1.2.2 bouyer
635 1.1.2.2 bouyer return tbl;
636 1.1.2.2 bouyer }
637 1.1.2.2 bouyer
638 1.1.2.2 bouyer libdm_dev_t
639 1.1.2.2 bouyer libdm_cmd_get_dev(libdm_iter_t iter)
640 1.1.2.2 bouyer {
641 1.1.2.2 bouyer libdm_dev_t dev;
642 1.1.2.2 bouyer
643 1.1.2.2 bouyer dev = malloc(sizeof(*dev));
644 1.1.2.2 bouyer if (dev == NULL)
645 1.1.2.2 bouyer return NULL;
646 1.1.2.2 bouyer
647 1.1.2.2 bouyer dev->ldm_dev = prop_object_iterator_next(iter->ldm_obji);
648 1.1.2.2 bouyer if (dev->ldm_dev == NULL) {
649 1.1.2.2 bouyer free(dev);
650 1.1.2.2 bouyer return NULL;
651 1.1.2.2 bouyer }
652 1.1.2.2 bouyer
653 1.1.2.2 bouyer return dev;
654 1.1.2.2 bouyer }
655 1.1.2.2 bouyer
656 1.1.2.2 bouyer /*
657 1.1.2.2 bouyer * Deps manipulation routines
658 1.1.2.2 bouyer */
659 1.1.2.2 bouyer uint64_t
660 1.1.2.2 bouyer libdm_cmd_get_deps(libdm_iter_t libdm_iter)
661 1.1.2.2 bouyer {
662 1.1.2.2 bouyer prop_object_t obj;
663 1.1.2.2 bouyer uint64_t deps;
664 1.1.2.2 bouyer
665 1.1.2.2 bouyer obj = prop_object_iterator_next(libdm_iter->ldm_obji);
666 1.1.2.2 bouyer deps = prop_number_unsigned_integer_value(obj);
667 1.1.2.2 bouyer
668 1.1.2.2 bouyer if (obj != NULL)
669 1.1.2.2 bouyer prop_object_release(obj);
670 1.1.2.2 bouyer
671 1.1.2.2 bouyer return deps;
672 1.1.2.2 bouyer }
673 1.1.2.2 bouyer
674 1.1.2.2 bouyer /*
675 1.1.2.2 bouyer * Table manipulation routines
676 1.1.2.2 bouyer */
677 1.1.2.2 bouyer libdm_table_t
678 1.1.2.2 bouyer libdm_table_create(void)
679 1.1.2.2 bouyer {
680 1.1.2.2 bouyer libdm_table_t table;
681 1.1.2.2 bouyer
682 1.1.2.2 bouyer table = malloc(sizeof(*table));
683 1.1.2.2 bouyer if (table == NULL)
684 1.1.2.2 bouyer return NULL;
685 1.1.2.2 bouyer
686 1.1.2.2 bouyer table->ldm_tbl = prop_dictionary_create();
687 1.1.2.2 bouyer
688 1.1.2.2 bouyer return table;
689 1.1.2.2 bouyer }
690 1.1.2.2 bouyer
691 1.1.2.2 bouyer void
692 1.1.2.2 bouyer libdm_table_destroy(libdm_table_t libdm_table)
693 1.1.2.2 bouyer {
694 1.1.2.2 bouyer
695 1.1.2.2 bouyer prop_object_release(libdm_table->ldm_tbl);
696 1.1.2.2 bouyer free(libdm_table);
697 1.1.2.2 bouyer }
698 1.1.2.2 bouyer
699 1.1.2.2 bouyer int
700 1.1.2.2 bouyer libdm_table_set_start(uint64_t start, libdm_table_t libdm_table)
701 1.1.2.2 bouyer {
702 1.1.2.2 bouyer
703 1.1.2.2 bouyer if (libdm_table == NULL)
704 1.1.2.2 bouyer return ENOENT;
705 1.1.2.2 bouyer
706 1.1.2.2 bouyer return prop_dictionary_set_uint64(libdm_table->ldm_tbl,
707 1.1.2.2 bouyer DM_TABLE_START, start);
708 1.1.2.2 bouyer }
709 1.1.2.2 bouyer
710 1.1.2.2 bouyer uint64_t
711 1.1.2.2 bouyer libdm_table_get_start(libdm_table_t libdm_table)
712 1.1.2.2 bouyer {
713 1.1.2.2 bouyer uint64_t start;
714 1.1.2.2 bouyer
715 1.1.2.2 bouyer if (libdm_table == NULL)
716 1.1.2.2 bouyer return ENOENT;
717 1.1.2.2 bouyer
718 1.1.2.2 bouyer (void)prop_dictionary_get_uint64(libdm_table->ldm_tbl, DM_TABLE_START,
719 1.1.2.2 bouyer &start);
720 1.1.2.2 bouyer
721 1.1.2.2 bouyer return start;
722 1.1.2.2 bouyer }
723 1.1.2.2 bouyer
724 1.1.2.2 bouyer int
725 1.1.2.2 bouyer libdm_table_set_length(uint64_t length, libdm_table_t libdm_table)
726 1.1.2.2 bouyer {
727 1.1.2.2 bouyer
728 1.1.2.2 bouyer if (libdm_table == NULL)
729 1.1.2.2 bouyer return ENOENT;
730 1.1.2.2 bouyer
731 1.1.2.2 bouyer return prop_dictionary_set_uint64(libdm_table->ldm_tbl,
732 1.1.2.2 bouyer DM_TABLE_LENGTH, length);
733 1.1.2.2 bouyer }
734 1.1.2.2 bouyer
735 1.1.2.2 bouyer uint64_t
736 1.1.2.2 bouyer libdm_table_get_length(libdm_table_t libdm_table)
737 1.1.2.2 bouyer {
738 1.1.2.2 bouyer uint64_t length;
739 1.1.2.2 bouyer
740 1.1.2.2 bouyer if (libdm_table == NULL)
741 1.1.2.2 bouyer return ENOENT;
742 1.1.2.2 bouyer
743 1.1.2.2 bouyer prop_dictionary_get_uint64(libdm_table->ldm_tbl, DM_TABLE_LENGTH,
744 1.1.2.2 bouyer &length);
745 1.1.2.2 bouyer
746 1.1.2.2 bouyer return length;
747 1.1.2.2 bouyer }
748 1.1.2.2 bouyer
749 1.1.2.2 bouyer int
750 1.1.2.2 bouyer libdm_table_set_target(const char *name, libdm_table_t libdm_table)
751 1.1.2.2 bouyer {
752 1.1.2.2 bouyer
753 1.1.2.2 bouyer if (libdm_table == NULL)
754 1.1.2.2 bouyer return ENOENT;
755 1.1.2.2 bouyer
756 1.1.2.2 bouyer return prop_dictionary_set_cstring(libdm_table->ldm_tbl, DM_TABLE_TYPE, name);
757 1.1.2.2 bouyer }
758 1.1.2.2 bouyer
759 1.1.2.2 bouyer char *
760 1.1.2.2 bouyer libdm_table_get_target(libdm_table_t libdm_table)
761 1.1.2.2 bouyer {
762 1.1.2.2 bouyer char *target;
763 1.1.2.2 bouyer
764 1.1.2.2 bouyer if (!prop_dictionary_get_cstring_nocopy(libdm_table->ldm_tbl, DM_TABLE_TYPE,
765 1.1.2.2 bouyer (const char **)&target))
766 1.1.2.2 bouyer return NULL;
767 1.1.2.2 bouyer
768 1.1.2.2 bouyer return target;
769 1.1.2.2 bouyer }
770 1.1.2.2 bouyer
771 1.1.2.2 bouyer int
772 1.1.2.2 bouyer libdm_table_set_params(const char *params, libdm_table_t libdm_table)
773 1.1.2.2 bouyer {
774 1.1.2.2 bouyer
775 1.1.2.2 bouyer if (libdm_table == NULL)
776 1.1.2.2 bouyer return ENOENT;
777 1.1.2.2 bouyer
778 1.1.2.2 bouyer return prop_dictionary_set_cstring(libdm_table->ldm_tbl,
779 1.1.2.2 bouyer DM_TABLE_PARAMS, params);
780 1.1.2.2 bouyer }
781 1.1.2.2 bouyer
782 1.1.2.2 bouyer /*
783 1.1.2.2 bouyer * Get table params string from libdm_table_t
784 1.1.2.2 bouyer * returned char * is dynamically allocated caller should free it.
785 1.1.2.2 bouyer */
786 1.1.2.2 bouyer char *
787 1.1.2.2 bouyer libdm_table_get_params(libdm_table_t libdm_table)
788 1.1.2.2 bouyer {
789 1.1.2.2 bouyer char *params;
790 1.1.2.2 bouyer
791 1.1.2.2 bouyer if (!prop_dictionary_get_cstring_nocopy(libdm_table->ldm_tbl, DM_TABLE_PARAMS,
792 1.1.2.2 bouyer (const char **)¶ms))
793 1.1.2.2 bouyer return NULL;
794 1.1.2.2 bouyer
795 1.1.2.2 bouyer return params;
796 1.1.2.2 bouyer }
797 1.1.2.2 bouyer
798 1.1.2.2 bouyer int32_t
799 1.1.2.2 bouyer libdm_table_get_status(libdm_table_t libdm_table)
800 1.1.2.2 bouyer {
801 1.1.2.2 bouyer int32_t status;
802 1.1.2.2 bouyer
803 1.1.2.2 bouyer (void)prop_dictionary_get_int32(libdm_table->ldm_tbl, DM_TABLE_STAT,
804 1.1.2.2 bouyer &status);
805 1.1.2.2 bouyer
806 1.1.2.2 bouyer return status;
807 1.1.2.2 bouyer }
808 1.1.2.2 bouyer
809 1.1.2.2 bouyer /*
810 1.1.2.2 bouyer * Target manipulation routines
811 1.1.2.2 bouyer */
812 1.1.2.2 bouyer void
813 1.1.2.2 bouyer libdm_target_destroy(libdm_target_t libdm_target)
814 1.1.2.2 bouyer {
815 1.1.2.2 bouyer
816 1.1.2.2 bouyer prop_object_release(libdm_target->ldm_trgt);
817 1.1.2.2 bouyer free(libdm_target);
818 1.1.2.2 bouyer }
819 1.1.2.2 bouyer
820 1.1.2.2 bouyer char *
821 1.1.2.2 bouyer libdm_target_get_name(libdm_target_t libdm_target)
822 1.1.2.2 bouyer {
823 1.1.2.2 bouyer char *name;
824 1.1.2.2 bouyer
825 1.1.2.2 bouyer if (!prop_dictionary_get_cstring_nocopy(libdm_target->ldm_trgt,
826 1.1.2.2 bouyer DM_TARGETS_NAME, (const char **)&name))
827 1.1.2.2 bouyer return NULL;
828 1.1.2.2 bouyer
829 1.1.2.2 bouyer return name;
830 1.1.2.2 bouyer }
831 1.1.2.2 bouyer
832 1.1.2.2 bouyer int32_t
833 1.1.2.2 bouyer libdm_target_get_version(libdm_target_t libdm_target, uint32_t *ver, size_t size)
834 1.1.2.2 bouyer {
835 1.1.2.2 bouyer prop_array_t prop_ver;
836 1.1.2.2 bouyer size_t i;
837 1.1.2.2 bouyer
838 1.1.2.2 bouyer prop_ver = prop_dictionary_get(libdm_target->ldm_trgt,
839 1.1.2.2 bouyer DM_TARGETS_VERSION);
840 1.1.2.2 bouyer
841 1.1.2.2 bouyer i = prop_array_count(prop_ver);
842 1.1.2.2 bouyer
843 1.1.2.2 bouyer if (i > size)
844 1.1.2.2 bouyer return -i;
845 1.1.2.2 bouyer
846 1.1.2.2 bouyer for (i = 0; i < size; i++)
847 1.1.2.2 bouyer prop_array_get_uint32(prop_ver, i, &ver[i]);
848 1.1.2.2 bouyer
849 1.1.2.2 bouyer return i;
850 1.1.2.2 bouyer }
851 1.1.2.2 bouyer
852 1.1.2.2 bouyer
853 1.1.2.2 bouyer /*
854 1.1.2.2 bouyer * Dev manipulation routines
855 1.1.2.2 bouyer */
856 1.1.2.2 bouyer void
857 1.1.2.2 bouyer libdm_dev_destroy(libdm_dev_t libdm_dev)
858 1.1.2.2 bouyer {
859 1.1.2.2 bouyer
860 1.1.2.2 bouyer prop_object_release(libdm_dev->ldm_dev);
861 1.1.2.2 bouyer free(libdm_dev);
862 1.1.2.2 bouyer }
863 1.1.2.2 bouyer
864 1.1.2.2 bouyer char *
865 1.1.2.2 bouyer libdm_dev_get_name(libdm_dev_t libdm_dev)
866 1.1.2.2 bouyer {
867 1.1.2.2 bouyer char *name;
868 1.1.2.2 bouyer
869 1.1.2.2 bouyer if (!prop_dictionary_get_cstring_nocopy(libdm_dev->ldm_dev,
870 1.1.2.2 bouyer DM_DEV_NAME, (const char **)&name))
871 1.1.2.2 bouyer return NULL;
872 1.1.2.2 bouyer
873 1.1.2.2 bouyer return name;
874 1.1.2.2 bouyer }
875 1.1.2.2 bouyer
876 1.1.2.2 bouyer uint32_t
877 1.1.2.2 bouyer libdm_dev_get_minor(libdm_dev_t libdm_dev)
878 1.1.2.2 bouyer {
879 1.1.2.2 bouyer uint32_t dev;
880 1.1.2.2 bouyer
881 1.1.2.2 bouyer (void)prop_dictionary_get_uint32(libdm_dev->ldm_dev, DM_DEV_DEV,
882 1.1.2.2 bouyer &dev);
883 1.1.2.2 bouyer
884 1.1.2.2 bouyer return dev;
885 1.1.2.2 bouyer }
886 1.1.2.2 bouyer
887 1.1.2.2 bouyer int
888 1.1.2.2 bouyer libdm_dev_set_newname(const char *newname, libdm_cmd_t libdm_cmd)
889 1.1.2.2 bouyer {
890 1.1.2.2 bouyer
891 1.1.2.2 bouyer if (newname == NULL)
892 1.1.2.2 bouyer return ENOENT;
893 1.1.2.2 bouyer
894 1.1.2.2 bouyer return prop_array_set_cstring(libdm_cmd->ldm_cmd, 0, newname);
895 1.1.2.2 bouyer }
896