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