t_pr.c revision 1.10 1 1.10 maya /* $NetBSD: t_pr.c,v 1.10 2017/03/26 18:26:05 maya Exp $ */
2 1.1 pooka
3 1.1 pooka #include <sys/types.h>
4 1.1 pooka #include <sys/mount.h>
5 1.1 pooka
6 1.1 pooka #include <atf-c.h>
7 1.1 pooka #include <err.h>
8 1.1 pooka #include <errno.h>
9 1.1 pooka #include <fcntl.h>
10 1.1 pooka #include <stdio.h>
11 1.1 pooka #include <unistd.h>
12 1.1 pooka #include <string.h>
13 1.1 pooka #include <stdlib.h>
14 1.1 pooka
15 1.1 pooka #include <rump/rump.h>
16 1.1 pooka #include <rump/rump_syscalls.h>
17 1.1 pooka
18 1.1 pooka #include <miscfs/union/union.h>
19 1.1 pooka
20 1.9 christos #include "h_macros.h"
21 1.1 pooka
22 1.1 pooka ATF_TC(multilayer);
23 1.1 pooka ATF_TC_HEAD(multilayer, tc)
24 1.1 pooka {
25 1.1 pooka atf_tc_set_md_var(tc, "descr", "mount_union -b twice");
26 1.1 pooka }
27 1.1 pooka
28 1.1 pooka ATF_TC_BODY(multilayer, tc)
29 1.1 pooka {
30 1.1 pooka struct union_args unionargs;
31 1.1 pooka
32 1.1 pooka rump_init();
33 1.1 pooka
34 1.1 pooka if (rump_sys_mkdir("/Tunion", 0777) == -1)
35 1.1 pooka atf_tc_fail_errno("mkdir mp1");
36 1.1 pooka if (rump_sys_mkdir("/Tunion2", 0777) == -1)
37 1.1 pooka atf_tc_fail_errno("mkdir mp2");
38 1.1 pooka if (rump_sys_mkdir("/Tunion2/A", 0777) == -1)
39 1.1 pooka atf_tc_fail_errno("mkdir A");
40 1.1 pooka if (rump_sys_mkdir("/Tunion2/B", 0777) == -1)
41 1.1 pooka atf_tc_fail_errno("mkdir B");
42 1.1 pooka
43 1.1 pooka unionargs.target = __UNCONST("/Tunion2/A");
44 1.1 pooka unionargs.mntflags = UNMNT_BELOW;
45 1.1 pooka
46 1.1 pooka if (rump_sys_mount(MOUNT_UNION, "/Tunion", 0,
47 1.1 pooka &unionargs, sizeof(unionargs)) == -1)
48 1.1 pooka atf_tc_fail_errno("union mount");
49 1.1 pooka
50 1.1 pooka unionargs.target = __UNCONST("/Tunion2/B");
51 1.1 pooka unionargs.mntflags = UNMNT_BELOW;
52 1.1 pooka
53 1.1 pooka rump_sys_mount(MOUNT_UNION, "/Tunion", 0,&unionargs,sizeof(unionargs));
54 1.1 pooka }
55 1.1 pooka
56 1.10 maya ATF_TC(multilayer2);
57 1.10 maya ATF_TC_HEAD(multilayer2, tc)
58 1.10 maya {
59 1.10 maya atf_tc_set_md_var(tc, "descr", "mount_union twice then unmount");
60 1.10 maya }
61 1.10 maya
62 1.10 maya ATF_TC_BODY(multilayer2, tc)
63 1.10 maya {
64 1.10 maya struct union_args unionargs;
65 1.10 maya
66 1.10 maya rump_init();
67 1.10 maya
68 1.10 maya if (rump_sys_mkdir("/Tunion", 0777) == -1)
69 1.10 maya atf_tc_fail_errno("mkdir mp1");
70 1.10 maya if (rump_sys_mkdir("/Tunion2", 0777) == -1)
71 1.10 maya atf_tc_fail_errno("mkdir mp2");
72 1.10 maya if (rump_sys_mkdir("/Tunion2/A", 0777) == -1)
73 1.10 maya atf_tc_fail_errno("mkdir A");
74 1.10 maya if (rump_sys_mkdir("/Tunion2/B", 0777) == -1)
75 1.10 maya atf_tc_fail_errno("mkdir B");
76 1.10 maya
77 1.10 maya unionargs.target = __UNCONST("/Tunion2/A");
78 1.10 maya unionargs.mntflags = UNMNT_ABOVE;
79 1.10 maya
80 1.10 maya if (rump_sys_mount(MOUNT_UNION, "/Tunion", 0,
81 1.10 maya &unionargs, sizeof(unionargs)) == -1)
82 1.10 maya atf_tc_fail_errno("union mount");
83 1.10 maya if (rump_sys_mkdir("/Tunion2/A/A", 0777) == -1)
84 1.10 maya atf_tc_fail_errno("mkdir A/A");
85 1.10 maya
86 1.10 maya unionargs.target = __UNCONST("/Tunion2/A/A");
87 1.10 maya unionargs.mntflags = UNMNT_ABOVE;
88 1.10 maya
89 1.10 maya rump_sys_mount(MOUNT_UNION, "/Tunion", 0,&unionargs,sizeof(unionargs));
90 1.10 maya
91 1.10 maya rump_sys_unmount("/Tunion/A", 0);
92 1.10 maya }
93 1.10 maya
94 1.10 maya ATF_TC(cyclic);
95 1.10 maya ATF_TC_HEAD(cyclic, tc)
96 1.10 maya {
97 1.10 maya atf_tc_set_md_var(tc, "descr", "cyclic mount_union");
98 1.10 maya }
99 1.10 maya
100 1.10 maya ATF_TC_BODY(cyclic, tc)
101 1.10 maya {
102 1.10 maya struct union_args unionargs;
103 1.10 maya
104 1.10 maya rump_init();
105 1.10 maya
106 1.10 maya if (rump_sys_mkdir("/Tunion", 0777) == -1)
107 1.10 maya atf_tc_fail_errno("mkdir mp1");
108 1.10 maya if (rump_sys_mkdir("/Tunion/A", 0777) == -1)
109 1.10 maya atf_tc_fail_errno("mkdir mp2");
110 1.10 maya
111 1.10 maya unionargs.target = __UNCONST("/Tunion/A");
112 1.10 maya unionargs.mntflags = UNMNT_ABOVE;
113 1.10 maya
114 1.10 maya if (rump_sys_mount(MOUNT_UNION, "/Tunion/A", 0,
115 1.10 maya &unionargs, sizeof(unionargs)) == -1)
116 1.10 maya atf_tc_fail_errno("union mount");
117 1.10 maya
118 1.10 maya if (rump_sys_mkdir("/Tunion/A/A", 0777) == -1)
119 1.10 maya atf_tc_fail_errno("mkdir failed");
120 1.10 maya }
121 1.10 maya
122 1.10 maya ATF_TC(cyclic2);
123 1.10 maya ATF_TC_HEAD(cyclic2, tc)
124 1.10 maya {
125 1.10 maya atf_tc_set_md_var(tc, "descr", "cyclic mount_union");
126 1.10 maya }
127 1.10 maya
128 1.10 maya ATF_TC_BODY(cyclic2, tc)
129 1.10 maya {
130 1.10 maya struct union_args unionargs;
131 1.10 maya
132 1.10 maya rump_init();
133 1.10 maya
134 1.10 maya if (rump_sys_mkdir("/Tunion", 0777) == -1)
135 1.10 maya atf_tc_fail_errno("mkdir mp1");
136 1.10 maya if (rump_sys_mkdir("/Tunion/A", 0777) == -1)
137 1.10 maya atf_tc_fail_errno("mkdir mp2");
138 1.10 maya if (rump_sys_mkdir("/Tunion/B", 0777) == -1)
139 1.10 maya atf_tc_fail_errno("mkdir mp3");
140 1.10 maya
141 1.10 maya unionargs.target = __UNCONST("/Tunion/A");
142 1.10 maya unionargs.mntflags = UNMNT_ABOVE;
143 1.10 maya
144 1.10 maya if (rump_sys_mount(MOUNT_UNION, "/Tunion/B", 0,
145 1.10 maya &unionargs, sizeof(unionargs)) == -1)
146 1.10 maya atf_tc_fail_errno("union mount");
147 1.10 maya
148 1.10 maya unionargs.target = __UNCONST("/Tunion/B");
149 1.10 maya unionargs.mntflags = UNMNT_ABOVE;
150 1.10 maya
151 1.10 maya if (rump_sys_mount(MOUNT_UNION, "/Tunion/A", 0,
152 1.10 maya &unionargs, sizeof(unionargs)) == -1)
153 1.10 maya atf_tc_fail_errno("union mount2");
154 1.10 maya
155 1.10 maya if (rump_sys_mkdir("/Tunion/A/A", 0777) == -1)
156 1.10 maya atf_tc_fail_errno("mkdir failed");
157 1.10 maya }
158 1.10 maya
159 1.4 pooka ATF_TC(devnull1);
160 1.4 pooka ATF_TC_HEAD(devnull1, tc)
161 1.4 pooka {
162 1.4 pooka atf_tc_set_md_var(tc, "descr", "mount_union -b and "
163 1.4 pooka "'echo x > /un/null'");
164 1.4 pooka }
165 1.4 pooka
166 1.4 pooka ATF_TC_BODY(devnull1, tc)
167 1.4 pooka {
168 1.4 pooka struct union_args unionargs;
169 1.8 hannken int fd, res;
170 1.4 pooka
171 1.4 pooka rump_init();
172 1.4 pooka
173 1.4 pooka if (rump_sys_mkdir("/mp", 0777) == -1)
174 1.4 pooka atf_tc_fail_errno("mkdir mp");
175 1.4 pooka
176 1.4 pooka unionargs.target = __UNCONST("/dev");
177 1.4 pooka unionargs.mntflags = UNMNT_BELOW;
178 1.4 pooka
179 1.4 pooka if (rump_sys_mount(MOUNT_UNION, "/mp", 0,
180 1.4 pooka &unionargs, sizeof(unionargs)) == -1)
181 1.4 pooka atf_tc_fail_errno("union mount");
182 1.4 pooka
183 1.4 pooka fd = rump_sys_open("/mp/null", O_WRONLY | O_CREAT | O_TRUNC);
184 1.4 pooka
185 1.8 hannken if (fd == -1)
186 1.8 hannken atf_tc_fail_errno("open");
187 1.6 pooka
188 1.8 hannken res = rump_sys_write(fd, &fd, sizeof(fd));
189 1.8 hannken if (res != sizeof(fd))
190 1.8 hannken atf_tc_fail("write");
191 1.4 pooka }
192 1.4 pooka
193 1.4 pooka ATF_TC(devnull2);
194 1.4 pooka ATF_TC_HEAD(devnull2, tc)
195 1.4 pooka {
196 1.4 pooka atf_tc_set_md_var(tc, "descr", "mount_union -b and "
197 1.4 pooka "'echo x >> /un/null'");
198 1.4 pooka }
199 1.4 pooka
200 1.4 pooka ATF_TC_BODY(devnull2, tc)
201 1.4 pooka {
202 1.4 pooka struct union_args unionargs;
203 1.8 hannken int fd, res;
204 1.4 pooka
205 1.4 pooka rump_init();
206 1.4 pooka
207 1.4 pooka if (rump_sys_mkdir("/mp", 0777) == -1)
208 1.4 pooka atf_tc_fail_errno("mkdir mp");
209 1.4 pooka
210 1.4 pooka unionargs.target = __UNCONST("/dev");
211 1.4 pooka unionargs.mntflags = UNMNT_BELOW;
212 1.4 pooka
213 1.4 pooka if (rump_sys_mount(MOUNT_UNION, "/mp", 0,
214 1.4 pooka &unionargs, sizeof(unionargs)) == -1)
215 1.4 pooka atf_tc_fail_errno("union mount");
216 1.4 pooka
217 1.4 pooka fd = rump_sys_open("/mp/null", O_WRONLY | O_CREAT | O_APPEND);
218 1.4 pooka if (fd == -1)
219 1.4 pooka atf_tc_fail_errno("open");
220 1.4 pooka
221 1.8 hannken res = rump_sys_write(fd, &fd, sizeof(fd));
222 1.8 hannken if (res != sizeof(fd))
223 1.8 hannken atf_tc_fail("write");
224 1.4 pooka }
225 1.4 pooka
226 1.1 pooka ATF_TP_ADD_TCS(tp)
227 1.1 pooka {
228 1.1 pooka ATF_TP_ADD_TC(tp, multilayer);
229 1.10 maya ATF_TP_ADD_TC(tp, multilayer2);
230 1.10 maya ATF_TP_ADD_TC(tp, cyclic);
231 1.10 maya ATF_TP_ADD_TC(tp, cyclic2);
232 1.4 pooka ATF_TP_ADD_TC(tp, devnull1);
233 1.4 pooka ATF_TP_ADD_TC(tp, devnull2);
234 1.1 pooka
235 1.1 pooka return atf_no_error();
236 1.1 pooka }
237