1 /* $NetBSD: t_quota2_remount.c,v 1.4 2012/03/15 02:02:22 joerg Exp $ */
4 * Basic tests for quota2
9 #include "../common/h_fsmacros.h"
11 #include <sys/types.h>
12 #include <sys/mount.h>
13 #include <sys/statvfs.h>
17 #include <ufs/ufs/ufsmount.h>
19 #include <rump/rump.h>
20 #include <rump/rump_syscalls.h>
22 #include "../../h_macros.h"
25 do_quota(const atf_tc_t
*tc
, int n
, const char *newfs_opts
, int log
)
31 struct ufs_args uargs
;
34 snprintf(buf
, sizeof(buf
), "newfs -q user -q group -F -s 4000 -n %d "
35 "%s %s", (n
+ 3), newfs_opts
, FSTEST_IMGNAME
);
36 if (system(buf
) == -1)
37 atf_tc_fail_errno("cannot create file system");
40 if (rump_sys_mkdir(FSTEST_MNTNAME
, 0777) == -1)
41 atf_tc_fail_errno("mount point create");
43 rump_pub_etfs_register("/diskdev", FSTEST_IMGNAME
, RUMP_ETFS_BLK
);
45 uargs
.fspec
= __UNCONST("/diskdev");
47 /* read-only doens't have quota enabled */
48 if (rump_sys_mount(MOUNT_FFS
, FSTEST_MNTNAME
, MNT_RDONLY
,
49 &uargs
, sizeof(uargs
)) == -1)
50 atf_tc_fail_errno("mount ffs ro %s", FSTEST_MNTNAME
);
52 if (rump_sys_statvfs1(FSTEST_MNTNAME
, &fst
, 0) != 0)
53 atf_tc_fail_errno("statbfs %s (1)", FSTEST_MNTNAME
);
55 if ((fst
.f_flag
& ST_QUOTA
) != 0)
56 atf_tc_fail("R/O filesystem has quota");
58 /* updating to read-write enables quota */
59 if (rump_sys_mount(MOUNT_FFS
, FSTEST_MNTNAME
,
60 MNT_UPDATE
| (log
? MNT_LOG
: 0), &uargs
, sizeof(uargs
)) == -1)
61 atf_tc_fail_errno("mount ffs rw %s", FSTEST_MNTNAME
);
63 if (rump_sys_statvfs1(FSTEST_MNTNAME
, &fst
, 0) != 0)
64 atf_tc_fail_errno("statbfs %s (2)", FSTEST_MNTNAME
);
66 if ((fst
.f_flag
& ST_QUOTA
) == 0)
67 atf_tc_fail("R/W filesystem has no quota");
69 /* we can update a second time */
70 if (rump_sys_mount(MOUNT_FFS
, FSTEST_MNTNAME
,
71 MNT_UPDATE
| (log
? MNT_LOG
: 0), &uargs
, sizeof(uargs
)) == -1)
72 atf_tc_fail_errno("mount ffs rw(2) %s", FSTEST_MNTNAME
);
74 if (rump_sys_statvfs1(FSTEST_MNTNAME
, &fst
, 0) != 0)
75 atf_tc_fail_errno("statbfs %s (3)", FSTEST_MNTNAME
);
77 if ((fst
.f_flag
& ST_QUOTA
) == 0)
78 atf_tc_fail("R/W filesystem has no quota");
80 /* create some files so fsck has something to check */
82 RL(rump_sys_chown(".", 0, 0));
83 for (i
= 0 ; i
< n
; i
++) {
84 sprintf(buf
, "file%d", i
);
85 RL(fd
= rump_sys_open(buf
, O_CREAT
| O_RDWR
, 0755));
86 sprintf(buf
, "test file no %d", i
);
87 RL(rump_sys_write(fd
, buf
, strlen(buf
)));
88 RL(rump_sys_fchown(fd
, i
, i
+80000));
92 if (rump_sys_unmount(FSTEST_MNTNAME
, 0) != 0) {
93 rump_pub_vfs_mount_print(FSTEST_MNTNAME
, 1);
94 atf_tc_fail_errno("unmount failed");
96 snprintf(buf
, 1024, "fsck_ffs -fn -F %s", FSTEST_IMGNAME
);
99 atf_tc_fail("fsck returned %d", res
);
102 #define DECL_TEST(nent, newops, name, descr, log) \
103 ATF_TC(quota_##name); \
105 ATF_TC_HEAD(quota_##name, tc) \
107 atf_tc_set_md_var(tc, "descr", \
108 "test filesystem remount with quotas, %s", descr); \
111 ATF_TC_BODY(quota_##name, tc) \
113 do_quota(tc, nent, newops, log); \
116 DECL_TEST(10, "-O1 -B le", 10_O1_le
, "UFS1 little-endian", 0)
117 DECL_TEST(10, "-O1 -B be", 10_O1_be
, "UFS1 big-endian", 0)
121 * this cause fsck to complain about summaries at the end.
122 * This sems to be related to -o log (reproductible on a fs with no
123 * quota enabled). not reproductible with a real kernel ...
125 DECL_TEST(10, "-O1", 10_O1_log
, "UFS1 log", 1)
126 DECL_TEST(10, "-O2", 10_O2_log
, "UFS2 log", 1)
132 ATF_TP_ADD_TC(tp
, quota_10_O1_le
);
133 ATF_TP_ADD_TC(tp
, quota_10_O1_be
);
135 ATF_TP_ADD_TC(tp
, quota_10_O1_log
);
136 ATF_TP_ADD_TC(tp
, quota_10_O2_log
);
138 return atf_no_error();