aboutsummaryrefslogtreecommitdiff
path: root/contrib/netbsd-tests/fs/ffs
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/netbsd-tests/fs/ffs')
-rwxr-xr-xcontrib/netbsd-tests/fs/ffs/ffs_common.sh99
-rw-r--r--contrib/netbsd-tests/fs/ffs/h_ffs_server.c113
-rw-r--r--contrib/netbsd-tests/fs/ffs/h_quota2_tests.c468
-rwxr-xr-xcontrib/netbsd-tests/fs/ffs/quotas_common.sh12
-rwxr-xr-xcontrib/netbsd-tests/fs/ffs/t_clearquota.sh91
-rw-r--r--contrib/netbsd-tests/fs/ffs/t_fifos.c158
-rwxr-xr-xcontrib/netbsd-tests/fs/ffs/t_getquota.sh112
-rwxr-xr-xcontrib/netbsd-tests/fs/ffs/t_miscquota.sh213
-rw-r--r--contrib/netbsd-tests/fs/ffs/t_mount.c138
-rw-r--r--contrib/netbsd-tests/fs/ffs/t_quota2_1.c114
-rw-r--r--contrib/netbsd-tests/fs/ffs/t_quota2_remount.c139
-rwxr-xr-xcontrib/netbsd-tests/fs/ffs/t_quotalimit.sh345
-rwxr-xr-xcontrib/netbsd-tests/fs/ffs/t_setquota.sh203
-rw-r--r--contrib/netbsd-tests/fs/ffs/t_snapshot.c43
-rw-r--r--contrib/netbsd-tests/fs/ffs/t_snapshot_log.c46
-rw-r--r--contrib/netbsd-tests/fs/ffs/t_snapshot_v2.c43
16 files changed, 2337 insertions, 0 deletions
diff --git a/contrib/netbsd-tests/fs/ffs/ffs_common.sh b/contrib/netbsd-tests/fs/ffs/ffs_common.sh
new file mode 100755
index 000000000000..eaf7142808a1
--- /dev/null
+++ b/contrib/netbsd-tests/fs/ffs/ffs_common.sh
@@ -0,0 +1,99 @@
+# $NetBSD: ffs_common.sh,v 1.2 2013/07/29 13:15:24 skrll Exp $
+
+create_ffs()
+{
+ local endian=$1; shift
+ local vers=$1; shift
+ local type=$1; shift
+ local op;
+ if [ ${type} = "both" ]; then
+ op="-q user -q group"
+ else
+ op="-q ${type}"
+ fi
+ atf_check -o ignore -e ignore newfs ${op} \
+ -B ${endian} -O ${vers} -s 4000 -F ${IMG}
+}
+
+create_ffs_server()
+{
+ local sarg=$1; shift
+ create_ffs $*
+ atf_check -o ignore -e ignore $(atf_get_srcdir)/h_ffs_server \
+ ${sarg} ${IMG} ${RUMP_SERVER}
+}
+
+rump_shutdown()
+{
+ for s in ${RUMP_SOCKETS_LIST}; do
+ atf_check -s exit:0 env RUMP_SERVER=unix://${s} rump.halt;
+ done
+# check that the quota inode creation didn't corrupt the filesystem
+ atf_check -s exit:0 -o "match:already clean" \
+ -o "match:Phase 6 - Check Quotas" \
+ fsck_ffs -nf -F ${IMG}
+}
+
+# from tests/ipf/h_common.sh via tests/sbin/resize_ffs
+test_case()
+{
+ local name="${1}"; shift
+ local check_function="${1}"; shift
+ local descr="${1}"; shift
+
+ atf_test_case "${name}" cleanup
+
+ eval "${name}_head() { \
+ atf_set "descr" "${descr}"
+ atf_set "timeout" "60"
+ }"
+ eval "${name}_body() { \
+ RUMP_SOCKETS_LIST=\${RUMP_SOCKET}; \
+ export RUMP_SERVER=unix://\${RUMP_SOCKET}; \
+ ${check_function} " "${@}" "; \
+ }"
+ eval "${name}_cleanup() { \
+ for s in \${RUMP_SOCKETS_LIST}; do \
+ export RUMP_SERVER=unix://\${s}; \
+ atf_check -s exit:1 -o ignore -e ignore rump.halt; \
+ done; \
+ }"
+ tests="${tests} ${name}"
+}
+
+test_case_root()
+{
+ local name="${1}"; shift
+ local check_function="${1}"; shift
+ local descr="${1}"; shift
+
+ atf_test_case "${name}" cleanup
+
+ eval "${name}_head() { \
+ atf_set "descr" "${descr}"
+ atf_set "require.user" "root"
+ atf_set "timeout" "360"
+ }"
+ eval "${name}_body() { \
+ RUMP_SOCKETS_LIST=\${RUMP_SOCKET}; \
+ export RUMP_SERVER=unix://\${RUMP_SOCKET}; \
+ ${check_function} " "${@}" "; \
+ }"
+ eval "${name}_cleanup() { \
+ for s in \${RUMP_SOCKETS_LIST}; do \
+ export RUMP_SERVER=unix://\${s}; \
+ atf_check -s exit:1 -o ignore -e ignore rump.halt; \
+ done; \
+ }"
+ tests="${tests} ${name}"
+}
+
+atf_init_test_cases()
+{
+ IMG=fsimage
+ DIR=target
+ RUMP_SOCKET=test;
+ for i in ${tests}; do
+ atf_add_test_case $i
+ done
+}
diff --git a/contrib/netbsd-tests/fs/ffs/h_ffs_server.c b/contrib/netbsd-tests/fs/ffs/h_ffs_server.c
new file mode 100644
index 000000000000..dd22d9faf1d8
--- /dev/null
+++ b/contrib/netbsd-tests/fs/ffs/h_ffs_server.c
@@ -0,0 +1,113 @@
+/* $NetBSD: h_ffs_server.c,v 1.2 2012/08/24 20:25:50 jmmv Exp $ */
+
+/*
+ * rump server for advanced quota tests
+ */
+
+#include "../common/h_fsmacros.h"
+
+#include <err.h>
+#include <semaphore.h>
+#include <sys/types.h>
+#include <sys/mount.h>
+
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <ufs/ufs/ufsmount.h>
+
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+
+int background = 0;
+
+static void
+usage(void)
+{
+ fprintf(stderr, "usage: %s [-b] [-l] diskimage bindurl\n",
+ getprogname());
+ exit(1);
+}
+
+static void
+die(const char *reason, int error)
+{
+
+ warnx("%s: %s", reason, strerror(error));
+ if (background)
+ rump_daemonize_done(error);
+ exit(1);
+}
+
+static sem_t sigsem;
+static void
+sigreboot(int sig)
+{
+
+ sem_post(&sigsem);
+}
+
+int
+main(int argc, char **argv)
+{
+ int error;
+ struct ufs_args uargs;
+ const char *filename;
+ const char *serverurl;
+ int log = 0;
+ int ch;
+
+ while ((ch = getopt(argc, argv, "bl")) != -1) {
+ switch(ch) {
+ case 'b':
+ background = 1;
+ break;
+ case 'l':
+ log = 1;
+ break;
+ default:
+ usage();
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc != 2)
+ usage();
+
+ filename = argv[0];
+ serverurl = argv[1];
+
+ if (background) {
+ error = rump_daemonize_begin();
+ if (error)
+ errx(1, "rump daemonize: %s", strerror(error));
+ }
+
+ error = rump_init();
+ if (error)
+ die("rump init failed", error);
+
+ if (rump_sys_mkdir(FSTEST_MNTNAME, 0777) == -1)
+ die("mount point create", errno);
+ rump_pub_etfs_register("/diskdev", filename, RUMP_ETFS_BLK);
+ uargs.fspec = __UNCONST("/diskdev");
+ if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME, (log) ? MNT_LOG : 0,
+ &uargs, sizeof(uargs)) == -1)
+ die("mount ffs", errno);
+
+ error = rump_init_server(serverurl);
+ if (error)
+ die("rump server init failed", error);
+ if (background)
+ rump_daemonize_done(RUMP_DAEMONIZE_SUCCESS);
+
+ sem_init(&sigsem, 0, 0);
+ signal(SIGTERM, sigreboot);
+ signal(SIGINT, sigreboot);
+ sem_wait(&sigsem);
+
+ rump_sys_reboot(0, NULL);
+ /*NOTREACHED*/
+ return 0;
+}
diff --git a/contrib/netbsd-tests/fs/ffs/h_quota2_tests.c b/contrib/netbsd-tests/fs/ffs/h_quota2_tests.c
new file mode 100644
index 000000000000..59f3ea3b0917
--- /dev/null
+++ b/contrib/netbsd-tests/fs/ffs/h_quota2_tests.c
@@ -0,0 +1,468 @@
+/* $NetBSD: h_quota2_tests.c,v 1.4 2012/09/30 21:26:57 bouyer Exp $ */
+
+/*
+ * rump server for advanced quota tests
+ * this one includes functions to run against the filesystem before
+ * starting to handle rump requests from clients.
+ */
+
+#include "../common/h_fsmacros.h"
+
+#include <err.h>
+#include <semaphore.h>
+#include <sys/types.h>
+#include <sys/mount.h>
+
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <ufs/ufs/ufsmount.h>
+#include <dev/fssvar.h>
+
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+
+#include "../../h_macros.h"
+
+int background = 0;
+
+#define TEST_NONROOT_ID 1
+
+static int
+quota_test0(const char *testopts)
+{
+ static char buf[512];
+ int fd;
+ int error;
+ unsigned int i;
+ int chowner = 1;
+ for (i =0; testopts && i < strlen(testopts); i++) {
+ switch(testopts[i]) {
+ case 'C':
+ chowner = 0;
+ break;
+ default:
+ errx(1, "test4: unknown option %c", testopts[i]);
+ }
+ }
+ if (chowner)
+ rump_sys_chown(".", TEST_NONROOT_ID, TEST_NONROOT_ID);
+ rump_sys_chmod(".", 0777);
+ if (rump_sys_setegid(TEST_NONROOT_ID) != 0) {
+ error = errno;
+ warn("rump_sys_setegid");
+ return error;
+ }
+ if (rump_sys_seteuid(TEST_NONROOT_ID) != 0) {
+ error = errno;
+ warn("rump_sys_seteuid");
+ return error;
+ }
+ fd = rump_sys_open("test_fillup", O_CREAT | O_RDWR, 0644);
+ if (fd < 0) {
+ error = errno;
+ warn("rump_sys_open");
+ } else {
+ while (rump_sys_write(fd, buf, sizeof(buf)) == sizeof(buf))
+ error = 0;
+ error = errno;
+ }
+ rump_sys_close(fd);
+ rump_sys_seteuid(0);
+ rump_sys_setegid(0);
+ return error;
+}
+
+static int
+quota_test1(const char *testopts)
+{
+ static char buf[512];
+ int fd;
+ int error;
+ rump_sys_chown(".", TEST_NONROOT_ID, TEST_NONROOT_ID);
+ rump_sys_chmod(".", 0777);
+ if (rump_sys_setegid(TEST_NONROOT_ID) != 0) {
+ error = errno;
+ warn("rump_sys_setegid");
+ return error;
+ }
+ if (rump_sys_seteuid(TEST_NONROOT_ID) != 0) {
+ error = errno;
+ warn("rump_sys_seteuid");
+ return error;
+ }
+ fd = rump_sys_open("test_fillup", O_CREAT | O_RDWR, 0644);
+ if (fd < 0) {
+ error = errno;
+ warn("rump_sys_open");
+ } else {
+ /*
+ * write up to the soft limit, wait a bit, an try to
+ * keep on writing
+ */
+ int i;
+
+ /* write 2k: with the directory this makes 2.5K */
+ for (i = 0; i < 4; i++) {
+ error = rump_sys_write(fd, buf, sizeof(buf));
+ if (error != sizeof(buf))
+ err(1, "write failed early");
+ }
+ sleep(2);
+ /* now try to write an extra .5k */
+ if (rump_sys_write(fd, buf, sizeof(buf)) != sizeof(buf))
+ error = errno;
+ else
+ error = 0;
+ }
+ rump_sys_close(fd);
+ rump_sys_seteuid(0);
+ rump_sys_setegid(0);
+ return error;
+}
+
+static int
+quota_test2(const char *testopts)
+{
+ static char buf[512];
+ int fd;
+ int error;
+ int i;
+ rump_sys_chown(".", TEST_NONROOT_ID, TEST_NONROOT_ID);
+ rump_sys_chmod(".", 0777);
+ if (rump_sys_setegid(TEST_NONROOT_ID) != 0) {
+ error = errno;
+ warn("rump_sys_setegid");
+ return error;
+ }
+ if (rump_sys_seteuid(TEST_NONROOT_ID) != 0) {
+ error = errno;
+ warn("rump_sys_seteuid");
+ return error;
+ }
+
+ for (i = 0; ; i++) {
+ sprintf(buf, "file%d", i);
+ fd = rump_sys_open(buf, O_CREAT | O_RDWR, 0644);
+ if (fd < 0)
+ break;
+ sprintf(buf, "test file no %d", i);
+ rump_sys_write(fd, buf, strlen(buf));
+ rump_sys_close(fd);
+ }
+ error = errno;
+
+ rump_sys_close(fd);
+ rump_sys_seteuid(0);
+ rump_sys_setegid(0);
+ return error;
+}
+
+static int
+quota_test3(const char *testopts)
+{
+ static char buf[512];
+ int fd;
+ int error;
+ int i;
+ rump_sys_chown(".", TEST_NONROOT_ID, TEST_NONROOT_ID);
+ rump_sys_chmod(".", 0777);
+ if (rump_sys_setegid(TEST_NONROOT_ID) != 0) {
+ error = errno;
+ warn("rump_sys_setegid");
+ return error;
+ }
+ if (rump_sys_seteuid(TEST_NONROOT_ID) != 0) {
+ error = errno;
+ warn("rump_sys_seteuid");
+ return error;
+ }
+
+ /*
+ * create files one past the soft limit: one less as we already own the
+ * root directory
+ */
+ for (i = 0; i < 4; i++) {
+ sprintf(buf, "file%d", i);
+ fd = rump_sys_open(buf, O_EXCL| O_CREAT | O_RDWR, 0644);
+ if (fd < 0)
+ err(1, "file create failed early");
+ sprintf(buf, "test file no %d", i);
+ rump_sys_write(fd, buf, strlen(buf));
+ rump_sys_close(fd);
+ }
+ /* now create an extra file after grace time: this should fail */
+ sleep(2);
+ sprintf(buf, "file%d", i);
+ fd = rump_sys_open(buf, O_EXCL| O_CREAT | O_RDWR, 0644);
+ if (fd < 0)
+ error = errno;
+ else
+ error = 0;
+
+ rump_sys_close(fd);
+ rump_sys_seteuid(0);
+ rump_sys_setegid(0);
+ return error;
+}
+
+static int
+quota_test4(const char *testopts)
+{
+ static char buf[512];
+ int fd, fssfd;
+ struct fss_set fss;
+ unsigned int i;
+ int unl=0;
+ int unconf=0;
+
+ /*
+ * take an internal snapshot of the filesystem, and create a new
+ * file with some data
+ */
+ rump_sys_chown(".", 0, 0);
+ rump_sys_chmod(".", 0777);
+
+ for (i =0; testopts && i < strlen(testopts); i++) {
+ switch(testopts[i]) {
+ case 'L':
+ unl++;
+ break;
+ case 'C':
+ unconf++;
+ break;
+ default:
+ errx(1, "test4: unknown option %c", testopts[i]);
+ }
+ }
+
+ /* first create the snapshot */
+
+ fd = rump_sys_open(FSTEST_MNTNAME "/le_snap", O_CREAT | O_RDWR, 0777);
+ if (fd == -1)
+ err(1, "create " FSTEST_MNTNAME "/le_snap");
+ rump_sys_close(fd);
+ fssfd = rump_sys_open("/dev/rfss0", O_RDWR);
+ if (fssfd == -1)
+ err(1, "cannot open fss");
+ memset(&fss, 0, sizeof(fss));
+ fss.fss_mount = __UNCONST("/mnt");
+ fss.fss_bstore = __UNCONST(FSTEST_MNTNAME "/le_snap");
+ fss.fss_csize = 0;
+ if (rump_sys_ioctl(fssfd, FSSIOCSET, &fss) == -1)
+ err(1, "create snapshot");
+ if (unl) {
+ if (rump_sys_unlink(FSTEST_MNTNAME "/le_snap") == -1)
+ err(1, "unlink snapshot");
+ }
+
+ /* now create some extra files */
+
+ for (i = 0; i < 4; i++) {
+ sprintf(buf, "file%d", i);
+ fd = rump_sys_open(buf, O_EXCL| O_CREAT | O_RDWR, 0644);
+ if (fd < 0)
+ err(1, "create %s", buf);
+ sprintf(buf, "test file no %d", i);
+ rump_sys_write(fd, buf, strlen(buf));
+ rump_sys_close(fd);
+ }
+ if (unconf)
+ if (rump_sys_ioctl(fssfd, FSSIOCCLR, NULL) == -1)
+ err(1, "unconfigure snapshot");
+ return 0;
+}
+
+static int
+quota_test5(const char *testopts)
+{
+ static char buf[512];
+ int fd;
+ int remount = 0;
+ int unlnk = 0;
+ int log = 0;
+ unsigned int i;
+
+ for (i =0; testopts && i < strlen(testopts); i++) {
+ switch(testopts[i]) {
+ case 'L':
+ log++;
+ break;
+ case 'R':
+ remount++;
+ break;
+ case 'U':
+ unlnk++;
+ break;
+ default:
+ errx(1, "test4: unknown option %c", testopts[i]);
+ }
+ }
+ if (remount) {
+ struct ufs_args uargs;
+ uargs.fspec = __UNCONST("/diskdev");
+ /* remount the fs read/write */
+ if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME,
+ MNT_UPDATE | (log ? MNT_LOG : 0),
+ &uargs, sizeof(uargs)) == -1)
+ err(1, "mount ffs rw %s", FSTEST_MNTNAME);
+ }
+
+ if (unlnk) {
+ /*
+ * open and unlink a file
+ */
+
+ fd = rump_sys_open("unlinked_file",
+ O_EXCL| O_CREAT | O_RDWR, 0644);
+ if (fd < 0)
+ err(1, "create %s", "unlinked_file");
+ sprintf(buf, "test unlinked_file");
+ rump_sys_write(fd, buf, strlen(buf));
+ if (rump_sys_unlink("unlinked_file") == -1)
+ err(1, "unlink unlinked_file");
+ if (rump_sys_fsync(fd) == -1)
+ err(1, "fsync unlinked_file");
+ rump_sys_reboot(RUMP_RB_NOSYNC, NULL);
+ errx(1, "reboot failed");
+ return 1;
+ }
+ return 0;
+}
+
+struct quota_test {
+ int (*func)(const char *);
+ const char *desc;
+};
+
+struct quota_test quota_tests[] = {
+ { quota_test0, "write up to hard limit"},
+ { quota_test1, "write beyond the soft limit after grace time"},
+ { quota_test2, "create file up to hard limit"},
+ { quota_test3, "create file beyond the soft limit after grace time"},
+ { quota_test4, "take a snapshot and add some data"},
+ { quota_test5, "open and unlink a file"},
+};
+
+static void
+usage(void)
+{
+ unsigned int test;
+ fprintf(stderr, "usage: %s [-b] [-l] test# diskimage bindurl\n",
+ getprogname());
+ fprintf(stderr, "available tests:\n");
+ for (test = 0; test < sizeof(quota_tests) / sizeof(quota_tests[0]);
+ test++)
+ fprintf(stderr, "\t%d: %s\n", test, quota_tests[test].desc);
+ exit(1);
+}
+
+static void
+die(const char *reason, int error)
+{
+
+ warnx("%s: %s", reason, strerror(error));
+ if (background)
+ rump_daemonize_done(error);
+ exit(1);
+}
+
+static sem_t sigsem;
+static void
+sigreboot(int sig)
+{
+
+ sem_post(&sigsem);
+}
+
+int
+main(int argc, char **argv)
+{
+ int error;
+ u_long test;
+ char *end;
+ struct ufs_args uargs;
+ const char *filename;
+ const char *serverurl;
+ const char *topts = NULL;
+ int mntopts = 0;
+ int ch;
+
+ while ((ch = getopt(argc, argv, "blo:r")) != -1) {
+ switch(ch) {
+ case 'b':
+ background = 1;
+ break;
+ case 'l':
+ mntopts |= MNT_LOG;
+ break;
+ case 'r':
+ mntopts |= MNT_RDONLY;
+ break;
+ case 'o':
+ topts = optarg;
+ break;
+ default:
+ usage();
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc != 3)
+ usage();
+
+ filename = argv[1];
+ serverurl = argv[2];
+
+ test = strtoul(argv[0], &end, 10);
+ if (*end != '\0') {
+ usage();
+ }
+ if (test > sizeof(quota_tests) / sizeof(quota_tests[0])) {
+ usage();
+ }
+
+ if (background) {
+ error = rump_daemonize_begin();
+ if (error)
+ errx(1, "rump daemonize: %s", strerror(error));
+ }
+
+ error = rump_init();
+ if (error)
+ die("rump init failed", error);
+
+ if (rump_sys_mkdir(FSTEST_MNTNAME, 0777) == -1)
+ err(1, "mount point create");
+ rump_pub_etfs_register("/diskdev", filename, RUMP_ETFS_BLK);
+ uargs.fspec = __UNCONST("/diskdev");
+ if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME, mntopts,
+ &uargs, sizeof(uargs)) == -1)
+ die("mount ffs", errno);
+
+ if (rump_sys_chdir(FSTEST_MNTNAME) == -1)
+ err(1, "cd %s", FSTEST_MNTNAME);
+ error = quota_tests[test].func(topts);
+ if (error) {
+ fprintf(stderr, " test %lu: %s returned %d: %s\n",
+ test, quota_tests[test].desc, error, strerror(error));
+ }
+ if (rump_sys_chdir("/") == -1)
+ err(1, "cd /");
+
+ error = rump_init_server(serverurl);
+ if (error)
+ die("rump server init failed", error);
+ if (background)
+ rump_daemonize_done(RUMP_DAEMONIZE_SUCCESS);
+
+ sem_init(&sigsem, 0, 0);
+ signal(SIGTERM, sigreboot);
+ signal(SIGINT, sigreboot);
+ sem_wait(&sigsem);
+
+ rump_sys_reboot(0, NULL);
+ /*NOTREACHED*/
+ return 0;
+}
diff --git a/contrib/netbsd-tests/fs/ffs/quotas_common.sh b/contrib/netbsd-tests/fs/ffs/quotas_common.sh
new file mode 100755
index 000000000000..0ad002f54ad5
--- /dev/null
+++ b/contrib/netbsd-tests/fs/ffs/quotas_common.sh
@@ -0,0 +1,12 @@
+# $NetBSD: quotas_common.sh,v 1.4 2012/01/18 20:51:23 bouyer Exp $
+
+rump_quota_shutdown()
+{
+ for s in ${RUMP_SOCKETS_LIST}; do
+ atf_check -s exit:0 env RUMP_SERVER=unix://${s} rump.halt;
+ done
+# check that the quota inode creation didn't corrupt the filesystem
+ atf_check -s exit:0 -o "match:already clean" \
+ -o "match:Phase 6 - Check Quotas" \
+ fsck_ffs -nf -F ${IMG}
+}
diff --git a/contrib/netbsd-tests/fs/ffs/t_clearquota.sh b/contrib/netbsd-tests/fs/ffs/t_clearquota.sh
new file mode 100755
index 000000000000..f62a494730cd
--- /dev/null
+++ b/contrib/netbsd-tests/fs/ffs/t_clearquota.sh
@@ -0,0 +1,91 @@
+# $NetBSD: t_clearquota.sh,v 1.4 2012/01/18 20:51:23 bouyer Exp $
+#
+# Copyright (c) 2011 Manuel Bouyer
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+for e in le be; do
+ for v in 1 2; do
+ for q in "user" "group"; do
+ test_case_root clear_${e}_${v}_${q} clear_quota \
+ "clear quota with ${q} enabled" -b ${e} ${v} ${q}
+ done
+ test_case_root clear_${e}_${v}_"both" clear_quota \
+ "clear quota with both enabled" -b ${e} ${v} "both"
+ test_case_root clear_${e}_${v}_"both_log" clear_quota \
+ "clear quota for new id with both enabled, WAPBL" -bl ${e} ${v} "both"
+ done
+done
+
+clear_quota()
+{
+ create_ffs_server $*
+ local q=$4
+ local expect
+ local fail
+ local id=1
+
+ case ${q} in
+ user)
+ expect=u
+ fail=g
+ ;;
+ group)
+ expect=g
+ fail=u
+ ;;
+ both)
+ expect="u g"
+ fail=""
+ ;;
+ *)
+ atf_fail "wrong quota type"
+ ;;
+ esac
+
+#set and check the expected quota
+ for q in ${expect} ; do
+ atf_check -s exit:0 \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -$q -s10k/20 -h40M/50k \
+ -t 2W/3D ${id}
+ atf_check -s exit:0 \
+-o "match:/mnt 0 10 40960 2weeks 0 20 51200 3days" \
+-o "match:Disk quotas for .*: $" \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -${q} -v ${id}
+ done
+#now clear the quotas
+ for q in ${expect} ; do
+ atf_check -s exit:0 \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -$q -c ${id}
+ done;
+
+#check that we do not get positive reply for any quota type
+ for q in u g ; do
+ atf_check -s exit:0 -o "not-match:/mnt" \
+ -o "not-match:Disk quotas for .*: $" \
+ -o "match:Disk quotas for .*: none$" \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -${q} -v ${id}
+ done
+ rump_quota_shutdown
+}
diff --git a/contrib/netbsd-tests/fs/ffs/t_fifos.c b/contrib/netbsd-tests/fs/ffs/t_fifos.c
new file mode 100644
index 000000000000..fe1d4254a352
--- /dev/null
+++ b/contrib/netbsd-tests/fs/ffs/t_fifos.c
@@ -0,0 +1,158 @@
+/* $NetBSD: t_fifos.c,v 1.5 2010/11/07 17:51:17 jmmv Exp $ */
+
+#include <sys/types.h>
+#include <sys/mount.h>
+
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+
+#include <ufs/ufs/ufsmount.h>
+
+#include "../../h_macros.h"
+
+ATF_TC_WITH_CLEANUP(fifos);
+ATF_TC_HEAD(fifos, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "test fifo support in ffs");
+ atf_tc_set_md_var(tc, "timeout", "5");
+}
+
+#define teststr1 "raving & drooling"
+#define teststr2 "haha, charade"
+
+static void *
+w1(void *arg)
+{
+ int fd;
+
+ fd = rump_sys_open("sheep", O_WRONLY);
+ if (fd == -1)
+ atf_tc_fail_errno("w1 open");
+ if (rump_sys_write(fd, teststr1, sizeof(teststr1)) != sizeof(teststr1))
+ atf_tc_fail_errno("w1 write");
+ rump_sys_close(fd);
+
+ return NULL;
+}
+
+static void *
+w2(void *arg)
+{
+ int fd;
+
+ fd = rump_sys_open("pigs", O_WRONLY);
+ if (fd == -1)
+ atf_tc_fail_errno("w2 open");
+ if (rump_sys_write(fd, teststr2, sizeof(teststr2)) != sizeof(teststr2))
+ atf_tc_fail_errno("w2 write");
+ rump_sys_close(fd);
+
+ return NULL;
+}
+
+static void *
+r1(void *arg)
+{
+ char buf[32];
+ int fd;
+
+ fd = rump_sys_open("sheep", O_RDONLY);
+ if (fd == -1)
+ atf_tc_fail_errno("r1 open");
+ if (rump_sys_read(fd, buf, sizeof(buf)) != sizeof(teststr1))
+ atf_tc_fail_errno("r1 read");
+ rump_sys_close(fd);
+
+ if (strcmp(teststr1, buf) != 0)
+ atf_tc_fail("got invalid str, %s vs. %s", buf, teststr1);
+
+ return NULL;
+}
+
+static void *
+r2(void *arg)
+{
+ char buf[32];
+ int fd;
+
+ fd = rump_sys_open("pigs", O_RDONLY);
+ if (fd == -1)
+ atf_tc_fail_errno("r2 open");
+ if (rump_sys_read(fd, buf, sizeof(buf)) != sizeof(teststr2))
+ atf_tc_fail_errno("r2 read");
+ rump_sys_close(fd);
+
+ if (strcmp(teststr2, buf) != 0)
+ atf_tc_fail("got invalid str, %s vs. %s", buf, teststr2);
+
+ return NULL;
+}
+
+#define IMGNAME "atf.img"
+
+const char *newfs = "newfs -F -s 10000 " IMGNAME;
+#define FAKEBLK "/dev/sp00ka"
+
+ATF_TC_BODY(fifos, tc)
+{
+ struct ufs_args args;
+ pthread_t ptw1, ptw2, ptr1, ptr2;
+
+ if (system(newfs) == -1)
+ atf_tc_fail_errno("newfs failed");
+
+ memset(&args, 0, sizeof(args));
+ args.fspec = __UNCONST(FAKEBLK);
+
+ rump_init();
+ if (rump_sys_mkdir("/animals", 0777) == -1)
+ atf_tc_fail_errno("cannot create mountpoint");
+ rump_pub_etfs_register(FAKEBLK, IMGNAME, RUMP_ETFS_BLK);
+ if (rump_sys_mount(MOUNT_FFS, "/animals", 0, &args, sizeof(args))==-1)
+ atf_tc_fail_errno("rump_sys_mount failed");
+
+ /* create fifos */
+ if (rump_sys_chdir("/animals") == 1)
+ atf_tc_fail_errno("chdir");
+ if (rump_sys_mkfifo("pigs", S_IFIFO | 0777) == -1)
+ atf_tc_fail_errno("mknod1");
+ if (rump_sys_mkfifo("sheep", S_IFIFO | 0777) == -1)
+ atf_tc_fail_errno("mknod2");
+
+ pthread_create(&ptw1, NULL, w1, NULL);
+ pthread_create(&ptw2, NULL, w2, NULL);
+ pthread_create(&ptr1, NULL, r1, NULL);
+ pthread_create(&ptr2, NULL, r2, NULL);
+
+ pthread_join(ptw1, NULL);
+ pthread_join(ptw2, NULL);
+ pthread_join(ptr1, NULL);
+ pthread_join(ptr2, NULL);
+
+ if (rump_sys_chdir("/") == 1)
+ atf_tc_fail_errno("chdir");
+
+ if (rump_sys_unmount("/animals", 0) == -1)
+ atf_tc_fail_errno("unmount failed");
+}
+
+ATF_TC_CLEANUP(fifos, tc)
+{
+
+ unlink(IMGNAME);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, fifos);
+ return 0;
+}
diff --git a/contrib/netbsd-tests/fs/ffs/t_getquota.sh b/contrib/netbsd-tests/fs/ffs/t_getquota.sh
new file mode 100755
index 000000000000..80f3cc7a6e76
--- /dev/null
+++ b/contrib/netbsd-tests/fs/ffs/t_getquota.sh
@@ -0,0 +1,112 @@
+# $NetBSD: t_getquota.sh,v 1.4 2012/01/18 20:51:23 bouyer Exp $
+#
+# Copyright (c) 2011 Manuel Bouyer
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+for e in le be; do
+ for v in 1 2; do
+ for q in "user" "group"; do
+ test_case get_${e}_${v}_${q} get_quota \
+ "get quota with ${q} enabled" -b ${e} ${v} ${q}
+ done
+ test_case get_${e}_${v}_"both" get_quota \
+ "get quota with both enabled" -b ${e} ${v} "both"
+ done
+done
+
+get_quota()
+{
+ create_ffs_server $*
+ local q=$4
+ local expect
+ local fail
+
+ case ${q} in
+ user)
+ expect=u
+ fail=g
+ ;;
+ group)
+ expect=g
+ fail=u
+ ;;
+ both)
+ expect="u g"
+ fail=""
+ ;;
+ *)
+ atf_fail "wrong quota type"
+ ;;
+ esac
+
+#check that we can get the expected quota
+ for q in ${expect} ; do
+ atf_check -s exit:0 \
+-o "match:/mnt 0 - - 7days 1 - - 7days" \
+-o "match:Disk quotas for .*: $" \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -${q} -v
+ atf_check -s exit:0 \
+-o "match:-- 0 - - 1 - -" \
+-o "not-match:\+\+" \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -${q} /mnt
+ done
+
+#check that we do not get positive reply for non-expected quota
+ for q in ${fail} ; do
+ atf_check -s exit:0 -o "not-match:/mnt" \
+ -o "not-match:Disk quotas for .*: $" \
+ -o "match:Disk quotas for .*: none$" \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -${q} -v
+ atf_check -s exit:0 \
+-o "not-match:-- 0 - - 1 - -" \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -${q} /mnt
+ done
+ rump_quota_shutdown
+}
+
+quota_walk_list()
+{
+ create_ffs_server $*
+ local q=$4
+ local expect
+
+ case ${q} in
+ user)
+ expect=u
+ fail=g
+ ;;
+ group)
+ expect=g
+ fail=u
+ ;;
+ both)
+ expect="u g"
+ fail=""
+ ;;
+ *)
+ atf_fail "wrong quota type"
+ ;;
+ esac
+}
diff --git a/contrib/netbsd-tests/fs/ffs/t_miscquota.sh b/contrib/netbsd-tests/fs/ffs/t_miscquota.sh
new file mode 100755
index 000000000000..904ea37f8f6c
--- /dev/null
+++ b/contrib/netbsd-tests/fs/ffs/t_miscquota.sh
@@ -0,0 +1,213 @@
+# $NetBSD: t_miscquota.sh,v 1.8 2013/01/22 06:24:11 dholland Exp $
+#
+# Copyright (c) 2011 Manuel Bouyer
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+test_case_root walk_list_user quota_walk_list \
+ "walk user quota list over several disk blocks" -b le 1 user
+
+test_case_root psnapshot_user quota_snap \
+ "create a persistent shapshot of quota-enabled fs, and do some writes" \
+ -b le 1 user
+
+test_case_root npsnapshot_user quota_snap \
+ "create a non-persistent shapshot of quota-enabled fs, and do some writes" \
+ -boL le 1 user
+
+test_case_root psnapshot_unconf_user quota_snap \
+ "create a persistent shapshot of quota-enabled fs, and do some writes and unconf" \
+ -boC le 1 user
+
+test_case_root npsnapshot_unconf_user quota_snap \
+ "create a non-persistent shapshot of quota-enabled fs, and do some writes and unconf" \
+ -boLC le 1 user
+
+test_case log_unlink quota_log \
+ "an unlinked file cleaned by the log replay should update quota" \
+ -l le 1 user
+
+test_case log_unlink_remount quota_log \
+ "an unlinked file cleaned by the log replay after remount" \
+ -oRL le 1 user
+
+
+test_case_root default_deny_user quota_default_deny \
+ "new quota entry denied by default entry" 5 -b le 1 user
+
+test_case_root default_deny_user_big quota_default_deny \
+ "new quota entry denied by default entry, with list on more than one block" 5000 -b le 1 user
+
+
+quota_walk_list()
+{
+ create_ffs_server $*
+ local q=$4
+ local expect
+
+ case ${q} in
+ user)
+ expect=u
+ fail=g
+ ;;
+ group)
+ expect=g
+ fail=u
+ ;;
+ *)
+ atf_fail "wrong quota type"
+ ;;
+ esac
+
+ # create 100 users, all in the same hash list
+ local i=1;
+ while [ $i -lt 101 ]; do
+ atf_check -s exit:0 \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -${expect} \
+ -s10k/20 -h40M/50k -t 2W/3D $((i * 4096))
+ i=$((i + 1))
+ done
+ # do a repquota
+ atf_check -s exit:0 -o 'match:user 409600 block *81920 20 0' \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -x -${expect} /mnt
+ rump_quota_shutdown
+}
+
+quota_snap()
+{
+ local flag=$1; shift
+ create_ffs $*
+ local q=$3
+ local expect
+
+ case ${q} in
+ user)
+ expect=u
+ fail=g
+ ;;
+ group)
+ expect=g
+ fail=u
+ ;;
+ *)
+ atf_fail "wrong quota type"
+ ;;
+ esac
+
+ #start our server which takes a snapshot
+ atf_check -s exit:0 -o ignore \
+ $(atf_get_srcdir)/h_quota2_tests ${flag} 4 ${IMG} ${RUMP_SERVER}
+ # create a few users
+ local i=1;
+ while [ $i -lt 11 ]; do
+ atf_check -s exit:0 \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -${expect} \
+ -s10k/20 -h40M/50k -t 2W/3D $i
+ i=$((i + 1))
+ done
+ # we should have 5 files (root + 4 regular files)
+ atf_check -s exit:0 \
+ -o 'match:- - 7days 5 - - 7days' \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -av
+ #shutdown and check filesystem
+ rump_quota_shutdown
+}
+
+quota_log()
+{
+ local srv2args=$1; shift
+ create_ffs $*
+ local q=$3
+ local expect
+
+ case ${q} in
+ user)
+ expect=u
+ fail=g
+ ;;
+ group)
+ expect=g
+ fail=u
+ ;;
+ *)
+ atf_fail "wrong quota type"
+ ;;
+ esac
+
+ #start our server which create a file and unlink while keeping
+ # it open. The server halts itself without flush
+ atf_check -s exit:0 -o ignore \
+ $(atf_get_srcdir)/h_quota2_tests -loU 5 ${IMG} ${RUMP_SERVER}
+ # we should have one unlinked file, but the log covers it.
+ atf_check -s exit:0 -o match:'3 files' -e ignore \
+ fsck_ffs -nf -F ${IMG}
+ # have a kernel mount the fs again; it should cleanup the
+ # unlinked file
+ atf_check -o ignore -e ignore $(atf_get_srcdir)/h_quota2_tests \
+ ${srv2args} -b 5 ${IMG} ${RUMP_SERVER}
+ #shutdown and check filesystem
+ rump_quota_shutdown
+}
+
+quota_default_deny()
+{
+ local nusers=$1; shift
+ create_ffs_server $*
+ local q=$4
+ local expect
+
+ case ${q} in
+ user)
+ expect=u
+ fail=g
+ ;;
+ group)
+ expect=g
+ fail=u
+ ;;
+ *)
+ atf_fail "wrong quota type"
+ ;;
+ esac
+
+ # create $nusers users, so we are sure the free list has entries
+ # from block 1. Start from 10, as non-root id is 1.
+ # set default to deny all
+ ( echo "@format netbsd-quota-dump v1"
+ echo "# idtype id objtype hard soft usage expire grace"
+ echo "$q default block 0 0 0 0 0"
+ echo "$q default file 0 0 0 0 0"
+ local i=10;
+ while [ $i -lt $(($nusers + 10)) ]; do
+ echo "$q $i block 0 0 0 0 0"
+ echo "$q $i file 0 0 0 0 0"
+ i=$((i + 1))
+ done
+ ) | atf_check -s exit:0 \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quotarestore -d /mnt
+ atf_check -s exit:0 rump.halt
+ #now start the server which does the limits tests
+ $(atf_get_srcdir)/h_quota2_tests -oC -b 0 ${IMG} ${RUMP_SERVER}
+ rump_quota_shutdown
+}
diff --git a/contrib/netbsd-tests/fs/ffs/t_mount.c b/contrib/netbsd-tests/fs/ffs/t_mount.c
new file mode 100644
index 000000000000..6a8f74f455f8
--- /dev/null
+++ b/contrib/netbsd-tests/fs/ffs/t_mount.c
@@ -0,0 +1,138 @@
+/* $NetBSD: t_mount.c,v 1.13 2012/11/27 16:01:49 jakllsch Exp $ */
+
+/*
+ * Basic tests for mounting
+ */
+
+/*
+ * 48Kimage:
+ * Adapted for rump and atf from a testcase supplied
+ * by Hubert Feyrer on netbsd-users@
+ */
+
+#include <atf-c.h>
+
+#define FSTEST_IMGSIZE (96 * 512)
+#include "../common/h_fsmacros.h"
+
+#include <sys/types.h>
+#include <sys/mount.h>
+
+#include <stdlib.h>
+
+#include <ufs/ufs/ufsmount.h>
+
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+
+#include "../../h_macros.h"
+
+ATF_TC(48Kimage);
+ATF_TC_HEAD(48Kimage, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "mount small 48K ffs image");
+}
+
+ATF_TC_BODY(48Kimage, tc)
+{
+ void *tmp;
+
+ atf_tc_expect_fail("PR kern/43573");
+ FSTEST_CONSTRUCTOR(tc, ffs, tmp);
+ atf_tc_expect_pass();
+
+ FSTEST_DESTRUCTOR(tc, ffs, tmp);
+}
+
+ATF_TC(fsbsizeovermaxphys);
+ATF_TC_HEAD(fsbsizeovermaxphys, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "mounts file system with "
+ "blocksize > MAXPHYS");
+ /* PR kern/43727 */
+}
+
+ATF_TC_BODY(fsbsizeovermaxphys, tc)
+{
+ char cmd[1024];
+ struct ufs_args args;
+ struct statvfs svb;
+
+ /*
+ * We cannot pass newfs parameters via the fstest interface,
+ * so do things the oldfashioned manual way.
+ */
+ snprintf(cmd, sizeof(cmd), "newfs -G -b %d -F -s 10000 "
+ "ffs.img > /dev/null", MAXPHYS * 2);
+ if (system(cmd))
+ atf_tc_fail("cannot create file system");
+
+ rump_init();
+ if (rump_pub_etfs_register("/devdisk", "ffs.img", RUMP_ETFS_BLK))
+ atf_tc_fail("cannot register rump fake device");
+
+ args.fspec = __UNCONST("/devdisk");
+
+ if (rump_sys_mkdir("/mp", 0777) == -1)
+ atf_tc_fail_errno("create mountpoint");
+
+ /* mount succeeded? bad omen. confirm we're in trouble. */
+ if (rump_sys_mount(MOUNT_FFS, "/mp", 0, &args, sizeof(args)) != -1) {
+ rump_sys_statvfs1("/mp", &svb, ST_WAIT);
+ atf_tc_fail("not expecting to be alive");
+ }
+
+ /* otherwise we're do-ne */
+}
+
+ATF_TC(fsbsizeovermaxbsize);
+ATF_TC_HEAD(fsbsizeovermaxbsize, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "mounts file system with "
+ "blocksize > MAXBSIZE");
+}
+
+ATF_TC_BODY(fsbsizeovermaxbsize, tc)
+{
+ char cmd[1024];
+ struct ufs_args args;
+ struct statvfs svb;
+
+ /*
+ * We cannot pass newfs parameters via the fstest interface,
+ * so do things the oldfashioned manual way.
+ */
+ snprintf(cmd, sizeof(cmd), "newfs -G -b %d -F -s 10000 "
+ "ffs.img > /dev/null", MAXBSIZE * 2);
+ if (system(cmd))
+ atf_tc_fail("cannot create file system");
+
+ rump_init();
+ if (rump_pub_etfs_register("/devdisk", "ffs.img", RUMP_ETFS_BLK))
+ atf_tc_fail("cannot register rump fake device");
+
+ args.fspec = __UNCONST("/devdisk");
+
+ if (rump_sys_mkdir("/mp", 0777) == -1)
+ atf_tc_fail_errno("create mountpoint");
+
+ /* mount succeeded? bad omen. confirm we're in trouble. */
+ if (rump_sys_mount(MOUNT_FFS, "/mp", 0, &args, sizeof(args)) != -1) {
+ rump_sys_statvfs1("/mp", &svb, ST_WAIT);
+ atf_tc_fail("not expecting to be alive");
+ }
+
+ /* otherwise we're do-ne */
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, 48Kimage);
+ ATF_TP_ADD_TC(tp, fsbsizeovermaxphys);
+ ATF_TP_ADD_TC(tp, fsbsizeovermaxbsize);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/fs/ffs/t_quota2_1.c b/contrib/netbsd-tests/fs/ffs/t_quota2_1.c
new file mode 100644
index 000000000000..333f3c712708
--- /dev/null
+++ b/contrib/netbsd-tests/fs/ffs/t_quota2_1.c
@@ -0,0 +1,114 @@
+/* $NetBSD: t_quota2_1.c,v 1.4 2012/03/15 02:02:22 joerg Exp $ */
+
+/*
+ * Basic tests for quota2
+ */
+
+#include <atf-c.h>
+
+#include "../common/h_fsmacros.h"
+
+#include <sys/types.h>
+#include <sys/mount.h>
+
+#include <stdlib.h>
+
+#include <ufs/ufs/ufsmount.h>
+
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+
+#include "../../h_macros.h"
+
+static void
+do_quota(const atf_tc_t *tc, int n, const char *newfs_opts, int log)
+{
+ int i;
+ char buf[1024];
+ int res;
+ int fd;
+ struct ufs_args uargs;
+
+ snprintf(buf, sizeof(buf), "newfs -q user -q group -F -s 4000 -n %d "
+ "%s %s", (n + 3), newfs_opts, FSTEST_IMGNAME);
+ if (system(buf) == -1)
+ atf_tc_fail_errno("cannot create file system");
+
+ rump_init();
+ if (rump_sys_mkdir(FSTEST_MNTNAME, 0777) == -1)
+ atf_tc_fail_errno("mount point create");
+
+ rump_pub_etfs_register("/diskdev", FSTEST_IMGNAME, RUMP_ETFS_BLK);
+
+ uargs.fspec = __UNCONST("/diskdev");
+ if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME, (log) ? MNT_LOG : 0,
+ &uargs, sizeof(uargs)) == -1)
+ atf_tc_fail_errno("mount ffs %s", FSTEST_MNTNAME);
+
+ atf_tc_expect_pass();
+ FSTEST_ENTER();
+ RL(rump_sys_chown(".", 0, 0));
+ for (i = 0 ; i < n; i++) {
+ sprintf(buf, "file%d", i);
+ RL(fd = rump_sys_open(buf, O_CREAT | O_RDWR, 0755));
+ sprintf(buf, "test file no %d", i);
+ RL(rump_sys_write(fd, buf, strlen(buf)));
+ RL(rump_sys_fchown(fd, i, i+80000));
+ rump_sys_close(fd);
+ }
+ FSTEST_EXIT();
+ if (rump_sys_unmount(FSTEST_MNTNAME, 0) != 0) {
+ rump_pub_vfs_mount_print(FSTEST_MNTNAME, 1);
+ atf_tc_fail_errno("unmount failed");
+ }
+ snprintf(buf, 1024, "fsck_ffs -fn -F %s", FSTEST_IMGNAME);
+ res = system(buf);
+ if (res != 0)
+ atf_tc_fail("fsck returned %d", res);
+}
+
+#define DECL_TEST(nent, newops, name, descr, log) \
+ATF_TC(quota_##name); \
+ \
+ATF_TC_HEAD(quota_##name, tc) \
+{ \
+ atf_tc_set_md_var(tc, "descr", \
+ "test quotas with %d users and groups, %s", \
+ nent, descr); \
+} \
+ \
+ATF_TC_BODY(quota_##name, tc) \
+{ \
+ do_quota(tc, nent, newops, log); \
+}
+
+DECL_TEST(40, "-O1 -B le", 40_O1_le, "UFS1 little-endian", 0)
+DECL_TEST(40, "-O1 -B be", 40_O1_be, "UFS1 big-endian", 0)
+
+DECL_TEST(40, "-O2 -B le", 40_O2_le, "UFS2 little-endian", 0)
+DECL_TEST(40, "-O2 -B be", 40_O2_be, "UFS2 big-endian", 0)
+
+DECL_TEST(40, "-O1", 40_O1_log, "UFS1 log", 1)
+DECL_TEST(40, "-O2", 40_O2_log, "UFS2 log", 1)
+
+DECL_TEST(1000, "-O1 -B le", 1000_O1_le, "UFS1 little-endian", 0)
+DECL_TEST(1000, "-O1 -B be", 1000_O1_be, "UFS1 big-endian", 0)
+
+DECL_TEST(1000, "-O2 -B le", 1000_O2_le, "UFS2 little-endian", 0)
+DECL_TEST(1000, "-O2 -B be", 1000_O2_be, "UFS2 big-endian", 0)
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, quota_40_O1_le);
+ ATF_TP_ADD_TC(tp, quota_40_O1_be);
+ ATF_TP_ADD_TC(tp, quota_40_O2_le);
+ ATF_TP_ADD_TC(tp, quota_40_O2_be);
+ ATF_TP_ADD_TC(tp, quota_40_O1_log);
+ ATF_TP_ADD_TC(tp, quota_40_O2_log);
+ ATF_TP_ADD_TC(tp, quota_1000_O1_le);
+ ATF_TP_ADD_TC(tp, quota_1000_O1_be);
+ ATF_TP_ADD_TC(tp, quota_1000_O2_le);
+ ATF_TP_ADD_TC(tp, quota_1000_O2_be);
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/fs/ffs/t_quota2_remount.c b/contrib/netbsd-tests/fs/ffs/t_quota2_remount.c
new file mode 100644
index 000000000000..f648856bbf70
--- /dev/null
+++ b/contrib/netbsd-tests/fs/ffs/t_quota2_remount.c
@@ -0,0 +1,139 @@
+/* $NetBSD: t_quota2_remount.c,v 1.4 2012/03/15 02:02:22 joerg Exp $ */
+
+/*
+ * Basic tests for quota2
+ */
+
+#include <atf-c.h>
+
+#include "../common/h_fsmacros.h"
+
+#include <sys/types.h>
+#include <sys/mount.h>
+#include <sys/statvfs.h>
+
+#include <stdlib.h>
+
+#include <ufs/ufs/ufsmount.h>
+
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+
+#include "../../h_macros.h"
+
+static void
+do_quota(const atf_tc_t *tc, int n, const char *newfs_opts, int log)
+{
+ int i;
+ char buf[1024];
+ int res;
+ int fd;
+ struct ufs_args uargs;
+ struct statvfs fst;
+
+ snprintf(buf, sizeof(buf), "newfs -q user -q group -F -s 4000 -n %d "
+ "%s %s", (n + 3), newfs_opts, FSTEST_IMGNAME);
+ if (system(buf) == -1)
+ atf_tc_fail_errno("cannot create file system");
+
+ rump_init();
+ if (rump_sys_mkdir(FSTEST_MNTNAME, 0777) == -1)
+ atf_tc_fail_errno("mount point create");
+
+ rump_pub_etfs_register("/diskdev", FSTEST_IMGNAME, RUMP_ETFS_BLK);
+
+ uargs.fspec = __UNCONST("/diskdev");
+
+ /* read-only doens't have quota enabled */
+ if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME, MNT_RDONLY,
+ &uargs, sizeof(uargs)) == -1)
+ atf_tc_fail_errno("mount ffs ro %s", FSTEST_MNTNAME);
+
+ if (rump_sys_statvfs1(FSTEST_MNTNAME, &fst, 0) != 0)
+ atf_tc_fail_errno("statbfs %s (1)", FSTEST_MNTNAME);
+
+ if ((fst.f_flag & ST_QUOTA) != 0)
+ atf_tc_fail("R/O filesystem has quota");
+
+ /* updating to read-write enables quota */
+ if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME,
+ MNT_UPDATE | (log ? MNT_LOG : 0), &uargs, sizeof(uargs)) == -1)
+ atf_tc_fail_errno("mount ffs rw %s", FSTEST_MNTNAME);
+
+ if (rump_sys_statvfs1(FSTEST_MNTNAME, &fst, 0) != 0)
+ atf_tc_fail_errno("statbfs %s (2)", FSTEST_MNTNAME);
+
+ if ((fst.f_flag & ST_QUOTA) == 0)
+ atf_tc_fail("R/W filesystem has no quota");
+
+ /* we can update a second time */
+ if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME,
+ MNT_UPDATE | (log ? MNT_LOG : 0), &uargs, sizeof(uargs)) == -1)
+ atf_tc_fail_errno("mount ffs rw(2) %s", FSTEST_MNTNAME);
+
+ if (rump_sys_statvfs1(FSTEST_MNTNAME, &fst, 0) != 0)
+ atf_tc_fail_errno("statbfs %s (3)", FSTEST_MNTNAME);
+
+ if ((fst.f_flag & ST_QUOTA) == 0)
+ atf_tc_fail("R/W filesystem has no quota");
+
+ /* create some files so fsck has something to check */
+ FSTEST_ENTER();
+ RL(rump_sys_chown(".", 0, 0));
+ for (i = 0 ; i < n; i++) {
+ sprintf(buf, "file%d", i);
+ RL(fd = rump_sys_open(buf, O_CREAT | O_RDWR, 0755));
+ sprintf(buf, "test file no %d", i);
+ RL(rump_sys_write(fd, buf, strlen(buf)));
+ RL(rump_sys_fchown(fd, i, i+80000));
+ rump_sys_close(fd);
+ }
+ FSTEST_EXIT();
+ if (rump_sys_unmount(FSTEST_MNTNAME, 0) != 0) {
+ rump_pub_vfs_mount_print(FSTEST_MNTNAME, 1);
+ atf_tc_fail_errno("unmount failed");
+ }
+ snprintf(buf, 1024, "fsck_ffs -fn -F %s", FSTEST_IMGNAME);
+ res = system(buf);
+ if (res != 0)
+ atf_tc_fail("fsck returned %d", res);
+}
+
+#define DECL_TEST(nent, newops, name, descr, log) \
+ATF_TC(quota_##name); \
+ \
+ATF_TC_HEAD(quota_##name, tc) \
+{ \
+ atf_tc_set_md_var(tc, "descr", \
+ "test filesystem remount with quotas, %s", descr); \
+} \
+ \
+ATF_TC_BODY(quota_##name, tc) \
+{ \
+ do_quota(tc, nent, newops, log); \
+}
+
+DECL_TEST(10, "-O1 -B le", 10_O1_le, "UFS1 little-endian", 0)
+DECL_TEST(10, "-O1 -B be", 10_O1_be, "UFS1 big-endian", 0)
+
+#if 0
+/*
+ * this cause fsck to complain about summaries at the end.
+ * This sems to be related to -o log (reproductible on a fs with no
+ * quota enabled). not reproductible with a real kernel ...
+ */
+DECL_TEST(10, "-O1", 10_O1_log, "UFS1 log", 1)
+DECL_TEST(10, "-O2", 10_O2_log, "UFS2 log", 1)
+#endif
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, quota_10_O1_le);
+ ATF_TP_ADD_TC(tp, quota_10_O1_be);
+#if 0
+ ATF_TP_ADD_TC(tp, quota_10_O1_log);
+ ATF_TP_ADD_TC(tp, quota_10_O2_log);
+#endif
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/fs/ffs/t_quotalimit.sh b/contrib/netbsd-tests/fs/ffs/t_quotalimit.sh
new file mode 100755
index 000000000000..16e47b7a8fb8
--- /dev/null
+++ b/contrib/netbsd-tests/fs/ffs/t_quotalimit.sh
@@ -0,0 +1,345 @@
+# $NetBSD: t_quotalimit.sh,v 1.4 2012/01/18 20:51:23 bouyer Exp $
+#
+# Copyright (c) 2011 Manuel Bouyer
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+for e in le; do
+ for v in 1; do
+ for q in "user" "group"; do
+ test_case_root limit_${e}_${v}_${q} limit_quota \
+ "hit hard limit quota with ${q} enabled" -b ${e} ${v} ${q}
+ test_case_root limit_${e}_${v}_${q}_log limit_quota \
+ "hit hard limit quota with ${q} enabled, WAPBL" -bl ${e} ${v} ${q}
+ test_case_root slimit_${e}_${v}_${q} limit_softquota \
+ "hit soft limit quota with ${q} enabled after grace time" \
+ -b ${e} ${v} ${q}
+ test_case_root inolimit_${e}_${v}_${q} limit_iquota \
+ "hit hard limit ino quota with ${q} enabled" -b ${e} ${v} ${q}
+ test_case_root inolimit_${e}_${v}_${q}_log limit_iquota \
+ "hit hard limit ino quota with ${q} enabled, WAPBL" -bl ${e} ${v} ${q}
+ test_case_root sinolimit_${e}_${v}_${q} limit_softiquota \
+ "hit soft limit ino quota with ${q} enabled after grace time" \
+ -b ${e} ${v} ${q}
+ test_case_root herit_defq_${e}_${v}_${q} inherit_defaultquota \
+ "new id herit from default for ${q} quota" -b ${e} ${v} ${q}
+ test_case_root herit_defq_${e}_${v}_${q}_log inherit_defaultquota \
+ "new id herit from default for ${q} quota, WAPBL" -bl ${e} ${v} ${q}
+ test_case_root herit_idefq_${e}_${v}_${q}_log inherit_defaultiquota \
+ "new id herit from default for ${q} ino quota, WAPBL" -bl ${e} ${v} ${q}
+ done
+ done
+done
+
+limit_quota()
+{
+ create_ffs_server $*
+ local q=$4
+ local expect
+ local id=1
+
+ case ${q} in
+ user)
+ expect=u
+ fail=g
+ ;;
+ group)
+ expect=g
+ fail=u
+ ;;
+ both)
+ expect="u g"
+ fail=""
+ ;;
+ *)
+ atf_fail "wrong quota type"
+ ;;
+ esac
+
+ for q in ${expect} ; do
+ atf_check -s exit:0 \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -$q -s2k/4 -h3k/6 \
+ -t 2h/2h ${id}
+ done
+ atf_check -s exit:0 rump.halt
+
+ #now start the server which does the limits tests
+ atf_check -s exit:0 -o ignore \
+-e match:'test 0: write up to hard limit returned 69: Disc quota exceeded' \
+ $(atf_get_srcdir)/h_quota2_tests -b 0 ${IMG} ${RUMP_SERVER}
+ for q in ${expect} ; do
+ atf_check -s exit:0 \
+ -o match:'/mnt 3072 B\* 2048 B 3072 B 2:0 2 4 6 ' \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -$q -h ${id}
+ atf_check -s exit:0 \
+ -o match:'daemon \+- 3 2 3 2:0 2 4 6' \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -$q /mnt
+ done
+ rump_quota_shutdown
+}
+
+limit_softquota()
+{
+ create_ffs_server $*
+ local q=$4
+ local expect
+ local id=1
+
+ case ${q} in
+ user)
+ expect=u
+ fail=g
+ ;;
+ group)
+ expect=g
+ fail=u
+ ;;
+ both)
+ expect="u g"
+ fail=""
+ ;;
+ *)
+ atf_fail "wrong quota type"
+ ;;
+ esac
+
+ for q in ${expect} ; do
+ atf_check -s exit:0 \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -$q -s2k/4 -h3k/6 \
+ -t 1s/1d ${id}
+ done
+ atf_check -s exit:0 rump.halt
+
+ #now start the server which does the limits tests
+ atf_check -s exit:0 -o ignore \
+-e match:'test 1: write beyond the soft limit after grace time returned 69: Disc quota exceeded' \
+ $(atf_get_srcdir)/h_quota2_tests -b 1 ${IMG} ${RUMP_SERVER}
+ for q in ${expect} ; do
+ atf_check -s exit:0 \
+ -o match:'/mnt 2560 B\* 2048 B 3072 B none 2 4 6 ' \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -$q -h ${id}
+ atf_check -s exit:0 \
+ -o match:'daemon \+- 2 2 3 none 2 4 6' \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -$q /mnt
+ done
+ rump_quota_shutdown
+}
+
+limit_iquota()
+{
+ create_ffs_server $*
+ local q=$4
+ local expect
+ local id=1
+
+ case ${q} in
+ user)
+ expect=u
+ fail=g
+ ;;
+ group)
+ expect=g
+ fail=u
+ ;;
+ both)
+ expect="u g"
+ fail=""
+ ;;
+ *)
+ atf_fail "wrong quota type"
+ ;;
+ esac
+
+ for q in ${expect} ; do
+ atf_check -s exit:0 \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -$q -s2m/4 -h3m/6 \
+ -t 2h/2h ${id}
+ done
+ atf_check -s exit:0 rump.halt
+
+ #now start the server which does the limits tests
+ atf_check -s exit:0 -o ignore \
+-e match:'test 2: create file up to hard limit returned 69: Disc quota exceeded' \
+ $(atf_get_srcdir)/h_quota2_tests -b 2 ${IMG} ${RUMP_SERVER}
+ for q in ${expect} ; do
+ atf_check -s exit:0 \
+ -o match:'/mnt 3072 B 2048 K 3072 K 6 \* 4 6 2:0' \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -$q -h ${id}
+ atf_check -s exit:0 \
+ -o match:'daemon -\+ 3 2048 3072 6 4 6 2:0' \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -$q /mnt
+ done
+ rump_quota_shutdown
+}
+
+limit_softiquota()
+{
+ create_ffs_server $*
+ local q=$4
+ local expect
+ local id=1
+
+ case ${q} in
+ user)
+ expect=u
+ fail=g
+ ;;
+ group)
+ expect=g
+ fail=u
+ ;;
+ both)
+ expect="u g"
+ fail=""
+ ;;
+ *)
+ atf_fail "wrong quota type"
+ ;;
+ esac
+
+ for q in ${expect} ; do
+ atf_check -s exit:0 \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -$q -s2m/4 -h3m/6 \
+ -t 1d/1s ${id}
+ done
+ atf_check -s exit:0 rump.halt
+
+ #now start the server which does the limits tests
+ atf_check -s exit:0 -o ignore \
+-e match:'test 3: create file beyond the soft limit after grace time returned 69: Disc quota exceeded' \
+ $(atf_get_srcdir)/h_quota2_tests -b 3 ${IMG} ${RUMP_SERVER}
+ for q in ${expect} ; do
+ atf_check -s exit:0 \
+ -o match:'/mnt 2560 B 2048 K 3072 K 5 \* 4 6 none' \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -$q -h ${id}
+ atf_check -s exit:0 \
+ -o match:'daemon -\+ 2 2048 3072 5 4 6 none' \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -$q /mnt
+ done
+ rump_quota_shutdown
+}
+
+inherit_defaultquota()
+{
+ create_ffs_server $*
+ local q=$4
+ local expect
+ local id=1
+
+ case ${q} in
+ user)
+ expect=u
+ fail=g
+ ;;
+ group)
+ expect=g
+ fail=u
+ ;;
+ both)
+ expect="u g"
+ fail=""
+ ;;
+ *)
+ atf_fail "wrong quota type"
+ ;;
+ esac
+
+ for q in ${expect} ; do
+ atf_check -s exit:0 \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -$q -s2k/4 -h3k/6 \
+ -t 2h/2h -d
+ done
+ for q in ${expect} ; do
+ atf_check -s exit:0 \
+ -o match:'Disk quotas for .*id 1\): none' \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -$q -v ${id}
+ done
+ atf_check -s exit:0 rump.halt
+
+ #now start the server which does the limits tests
+ atf_check -s exit:0 -o ignore \
+-e match:'test 0: write up to hard limit returned 69: Disc quota exceeded' \
+ $(atf_get_srcdir)/h_quota2_tests -b 0 ${IMG} ${RUMP_SERVER}
+ for q in ${expect} ; do
+ atf_check -s exit:0 \
+ -o match:'/mnt 3072 B\* 2048 B 3072 B 2:0 2 4 6 ' \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -$q -h ${id}
+ atf_check -s exit:0 \
+ -o match:'daemon \+- 3 2 3 2:0 2 4 6' \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -$q /mnt
+ done
+ rump_quota_shutdown
+}
+
+inherit_defaultiquota()
+{
+ create_ffs_server $*
+ local q=$4
+ local expect
+ local id=1
+
+ case ${q} in
+ user)
+ expect=u
+ fail=g
+ ;;
+ group)
+ expect=g
+ fail=u
+ ;;
+ both)
+ expect="u g"
+ fail=""
+ ;;
+ *)
+ atf_fail "wrong quota type"
+ ;;
+ esac
+
+ for q in ${expect} ; do
+ atf_check -s exit:0 \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -$q -s2m/4 -h3m/6 \
+ -t 2h/2h -d
+ done
+ for q in ${expect} ; do
+ atf_check -s exit:0 \
+ -o match:'Disk quotas for .*id 1\): none' \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -$q -v ${id}
+ done
+ atf_check -s exit:0 rump.halt
+
+ #now start the server which does the limits tests
+ atf_check -s exit:0 -o ignore \
+-e match:'test 2: create file up to hard limit returned 69: Disc quota exceeded' \
+ $(atf_get_srcdir)/h_quota2_tests -b 2 ${IMG} ${RUMP_SERVER}
+ for q in ${expect} ; do
+ atf_check -s exit:0 \
+ -o match:'/mnt 3072 B 2048 K 3072 K 6 \* 4 6 2:0' \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -$q -h ${id}
+ atf_check -s exit:0 \
+ -o match:'daemon -\+ 3 2048 3072 6 4 6 2:0' \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -$q /mnt
+ done
+ rump_quota_shutdown
+}
diff --git a/contrib/netbsd-tests/fs/ffs/t_setquota.sh b/contrib/netbsd-tests/fs/ffs/t_setquota.sh
new file mode 100755
index 000000000000..5795fe4d46b6
--- /dev/null
+++ b/contrib/netbsd-tests/fs/ffs/t_setquota.sh
@@ -0,0 +1,203 @@
+# $NetBSD: t_setquota.sh,v 1.4 2012/01/18 20:51:23 bouyer Exp $
+#
+# Copyright (c) 2011 Manuel Bouyer
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+for e in le be; do
+ for v in 1 2; do
+ for q in "user" "group"; do
+ test_case_root set_${e}_${v}_${q} set_quota \
+ "set quota with ${q} enabled" -b ${e} ${v} ${q}
+ test_case_root set_new_${e}_${v}_${q} set_quota_new \
+ "set quota for new id with ${q} enabled" -b ${e} ${v} ${q}
+ test_case_root set_default_${e}_${v}_${q} set_quota_default \
+ "set default quota with ${q} enabled" -b ${e} ${v} ${q}
+ done
+ test_case_root set_${e}_${v}_"both" set_quota \
+ "set quota with both enabled" -b ${e} ${v} "both"
+ test_case_root set_new_${e}_${v}_"both" set_quota_new \
+ "set quota for new id with both enabled" -b ${e} ${v} "both"
+ test_case_root set_new_${e}_${v}_"both_log" set_quota_new \
+ "set quota for new id with both enabled, WAPBL" -bl ${e} ${v} "both"
+ test_case_root set_default_${e}_${v}_"both" set_quota_default \
+ "set default quota with both enabled" -b ${e} ${v} "both"
+ done
+done
+
+set_quota()
+{
+ create_ffs_server $*
+ local q=$4
+ local expect
+ local fail
+
+ case ${q} in
+ user)
+ expect=u
+ fail=g
+ ;;
+ group)
+ expect=g
+ fail=u
+ ;;
+ both)
+ expect="u g"
+ fail=""
+ ;;
+ *)
+ atf_fail "wrong quota type"
+ ;;
+ esac
+
+#check that we can set the expected quota
+ for q in ${expect} ; do
+ local id=$(id -${q})
+ atf_check -s exit:0 \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -$q -s10k/20 -h40M/50k \
+ -t 2W/3D ${id}
+ atf_check -s exit:0 \
+-o "match:/mnt 0 10 40960 2weeks 1 20 51200 3days" \
+-o "match:Disk quotas for .*: $" \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -${q} -v
+ atf_check -s exit:0 \
+-o "match:-- 0 10 40960 1 20 51200" \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -${q} /mnt
+ done
+
+#check that we do not get positive reply for non-expected quota
+ for q in ${fail} ; do
+ local id=$(id -${q})
+ atf_check -s exit:0 \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -$q -s10k/20 -h40M/50k ${id}
+ atf_check -s exit:0 -o "not-match:/mnt" \
+ -o "not-match:Disk quotas for .*: $" \
+ -o "match:Disk quotas for .*: none$" \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -${q} -v
+ atf_check -s exit:0 \
+-o "not-match:-- 0 - -" \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt repquota -${q} /mnt
+ done
+ rump_quota_shutdown
+}
+
+set_quota_new()
+{
+ create_ffs_server $*
+ local q=$4
+ local expect
+ local fail
+
+ case ${q} in
+ user)
+ expect=u
+ fail=g
+ ;;
+ group)
+ expect=g
+ fail=u
+ ;;
+ both)
+ expect="u g"
+ fail=""
+ ;;
+ *)
+ atf_fail "wrong quota type"
+ ;;
+ esac
+
+#check that we can set the expected quota
+ for q in ${expect} ; do
+ local id=1
+ atf_check -s exit:0 \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -$q -s10k/20 -h40M/50k \
+ -t 120W/255D ${id}
+ atf_check -s exit:0 \
+-o "match:/mnt 0 10 40960 2years 0 20 51200 9months" \
+-o "match:Disk quotas for .*: $" \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -${q} -v ${id}
+ done
+
+#check that we do not get positive reply for non-expected quota
+ for q in ${fail} ; do
+ local id=$(id -${q})
+ atf_check -s exit:0 \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -$q -s10k/20 -h40M/50k ${id}
+ atf_check -s exit:0 -o "not-match:/mnt" \
+ -o "not-match:Disk quotas for .*: $" \
+ -o "match:Disk quotas for .*: none$" \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -${q} -v ${id}
+ done
+ rump_quota_shutdown
+}
+
+set_quota_default()
+{
+ create_ffs_server $*
+ local q=$4
+ local expect
+ local fail
+
+ case ${q} in
+ user)
+ expect=u
+ fail=g
+ ;;
+ group)
+ expect=g
+ fail=u
+ ;;
+ both)
+ expect="u g"
+ fail=""
+ ;;
+ *)
+ atf_fail "wrong quota type"
+ ;;
+ esac
+
+#check that we can set the expected quota
+ for q in ${expect} ; do
+ local id="-d"
+ atf_check -s exit:0 \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -$q -s10k/20 -h40M/50k \
+ -t 2H2M/3540 ${id}
+ atf_check -s exit:0 \
+-o "match:/mnt 0 10 40960 2:2 0 20 51200 59" \
+-o "match:Default (user|group) disk quotas: $" \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -${q} -v ${id}
+ done
+
+#check that we do not get positive reply for non-expected quota
+ for q in ${fail} ; do
+ local id="-d"
+ atf_check -s exit:0 \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt edquota -$q -s10k/20 -h40M/50k ${id}
+ atf_check -s exit:0 -o "not-match:/mnt" \
+ -o "not-match:Default (user|group) disk quotas: $" \
+ -o "match:Default (user|group) disk quotas: none$" \
+ env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/mnt quota -${q} -v ${id}
+ done
+ rump_quota_shutdown
+}
diff --git a/contrib/netbsd-tests/fs/ffs/t_snapshot.c b/contrib/netbsd-tests/fs/ffs/t_snapshot.c
new file mode 100644
index 000000000000..180a8ccd92b0
--- /dev/null
+++ b/contrib/netbsd-tests/fs/ffs/t_snapshot.c
@@ -0,0 +1,43 @@
+/* $NetBSD: t_snapshot.c,v 1.6 2013/02/06 09:05:01 hannken Exp $ */
+
+#include <sys/types.h>
+#include <sys/mount.h>
+
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+
+#include <ufs/ufs/ufsmount.h>
+
+#include <atf-c.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "../../h_macros.h"
+
+#define IMGNAME "ffs.img"
+#define NEWFS "newfs -F -s 10000 " IMGNAME
+#define FSCK "fsck_ffs -fn -F"
+#define BAKNAME "/mnt/le_snapp"
+
+static void
+mount_diskfs(const char *fspec, const char *path)
+{
+ struct ufs_args uargs;
+
+ uargs.fspec = __UNCONST(fspec);
+
+ if (rump_sys_mount(MOUNT_FFS, path, 0, &uargs, sizeof(uargs)) == -1)
+ atf_tc_fail_errno("mount ffs %s", path);
+}
+
+static void
+begin(void)
+{
+
+ /* empty */
+}
+
+#include "../common/snapshot.c"
diff --git a/contrib/netbsd-tests/fs/ffs/t_snapshot_log.c b/contrib/netbsd-tests/fs/ffs/t_snapshot_log.c
new file mode 100644
index 000000000000..e1ce17e1006a
--- /dev/null
+++ b/contrib/netbsd-tests/fs/ffs/t_snapshot_log.c
@@ -0,0 +1,46 @@
+/* $NetBSD: t_snapshot_log.c,v 1.2 2013/02/06 09:05:01 hannken Exp $ */
+
+#include <sys/types.h>
+#include <sys/mount.h>
+
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+
+#include <ufs/ufs/ufsmount.h>
+
+#include <atf-c.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "../../h_macros.h"
+
+#define IMGNAME "ffs.img"
+#define NEWFS "newfs -F -s 10000 " IMGNAME
+#define FSCK "fsck_ffs -fn -F"
+#define BAKNAME "/mnt/le_snapp"
+
+static void
+mount_diskfs(const char *fspec, const char *path)
+{
+ struct ufs_args uargs;
+ static int flags = MNT_LOG;
+
+ uargs.fspec = __UNCONST(fspec);
+
+ if (rump_sys_mount(MOUNT_FFS,
+ path, flags, &uargs, sizeof(uargs)) == -1)
+ atf_tc_fail_errno("mount ffs %s", path);
+ flags = 0;
+}
+
+static void
+begin(void)
+{
+
+ /* empty */
+}
+
+#include "../common/snapshot.c"
diff --git a/contrib/netbsd-tests/fs/ffs/t_snapshot_v2.c b/contrib/netbsd-tests/fs/ffs/t_snapshot_v2.c
new file mode 100644
index 000000000000..393f3d41a6c3
--- /dev/null
+++ b/contrib/netbsd-tests/fs/ffs/t_snapshot_v2.c
@@ -0,0 +1,43 @@
+/* $NetBSD: t_snapshot_v2.c,v 1.2 2013/02/06 09:05:01 hannken Exp $ */
+
+#include <sys/types.h>
+#include <sys/mount.h>
+
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+
+#include <ufs/ufs/ufsmount.h>
+
+#include <atf-c.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "../../h_macros.h"
+
+#define IMGNAME "ffs.img"
+#define NEWFS "newfs -F -s 10000 -O 2 " IMGNAME
+#define FSCK "fsck_ffs -fn -F"
+#define BAKNAME "/mnt/le_snapp"
+
+static void
+mount_diskfs(const char *fspec, const char *path)
+{
+ struct ufs_args uargs;
+
+ uargs.fspec = __UNCONST(fspec);
+
+ if (rump_sys_mount(MOUNT_FFS, path, 0, &uargs, sizeof(uargs)) == -1)
+ atf_tc_fail_errno("mount ffs %s", path);
+}
+
+static void
+begin(void)
+{
+
+ /* empty */
+}
+
+#include "../common/snapshot.c"