1*11be35a1SLionel Sambuc /* $NetBSD: t_pr.c,v 1.8 2011/08/10 06:27:02 hannken Exp $ */
2*11be35a1SLionel Sambuc
3*11be35a1SLionel Sambuc #include <sys/types.h>
4*11be35a1SLionel Sambuc #include <sys/mount.h>
5*11be35a1SLionel Sambuc
6*11be35a1SLionel Sambuc #include <atf-c.h>
7*11be35a1SLionel Sambuc #include <err.h>
8*11be35a1SLionel Sambuc #include <errno.h>
9*11be35a1SLionel Sambuc #include <fcntl.h>
10*11be35a1SLionel Sambuc #include <stdio.h>
11*11be35a1SLionel Sambuc #include <unistd.h>
12*11be35a1SLionel Sambuc #include <string.h>
13*11be35a1SLionel Sambuc #include <stdlib.h>
14*11be35a1SLionel Sambuc
15*11be35a1SLionel Sambuc #include <rump/rump.h>
16*11be35a1SLionel Sambuc #include <rump/rump_syscalls.h>
17*11be35a1SLionel Sambuc
18*11be35a1SLionel Sambuc #include <miscfs/union/union.h>
19*11be35a1SLionel Sambuc
20*11be35a1SLionel Sambuc #include "../../h_macros.h"
21*11be35a1SLionel Sambuc
22*11be35a1SLionel Sambuc ATF_TC(multilayer);
ATF_TC_HEAD(multilayer,tc)23*11be35a1SLionel Sambuc ATF_TC_HEAD(multilayer, tc)
24*11be35a1SLionel Sambuc {
25*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "mount_union -b twice");
26*11be35a1SLionel Sambuc }
27*11be35a1SLionel Sambuc
ATF_TC_BODY(multilayer,tc)28*11be35a1SLionel Sambuc ATF_TC_BODY(multilayer, tc)
29*11be35a1SLionel Sambuc {
30*11be35a1SLionel Sambuc struct union_args unionargs;
31*11be35a1SLionel Sambuc
32*11be35a1SLionel Sambuc rump_init();
33*11be35a1SLionel Sambuc
34*11be35a1SLionel Sambuc if (rump_sys_mkdir("/Tunion", 0777) == -1)
35*11be35a1SLionel Sambuc atf_tc_fail_errno("mkdir mp1");
36*11be35a1SLionel Sambuc if (rump_sys_mkdir("/Tunion2", 0777) == -1)
37*11be35a1SLionel Sambuc atf_tc_fail_errno("mkdir mp2");
38*11be35a1SLionel Sambuc if (rump_sys_mkdir("/Tunion2/A", 0777) == -1)
39*11be35a1SLionel Sambuc atf_tc_fail_errno("mkdir A");
40*11be35a1SLionel Sambuc if (rump_sys_mkdir("/Tunion2/B", 0777) == -1)
41*11be35a1SLionel Sambuc atf_tc_fail_errno("mkdir B");
42*11be35a1SLionel Sambuc
43*11be35a1SLionel Sambuc unionargs.target = __UNCONST("/Tunion2/A");
44*11be35a1SLionel Sambuc unionargs.mntflags = UNMNT_BELOW;
45*11be35a1SLionel Sambuc
46*11be35a1SLionel Sambuc if (rump_sys_mount(MOUNT_UNION, "/Tunion", 0,
47*11be35a1SLionel Sambuc &unionargs, sizeof(unionargs)) == -1)
48*11be35a1SLionel Sambuc atf_tc_fail_errno("union mount");
49*11be35a1SLionel Sambuc
50*11be35a1SLionel Sambuc unionargs.target = __UNCONST("/Tunion2/B");
51*11be35a1SLionel Sambuc unionargs.mntflags = UNMNT_BELOW;
52*11be35a1SLionel Sambuc
53*11be35a1SLionel Sambuc rump_sys_mount(MOUNT_UNION, "/Tunion", 0,&unionargs,sizeof(unionargs));
54*11be35a1SLionel Sambuc }
55*11be35a1SLionel Sambuc
56*11be35a1SLionel Sambuc ATF_TC(devnull1);
ATF_TC_HEAD(devnull1,tc)57*11be35a1SLionel Sambuc ATF_TC_HEAD(devnull1, tc)
58*11be35a1SLionel Sambuc {
59*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "mount_union -b and "
60*11be35a1SLionel Sambuc "'echo x > /un/null'");
61*11be35a1SLionel Sambuc }
62*11be35a1SLionel Sambuc
ATF_TC_BODY(devnull1,tc)63*11be35a1SLionel Sambuc ATF_TC_BODY(devnull1, tc)
64*11be35a1SLionel Sambuc {
65*11be35a1SLionel Sambuc struct union_args unionargs;
66*11be35a1SLionel Sambuc int fd, res;
67*11be35a1SLionel Sambuc
68*11be35a1SLionel Sambuc rump_init();
69*11be35a1SLionel Sambuc
70*11be35a1SLionel Sambuc if (rump_sys_mkdir("/mp", 0777) == -1)
71*11be35a1SLionel Sambuc atf_tc_fail_errno("mkdir mp");
72*11be35a1SLionel Sambuc
73*11be35a1SLionel Sambuc unionargs.target = __UNCONST("/dev");
74*11be35a1SLionel Sambuc unionargs.mntflags = UNMNT_BELOW;
75*11be35a1SLionel Sambuc
76*11be35a1SLionel Sambuc if (rump_sys_mount(MOUNT_UNION, "/mp", 0,
77*11be35a1SLionel Sambuc &unionargs, sizeof(unionargs)) == -1)
78*11be35a1SLionel Sambuc atf_tc_fail_errno("union mount");
79*11be35a1SLionel Sambuc
80*11be35a1SLionel Sambuc fd = rump_sys_open("/mp/null", O_WRONLY | O_CREAT | O_TRUNC);
81*11be35a1SLionel Sambuc
82*11be35a1SLionel Sambuc if (fd == -1)
83*11be35a1SLionel Sambuc atf_tc_fail_errno("open");
84*11be35a1SLionel Sambuc
85*11be35a1SLionel Sambuc res = rump_sys_write(fd, &fd, sizeof(fd));
86*11be35a1SLionel Sambuc if (res != sizeof(fd))
87*11be35a1SLionel Sambuc atf_tc_fail("write");
88*11be35a1SLionel Sambuc }
89*11be35a1SLionel Sambuc
90*11be35a1SLionel Sambuc ATF_TC(devnull2);
ATF_TC_HEAD(devnull2,tc)91*11be35a1SLionel Sambuc ATF_TC_HEAD(devnull2, tc)
92*11be35a1SLionel Sambuc {
93*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "mount_union -b and "
94*11be35a1SLionel Sambuc "'echo x >> /un/null'");
95*11be35a1SLionel Sambuc }
96*11be35a1SLionel Sambuc
ATF_TC_BODY(devnull2,tc)97*11be35a1SLionel Sambuc ATF_TC_BODY(devnull2, tc)
98*11be35a1SLionel Sambuc {
99*11be35a1SLionel Sambuc struct union_args unionargs;
100*11be35a1SLionel Sambuc int fd, res;
101*11be35a1SLionel Sambuc
102*11be35a1SLionel Sambuc rump_init();
103*11be35a1SLionel Sambuc
104*11be35a1SLionel Sambuc if (rump_sys_mkdir("/mp", 0777) == -1)
105*11be35a1SLionel Sambuc atf_tc_fail_errno("mkdir mp");
106*11be35a1SLionel Sambuc
107*11be35a1SLionel Sambuc unionargs.target = __UNCONST("/dev");
108*11be35a1SLionel Sambuc unionargs.mntflags = UNMNT_BELOW;
109*11be35a1SLionel Sambuc
110*11be35a1SLionel Sambuc if (rump_sys_mount(MOUNT_UNION, "/mp", 0,
111*11be35a1SLionel Sambuc &unionargs, sizeof(unionargs)) == -1)
112*11be35a1SLionel Sambuc atf_tc_fail_errno("union mount");
113*11be35a1SLionel Sambuc
114*11be35a1SLionel Sambuc fd = rump_sys_open("/mp/null", O_WRONLY | O_CREAT | O_APPEND);
115*11be35a1SLionel Sambuc if (fd == -1)
116*11be35a1SLionel Sambuc atf_tc_fail_errno("open");
117*11be35a1SLionel Sambuc
118*11be35a1SLionel Sambuc res = rump_sys_write(fd, &fd, sizeof(fd));
119*11be35a1SLionel Sambuc if (res != sizeof(fd))
120*11be35a1SLionel Sambuc atf_tc_fail("write");
121*11be35a1SLionel Sambuc }
122*11be35a1SLionel Sambuc
ATF_TP_ADD_TCS(tp)123*11be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
124*11be35a1SLionel Sambuc {
125*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, multilayer);
126*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, devnull1);
127*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, devnull2);
128*11be35a1SLionel Sambuc
129*11be35a1SLionel Sambuc return atf_no_error();
130*11be35a1SLionel Sambuc }
131