xref: /freebsd/contrib/netbsd-tests/fs/ffs/t_mount.c (revision 8ddb146abcdf061be9f2c0db7e391697dafad85c)
1 /*	$NetBSD: t_mount.c,v 1.14 2017/01/13 21:30:39 christos 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 }
35 
36 ATF_TC_BODY(48Kimage, tc)
37 {
38 	void *tmp;
39 
40 	atf_tc_expect_fail("PR kern/43573");
41 	FSTEST_CONSTRUCTOR(tc, ffs, tmp);
42 	atf_tc_expect_pass();
43 
44 	FSTEST_DESTRUCTOR(tc, ffs, tmp);
45 }
46 
47 ATF_TC(fsbsizeovermaxphys);
48 ATF_TC_HEAD(fsbsizeovermaxphys, tc)
49 {
50 
51 	atf_tc_set_md_var(tc, "descr", "mounts file system with "
52 	    "blocksize > MAXPHYS");
53 	/* PR kern/43727 */
54 }
55 
56 ATF_TC_BODY(fsbsizeovermaxphys, tc)
57 {
58 	char cmd[1024];
59 	struct ufs_args args;
60 	struct statvfs svb;
61 
62 	/*
63 	 * We cannot pass newfs parameters via the fstest interface,
64 	 * so do things the oldfashioned manual way.
65 	 */
66 	snprintf(cmd, sizeof(cmd), "newfs -G -b %d -F -s 10000 "
67 	    "ffs.img > /dev/null", MAXPHYS * 2);
68 	if (system(cmd))
69 		atf_tc_fail("cannot create file system");
70 
71 	rump_init();
72 	if (rump_pub_etfs_register("/devdisk", "ffs.img", RUMP_ETFS_BLK))
73 		atf_tc_fail("cannot register rump fake device");
74 
75 	args.fspec = __UNCONST("/devdisk");
76 
77 	if (rump_sys_mkdir("/mp", 0777) == -1)
78 		atf_tc_fail_errno("create mountpoint");
79 
80 	/* mount succeeded?  bad omen.  confirm we're in trouble.  */
81 	if (rump_sys_mount(MOUNT_FFS, "/mp", 0, &args, sizeof(args)) != -1) {
82 		rump_sys_statvfs1("/mp", &svb, ST_WAIT);
83 		atf_tc_fail("not expecting to be alive");
84 	}
85 
86 	/* otherwise we're do-ne */
87 }
88 
89 ATF_TC(fsbsizeovermaxbsize);
90 ATF_TC_HEAD(fsbsizeovermaxbsize, tc)
91 {
92 
93 	atf_tc_set_md_var(tc, "descr", "mounts file system with "
94 	    "blocksize > MAXBSIZE");
95 }
96 
97 ATF_TC_BODY(fsbsizeovermaxbsize, tc)
98 {
99 	char cmd[1024];
100 	struct ufs_args args;
101 	struct statvfs svb;
102 
103 	/*
104 	 * We cannot pass newfs parameters via the fstest interface,
105 	 * so do things the oldfashioned manual way.
106 	 */
107 	snprintf(cmd, sizeof(cmd), "newfs -G -b %d -F -s 10000 "
108 	    "ffs.img > /dev/null", MAXBSIZE * 2);
109 	if (system(cmd))
110 		atf_tc_fail("cannot create file system");
111 
112 	rump_init();
113 	if (rump_pub_etfs_register("/devdisk", "ffs.img", RUMP_ETFS_BLK))
114 		atf_tc_fail("cannot register rump fake device");
115 
116 	args.fspec = __UNCONST("/devdisk");
117 
118 	if (rump_sys_mkdir("/mp", 0777) == -1)
119 		atf_tc_fail_errno("create mountpoint");
120 
121 	/* mount succeeded?  bad omen.  confirm we're in trouble.  */
122 	if (rump_sys_mount(MOUNT_FFS, "/mp", 0, &args, sizeof(args)) != -1) {
123 		rump_sys_statvfs1("/mp", &svb, ST_WAIT);
124 		atf_tc_fail("not expecting to be alive");
125 	}
126 
127 	/* otherwise we're do-ne */
128 }
129 
130 ATF_TP_ADD_TCS(tp)
131 {
132 
133 	ATF_TP_ADD_TC(tp, 48Kimage);
134 	ATF_TP_ADD_TC(tp, fsbsizeovermaxphys);
135 	ATF_TP_ADD_TC(tp, fsbsizeovermaxbsize);
136 
137 	return atf_no_error();
138 }
139