1 /* $NetBSD: t_vnops.c,v 1.43 2014/09/09 06:51:00 gson Exp $ */
4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/statvfs.h>
40 #include <rump/rump_syscalls.h>
41 #include <rump/rump.h>
43 #include "../common/h_fsmacros.h"
44 #include "../../h_macros.h"
46 #define TESTFILE "afile"
49 if (FSTYPE_SYSVBFS(tc)) \
50 atf_tc_skip("directories not supported by file system")
52 #define USES_SYMLINKS \
53 if (FSTYPE_SYSVBFS(tc) || FSTYPE_MSDOS(tc)) \
54 atf_tc_skip("symlinks not supported by file system")
57 md(char *buf, const char *base, const char *tail)
60 sprintf(buf, "%s/%s", base, tail);
65 lookup_simple(const atf_tc_t *tc, const char *mountpath)
67 char pb[MAXPATHLEN], final[MAXPATHLEN];
70 strcpy(final, mountpath);
71 sprintf(pb, "%s/../%s", mountpath, basename(final));
72 if (rump_sys_stat(pb, &sb1) == -1)
73 atf_tc_fail_errno("stat 1");
75 sprintf(pb, "%s/./../%s", mountpath, basename(final));
76 if (rump_sys_stat(pb, &sb2) == -1)
77 atf_tc_fail_errno("stat 2");
79 ATF_REQUIRE(memcmp(&sb1, &sb2, sizeof(sb1)) == 0);
83 lookup_complex(const atf_tc_t *tc, const char *mountpath)
91 atf_tc_expect_fail("PR kern/49033");
93 sprintf(pb, "%s/dir", mountpath);
94 if (rump_sys_mkdir(pb, 0777) == -1)
95 atf_tc_fail_errno("mkdir");
96 if (rump_sys_stat(pb, &sb1) == -1)
97 atf_tc_fail_errno("stat 1");
99 sprintf(pb, "%s/./dir/../././dir/.", mountpath);
100 if (rump_sys_stat(pb, &sb2) == -1)
101 atf_tc_fail_errno("stat 2");
103 if (memcmp(&sb1, &sb2, sizeof(sb1)) != 0) {
104 printf("what\tsb1\t\tsb2\n");
107 printf(#FN "\t%lld\t%lld\n", \
108 (long long)sb1.FN, (long long)sb2.FN)
110 printf(#FN "\t%lld.%ld\t%lld.%ld\n", \
111 (long long)sb1.FN.tv_sec, sb1.FN.tv_nsec, \
112 (long long)sb2.FN.tv_sec, sb2.FN.tv_nsec)
133 atf_tc_fail("stat results differ, see ouput for more details");
136 atf_tc_fail("random failure of PR kern/49033 "
137 "did not happen this time");
141 dir_simple(const atf_tc_t *tc, const char *mountpath)
148 /* check we can create directories */
149 sprintf(pb, "%s/dir", mountpath);
150 if (rump_sys_mkdir(pb, 0777) == -1)
151 atf_tc_fail_errno("mkdir");
152 if (rump_sys_stat(pb, &sb) == -1)
153 atf_tc_fail_errno("stat new directory");
155 /* check we can remove then and that it makes them unreachable */
156 if (rump_sys_rmdir(pb) == -1)
157 atf_tc_fail_errno("rmdir");
158 if (rump_sys_stat(pb, &sb) != -1 || errno != ENOENT)
159 atf_tc_fail("ENOENT expected from stat");
163 dir_notempty(const atf_tc_t *tc, const char *mountpath)
165 char pb[MAXPATHLEN], pb2[MAXPATHLEN];
170 /* check we can create directories */
171 sprintf(pb, "%s/dir", mountpath);
172 if (rump_sys_mkdir(pb, 0777) == -1)
173 atf_tc_fail_errno("mkdir");
175 sprintf(pb2, "%s/dir/file", mountpath);
176 fd = rump_sys_open(pb2, O_RDWR | O_CREAT, 0777);
178 atf_tc_fail_errno("create file");
181 rv = rump_sys_rmdir(pb);
183 atf_tc_expect_fail("PR kern/47656: Test known to be broken");
184 if (rv != -1 || errno != ENOTEMPTY)
185 atf_tc_fail("non-empty directory removed succesfully");
187 if (rump_sys_unlink(pb2) == -1)
188 atf_tc_fail_errno("cannot remove dir/file");
190 if (rump_sys_rmdir(pb) == -1)
191 atf_tc_fail_errno("remove directory");
195 dir_rmdirdotdot(const atf_tc_t *tc, const char *mp)
203 RL(rump_sys_mkdir("test", 0777));
204 RL(rump_sys_chdir("test"));
206 RL(rump_sys_mkdir("subtest", 0777));
207 RL(rump_sys_chdir("subtest"));
209 md(pb, mp, "test/subtest");
210 RL(rump_sys_rmdir(pb));
212 RL(rump_sys_rmdir(pb));
218 ATF_REQUIRE_ERRNO(xerrno, rump_sys_chdir("..") == -1);
223 checkfile(const char *path, struct stat *refp)
225 char buf[MAXPATHLEN];
229 md(buf, path, "file");
230 if (rump_sys_stat(buf, &sb) == -1)
231 atf_tc_fail_errno("cannot stat file %d (%s)", n, buf);
232 if (memcmp(&sb, refp, sizeof(sb)) != 0)
233 atf_tc_fail("stat mismatch %d", n);
238 rename_dir(const atf_tc_t *tc, const char *mp)
240 char pb1[MAXPATHLEN], pb2[MAXPATHLEN], pb3[MAXPATHLEN];
243 if (FSTYPE_RUMPFS(tc))
244 atf_tc_skip("rename not supported by file system");
249 if (rump_sys_mkdir(pb1, 0777) == -1)
250 atf_tc_fail_errno("mkdir 1");
253 if (rump_sys_mkdir(pb2, 0777) == -1)
254 atf_tc_fail_errno("mkdir 2");
255 md(pb2, mp, "dir2/subdir");
256 if (rump_sys_mkdir(pb2, 0777) == -1)
257 atf_tc_fail_errno("mkdir 3");
259 md(pb3, mp, "dir1/file");
260 if (rump_sys_mknod(pb3, S_IFREG | 0777, -1) == -1)
261 atf_tc_fail_errno("create file");
262 if (rump_sys_stat(pb3, &ref) == -1)
263 atf_tc_fail_errno("stat of file");
266 * First try ops which should succeed.
269 /* rename within directory */
271 if (rump_sys_rename(pb1, pb3) == -1)
272 atf_tc_fail_errno("rename 1");
273 checkfile(pb3, &ref);
275 /* rename directory onto itself (two ways, should fail) */
276 md(pb1, mp, "dir3/.");
277 if (rump_sys_rename(pb1, pb3) != -1 || errno != EINVAL)
278 atf_tc_fail_errno("rename 2");
280 atf_tc_expect_fail("PR kern/47656: Test known to be broken");
281 if (rump_sys_rename(pb3, pb1) != -1 || errno != EISDIR)
282 atf_tc_fail_errno("rename 3");
284 checkfile(pb3, &ref);
286 /* rename father of directory into directory */
287 md(pb1, mp, "dir2/dir");
289 if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL)
290 atf_tc_fail_errno("rename 4");
292 /* same for grandfather */
293 md(pb1, mp, "dir2/subdir/dir2");
294 if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL)
295 atf_tc_fail("rename 5");
297 checkfile(pb3, &ref);
299 /* rename directory over a non-empty directory */
300 if (rump_sys_rename(pb2, pb3) != -1 || errno != ENOTEMPTY)
301 atf_tc_fail("rename 6");
303 /* cross-directory rename */
305 md(pb2, mp, "dir2/somedir");
306 if (rump_sys_rename(pb1, pb2) == -1)
307 atf_tc_fail_errno("rename 7");
308 checkfile(pb2, &ref);
310 /* move to parent directory */
311 md(pb1, mp, "dir2/somedir/../../dir3");
312 if (rump_sys_rename(pb2, pb1) == -1)
313 atf_tc_fail_errno("rename 8");
314 md(pb1, mp, "dir2/../dir3");
315 checkfile(pb1, &ref);
317 /* atomic cross-directory rename */
318 md(pb3, mp, "dir2/subdir");
319 if (rump_sys_rename(pb1, pb3) == -1)
320 atf_tc_fail_errno("rename 9");
321 checkfile(pb3, &ref);
323 /* rename directory over an empty directory */
324 md(pb1, mp, "parent");
325 md(pb2, mp, "parent/dir1");
326 md(pb3, mp, "parent/dir2");
327 RL(rump_sys_mkdir(pb1, 0777));
328 RL(rump_sys_mkdir(pb2, 0777));
329 RL(rump_sys_mkdir(pb3, 0777));
330 RL(rump_sys_rename(pb2, pb3));
332 RL(rump_sys_stat(pb1, &sb));
333 if (! FSTYPE_MSDOS(tc))
334 ATF_CHECK_EQ(sb.st_nlink, 3);
335 RL(rump_sys_rmdir(pb3));
336 RL(rump_sys_rmdir(pb1));
340 rename_dotdot(const atf_tc_t *tc, const char *mp)
343 if (FSTYPE_RUMPFS(tc))
344 atf_tc_skip("rename not supported by file system");
348 if (rump_sys_chdir(mp) == -1)
349 atf_tc_fail_errno("chdir mountpoint");
351 if (rump_sys_mkdir("dir1", 0777) == -1)
352 atf_tc_fail_errno("mkdir 1");
353 if (rump_sys_mkdir("dir2", 0777) == -1)
354 atf_tc_fail_errno("mkdir 2");
356 if (rump_sys_rename("dir1", "dir1/..") != -1 || errno != EINVAL)
357 atf_tc_fail_errno("self-dotdot to");
359 if (rump_sys_rename("dir1/..", "sometarget") != -1 || errno != EINVAL)
360 atf_tc_fail_errno("self-dotdot from");
362 if (rump_sys_rename("dir1", "dir2/..") != -1 || errno != EINVAL)
363 atf_tc_fail("other-dotdot");
369 rename_reg_nodir(const atf_tc_t *tc, const char *mp)
375 if (FSTYPE_RUMPFS(tc))
376 atf_tc_skip("rename not supported by file system");
378 if (rump_sys_chdir(mp) == -1)
379 atf_tc_fail_errno("chdir mountpoint");
381 if (FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))
386 if (rump_sys_mknod("file1", S_IFREG | 0777, -1) == -1)
387 atf_tc_fail_errno("create file");
388 if (rump_sys_mknod("file2", S_IFREG | 0777, -1) == -1)
389 atf_tc_fail_errno("create file");
391 if (rump_sys_stat("file1", &sb) == -1)
392 atf_tc_fail_errno("stat");
396 if (rump_sys_link("file1", "file_link") == -1)
397 atf_tc_fail_errno("link");
398 if (rump_sys_stat("file_link", &sb) == -1)
399 atf_tc_fail_errno("stat");
400 ATF_REQUIRE_EQ(sb.st_ino, f1ino);
401 ATF_REQUIRE_EQ(sb.st_nlink, 2);
404 if (rump_sys_stat("file2", &sb) == -1)
405 atf_tc_fail_errno("stat");
407 if (rump_sys_rename("file1", "file3") == -1)
408 atf_tc_fail_errno("rename 1");
409 if (rump_sys_stat("file3", &sb) == -1)
410 atf_tc_fail_errno("stat 1");
412 ATF_REQUIRE_EQ(sb.st_ino, f1ino);
414 if (rump_sys_stat("file1", &sb) != -1 || errno != ENOENT)
415 atf_tc_fail_errno("source 1");
417 if (rump_sys_rename("file3", "file2") == -1)
418 atf_tc_fail_errno("rename 2");
419 if (rump_sys_stat("file2", &sb) == -1)
420 atf_tc_fail_errno("stat 2");
422 ATF_REQUIRE_EQ(sb.st_ino, f1ino);
425 if (rump_sys_stat("file3", &sb) != -1 || errno != ENOENT)
426 atf_tc_fail_errno("source 2");
429 if (rump_sys_rename("file2", "file_link") == -1)
430 atf_tc_fail_errno("rename hardlink");
431 if (rump_sys_stat("file2", &sb) != -1 || errno != ENOENT)
432 atf_tc_fail_errno("source 3");
433 if (rump_sys_stat("file_link", &sb) == -1)
434 atf_tc_fail_errno("stat 2");
435 ATF_REQUIRE_EQ(sb.st_ino, f1ino);
436 ATF_REQUIRE_EQ(sb.st_nlink, 1);
439 ATF_CHECK_ERRNO(EFAULT, rump_sys_rename("file2", NULL) == -1);
440 ATF_CHECK_ERRNO(EFAULT, rump_sys_rename(NULL, "file2") == -1);
446 create_nametoolong(const atf_tc_t *tc, const char *mp)
453 if (rump_sys_chdir(mp) == -1)
454 atf_tc_fail_errno("chdir mountpoint");
456 val = rump_sys_pathconf(".", _PC_NAME_MAX);
458 atf_tc_fail_errno("pathconf");
461 name = malloc(len+1);
463 atf_tc_fail_errno("malloc");
465 memset(name, 'a', len);
468 val = rump_sys_pathconf(".", _PC_NO_TRUNC);
470 atf_tc_fail_errno("pathconf");
472 fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666);
473 if (val != 0 && (fd != -1 || errno != ENAMETOOLONG))
474 atf_tc_fail_errno("open");
476 if (val == 0 && rump_sys_close(fd) == -1)
477 atf_tc_fail_errno("close");
478 if (val == 0 && rump_sys_unlink(name) == -1)
479 atf_tc_fail_errno("unlink");
487 create_exist(const atf_tc_t *tc, const char *mp)
489 const char *name = "hoge";
492 RL(rump_sys_chdir(mp));
493 RL(fd = rump_sys_open(name, O_RDWR|O_CREAT|O_EXCL, 0666));
494 RL(rump_sys_close(fd));
495 RL(rump_sys_unlink(name));
496 RL(fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666));
497 RL(rump_sys_close(fd));
498 RL(fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666));
499 RL(rump_sys_close(fd));
500 ATF_REQUIRE_ERRNO(EEXIST,
501 (fd = rump_sys_open(name, O_RDWR|O_CREAT|O_EXCL, 0666)));
502 RL(rump_sys_unlink(name));
503 RL(rump_sys_chdir("/"));
507 rename_nametoolong(const atf_tc_t *tc, const char *mp)
514 if (FSTYPE_RUMPFS(tc))
515 atf_tc_skip("rename not supported by file system");
517 if (rump_sys_chdir(mp) == -1)
518 atf_tc_fail_errno("chdir mountpoint");
520 val = rump_sys_pathconf(".", _PC_NAME_MAX);
522 atf_tc_fail_errno("pathconf");
525 name = malloc(len+1);
527 atf_tc_fail_errno("malloc");
529 memset(name, 'a', len);
532 fd = rump_sys_open("dummy", O_RDWR|O_CREAT, 0666);
534 atf_tc_fail_errno("open");
535 if (rump_sys_close(fd) == -1)
536 atf_tc_fail_errno("close");
538 val = rump_sys_pathconf(".", _PC_NO_TRUNC);
540 atf_tc_fail_errno("pathconf");
542 res = rump_sys_rename("dummy", name);
543 if (val != 0 && (res != -1 || errno != ENAMETOOLONG))
544 atf_tc_fail_errno("rename");
546 if (val == 0 && rump_sys_unlink(name) == -1)
547 atf_tc_fail_errno("unlink");
555 * Test creating a symlink whose length is "len" bytes, not including
556 * the terminating NUL.
559 symlink_len(const atf_tc_t *tc, const char *mp, size_t len)
566 RL(rump_sys_chdir(mp));
568 buf = malloc(len + 1);
570 memset(buf, 'a', len);
572 r = rump_sys_symlink(buf, "afile");
574 ATF_REQUIRE_ERRNO(ENAMETOOLONG, r);
576 RL(rump_sys_unlink("afile"));
580 RL(rump_sys_chdir("/"));
584 symlink_zerolen(const atf_tc_t *tc, const char *mp)
586 symlink_len(tc, mp, 0);
590 symlink_long(const atf_tc_t *tc, const char *mp)
593 * Test lengths close to powers of two, as those are likely
598 for (len = 2; len <= 65536; len *= 2) {
599 for (fuzz = -1; fuzz <= 1; fuzz++) {
600 symlink_len(tc, mp, len + fuzz);
606 symlink_root(const atf_tc_t *tc, const char *mp)
611 RL(rump_sys_chdir(mp));
612 RL(rump_sys_symlink("/", "foo"));
613 RL(rump_sys_chdir("foo"));
617 attrs(const atf_tc_t *tc, const char *mp)
620 struct timeval tv[2];
624 RL(fd = rump_sys_open(TESTFILE, O_RDWR | O_CREAT, 0755));
625 RL(rump_sys_close(fd));
626 RL(rump_sys_stat(TESTFILE, &sb));
627 if (!(FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))) {
628 RL(rump_sys_chown(TESTFILE, 1, 2));
631 RL(rump_sys_chmod(TESTFILE, 0123));
632 sb.st_mode = (sb.st_mode & ~ACCESSPERMS) | 0123;
635 tv[0].tv_sec = 1000000000; /* need something >1980 for msdosfs */
637 tv[1].tv_sec = 1000000002; /* need even seconds for msdosfs */
639 RL(rump_sys_utimes(TESTFILE, tv));
640 RL(rump_sys_utimes(TESTFILE, tv)); /* XXX: utimes & birthtime */
641 sb.st_atimespec.tv_sec = 1000000000;
642 sb.st_atimespec.tv_nsec = 1000;
643 sb.st_mtimespec.tv_sec = 1000000002;
644 sb.st_mtimespec.tv_nsec = 3000;
646 RL(rump_sys_stat(TESTFILE, &sb2));
647 #define CHECK(a) ATF_REQUIRE_EQ(sb.a, sb2.a)
649 atf_tc_expect_fail("PR kern/47656: Test known to be broken");
650 if (!(FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))) {
655 if (!FSTYPE_MSDOS(tc)) {
656 /* msdosfs has only access date, not time */
657 CHECK(st_atimespec.tv_sec);
659 CHECK(st_mtimespec.tv_sec);
660 if (!(FSTYPE_EXT2FS(tc) || FSTYPE_MSDOS(tc) ||
661 FSTYPE_SYSVBFS(tc) || FSTYPE_V7FS(tc))) {
662 CHECK(st_atimespec.tv_nsec);
663 CHECK(st_mtimespec.tv_nsec);
671 fcntl_lock(const atf_tc_t *tc, const char *mp)
675 struct lwp *lwp1, *lwp2;
679 l.l_start = l.l_len = 1024;
680 l.l_type = F_RDLCK | F_WRLCK;
681 l.l_whence = SEEK_END;
683 lwp1 = rump_pub_lwproc_curlwp();
684 RL(fd = rump_sys_open(TESTFILE, O_RDWR | O_CREAT, 0755));
685 RL(rump_sys_ftruncate(fd, 8192));
689 atf_tc_expect_fail("PR kern/47656: Test known to be broken");
690 RL(rump_sys_fcntl(fd, F_SETLK, &l));
692 /* Next, we fork and try to lock the same area */
693 RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
694 lwp2 = rump_pub_lwproc_curlwp();
695 RL(fd2 = rump_sys_open(TESTFILE, O_RDWR, 0));
696 ATF_REQUIRE_ERRNO(EAGAIN, rump_sys_fcntl(fd2, F_SETLK, &l));
698 /* Switch back and unlock... */
699 rump_pub_lwproc_switch(lwp1);
701 RL(rump_sys_fcntl(fd, F_SETLK, &l));
703 /* ... and try to lock again */
704 rump_pub_lwproc_switch(lwp2);
705 l.l_type = F_RDLCK | F_WRLCK;
706 RL(rump_sys_fcntl(fd2, F_SETLK, &l));
708 RL(rump_sys_close(fd2));
709 rump_pub_lwproc_releaselwp();
711 RL(rump_sys_close(fd));
717 flock_compare(const void *p, const void *q)
719 int a = ((const struct flock *)p)->l_start;
720 int b = ((const struct flock *)q)->l_start;
721 return a < b ? -1 : (a > b ? 1 : 0);
725 * Find all locks set by fcntl_getlock_pids test
726 * using GETLK for a range [start, start+end], and,
727 * if there is a blocking lock, recursively find
728 * all locks to the left (toward the beginning of
729 * a file) and to the right of the lock.
730 * The function also understands "until end of file"
731 * convention when len==0.
734 fcntl_getlocks(int fildes, off_t start, off_t len,
735 struct flock *lock, struct flock *end)
738 const struct flock l = { start, len, 0, F_RDLCK, SEEK_SET };
743 RL(rump_sys_fcntl(fildes, F_GETLK, &l));
745 if (l.l_type == F_UNLCK)
751 ATF_REQUIRE(l.l_whence == SEEK_SET);
753 if (l.l_start > start) {
755 fcntl_getlocks(fildes, start, l.l_start - start, lock, end);
762 if (l.l_len == 0) /* does l spans until the end? */
765 if (len == 0) /* are we looking for locks until the end? */ {
766 rv += fcntl_getlocks(fildes, l.l_start + l.l_len, len, lock, end);
767 } else if (l.l_start + l.l_len < start + len) {
768 len -= l.l_start + l.l_len - start;
769 rv += fcntl_getlocks(fildes, l.l_start + l.l_len, len, lock, end);
776 fcntl_getlock_pids(const atf_tc_t *tc, const char *mp)
778 /* test non-overlaping ranges */
779 struct flock expect[4];
780 const struct flock lock[4] = {
781 { 0, 2, 0, F_WRLCK, SEEK_SET },
782 { 2, 1, 0, F_WRLCK, SEEK_SET },
783 { 7, 5, 0, F_WRLCK, SEEK_SET },
784 { 4, 3, 0, F_WRLCK, SEEK_SET },
787 /* Add extra element to make sure recursion does't stop at array end */
788 struct flock result[5];
790 /* Add 5th process */
796 const off_t sz = 8192;
798 int oflags = O_RDWR | O_CREAT;
800 memcpy(expect, lock, sizeof(lock));
805 * First, we create 4 processes and let each lock a range of the
806 * file. Note that the third and fourth processes lock in
807 * "reverse" order, i.e. the greater pid locks a range before
809 * Then, we create 5th process which doesn't lock anything.
811 for (i = 0; i < __arraycount(lwp); i++) {
812 RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
814 lwp[i] = rump_pub_lwproc_curlwp();
815 pid[i] = rump_sys_getpid();
817 RL(fd[i] = rump_sys_open(TESTFILE, oflags, omode));
821 RL(rump_sys_ftruncate(fd[i], sz));
824 atf_tc_expect_fail("PR kern/47656: Test known to be "
826 if (i < __arraycount(lock)) {
827 RL(rump_sys_fcntl(fd[i], F_SETLK, &lock[i]));
828 expect[i].l_pid = pid[i];
832 qsort(expect, __arraycount(expect), sizeof(expect[0]), &flock_compare);
835 * In the context of each process, recursively find all locks
836 * that would block the current process. Processes 1-4 don't
837 * see their own lock, we insert it to simplify checks.
838 * Process 5 sees all 4 locks.
840 for (i = 0; i < __arraycount(lwp); i++) {
843 rump_pub_lwproc_switch(lwp[i]);
845 memset(result, 0, sizeof(result));
846 nlocks = fcntl_getlocks(fd[i], 0, sz,
847 result, result + __arraycount(result));
849 if (i < __arraycount(lock)) {
850 ATF_REQUIRE(nlocks < __arraycount(result));
851 result[nlocks] = lock[i];
852 result[nlocks].l_pid = pid[i];
856 ATF_CHECK_EQ(nlocks, __arraycount(expect));
858 qsort(result, nlocks, sizeof(result[0]), &flock_compare);
860 for (j = 0; j < nlocks; j++) {
861 ATF_CHECK_EQ(result[j].l_start, expect[j].l_start );
862 ATF_CHECK_EQ(result[j].l_len, expect[j].l_len );
863 ATF_CHECK_EQ(result[j].l_pid, expect[j].l_pid );
864 ATF_CHECK_EQ(result[j].l_type, expect[j].l_type );
865 ATF_CHECK_EQ(result[j].l_whence, expect[j].l_whence);
870 * Release processes. This also releases the fds and locks
871 * making fs unmount possible
873 for (i = 0; i < __arraycount(lwp); i++) {
874 rump_pub_lwproc_switch(lwp[i]);
875 rump_pub_lwproc_releaselwp();
882 access_simple(const atf_tc_t *tc, const char *mp)
888 RL(fd = rump_sys_open("tfile", O_CREAT | O_RDWR, 0777));
889 RL(rump_sys_close(fd));
891 #define ALLACC (F_OK | X_OK | W_OK | R_OK)
892 if (FSTYPE_SYSVBFS(tc) || FSTYPE_MSDOS(tc))
897 RL(rump_sys_access("tfile", tmode));
900 ATF_REQUIRE_ERRNO(EINVAL, rump_sys_access("tfile", ALLACC+1) == -1);
906 read_directory(const atf_tc_t *tc, const char *mp)
913 fd = rump_sys_open(".", O_DIRECTORY | O_RDONLY, 0777);
914 ATF_REQUIRE(fd != -1);
916 size = rump_sys_pread(fd, buf, sizeof(buf), 0);
917 ATF_CHECK(size != -1 || errno == EISDIR);
918 size = rump_sys_read(fd, buf, sizeof(buf));
919 ATF_CHECK(size != -1 || errno == EISDIR);
921 res = rump_sys_close(fd);
922 ATF_REQUIRE(res != -1);
927 lstat_symlink(const atf_tc_t *tc, const char *mp)
929 const char *src, *dst;
936 atf_tc_expect_fail("PR kern/48864");
943 res = rump_sys_symlink(src, dst);
944 ATF_REQUIRE(res != -1);
945 res = rump_sys_lstat(dst, &st);
946 ATF_REQUIRE(res != -1);
948 ATF_CHECK(S_ISLNK(st.st_mode) != 0);
949 ATF_CHECK(st.st_size == (off_t)strlen(src));
954 ATF_TC_FSAPPLY(lookup_simple, "simple lookup (./.. on root)");
955 ATF_TC_FSAPPLY(lookup_complex, "lookup of non-dot entries");
956 ATF_TC_FSAPPLY(dir_simple, "mkdir/rmdir");
957 ATF_TC_FSAPPLY(dir_notempty, "non-empty directories cannot be removed");
958 ATF_TC_FSAPPLY(dir_rmdirdotdot, "remove .. and try to cd out (PR kern/44657)");
959 ATF_TC_FSAPPLY(rename_dir, "exercise various directory renaming ops "
961 ATF_TC_FSAPPLY(rename_dotdot, "rename dir .. (PR kern/43617)");
962 ATF_TC_FSAPPLY(rename_reg_nodir, "rename regular files, no subdirectories");
963 ATF_TC_FSAPPLY(create_nametoolong, "create file with name too long");
964 ATF_TC_FSAPPLY(create_exist, "create with O_EXCL");
965 ATF_TC_FSAPPLY(rename_nametoolong, "rename to file with name too long");
966 ATF_TC_FSAPPLY(symlink_zerolen, "symlink with target of length 0");
967 ATF_TC_FSAPPLY(symlink_long, "symlink with target of length > 0");
968 ATF_TC_FSAPPLY(symlink_root, "symlink to root directory");
969 ATF_TC_FSAPPLY(attrs, "check setting attributes works");
970 ATF_TC_FSAPPLY(fcntl_lock, "check fcntl F_SETLK");
971 ATF_TC_FSAPPLY(fcntl_getlock_pids,"fcntl F_GETLK w/ many procs, PR kern/44494");
972 ATF_TC_FSAPPLY(access_simple, "access(2)");
973 ATF_TC_FSAPPLY(read_directory, "read(2) on directories");
974 ATF_TC_FSAPPLY(lstat_symlink, "lstat(2) values for symbolic links");
979 ATF_TP_FSAPPLY(lookup_simple);
980 ATF_TP_FSAPPLY(lookup_complex);
981 ATF_TP_FSAPPLY(dir_simple);
982 ATF_TP_FSAPPLY(dir_notempty);
983 ATF_TP_FSAPPLY(dir_rmdirdotdot);
984 ATF_TP_FSAPPLY(rename_dir);
985 ATF_TP_FSAPPLY(rename_dotdot);
986 ATF_TP_FSAPPLY(rename_reg_nodir);
987 ATF_TP_FSAPPLY(create_nametoolong);
988 ATF_TP_FSAPPLY(create_exist);
989 ATF_TP_FSAPPLY(rename_nametoolong);
990 ATF_TP_FSAPPLY(symlink_zerolen);
991 ATF_TP_FSAPPLY(symlink_long);
992 ATF_TP_FSAPPLY(symlink_root);
993 ATF_TP_FSAPPLY(attrs);
994 ATF_TP_FSAPPLY(fcntl_lock);
995 ATF_TP_FSAPPLY(fcntl_getlock_pids);
996 ATF_TP_FSAPPLY(access_simple);
997 ATF_TP_FSAPPLY(read_directory);
998 ATF_TP_FSAPPLY(lstat_symlink);
1000 return atf_no_error();