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