xref: /minix3/tests/fs/ffs/t_quota2_1.c (revision 11be35a165022172ed3cea20f2b5df0307540b0e)
1*11be35a1SLionel Sambuc /*	$NetBSD: t_quota2_1.c,v 1.4 2012/03/15 02:02:22 joerg Exp $	*/
2*11be35a1SLionel Sambuc 
3*11be35a1SLionel Sambuc /*
4*11be35a1SLionel Sambuc  * Basic tests for quota2
5*11be35a1SLionel Sambuc  */
6*11be35a1SLionel Sambuc 
7*11be35a1SLionel Sambuc #include <atf-c.h>
8*11be35a1SLionel Sambuc 
9*11be35a1SLionel Sambuc #include "../common/h_fsmacros.h"
10*11be35a1SLionel Sambuc 
11*11be35a1SLionel Sambuc #include <sys/types.h>
12*11be35a1SLionel Sambuc #include <sys/mount.h>
13*11be35a1SLionel Sambuc 
14*11be35a1SLionel Sambuc #include <stdlib.h>
15*11be35a1SLionel Sambuc 
16*11be35a1SLionel Sambuc #include <ufs/ufs/ufsmount.h>
17*11be35a1SLionel Sambuc 
18*11be35a1SLionel Sambuc #include <rump/rump.h>
19*11be35a1SLionel Sambuc #include <rump/rump_syscalls.h>
20*11be35a1SLionel Sambuc 
21*11be35a1SLionel Sambuc #include "../../h_macros.h"
22*11be35a1SLionel Sambuc 
23*11be35a1SLionel Sambuc static void
do_quota(const atf_tc_t * tc,int n,const char * newfs_opts,int log)24*11be35a1SLionel Sambuc do_quota(const atf_tc_t *tc, int n, const char *newfs_opts, int log)
25*11be35a1SLionel Sambuc {
26*11be35a1SLionel Sambuc 	int i;
27*11be35a1SLionel Sambuc 	char buf[1024];
28*11be35a1SLionel Sambuc 	int res;
29*11be35a1SLionel Sambuc 	int fd;
30*11be35a1SLionel Sambuc 	struct ufs_args uargs;
31*11be35a1SLionel Sambuc 
32*11be35a1SLionel Sambuc 	snprintf(buf, sizeof(buf), "newfs -q user -q group -F -s 4000 -n %d "
33*11be35a1SLionel Sambuc 	    "%s %s", (n + 3),  newfs_opts, FSTEST_IMGNAME);
34*11be35a1SLionel Sambuc         if (system(buf) == -1)
35*11be35a1SLionel Sambuc                 atf_tc_fail_errno("cannot create file system");
36*11be35a1SLionel Sambuc 
37*11be35a1SLionel Sambuc 	rump_init();
38*11be35a1SLionel Sambuc 	if (rump_sys_mkdir(FSTEST_MNTNAME, 0777) == -1)
39*11be35a1SLionel Sambuc 		atf_tc_fail_errno("mount point create");
40*11be35a1SLionel Sambuc 
41*11be35a1SLionel Sambuc 	rump_pub_etfs_register("/diskdev", FSTEST_IMGNAME, RUMP_ETFS_BLK);
42*11be35a1SLionel Sambuc 
43*11be35a1SLionel Sambuc 	uargs.fspec = __UNCONST("/diskdev");
44*11be35a1SLionel Sambuc 	if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME, (log) ? MNT_LOG : 0,
45*11be35a1SLionel Sambuc 	    &uargs, sizeof(uargs)) == -1)
46*11be35a1SLionel Sambuc 		atf_tc_fail_errno("mount ffs %s", FSTEST_MNTNAME);
47*11be35a1SLionel Sambuc 
48*11be35a1SLionel Sambuc 	atf_tc_expect_pass();
49*11be35a1SLionel Sambuc 	FSTEST_ENTER();
50*11be35a1SLionel Sambuc 	RL(rump_sys_chown(".", 0, 0));
51*11be35a1SLionel Sambuc 	for (i = 0 ; i < n; i++) {
52*11be35a1SLionel Sambuc 		sprintf(buf, "file%d", i);
53*11be35a1SLionel Sambuc 		RL(fd = rump_sys_open(buf, O_CREAT | O_RDWR, 0755));
54*11be35a1SLionel Sambuc 		sprintf(buf, "test file no %d", i);
55*11be35a1SLionel Sambuc 		RL(rump_sys_write(fd, buf, strlen(buf)));
56*11be35a1SLionel Sambuc 		RL(rump_sys_fchown(fd, i, i+80000));
57*11be35a1SLionel Sambuc 		rump_sys_close(fd);
58*11be35a1SLionel Sambuc 	}
59*11be35a1SLionel Sambuc 	FSTEST_EXIT();
60*11be35a1SLionel Sambuc 	if (rump_sys_unmount(FSTEST_MNTNAME, 0) != 0) {
61*11be35a1SLionel Sambuc 		rump_pub_vfs_mount_print(FSTEST_MNTNAME, 1);
62*11be35a1SLionel Sambuc 		atf_tc_fail_errno("unmount failed");
63*11be35a1SLionel Sambuc 	}
64*11be35a1SLionel Sambuc 	snprintf(buf, 1024, "fsck_ffs -fn -F %s",  FSTEST_IMGNAME);
65*11be35a1SLionel Sambuc 	res = system(buf);
66*11be35a1SLionel Sambuc 	if (res != 0)
67*11be35a1SLionel Sambuc 		atf_tc_fail("fsck returned %d", res);
68*11be35a1SLionel Sambuc }
69*11be35a1SLionel Sambuc 
70*11be35a1SLionel Sambuc #define DECL_TEST(nent, newops, name, descr, log) \
71*11be35a1SLionel Sambuc ATF_TC(quota_##name);							\
72*11be35a1SLionel Sambuc 									\
73*11be35a1SLionel Sambuc ATF_TC_HEAD(quota_##name, tc)						\
74*11be35a1SLionel Sambuc {									\
75*11be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr",					\
76*11be35a1SLionel Sambuc 	    "test quotas with %d users and groups, %s",			\
77*11be35a1SLionel Sambuc 	    nent, descr);						\
78*11be35a1SLionel Sambuc }									\
79*11be35a1SLionel Sambuc 									\
80*11be35a1SLionel Sambuc ATF_TC_BODY(quota_##name, tc)						\
81*11be35a1SLionel Sambuc {									\
82*11be35a1SLionel Sambuc 	do_quota(tc, nent, newops, log);				\
83*11be35a1SLionel Sambuc }
84*11be35a1SLionel Sambuc 
85*11be35a1SLionel Sambuc DECL_TEST(40, "-O1 -B le", 40_O1_le, "UFS1 little-endian", 0)
86*11be35a1SLionel Sambuc DECL_TEST(40, "-O1 -B be", 40_O1_be, "UFS1 big-endian", 0)
87*11be35a1SLionel Sambuc 
88*11be35a1SLionel Sambuc DECL_TEST(40, "-O2 -B le", 40_O2_le, "UFS2 little-endian", 0)
89*11be35a1SLionel Sambuc DECL_TEST(40, "-O2 -B be", 40_O2_be, "UFS2 big-endian", 0)
90*11be35a1SLionel Sambuc 
91*11be35a1SLionel Sambuc DECL_TEST(40, "-O1", 40_O1_log, "UFS1 log", 1)
92*11be35a1SLionel Sambuc DECL_TEST(40, "-O2", 40_O2_log, "UFS2 log", 1)
93*11be35a1SLionel Sambuc 
94*11be35a1SLionel Sambuc DECL_TEST(1000, "-O1 -B le", 1000_O1_le, "UFS1 little-endian", 0)
95*11be35a1SLionel Sambuc DECL_TEST(1000, "-O1 -B be", 1000_O1_be, "UFS1 big-endian", 0)
96*11be35a1SLionel Sambuc 
97*11be35a1SLionel Sambuc DECL_TEST(1000, "-O2 -B le", 1000_O2_le, "UFS2 little-endian", 0)
98*11be35a1SLionel Sambuc DECL_TEST(1000, "-O2 -B be", 1000_O2_be, "UFS2 big-endian", 0)
99*11be35a1SLionel Sambuc 
ATF_TP_ADD_TCS(tp)100*11be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
101*11be35a1SLionel Sambuc {
102*11be35a1SLionel Sambuc 
103*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, quota_40_O1_le);
104*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, quota_40_O1_be);
105*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, quota_40_O2_le);
106*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, quota_40_O2_be);
107*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, quota_40_O1_log);
108*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, quota_40_O2_log);
109*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, quota_1000_O1_le);
110*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, quota_1000_O1_be);
111*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, quota_1000_O2_le);
112*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, quota_1000_O2_be);
113*11be35a1SLionel Sambuc 	return atf_no_error();
114*11be35a1SLionel Sambuc }
115