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