Home | History | Annotate | Line # | Download | only in union
t_pr.c revision 1.6
      1  1.6  pooka /*	$NetBSD: t_pr.c,v 1.6 2010/07/03 12:23:04 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.6  pooka 	if (fd == -1 && errno == EROFS)
     85  1.6  pooka 		atf_tc_fail("open returned EROFS");
     86  1.6  pooka 	else if (fd == -1)
     87  1.6  pooka 		atf_tc_fail_errno("open fail");
     88  1.6  pooka 
     89  1.6  pooka 	atf_tc_expect_pass();
     90  1.4  pooka }
     91  1.4  pooka 
     92  1.4  pooka ATF_TC(devnull2);
     93  1.4  pooka ATF_TC_HEAD(devnull2, tc)
     94  1.4  pooka {
     95  1.4  pooka 	atf_tc_set_md_var(tc, "descr", "mount_union -b and "
     96  1.4  pooka 	    "'echo x >> /un/null'");
     97  1.4  pooka }
     98  1.4  pooka 
     99  1.4  pooka ATF_TC_BODY(devnull2, tc)
    100  1.4  pooka {
    101  1.4  pooka 	struct union_args unionargs;
    102  1.4  pooka 	int fd;
    103  1.4  pooka 
    104  1.4  pooka 	rump_init();
    105  1.4  pooka 
    106  1.4  pooka 	if (rump_sys_mkdir("/mp", 0777) == -1)
    107  1.4  pooka 		atf_tc_fail_errno("mkdir mp");
    108  1.4  pooka 
    109  1.4  pooka 	unionargs.target = __UNCONST("/dev");
    110  1.4  pooka 	unionargs.mntflags = UNMNT_BELOW;
    111  1.4  pooka 
    112  1.4  pooka 	if (rump_sys_mount(MOUNT_UNION, "/mp", 0,
    113  1.4  pooka 	    &unionargs, sizeof(unionargs)) == -1)
    114  1.4  pooka 		atf_tc_fail_errno("union mount");
    115  1.4  pooka 
    116  1.4  pooka 	fd = rump_sys_open("/mp/null", O_WRONLY | O_CREAT | O_APPEND);
    117  1.4  pooka 	if (fd == -1)
    118  1.4  pooka 		atf_tc_fail_errno("open");
    119  1.4  pooka 
    120  1.4  pooka 	atf_tc_expect_signal(-1, "PR kern/43560");
    121  1.4  pooka 	rump_sys_write(fd, &fd, sizeof(fd));
    122  1.4  pooka }
    123  1.4  pooka 
    124  1.1  pooka ATF_TP_ADD_TCS(tp)
    125  1.1  pooka {
    126  1.1  pooka 	ATF_TP_ADD_TC(tp, multilayer);
    127  1.4  pooka 	ATF_TP_ADD_TC(tp, devnull1);
    128  1.4  pooka 	ATF_TP_ADD_TC(tp, devnull2);
    129  1.1  pooka 
    130  1.1  pooka 	return atf_no_error();
    131  1.1  pooka }
    132