static void read_after_unlink(const atf_tc_t *tc, const char *mp) { char buf[TBSIZE], buf2[TBSIZE]; int fd; FSTEST_ENTER(); /* create file and put some content into it */ RL(fd = rump_sys_open("file", O_RDWR|O_CREAT, 0666)); memset(buf, 'D', TBSIZE); ATF_REQUIRE_EQ(rump_sys_write(fd, buf, TBSIZE), TBSIZE); rump_sys_close(fd); /* flush buffers from UBC to file system */ ATF_REQUIRE_ERRNO(EBUSY, rump_sys_unmount(mp, 0) == -1); RL(fd = rump_sys_open("file", O_RDWR)); RL(rump_sys_unlink("file")); ATF_REQUIRE_EQ(rump_sys_read(fd, buf2, TBSIZE), TBSIZE); ATF_REQUIRE_EQ(memcmp(buf, buf2, TBSIZE), 0); rump_sys_close(fd); FSTEST_EXIT(); }
static void wrrd_after_unlink(const atf_tc_t *tc, const char *mp) { int value = 0x11; int v2; int fd; FSTEST_ENTER(); RL(fd = rump_sys_open("file", O_RDWR|O_CREAT, 0666)); RL(rump_sys_unlink("file")); RL(rump_sys_pwrite(fd, &value, sizeof(value), 654321)); /* * We can't easily invalidate the buffer since we hold a * reference, but try to get them to flush anyway. */ RL(rump_sys_fsync(fd)); RL(rump_sys_pread(fd, &v2, sizeof(v2), 654321)); rump_sys_close(fd); ATF_REQUIRE_EQ(value, v2); FSTEST_EXIT(); }
static void holywrite(const atf_tc_t *tc, const char *mp) { char buf[1024]; char *b2, *b3; size_t therange = getpagesize()+1; int fd; FSTEST_ENTER(); RL(fd = rump_sys_open("file", O_RDWR|O_CREAT|O_TRUNC, 0666)); memset(buf, 'A', sizeof(buf)); RL(rump_sys_pwrite(fd, buf, 1, getpagesize())); memset(buf, 'B', sizeof(buf)); RL(rump_sys_pwrite(fd, buf, 2, getpagesize()-1)); REQUIRE_LIBC(b2 = malloc(2 * getpagesize()), NULL); REQUIRE_LIBC(b3 = malloc(2 * getpagesize()), NULL); RL(rump_sys_pread(fd, b2, therange, 0)); memset(b3, 0, therange); memset(b3 + getpagesize() - 1, 'B', 2); ATF_REQUIRE_EQ(memcmp(b2, b3, therange), 0); rump_sys_close(fd); FSTEST_EXIT(); }
static void dir_rmdirdotdot(const atf_tc_t *tc, const char *mp) { char pb[MAXPATHLEN]; int xerrno; USES_DIRS; FSTEST_ENTER(); RL(rump_sys_mkdir("test", 0777)); RL(rump_sys_chdir("test")); RL(rump_sys_mkdir("subtest", 0777)); RL(rump_sys_chdir("subtest")); md(pb, mp, "test/subtest"); RL(rump_sys_rmdir(pb)); md(pb, mp, "test"); RL(rump_sys_rmdir(pb)); if (FSTYPE_NFS(tc)) xerrno = ESTALE; else xerrno = ENOENT; ATF_REQUIRE_ERRNO(xerrno, rump_sys_chdir("..") == -1); FSTEST_EXIT(); }
static void owner(const atf_tc_t *tc, const char *mp) { USES_OWNER; FSTEST_ENTER(); rump_pub_lwproc_rfork(RUMP_RFCFDG); if (rump_sys_setuid(1) == -1) atf_tc_fail_errno("setuid"); if (rump_sys_chown(".", 1, -1) != -1 || errno != EPERM) atf_tc_fail_errno("chown"); if (rump_sys_chmod(".", 0000) != -1 || errno != EPERM) atf_tc_fail_errno("chmod"); rump_pub_lwproc_releaselwp(); if (rump_sys_chown(".", 1, -1) == -1) atf_tc_fail_errno("chown"); rump_pub_lwproc_rfork(RUMP_RFCFDG); if (rump_sys_setuid(1) == -1) atf_tc_fail_errno("setuid"); if (rump_sys_chown(".", 1, -1) == -1) atf_tc_fail_errno("chown"); if (rump_sys_chmod(".", 0000) == -1) atf_tc_fail_errno("chmod"); rump_pub_lwproc_releaselwp(); FSTEST_EXIT(); }
static void lstat_symlink(const atf_tc_t *tc, const char *mp) { const char *src, *dst; int res; struct stat st; USES_SYMLINKS; if (FSTYPE_V7FS(tc)) atf_tc_expect_fail("PR kern/48864"); FSTEST_ENTER(); src = "source"; dst = "destination"; res = rump_sys_symlink(src, dst); ATF_REQUIRE(res != -1); res = rump_sys_lstat(dst, &st); ATF_REQUIRE(res != -1); ATF_CHECK(S_ISLNK(st.st_mode) != 0); ATF_CHECK(st.st_size == (off_t)strlen(src)); FSTEST_EXIT(); }
static void shrinkfile(const atf_tc_t *tc, const char *mp) { int fd; FSTEST_ENTER(); RL(fd = rump_sys_open("file", O_RDWR|O_CREAT|O_TRUNC, 0666)); RL(rump_sys_ftruncate(fd, 2)); RL(rump_sys_ftruncate(fd, 1)); rump_sys_close(fd); FSTEST_EXIT(); }
static void attrs(const atf_tc_t *tc, const char *mp) { struct stat sb, sb2; struct timeval tv[2]; int fd; FSTEST_ENTER(); RL(fd = rump_sys_open(TESTFILE, O_RDWR | O_CREAT, 0755)); RL(rump_sys_close(fd)); RL(rump_sys_stat(TESTFILE, &sb)); if (!(FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))) { RL(rump_sys_chown(TESTFILE, 1, 2)); sb.st_uid = 1; sb.st_gid = 2; RL(rump_sys_chmod(TESTFILE, 0123)); sb.st_mode = (sb.st_mode & ~ACCESSPERMS) | 0123; } tv[0].tv_sec = 1000000000; /* need something >1980 for msdosfs */ tv[0].tv_usec = 1; tv[1].tv_sec = 1000000002; /* need even seconds for msdosfs */ tv[1].tv_usec = 3; RL(rump_sys_utimes(TESTFILE, tv)); RL(rump_sys_utimes(TESTFILE, tv)); /* XXX: utimes & birthtime */ sb.st_atimespec.tv_sec = 1000000000; sb.st_atimespec.tv_nsec = 1000; sb.st_mtimespec.tv_sec = 1000000002; sb.st_mtimespec.tv_nsec = 3000; RL(rump_sys_stat(TESTFILE, &sb2)); #define CHECK(a) ATF_REQUIRE_EQ(sb.a, sb2.a) if (FSTYPE_ZFS(tc)) atf_tc_expect_fail("PR kern/47656: Test known to be broken"); if (!(FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))) { CHECK(st_uid); CHECK(st_gid); CHECK(st_mode); } if (!FSTYPE_MSDOS(tc)) { /* msdosfs has only access date, not time */ CHECK(st_atimespec.tv_sec); } CHECK(st_mtimespec.tv_sec); if (!(FSTYPE_EXT2FS(tc) || FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc) || FSTYPE_V7FS(tc))) { CHECK(st_atimespec.tv_nsec); CHECK(st_mtimespec.tv_nsec); } #undef CHECK FSTEST_EXIT(); }
static void times(const atf_tc_t *tc, const char *mp) { const char *name = "file.test"; int fd; unsigned int i, j; struct timeval tmv[2]; static struct timeval tmvs[] = { { QUAD_MIN, 0 }, { 0, 0 }, { QUAD_MAX, 999999 } }; FSTEST_ENTER(); if ((fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666)) == -1) atf_tc_fail_errno("open"); if (rump_sys_close(fd) == -1) atf_tc_fail_errno("close"); rump_pub_lwproc_rfork(RUMP_RFCFDG); if (rump_sys_setuid(1) == -1) atf_tc_fail_errno("setuid"); if (FSTYPE_ZFS(tc)) atf_tc_expect_fail("PR kern/47656: Test known to be broken"); if (rump_sys_utimes(name, NULL) != -1 || errno != EACCES) atf_tc_fail_errno("utimes"); rump_pub_lwproc_releaselwp(); if (rump_sys_utimes(name, NULL) == -1) atf_tc_fail_errno("utimes"); for (i = 0; i < sizeof(tmvs) / sizeof(tmvs[0]); i++) { for (j = 0; j < sizeof(tmvs) / sizeof(tmvs[0]); j++) { tmv[0] = tmvs[i]; tmv[1] = tmvs[j]; rump_pub_lwproc_rfork(RUMP_RFCFDG); if (rump_sys_setuid(1) == -1) atf_tc_fail_errno("setuid"); if (rump_sys_utimes(name, tmv) != -1 || errno != EPERM) atf_tc_fail_errno("utimes"); rump_pub_lwproc_releaselwp(); if (rump_sys_utimes(name, tmv) == -1) atf_tc_fail_errno("utimes"); } } if (rump_sys_unlink(name) == -1) atf_tc_fail_errno("unlink"); FSTEST_EXIT(); }
static void read_fault(const atf_tc_t *tc, const char *mp) { char ch = 123; int fd; FSTEST_ENTER(); RL(fd = rump_sys_open("file", O_CREAT | O_RDWR, 0777)); ATF_REQUIRE_EQ(rump_sys_write(fd, &ch, 1), 1); RL(rump_sys_close(fd)); RL(fd = rump_sys_open("file", O_RDONLY | O_SYNC | O_RSYNC)); ATF_REQUIRE_ERRNO(EFAULT, rump_sys_read(fd, NULL, 1) == -1); RL(rump_sys_close(fd)); FSTEST_EXIT(); }
static void flags(const atf_tc_t *tc, const char *mp) { const char *name = "file.test"; int fd, fflags; struct stat st; FSTEST_ENTER(); if ((fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666)) == -1) atf_tc_fail_errno("open"); if (rump_sys_close(fd) == -1) atf_tc_fail_errno("close"); if (rump_sys_stat(name, &st) == -1) atf_tc_fail_errno("stat"); if (FSTYPE_ZFS(tc)) atf_tc_expect_fail("PR kern/47656: Test known to be broken"); if (rump_sys_chflags(name, st.st_flags) == -1) { if (errno == EOPNOTSUPP) atf_tc_skip("file flags not supported by file system"); atf_tc_fail_errno("chflags"); } fflags = st.st_flags | UF_IMMUTABLE; rump_pub_lwproc_rfork(RUMP_RFCFDG); if (rump_sys_setuid(1) == -1) atf_tc_fail_errno("setuid"); fflags |= UF_IMMUTABLE; if (rump_sys_chflags(name, fflags) != -1 || errno != EPERM) atf_tc_fail_errno("chflags"); rump_pub_lwproc_releaselwp(); if (rump_sys_chflags(name, fflags) == -1) atf_tc_fail_errno("chflags"); fflags &= ~UF_IMMUTABLE; if (rump_sys_chflags(name, fflags) == -1) atf_tc_fail_errno("chflags"); if (rump_sys_unlink(name) == -1) atf_tc_fail_errno("unlink"); FSTEST_EXIT(); }
static void fcntl_lock(const atf_tc_t *tc, const char *mp) { int fd, fd2; struct flock l; struct lwp *lwp1, *lwp2; FSTEST_ENTER(); l.l_pid = 0; l.l_start = l.l_len = 1024; l.l_type = F_RDLCK | F_WRLCK; l.l_whence = SEEK_END; lwp1 = rump_pub_lwproc_curlwp(); RL(fd = rump_sys_open(TESTFILE, O_RDWR | O_CREAT, 0755)); RL(rump_sys_ftruncate(fd, 8192)); /* PR kern/43321 */ if (FSTYPE_ZFS(tc)) atf_tc_expect_fail("PR kern/47656: Test known to be broken"); RL(rump_sys_fcntl(fd, F_SETLK, &l)); /* Next, we fork and try to lock the same area */ RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG)); lwp2 = rump_pub_lwproc_curlwp(); RL(fd2 = rump_sys_open(TESTFILE, O_RDWR, 0)); ATF_REQUIRE_ERRNO(EAGAIN, rump_sys_fcntl(fd2, F_SETLK, &l)); /* Switch back and unlock... */ rump_pub_lwproc_switch(lwp1); l.l_type = F_UNLCK; RL(rump_sys_fcntl(fd, F_SETLK, &l)); /* ... and try to lock again */ rump_pub_lwproc_switch(lwp2); l.l_type = F_RDLCK | F_WRLCK; RL(rump_sys_fcntl(fd2, F_SETLK, &l)); RL(rump_sys_close(fd2)); rump_pub_lwproc_releaselwp(); RL(rump_sys_close(fd)); FSTEST_EXIT(); }
static void dirperms(const atf_tc_t *tc, const char *mp) { char name[] = "dir.test/file.test"; char *dir = dirname(name); int fd; if (FSTYPE_SYSVBFS(tc)) atf_tc_skip("directories not supported by file system"); FSTEST_ENTER(); if (rump_sys_mkdir(dir, 0777) == -1) atf_tc_fail_errno("mkdir"); rump_pub_lwproc_rfork(RUMP_RFCFDG); if (rump_sys_setuid(1) == -1) atf_tc_fail_errno("setuid"); if (FSTYPE_ZFS(tc)) atf_tc_expect_fail("PR kern/47656: Test known to be broken"); if (rump_sys_open(name, O_RDWR|O_CREAT, 0666) != -1 || errno != EACCES) atf_tc_fail_errno("open"); rump_pub_lwproc_releaselwp(); if ((fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666)) == -1) atf_tc_fail_errno("open"); if (rump_sys_close(fd) == -1) atf_tc_fail_errno("close"); rump_pub_lwproc_rfork(RUMP_RFCFDG); if (rump_sys_setuid(1) == -1) atf_tc_fail_errno("setuid"); if (rump_sys_unlink(name) != -1 || errno != EACCES) atf_tc_fail_errno("unlink"); rump_pub_lwproc_releaselwp(); if (rump_sys_unlink(name) == -1) atf_tc_fail_errno("unlink"); if (rump_sys_rmdir(dir) == -1) atf_tc_fail_errno("rmdir"); FSTEST_EXIT(); }
static void overwritebody(const atf_tc_t *tc, off_t count, bool dotrunc) { char *buf; int fd; REQUIRE_LIBC(buf = malloc(count), NULL); FSTEST_ENTER(); RL(fd = rump_sys_open("testi", O_CREAT | O_RDWR, 0666)); ATF_REQUIRE_EQ(rump_sys_write(fd, buf, count), count); RL(rump_sys_close(fd)); RL(fd = rump_sys_open("testi", O_RDWR)); if (dotrunc) RL(rump_sys_ftruncate(fd, 0)); ATF_REQUIRE_EQ(rump_sys_write(fd, buf, count), count); RL(rump_sys_close(fd)); FSTEST_EXIT(); }
static void read_directory(const atf_tc_t *tc, const char *mp) { char buf[1024]; int fd, res; ssize_t size; FSTEST_ENTER(); fd = rump_sys_open(".", O_DIRECTORY | O_RDONLY, 0777); ATF_REQUIRE(fd != -1); size = rump_sys_pread(fd, buf, sizeof(buf), 0); ATF_CHECK(size != -1 || errno == EISDIR); size = rump_sys_read(fd, buf, sizeof(buf)); ATF_CHECK(size != -1 || errno == EISDIR); res = rump_sys_close(fd); ATF_REQUIRE(res != -1); FSTEST_EXIT(); }
static void access_simple(const atf_tc_t *tc, const char *mp) { int fd; int tmode; FSTEST_ENTER(); RL(fd = rump_sys_open("tfile", O_CREAT | O_RDWR, 0777)); RL(rump_sys_close(fd)); #define ALLACC (F_OK | X_OK | W_OK | R_OK) if (FSTYPE_SYSVBFS(tc) || FSTYPE_MSDOS(tc)) tmode = F_OK; else tmode = ALLACC; RL(rump_sys_access("tfile", tmode)); /* PR kern/44648 */ ATF_REQUIRE_ERRNO(EINVAL, rump_sys_access("tfile", ALLACC+1) == -1); #undef ALLACC FSTEST_EXIT(); }
static void extendbody(const atf_tc_t *tc, off_t seekcnt) { char buf[TESTSZ+1]; struct stat sb; int fd; FSTEST_ENTER(); RL(fd = rump_sys_open("testfile", O_CREAT | O_RDWR | (seekcnt ? O_APPEND : 0))); RL(rump_sys_ftruncate(fd, seekcnt)); RL(rump_sys_fstat(fd, &sb)); ATF_REQUIRE_EQ(sb.st_size, seekcnt); ATF_REQUIRE_EQ(rump_sys_write(fd, TESTSTR, TESTSZ), TESTSZ); ATF_REQUIRE_EQ(rump_sys_pread(fd, buf, TESTSZ, seekcnt), TESTSZ); ATF_REQUIRE_STREQ(buf, TESTSTR); RL(rump_sys_fstat(fd, &sb)); ATF_REQUIRE_EQ(sb.st_size, (off_t)TESTSZ + seekcnt); RL(rump_sys_close(fd)); FSTEST_EXIT(); }
static void fcntl_getlock_pids(const atf_tc_t *tc, const char *mp) { /* test non-overlaping ranges */ struct flock expect[4]; const struct flock lock[4] = { { 0, 2, 0, F_WRLCK, SEEK_SET }, { 2, 1, 0, F_WRLCK, SEEK_SET }, { 7, 5, 0, F_WRLCK, SEEK_SET }, { 4, 3, 0, F_WRLCK, SEEK_SET }, }; /* Add extra element to make sure recursion does't stop at array end */ struct flock result[5]; /* Add 5th process */ int fd[5]; pid_t pid[5]; struct lwp *lwp[5]; unsigned int i, j; const off_t sz = 8192; int omode = 0755; int oflags = O_RDWR | O_CREAT; memcpy(expect, lock, sizeof(lock)); FSTEST_ENTER(); /* * First, we create 4 processes and let each lock a range of the * file. Note that the third and fourth processes lock in * "reverse" order, i.e. the greater pid locks a range before * the lesser pid. * Then, we create 5th process which doesn't lock anything. */ for (i = 0; i < __arraycount(lwp); i++) { RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG)); lwp[i] = rump_pub_lwproc_curlwp(); pid[i] = rump_sys_getpid(); RL(fd[i] = rump_sys_open(TESTFILE, oflags, omode)); oflags = O_RDWR; omode = 0; RL(rump_sys_ftruncate(fd[i], sz)); if (FSTYPE_ZFS(tc)) atf_tc_expect_fail("PR kern/47656: Test known to be " "broken"); if (i < __arraycount(lock)) { RL(rump_sys_fcntl(fd[i], F_SETLK, &lock[i])); expect[i].l_pid = pid[i]; } } qsort(expect, __arraycount(expect), sizeof(expect[0]), &flock_compare); /* * In the context of each process, recursively find all locks * that would block the current process. Processes 1-4 don't * see their own lock, we insert it to simplify checks. * Process 5 sees all 4 locks. */ for (i = 0; i < __arraycount(lwp); i++) { unsigned int nlocks; rump_pub_lwproc_switch(lwp[i]); memset(result, 0, sizeof(result)); nlocks = fcntl_getlocks(fd[i], 0, sz, result, result + __arraycount(result)); if (i < __arraycount(lock)) { ATF_REQUIRE(nlocks < __arraycount(result)); result[nlocks] = lock[i]; result[nlocks].l_pid = pid[i]; nlocks++; } ATF_CHECK_EQ(nlocks, __arraycount(expect)); qsort(result, nlocks, sizeof(result[0]), &flock_compare); for (j = 0; j < nlocks; j++) { ATF_CHECK_EQ(result[j].l_start, expect[j].l_start ); ATF_CHECK_EQ(result[j].l_len, expect[j].l_len ); ATF_CHECK_EQ(result[j].l_pid, expect[j].l_pid ); ATF_CHECK_EQ(result[j].l_type, expect[j].l_type ); ATF_CHECK_EQ(result[j].l_whence, expect[j].l_whence); } } /* * Release processes. This also releases the fds and locks * making fs unmount possible */ for (i = 0; i < __arraycount(lwp); i++) { rump_pub_lwproc_switch(lwp[i]); rump_pub_lwproc_releaselwp(); } FSTEST_EXIT(); }