t_pr.c revision 1.5 1 1.5 pooka /* $NetBSD: t_pr.c,v 1.5 2010/07/03 12:10:35 pooka 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.1 pooka #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.3 jmmv /* atf_tc_expect_signal(-1, "PR kern/23986"); */
54 1.1 pooka rump_sys_mount(MOUNT_UNION, "/Tunion", 0,&unionargs,sizeof(unionargs));
55 1.1 pooka }
56 1.1 pooka
57 1.4 pooka ATF_TC(devnull1);
58 1.4 pooka ATF_TC_HEAD(devnull1, tc)
59 1.4 pooka {
60 1.4 pooka atf_tc_set_md_var(tc, "descr", "mount_union -b and "
61 1.4 pooka "'echo x > /un/null'");
62 1.4 pooka }
63 1.4 pooka
64 1.4 pooka ATF_TC_BODY(devnull1, tc)
65 1.4 pooka {
66 1.4 pooka struct union_args unionargs;
67 1.4 pooka int fd;
68 1.4 pooka
69 1.4 pooka rump_init();
70 1.4 pooka
71 1.4 pooka if (rump_sys_mkdir("/mp", 0777) == -1)
72 1.4 pooka atf_tc_fail_errno("mkdir mp");
73 1.4 pooka
74 1.4 pooka unionargs.target = __UNCONST("/dev");
75 1.4 pooka unionargs.mntflags = UNMNT_BELOW;
76 1.4 pooka
77 1.4 pooka if (rump_sys_mount(MOUNT_UNION, "/mp", 0,
78 1.4 pooka &unionargs, sizeof(unionargs)) == -1)
79 1.4 pooka atf_tc_fail_errno("union mount");
80 1.4 pooka
81 1.4 pooka fd = rump_sys_open("/mp/null", O_WRONLY | O_CREAT | O_TRUNC);
82 1.4 pooka
83 1.4 pooka atf_tc_expect_fail("PR kern/43560");
84 1.4 pooka if (fd == -1)
85 1.4 pooka atf_tc_fail_errno("open");
86 1.4 pooka }
87 1.4 pooka
88 1.4 pooka ATF_TC(devnull2);
89 1.4 pooka ATF_TC_HEAD(devnull2, tc)
90 1.4 pooka {
91 1.4 pooka atf_tc_set_md_var(tc, "descr", "mount_union -b and "
92 1.4 pooka "'echo x >> /un/null'");
93 1.4 pooka }
94 1.4 pooka
95 1.4 pooka ATF_TC_BODY(devnull2, tc)
96 1.4 pooka {
97 1.4 pooka struct union_args unionargs;
98 1.4 pooka int fd;
99 1.4 pooka
100 1.4 pooka rump_init();
101 1.4 pooka
102 1.4 pooka if (rump_sys_mkdir("/mp", 0777) == -1)
103 1.4 pooka atf_tc_fail_errno("mkdir mp");
104 1.4 pooka
105 1.4 pooka unionargs.target = __UNCONST("/dev");
106 1.4 pooka unionargs.mntflags = UNMNT_BELOW;
107 1.4 pooka
108 1.4 pooka if (rump_sys_mount(MOUNT_UNION, "/mp", 0,
109 1.4 pooka &unionargs, sizeof(unionargs)) == -1)
110 1.4 pooka atf_tc_fail_errno("union mount");
111 1.4 pooka
112 1.4 pooka fd = rump_sys_open("/mp/null", O_WRONLY | O_CREAT | O_APPEND);
113 1.4 pooka if (fd == -1)
114 1.4 pooka atf_tc_fail_errno("open");
115 1.4 pooka
116 1.4 pooka atf_tc_expect_signal(-1, "PR kern/43560");
117 1.4 pooka rump_sys_write(fd, &fd, sizeof(fd));
118 1.4 pooka }
119 1.4 pooka
120 1.1 pooka ATF_TP_ADD_TCS(tp)
121 1.1 pooka {
122 1.1 pooka ATF_TP_ADD_TC(tp, multilayer);
123 1.4 pooka ATF_TP_ADD_TC(tp, devnull1);
124 1.4 pooka ATF_TP_ADD_TC(tp, devnull2);
125 1.1 pooka
126 1.1 pooka return atf_no_error();
127 1.1 pooka }
128