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