xref: /minix3/tests/dev/dm/h_dm.c (revision 11be35a165022172ed3cea20f2b5df0307540b0e)
1*11be35a1SLionel Sambuc /*	$NetBSD: h_dm.c,v 1.1 2010/10/06 11:24:55 haad Exp $	*/
2*11be35a1SLionel Sambuc 
3*11be35a1SLionel Sambuc /*
4*11be35a1SLionel Sambuc  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
5*11be35a1SLionel Sambuc  *
6*11be35a1SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
7*11be35a1SLionel Sambuc  * modification, are permitted provided that the following conditions
8*11be35a1SLionel Sambuc  * are met:
9*11be35a1SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
10*11be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
11*11be35a1SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
12*11be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
13*11be35a1SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
14*11be35a1SLionel Sambuc  *
15*11be35a1SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16*11be35a1SLionel Sambuc  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17*11be35a1SLionel Sambuc  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18*11be35a1SLionel Sambuc  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19*11be35a1SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*11be35a1SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21*11be35a1SLionel Sambuc  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*11be35a1SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*11be35a1SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*11be35a1SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*11be35a1SLionel Sambuc  * SUCH DAMAGE.
26*11be35a1SLionel Sambuc  */
27*11be35a1SLionel Sambuc 
28*11be35a1SLionel Sambuc #include <sys/types.h>
29*11be35a1SLionel Sambuc 
30*11be35a1SLionel Sambuc #include <rump/rump.h>
31*11be35a1SLionel Sambuc #include <rump/rump_syscalls.h>
32*11be35a1SLionel Sambuc 
33*11be35a1SLionel Sambuc #include <sys/param.h>
34*11be35a1SLionel Sambuc #include <sys/ioctl.h>
35*11be35a1SLionel Sambuc #include <sys/stat.h>
36*11be35a1SLionel Sambuc #include <sys/disklabel.h>
37*11be35a1SLionel Sambuc 
38*11be35a1SLionel Sambuc #include <ctype.h>
39*11be35a1SLionel Sambuc #include <err.h>
40*11be35a1SLionel Sambuc #include <errno.h>
41*11be35a1SLionel Sambuc #include <fcntl.h>
42*11be35a1SLionel Sambuc #include <stdio.h>
43*11be35a1SLionel Sambuc #include <stdlib.h>
44*11be35a1SLionel Sambuc #include <string.h>
45*11be35a1SLionel Sambuc #include <unistd.h>
46*11be35a1SLionel Sambuc #include <util.h>
47*11be35a1SLionel Sambuc 
48*11be35a1SLionel Sambuc #include <dev/dm/netbsd-dm.h>
49*11be35a1SLionel Sambuc 
50*11be35a1SLionel Sambuc int dm_test_targets(void);
51*11be35a1SLionel Sambuc int dm_test_versions(void);
52*11be35a1SLionel Sambuc 
53*11be35a1SLionel Sambuc /*
54*11be35a1SLionel Sambuc  * Test simple dm versions command on device-mapper device.
55*11be35a1SLionel Sambuc  */
56*11be35a1SLionel Sambuc int
dm_test_versions(void)57*11be35a1SLionel Sambuc dm_test_versions(void) {
58*11be35a1SLionel Sambuc 	int fd;
59*11be35a1SLionel Sambuc 	int error;
60*11be35a1SLionel Sambuc 	prop_dictionary_t dict_in, dict_out;
61*11be35a1SLionel Sambuc 	struct plistref prefp;
62*11be35a1SLionel Sambuc 	char *xml;
63*11be35a1SLionel Sambuc 
64*11be35a1SLionel Sambuc 	error = 0;
65*11be35a1SLionel Sambuc 
66*11be35a1SLionel Sambuc 	error = rump_init();
67*11be35a1SLionel Sambuc 	if (error != 0)
68*11be35a1SLionel Sambuc 		err(1, "Rump init failed");
69*11be35a1SLionel Sambuc 
70*11be35a1SLionel Sambuc 	fd = rump_sys_open("/dev/mapper/control", O_RDWR, 0);
71*11be35a1SLionel Sambuc 	if (fd == -1)
72*11be35a1SLionel Sambuc 		err(1, "Open dm device failed");
73*11be35a1SLionel Sambuc 
74*11be35a1SLionel Sambuc 	dict_in  = prop_dictionary_internalize_from_file("dm_version_cmd.plist");
75*11be35a1SLionel Sambuc 	dict_out = prop_dictionary_create();
76*11be35a1SLionel Sambuc 
77*11be35a1SLionel Sambuc 	prop_dictionary_externalize_to_pref(dict_in, &prefp);
78*11be35a1SLionel Sambuc 
79*11be35a1SLionel Sambuc 	error = rump_sys_ioctl(fd, NETBSD_DM_IOCTL, &prefp);
80*11be35a1SLionel Sambuc 	if (error < 0)
81*11be35a1SLionel Sambuc 		err(1, "Dm control ioctl failed");
82*11be35a1SLionel Sambuc 
83*11be35a1SLionel Sambuc 	dict_out = prop_dictionary_internalize(prefp.pref_plist);
84*11be35a1SLionel Sambuc 
85*11be35a1SLionel Sambuc 	xml = prop_dictionary_externalize(dict_out);
86*11be35a1SLionel Sambuc 
87*11be35a1SLionel Sambuc 	rump_sys_close(fd);
88*11be35a1SLionel Sambuc 
89*11be35a1SLionel Sambuc 	return error;
90*11be35a1SLionel Sambuc }
91*11be35a1SLionel Sambuc 
92*11be35a1SLionel Sambuc /*
93*11be35a1SLionel Sambuc  * Test simple dm targets command on device-mapper device.
94*11be35a1SLionel Sambuc  */
95*11be35a1SLionel Sambuc int
dm_test_targets(void)96*11be35a1SLionel Sambuc dm_test_targets(void) {
97*11be35a1SLionel Sambuc 	int fd;
98*11be35a1SLionel Sambuc 	int error;
99*11be35a1SLionel Sambuc 	prop_dictionary_t dict_in, dict_out;
100*11be35a1SLionel Sambuc 	struct plistref prefp;
101*11be35a1SLionel Sambuc 	char *xml;
102*11be35a1SLionel Sambuc 
103*11be35a1SLionel Sambuc 	error = 0;
104*11be35a1SLionel Sambuc 
105*11be35a1SLionel Sambuc 	error = rump_init();
106*11be35a1SLionel Sambuc 	if (error != 0)
107*11be35a1SLionel Sambuc 		err(1, "Rump init failed");
108*11be35a1SLionel Sambuc 
109*11be35a1SLionel Sambuc 	fd = rump_sys_open("/dev/mapper/control", O_RDWR, 0);
110*11be35a1SLionel Sambuc 	if (fd == -1)
111*11be35a1SLionel Sambuc 		err(1, "Open dm device failed");
112*11be35a1SLionel Sambuc 
113*11be35a1SLionel Sambuc 	dict_in  = prop_dictionary_internalize_from_file("dm_targets_cmd.plist");
114*11be35a1SLionel Sambuc 	dict_out = prop_dictionary_create();
115*11be35a1SLionel Sambuc 
116*11be35a1SLionel Sambuc 	prop_dictionary_externalize_to_pref(dict_in, &prefp);
117*11be35a1SLionel Sambuc 
118*11be35a1SLionel Sambuc 	error = rump_sys_ioctl(fd, NETBSD_DM_IOCTL, &prefp);
119*11be35a1SLionel Sambuc 	if (error < 0)
120*11be35a1SLionel Sambuc 		err(1, "Dm control ioctl failed");
121*11be35a1SLionel Sambuc 
122*11be35a1SLionel Sambuc 	dict_out = prop_dictionary_internalize(prefp.pref_plist);
123*11be35a1SLionel Sambuc 
124*11be35a1SLionel Sambuc 	xml = prop_dictionary_externalize(dict_out);
125*11be35a1SLionel Sambuc 
126*11be35a1SLionel Sambuc 	rump_sys_close(fd);
127*11be35a1SLionel Sambuc 
128*11be35a1SLionel Sambuc 	return error;
129*11be35a1SLionel Sambuc }
130*11be35a1SLionel Sambuc 
131*11be35a1SLionel Sambuc int
main(int argc,char ** argv)132*11be35a1SLionel Sambuc main(int argc, char **argv) {
133*11be35a1SLionel Sambuc 	int error;
134*11be35a1SLionel Sambuc 
135*11be35a1SLionel Sambuc 	error = 0;
136*11be35a1SLionel Sambuc 
137*11be35a1SLionel Sambuc 	error = dm_test_versions();
138*11be35a1SLionel Sambuc 	if (error != 0)
139*11be35a1SLionel Sambuc 		err(1, "dm_test_versions failed");
140*11be35a1SLionel Sambuc 
141*11be35a1SLionel Sambuc 	error = dm_test_targets();
142*11be35a1SLionel Sambuc 	if (error != 0)
143*11be35a1SLionel Sambuc 		err(1, "dm_test_targets failed");
144*11be35a1SLionel Sambuc 
145*11be35a1SLionel Sambuc 	return error;
146*11be35a1SLionel Sambuc }
147