xref: /minix3/tests/fs/ffs/t_mount.c (revision 11be35a165022172ed3cea20f2b5df0307540b0e)
1*11be35a1SLionel Sambuc /*	$NetBSD: t_mount.c,v 1.13 2012/11/27 16:01:49 jakllsch Exp $	*/
2*11be35a1SLionel Sambuc 
3*11be35a1SLionel Sambuc /*
4*11be35a1SLionel Sambuc  * Basic tests for mounting
5*11be35a1SLionel Sambuc  */
6*11be35a1SLionel Sambuc 
7*11be35a1SLionel Sambuc /*
8*11be35a1SLionel Sambuc  * 48Kimage:
9*11be35a1SLionel Sambuc  * Adapted for rump and atf from a testcase supplied
10*11be35a1SLionel Sambuc  * by Hubert Feyrer on netbsd-users@
11*11be35a1SLionel Sambuc  */
12*11be35a1SLionel Sambuc 
13*11be35a1SLionel Sambuc #include <atf-c.h>
14*11be35a1SLionel Sambuc 
15*11be35a1SLionel Sambuc #define FSTEST_IMGSIZE (96 * 512)
16*11be35a1SLionel Sambuc #include "../common/h_fsmacros.h"
17*11be35a1SLionel Sambuc 
18*11be35a1SLionel Sambuc #include <sys/types.h>
19*11be35a1SLionel Sambuc #include <sys/mount.h>
20*11be35a1SLionel Sambuc 
21*11be35a1SLionel Sambuc #include <stdlib.h>
22*11be35a1SLionel Sambuc 
23*11be35a1SLionel Sambuc #include <ufs/ufs/ufsmount.h>
24*11be35a1SLionel Sambuc 
25*11be35a1SLionel Sambuc #include <rump/rump.h>
26*11be35a1SLionel Sambuc #include <rump/rump_syscalls.h>
27*11be35a1SLionel Sambuc 
28*11be35a1SLionel Sambuc #include "../../h_macros.h"
29*11be35a1SLionel Sambuc 
30*11be35a1SLionel Sambuc ATF_TC(48Kimage);
31*11be35a1SLionel Sambuc ATF_TC_HEAD(48Kimage, tc)
32*11be35a1SLionel Sambuc {
33*11be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "mount small 48K ffs image");
34*11be35a1SLionel Sambuc }
35*11be35a1SLionel Sambuc 
36*11be35a1SLionel Sambuc ATF_TC_BODY(48Kimage, tc)
37*11be35a1SLionel Sambuc {
38*11be35a1SLionel Sambuc 	void *tmp;
39*11be35a1SLionel Sambuc 
40*11be35a1SLionel Sambuc 	atf_tc_expect_fail("PR kern/43573");
41*11be35a1SLionel Sambuc 	FSTEST_CONSTRUCTOR(tc, ffs, tmp);
42*11be35a1SLionel Sambuc 	atf_tc_expect_pass();
43*11be35a1SLionel Sambuc 
44*11be35a1SLionel Sambuc 	FSTEST_DESTRUCTOR(tc, ffs, tmp);
45*11be35a1SLionel Sambuc }
46*11be35a1SLionel Sambuc 
47*11be35a1SLionel Sambuc ATF_TC(fsbsizeovermaxphys);
ATF_TC_HEAD(fsbsizeovermaxphys,tc)48*11be35a1SLionel Sambuc ATF_TC_HEAD(fsbsizeovermaxphys, tc)
49*11be35a1SLionel Sambuc {
50*11be35a1SLionel Sambuc 
51*11be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "mounts file system with "
52*11be35a1SLionel Sambuc 	    "blocksize > MAXPHYS");
53*11be35a1SLionel Sambuc 	/* PR kern/43727 */
54*11be35a1SLionel Sambuc }
55*11be35a1SLionel Sambuc 
ATF_TC_BODY(fsbsizeovermaxphys,tc)56*11be35a1SLionel Sambuc ATF_TC_BODY(fsbsizeovermaxphys, tc)
57*11be35a1SLionel Sambuc {
58*11be35a1SLionel Sambuc 	char cmd[1024];
59*11be35a1SLionel Sambuc 	struct ufs_args args;
60*11be35a1SLionel Sambuc 	struct statvfs svb;
61*11be35a1SLionel Sambuc 
62*11be35a1SLionel Sambuc 	/*
63*11be35a1SLionel Sambuc 	 * We cannot pass newfs parameters via the fstest interface,
64*11be35a1SLionel Sambuc 	 * so do things the oldfashioned manual way.
65*11be35a1SLionel Sambuc 	 */
66*11be35a1SLionel Sambuc 	snprintf(cmd, sizeof(cmd), "newfs -G -b %d -F -s 10000 "
67*11be35a1SLionel Sambuc 	    "ffs.img > /dev/null", MAXPHYS * 2);
68*11be35a1SLionel Sambuc 	if (system(cmd))
69*11be35a1SLionel Sambuc 		atf_tc_fail("cannot create file system");
70*11be35a1SLionel Sambuc 
71*11be35a1SLionel Sambuc 	rump_init();
72*11be35a1SLionel Sambuc 	if (rump_pub_etfs_register("/devdisk", "ffs.img", RUMP_ETFS_BLK))
73*11be35a1SLionel Sambuc 		atf_tc_fail("cannot register rump fake device");
74*11be35a1SLionel Sambuc 
75*11be35a1SLionel Sambuc 	args.fspec = __UNCONST("/devdisk");
76*11be35a1SLionel Sambuc 
77*11be35a1SLionel Sambuc 	if (rump_sys_mkdir("/mp", 0777) == -1)
78*11be35a1SLionel Sambuc 		atf_tc_fail_errno("create mountpoint");
79*11be35a1SLionel Sambuc 
80*11be35a1SLionel Sambuc 	/* mount succeeded?  bad omen.  confirm we're in trouble.  */
81*11be35a1SLionel Sambuc 	if (rump_sys_mount(MOUNT_FFS, "/mp", 0, &args, sizeof(args)) != -1) {
82*11be35a1SLionel Sambuc 		rump_sys_statvfs1("/mp", &svb, ST_WAIT);
83*11be35a1SLionel Sambuc 		atf_tc_fail("not expecting to be alive");
84*11be35a1SLionel Sambuc 	}
85*11be35a1SLionel Sambuc 
86*11be35a1SLionel Sambuc 	/* otherwise we're do-ne */
87*11be35a1SLionel Sambuc }
88*11be35a1SLionel Sambuc 
89*11be35a1SLionel Sambuc ATF_TC(fsbsizeovermaxbsize);
ATF_TC_HEAD(fsbsizeovermaxbsize,tc)90*11be35a1SLionel Sambuc ATF_TC_HEAD(fsbsizeovermaxbsize, tc)
91*11be35a1SLionel Sambuc {
92*11be35a1SLionel Sambuc 
93*11be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "mounts file system with "
94*11be35a1SLionel Sambuc 	    "blocksize > MAXBSIZE");
95*11be35a1SLionel Sambuc }
96*11be35a1SLionel Sambuc 
ATF_TC_BODY(fsbsizeovermaxbsize,tc)97*11be35a1SLionel Sambuc ATF_TC_BODY(fsbsizeovermaxbsize, tc)
98*11be35a1SLionel Sambuc {
99*11be35a1SLionel Sambuc 	char cmd[1024];
100*11be35a1SLionel Sambuc 	struct ufs_args args;
101*11be35a1SLionel Sambuc 	struct statvfs svb;
102*11be35a1SLionel Sambuc 
103*11be35a1SLionel Sambuc 	/*
104*11be35a1SLionel Sambuc 	 * We cannot pass newfs parameters via the fstest interface,
105*11be35a1SLionel Sambuc 	 * so do things the oldfashioned manual way.
106*11be35a1SLionel Sambuc 	 */
107*11be35a1SLionel Sambuc 	snprintf(cmd, sizeof(cmd), "newfs -G -b %d -F -s 10000 "
108*11be35a1SLionel Sambuc 	    "ffs.img > /dev/null", MAXBSIZE * 2);
109*11be35a1SLionel Sambuc 	if (system(cmd))
110*11be35a1SLionel Sambuc 		atf_tc_fail("cannot create file system");
111*11be35a1SLionel Sambuc 
112*11be35a1SLionel Sambuc 	rump_init();
113*11be35a1SLionel Sambuc 	if (rump_pub_etfs_register("/devdisk", "ffs.img", RUMP_ETFS_BLK))
114*11be35a1SLionel Sambuc 		atf_tc_fail("cannot register rump fake device");
115*11be35a1SLionel Sambuc 
116*11be35a1SLionel Sambuc 	args.fspec = __UNCONST("/devdisk");
117*11be35a1SLionel Sambuc 
118*11be35a1SLionel Sambuc 	if (rump_sys_mkdir("/mp", 0777) == -1)
119*11be35a1SLionel Sambuc 		atf_tc_fail_errno("create mountpoint");
120*11be35a1SLionel Sambuc 
121*11be35a1SLionel Sambuc 	/* mount succeeded?  bad omen.  confirm we're in trouble.  */
122*11be35a1SLionel Sambuc 	if (rump_sys_mount(MOUNT_FFS, "/mp", 0, &args, sizeof(args)) != -1) {
123*11be35a1SLionel Sambuc 		rump_sys_statvfs1("/mp", &svb, ST_WAIT);
124*11be35a1SLionel Sambuc 		atf_tc_fail("not expecting to be alive");
125*11be35a1SLionel Sambuc 	}
126*11be35a1SLionel Sambuc 
127*11be35a1SLionel Sambuc 	/* otherwise we're do-ne */
128*11be35a1SLionel Sambuc }
129*11be35a1SLionel Sambuc 
ATF_TP_ADD_TCS(tp)130*11be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
131*11be35a1SLionel Sambuc {
132*11be35a1SLionel Sambuc 
133*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, 48Kimage);
134*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, fsbsizeovermaxphys);
135*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, fsbsizeovermaxbsize);
136*11be35a1SLionel Sambuc 
137*11be35a1SLionel Sambuc 	return atf_no_error();
138*11be35a1SLionel Sambuc }
139