Home | History | Annotate | Line # | Download | only in vfs
t_vnops.c revision 1.12.2.2
      1  1.12.2.2  bouyer /*	$NetBSD: t_vnops.c,v 1.12.2.2 2011/03/05 15:10:55 bouyer Exp $	*/
      2       1.1   pooka 
      3       1.1   pooka /*-
      4       1.1   pooka  * Copyright (c) 2010 The NetBSD Foundation, Inc.
      5       1.1   pooka  * All rights reserved.
      6       1.1   pooka  *
      7       1.1   pooka  * Redistribution and use in source and binary forms, with or without
      8       1.1   pooka  * modification, are permitted provided that the following conditions
      9       1.1   pooka  * are met:
     10       1.1   pooka  * 1. Redistributions of source code must retain the above copyright
     11       1.1   pooka  *    notice, this list of conditions and the following disclaimer.
     12       1.1   pooka  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1   pooka  *    notice, this list of conditions and the following disclaimer in the
     14       1.1   pooka  *    documentation and/or other materials provided with the distribution.
     15       1.1   pooka  *
     16       1.1   pooka  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17       1.1   pooka  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18       1.1   pooka  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19       1.1   pooka  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20       1.1   pooka  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21       1.1   pooka  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22       1.1   pooka  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23       1.1   pooka  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24       1.1   pooka  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25       1.1   pooka  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26       1.1   pooka  * POSSIBILITY OF SUCH DAMAGE.
     27       1.1   pooka  */
     28       1.1   pooka 
     29       1.1   pooka #include <sys/stat.h>
     30       1.1   pooka #include <sys/statvfs.h>
     31       1.1   pooka 
     32  1.12.2.1  bouyer #include <assert.h>
     33       1.1   pooka #include <atf-c.h>
     34       1.1   pooka #include <fcntl.h>
     35       1.1   pooka #include <libgen.h>
     36       1.5   njoly #include <stdlib.h>
     37  1.12.2.1  bouyer #include <string.h>
     38       1.1   pooka #include <unistd.h>
     39       1.1   pooka 
     40       1.1   pooka #include <rump/rump_syscalls.h>
     41       1.1   pooka #include <rump/rump.h>
     42       1.1   pooka 
     43       1.1   pooka #include "../common/h_fsmacros.h"
     44       1.1   pooka #include "../../h_macros.h"
     45       1.1   pooka 
     46      1.11   pooka #define TESTFILE "afile"
     47      1.11   pooka 
     48       1.1   pooka #define USES_DIRS \
     49       1.1   pooka     if (FSTYPE_SYSVBFS(tc)) atf_tc_skip("dirs not supported by file system")
     50       1.1   pooka 
     51       1.7   pooka #define USES_SYMLINKS					\
     52       1.7   pooka     if (FSTYPE_SYSVBFS(tc) || FSTYPE_MSDOS(tc))		\
     53       1.9   njoly 	atf_tc_skip("symlinks not supported by file system")
     54       1.7   pooka 
     55       1.2   pooka static char *
     56       1.2   pooka md(char *buf, const char *base, const char *tail)
     57       1.2   pooka {
     58       1.2   pooka 
     59       1.2   pooka 	sprintf(buf, "%s/%s", base, tail);
     60       1.2   pooka 	return buf;
     61       1.2   pooka }
     62       1.2   pooka 
     63       1.1   pooka static void
     64       1.1   pooka lookup_simple(const atf_tc_t *tc, const char *mountpath)
     65       1.1   pooka {
     66       1.1   pooka 	char pb[MAXPATHLEN], final[MAXPATHLEN];
     67       1.1   pooka 	struct stat sb1, sb2;
     68       1.1   pooka 
     69       1.1   pooka 	strcpy(final, mountpath);
     70       1.1   pooka 	sprintf(pb, "%s/../%s", mountpath, basename(final));
     71       1.1   pooka 	if (rump_sys_stat(pb, &sb1) == -1)
     72       1.1   pooka 		atf_tc_fail_errno("stat 1");
     73       1.1   pooka 
     74       1.1   pooka 	sprintf(pb, "%s/./../%s", mountpath, basename(final));
     75       1.1   pooka 	if (rump_sys_stat(pb, &sb2) == -1)
     76       1.1   pooka 		atf_tc_fail_errno("stat 2");
     77       1.1   pooka 
     78       1.1   pooka 	ATF_REQUIRE(memcmp(&sb1, &sb2, sizeof(sb1)) == 0);
     79       1.1   pooka }
     80       1.1   pooka 
     81       1.1   pooka static void
     82       1.1   pooka lookup_complex(const atf_tc_t *tc, const char *mountpath)
     83       1.1   pooka {
     84       1.1   pooka 	char pb[MAXPATHLEN];
     85       1.1   pooka 	struct stat sb1, sb2;
     86       1.1   pooka 
     87       1.1   pooka 	USES_DIRS;
     88       1.1   pooka 
     89       1.1   pooka 	sprintf(pb, "%s/dir", mountpath);
     90       1.1   pooka 	if (rump_sys_mkdir(pb, 0777) == -1)
     91       1.1   pooka 		atf_tc_fail_errno("mkdir");
     92       1.1   pooka 	if (rump_sys_stat(pb, &sb1) == -1)
     93       1.1   pooka 		atf_tc_fail_errno("stat 1");
     94       1.1   pooka 
     95       1.1   pooka 	sprintf(pb, "%s/./dir/../././dir/.", mountpath);
     96       1.1   pooka 	if (rump_sys_stat(pb, &sb2) == -1)
     97       1.1   pooka 		atf_tc_fail_errno("stat 2");
     98       1.1   pooka 
     99       1.1   pooka 	ATF_REQUIRE(memcmp(&sb1, &sb2, sizeof(sb1)) == 0);
    100       1.1   pooka }
    101       1.1   pooka 
    102       1.1   pooka static void
    103       1.1   pooka dir_simple(const atf_tc_t *tc, const char *mountpath)
    104       1.1   pooka {
    105       1.1   pooka 	char pb[MAXPATHLEN];
    106       1.1   pooka 	struct stat sb;
    107       1.1   pooka 
    108       1.1   pooka 	USES_DIRS;
    109       1.1   pooka 
    110       1.1   pooka 	/* check we can create directories */
    111       1.1   pooka 	sprintf(pb, "%s/dir", mountpath);
    112       1.1   pooka 	if (rump_sys_mkdir(pb, 0777) == -1)
    113       1.1   pooka 		atf_tc_fail_errno("mkdir");
    114       1.1   pooka 	if (rump_sys_stat(pb, &sb) == -1)
    115       1.1   pooka 		atf_tc_fail_errno("stat new directory");
    116       1.1   pooka 
    117       1.1   pooka 	/* check we can remove then and that it makes them unreachable */
    118       1.1   pooka 	if (rump_sys_rmdir(pb) == -1)
    119       1.1   pooka 		atf_tc_fail_errno("rmdir");
    120       1.1   pooka 	if (rump_sys_stat(pb, &sb) != -1 || errno != ENOENT)
    121       1.1   pooka 		atf_tc_fail("ENOENT expected from stat");
    122       1.1   pooka }
    123       1.1   pooka 
    124       1.1   pooka static void
    125       1.1   pooka dir_notempty(const atf_tc_t *tc, const char *mountpath)
    126       1.1   pooka {
    127       1.1   pooka 	char pb[MAXPATHLEN], pb2[MAXPATHLEN];
    128       1.1   pooka 	int fd, rv;
    129       1.1   pooka 
    130       1.1   pooka 	USES_DIRS;
    131       1.1   pooka 
    132       1.1   pooka 	/* check we can create directories */
    133       1.1   pooka 	sprintf(pb, "%s/dir", mountpath);
    134       1.1   pooka 	if (rump_sys_mkdir(pb, 0777) == -1)
    135       1.1   pooka 		atf_tc_fail_errno("mkdir");
    136       1.1   pooka 
    137       1.1   pooka 	sprintf(pb2, "%s/dir/file", mountpath);
    138       1.1   pooka 	fd = rump_sys_open(pb2, O_RDWR | O_CREAT, 0777);
    139       1.1   pooka 	if (fd == -1)
    140       1.1   pooka 		atf_tc_fail_errno("create file");
    141       1.1   pooka 	rump_sys_close(fd);
    142       1.1   pooka 
    143       1.1   pooka 	rv = rump_sys_rmdir(pb);
    144       1.1   pooka 	if (rv != -1 || errno != ENOTEMPTY)
    145       1.1   pooka 		atf_tc_fail("non-empty directory removed succesfully");
    146       1.1   pooka 
    147       1.1   pooka 	if (rump_sys_unlink(pb2) == -1)
    148       1.1   pooka 		atf_tc_fail_errno("cannot remove dir/file");
    149       1.1   pooka 
    150       1.1   pooka 	if (rump_sys_rmdir(pb) == -1)
    151       1.1   pooka 		atf_tc_fail_errno("remove directory");
    152       1.1   pooka }
    153       1.1   pooka 
    154       1.2   pooka static void
    155  1.12.2.2  bouyer dir_rmdirdotdot(const atf_tc_t *tc, const char *mp)
    156  1.12.2.2  bouyer {
    157  1.12.2.2  bouyer 	char pb[MAXPATHLEN];
    158  1.12.2.2  bouyer 	int xerrno;
    159  1.12.2.2  bouyer 
    160  1.12.2.2  bouyer 	USES_DIRS;
    161  1.12.2.2  bouyer 
    162  1.12.2.2  bouyer 	FSTEST_ENTER();
    163  1.12.2.2  bouyer 	RL(rump_sys_mkdir("test", 0777));
    164  1.12.2.2  bouyer 	RL(rump_sys_chdir("test"));
    165  1.12.2.2  bouyer 
    166  1.12.2.2  bouyer 	RL(rump_sys_mkdir("subtest", 0777));
    167  1.12.2.2  bouyer 	RL(rump_sys_chdir("subtest"));
    168  1.12.2.2  bouyer 
    169  1.12.2.2  bouyer 	md(pb, mp, "test/subtest");
    170  1.12.2.2  bouyer 	RL(rump_sys_rmdir(pb));
    171  1.12.2.2  bouyer 	md(pb, mp, "test");
    172  1.12.2.2  bouyer 	RL(rump_sys_rmdir(pb));
    173  1.12.2.2  bouyer 
    174  1.12.2.2  bouyer 	if (FSTYPE_NFS(tc))
    175  1.12.2.2  bouyer 		xerrno = ESTALE;
    176  1.12.2.2  bouyer 	else
    177  1.12.2.2  bouyer 		xerrno = ENOENT;
    178  1.12.2.2  bouyer 	if (FSTYPE_TMPFS(tc))
    179  1.12.2.2  bouyer 		atf_tc_expect_signal(-1, "PR kern/44657");
    180  1.12.2.2  bouyer 	ATF_REQUIRE_ERRNO(xerrno, rump_sys_chdir("..") == -1);
    181  1.12.2.2  bouyer 	FSTEST_EXIT();
    182  1.12.2.2  bouyer }
    183  1.12.2.2  bouyer 
    184  1.12.2.2  bouyer static void
    185       1.2   pooka checkfile(const char *path, struct stat *refp)
    186       1.2   pooka {
    187       1.2   pooka 	char buf[MAXPATHLEN];
    188       1.2   pooka 	struct stat sb;
    189       1.2   pooka 	static int n = 1;
    190       1.2   pooka 
    191       1.2   pooka 	md(buf, path, "file");
    192       1.2   pooka 	if (rump_sys_stat(buf, &sb) == -1)
    193       1.2   pooka 		atf_tc_fail_errno("cannot stat file %d (%s)", n, buf);
    194       1.2   pooka 	if (memcmp(&sb, refp, sizeof(sb)) != 0)
    195       1.2   pooka 		atf_tc_fail("stat mismatch %d", n);
    196       1.2   pooka 	n++;
    197       1.2   pooka }
    198       1.2   pooka 
    199       1.2   pooka static void
    200       1.2   pooka rename_dir(const atf_tc_t *tc, const char *mp)
    201       1.2   pooka {
    202       1.2   pooka 	char pb1[MAXPATHLEN], pb2[MAXPATHLEN], pb3[MAXPATHLEN];
    203  1.12.2.2  bouyer 	struct stat ref, sb;
    204       1.3   pooka 
    205      1.10   pooka 	if (FSTYPE_RUMPFS(tc))
    206      1.10   pooka 		atf_tc_skip("rename not supported by fs");
    207      1.10   pooka 
    208       1.2   pooka 	USES_DIRS;
    209       1.2   pooka 
    210       1.2   pooka 	md(pb1, mp, "dir1");
    211       1.2   pooka 	if (rump_sys_mkdir(pb1, 0777) == -1)
    212       1.2   pooka 		atf_tc_fail_errno("mkdir 1");
    213       1.2   pooka 
    214       1.2   pooka 	md(pb2, mp, "dir2");
    215       1.2   pooka 	if (rump_sys_mkdir(pb2, 0777) == -1)
    216       1.2   pooka 		atf_tc_fail_errno("mkdir 2");
    217       1.2   pooka 	md(pb2, mp, "dir2/subdir");
    218       1.2   pooka 	if (rump_sys_mkdir(pb2, 0777) == -1)
    219       1.2   pooka 		atf_tc_fail_errno("mkdir 3");
    220       1.2   pooka 
    221       1.2   pooka 	md(pb3, mp, "dir1/file");
    222       1.2   pooka 	if (rump_sys_mknod(pb3, S_IFREG | 0777, -1) == -1)
    223       1.2   pooka 		atf_tc_fail_errno("create file");
    224       1.2   pooka 	if (rump_sys_stat(pb3, &ref) == -1)
    225       1.2   pooka 		atf_tc_fail_errno("stat of file");
    226       1.2   pooka 
    227       1.2   pooka 	/*
    228       1.2   pooka 	 * First try ops which should succeed.
    229       1.2   pooka 	 */
    230       1.2   pooka 
    231       1.2   pooka 	/* rename within directory */
    232       1.2   pooka 	md(pb3, mp, "dir3");
    233       1.2   pooka 	if (rump_sys_rename(pb1, pb3) == -1)
    234       1.2   pooka 		atf_tc_fail_errno("rename 1");
    235       1.2   pooka 	checkfile(pb3, &ref);
    236       1.2   pooka 
    237       1.2   pooka 	/* rename directory onto itself (two ways, should fail) */
    238       1.2   pooka 	md(pb1, mp, "dir3/.");
    239       1.2   pooka 	if (rump_sys_rename(pb1, pb3) != -1 || errno != EINVAL)
    240       1.2   pooka 		atf_tc_fail_errno("rename 2");
    241       1.2   pooka 	if (rump_sys_rename(pb3, pb1) != -1 || errno != EISDIR)
    242       1.2   pooka 		atf_tc_fail_errno("rename 3");
    243       1.2   pooka 
    244       1.2   pooka 	checkfile(pb3, &ref);
    245       1.2   pooka 
    246       1.2   pooka 	/* rename father of directory into directory */
    247       1.2   pooka 	md(pb1, mp, "dir2/dir");
    248       1.2   pooka 	md(pb2, mp, "dir2");
    249       1.2   pooka 	if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL)
    250       1.2   pooka 		atf_tc_fail_errno("rename 4");
    251       1.2   pooka 
    252       1.2   pooka 	/* same for grandfather */
    253       1.2   pooka 	md(pb1, mp, "dir2/subdir/dir2");
    254       1.2   pooka 	if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL)
    255       1.2   pooka 		atf_tc_fail("rename 5");
    256       1.2   pooka 
    257       1.2   pooka 	checkfile(pb3, &ref);
    258       1.2   pooka 
    259       1.2   pooka 	/* rename directory over a non-empty directory */
    260       1.2   pooka 	if (rump_sys_rename(pb2, pb3) != -1 || errno != ENOTEMPTY)
    261       1.2   pooka 		atf_tc_fail("rename 6");
    262       1.2   pooka 
    263       1.2   pooka 	/* cross-directory rename */
    264       1.2   pooka 	md(pb1, mp, "dir3");
    265       1.2   pooka 	md(pb2, mp, "dir2/somedir");
    266       1.2   pooka 	if (rump_sys_rename(pb1, pb2) == -1)
    267       1.2   pooka 		atf_tc_fail_errno("rename 7");
    268       1.2   pooka 	checkfile(pb2, &ref);
    269       1.2   pooka 
    270       1.2   pooka 	/* move to parent directory */
    271       1.2   pooka 	md(pb1, mp, "dir2/somedir/../../dir3");
    272       1.2   pooka 	if (rump_sys_rename(pb2, pb1) == -1)
    273       1.2   pooka 		atf_tc_fail_errno("rename 8");
    274       1.2   pooka 	md(pb1, mp, "dir2/../dir3");
    275       1.2   pooka 	checkfile(pb1, &ref);
    276       1.2   pooka 
    277  1.12.2.2  bouyer 	/* atomic cross-directory rename */
    278       1.2   pooka 	md(pb3, mp, "dir2/subdir");
    279       1.2   pooka 	if (rump_sys_rename(pb1, pb3) == -1)
    280       1.2   pooka 		atf_tc_fail_errno("rename 9");
    281       1.2   pooka 	checkfile(pb3, &ref);
    282  1.12.2.2  bouyer 
    283  1.12.2.2  bouyer 	/* rename directory over an empty directory */
    284  1.12.2.2  bouyer 	md(pb1, mp, "parent");
    285  1.12.2.2  bouyer 	md(pb2, mp, "parent/dir1");
    286  1.12.2.2  bouyer 	md(pb3, mp, "parent/dir2");
    287  1.12.2.2  bouyer 	RL(rump_sys_mkdir(pb1, 0777));
    288  1.12.2.2  bouyer 	RL(rump_sys_mkdir(pb2, 0777));
    289  1.12.2.2  bouyer 	RL(rump_sys_mkdir(pb3, 0777));
    290  1.12.2.2  bouyer 	RL(rump_sys_rename(pb2, pb3));
    291  1.12.2.2  bouyer 
    292  1.12.2.2  bouyer 	RL(rump_sys_stat(pb1, &sb));
    293  1.12.2.2  bouyer 	ATF_CHECK_EQ(sb.st_nlink, 3);
    294  1.12.2.2  bouyer 	RL(rump_sys_rmdir(pb3));
    295  1.12.2.2  bouyer 	if (FSTYPE_TMPFS(tc))
    296  1.12.2.2  bouyer 		atf_tc_expect_signal(-1, "PR kern/44288");
    297  1.12.2.2  bouyer 	RL(rump_sys_rmdir(pb1));
    298  1.12.2.2  bouyer 
    299  1.12.2.2  bouyer 	if (FSTYPE_MSDOS(tc))
    300  1.12.2.2  bouyer 		atf_tc_expect_fail("PR kern/44661");
    301       1.2   pooka }
    302       1.2   pooka 
    303       1.2   pooka static void
    304       1.2   pooka rename_dotdot(const atf_tc_t *tc, const char *mp)
    305       1.2   pooka {
    306       1.2   pooka 
    307      1.10   pooka 	if (FSTYPE_RUMPFS(tc))
    308      1.10   pooka 		atf_tc_skip("rename not supported by fs");
    309      1.10   pooka 
    310       1.2   pooka 	USES_DIRS;
    311       1.2   pooka 
    312       1.2   pooka 	if (rump_sys_chdir(mp) == -1)
    313       1.2   pooka 		atf_tc_fail_errno("chdir mountpoint");
    314       1.2   pooka 
    315       1.2   pooka 	if (rump_sys_mkdir("dir1", 0777) == -1)
    316       1.2   pooka 		atf_tc_fail_errno("mkdir 1");
    317       1.2   pooka 	if (rump_sys_mkdir("dir2", 0777) == -1)
    318       1.2   pooka 		atf_tc_fail_errno("mkdir 2");
    319       1.2   pooka 
    320       1.2   pooka 	if (rump_sys_rename("dir1", "dir1/..") != -1 || errno != EINVAL)
    321       1.2   pooka 		atf_tc_fail_errno("self-dotdot to");
    322       1.2   pooka 
    323       1.2   pooka 	if (rump_sys_rename("dir1/..", "sometarget") != -1 || errno != EINVAL)
    324       1.2   pooka 		atf_tc_fail_errno("self-dotdot from");
    325       1.2   pooka 	atf_tc_expect_pass();
    326       1.2   pooka 
    327       1.2   pooka 	if (FSTYPE_TMPFS(tc)) {
    328       1.2   pooka 		atf_tc_expect_fail("PR kern/43617");
    329       1.2   pooka 	}
    330       1.2   pooka 	if (rump_sys_rename("dir1", "dir2/..") != -1 || errno != EINVAL)
    331       1.2   pooka 		atf_tc_fail("other-dotdot");
    332       1.2   pooka 
    333       1.2   pooka 	rump_sys_chdir("/");
    334       1.2   pooka }
    335       1.2   pooka 
    336       1.2   pooka static void
    337       1.2   pooka rename_reg_nodir(const atf_tc_t *tc, const char *mp)
    338       1.2   pooka {
    339       1.2   pooka 	bool haslinks;
    340       1.2   pooka 	struct stat sb;
    341       1.2   pooka 	ino_t f1ino, f2ino;
    342       1.2   pooka 
    343      1.10   pooka 	if (FSTYPE_RUMPFS(tc))
    344      1.10   pooka 		atf_tc_skip("rename not supported by fs");
    345      1.10   pooka 
    346       1.2   pooka 	if (rump_sys_chdir(mp) == -1)
    347       1.2   pooka 		atf_tc_fail_errno("chdir mountpoint");
    348       1.2   pooka 
    349       1.2   pooka 	if (FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))
    350       1.2   pooka 		haslinks = false;
    351       1.2   pooka 	else
    352       1.2   pooka 		haslinks = true;
    353       1.2   pooka 
    354       1.2   pooka 	if (rump_sys_mknod("file1", S_IFREG | 0777, -1) == -1)
    355       1.2   pooka 		atf_tc_fail_errno("create file");
    356       1.2   pooka 	if (rump_sys_mknod("file2", S_IFREG | 0777, -1) == -1)
    357       1.2   pooka 		atf_tc_fail_errno("create file");
    358       1.2   pooka 
    359       1.2   pooka 	if (rump_sys_stat("file1", &sb) == -1)
    360       1.2   pooka 		atf_tc_fail_errno("stat");
    361       1.2   pooka 	f1ino = sb.st_ino;
    362       1.2   pooka 
    363       1.2   pooka 	if (haslinks) {
    364       1.2   pooka 		if (rump_sys_link("file1", "file_link") == -1)
    365       1.2   pooka 			atf_tc_fail_errno("link");
    366       1.2   pooka 		if (rump_sys_stat("file_link", &sb) == -1)
    367       1.2   pooka 			atf_tc_fail_errno("stat");
    368       1.2   pooka 		ATF_REQUIRE_EQ(sb.st_ino, f1ino);
    369       1.2   pooka 		ATF_REQUIRE_EQ(sb.st_nlink, 2);
    370       1.2   pooka 	}
    371       1.2   pooka 
    372       1.2   pooka 	if (rump_sys_stat("file2", &sb) == -1)
    373       1.2   pooka 		atf_tc_fail_errno("stat");
    374       1.2   pooka 	f2ino = sb.st_ino;
    375       1.2   pooka 
    376       1.2   pooka 	if (rump_sys_rename("file1", "file3") == -1)
    377       1.2   pooka 		atf_tc_fail_errno("rename 1");
    378       1.2   pooka 	if (rump_sys_stat("file3", &sb) == -1)
    379       1.2   pooka 		atf_tc_fail_errno("stat 1");
    380       1.2   pooka 	if (haslinks) {
    381       1.2   pooka 		ATF_REQUIRE_EQ(sb.st_ino, f1ino);
    382       1.2   pooka 	}
    383       1.2   pooka 	if (rump_sys_stat("file1", &sb) != -1 || errno != ENOENT)
    384       1.2   pooka 		atf_tc_fail_errno("source 1");
    385       1.2   pooka 
    386       1.2   pooka 	if (rump_sys_rename("file3", "file2") == -1)
    387       1.2   pooka 		atf_tc_fail_errno("rename 2");
    388       1.2   pooka 	if (rump_sys_stat("file2", &sb) == -1)
    389       1.2   pooka 		atf_tc_fail_errno("stat 2");
    390       1.2   pooka 	if (haslinks) {
    391       1.2   pooka 		ATF_REQUIRE_EQ(sb.st_ino, f1ino);
    392       1.2   pooka 	}
    393       1.2   pooka 
    394       1.2   pooka 	if (rump_sys_stat("file3", &sb) != -1 || errno != ENOENT)
    395       1.2   pooka 		atf_tc_fail_errno("source 2");
    396       1.2   pooka 
    397       1.2   pooka 	if (haslinks) {
    398       1.2   pooka 		if (rump_sys_rename("file2", "file_link") == -1)
    399       1.2   pooka 			atf_tc_fail_errno("rename hardlink");
    400       1.2   pooka 		if (rump_sys_stat("file2", &sb) != -1 || errno != ENOENT)
    401       1.2   pooka 			atf_tc_fail_errno("source 3");
    402       1.2   pooka 		if (rump_sys_stat("file_link", &sb) == -1)
    403       1.2   pooka 			atf_tc_fail_errno("stat 2");
    404       1.2   pooka 		ATF_REQUIRE_EQ(sb.st_ino, f1ino);
    405       1.2   pooka 		ATF_REQUIRE_EQ(sb.st_nlink, 1);
    406       1.2   pooka 	}
    407       1.2   pooka 
    408       1.2   pooka 	rump_sys_chdir("/");
    409       1.2   pooka }
    410       1.2   pooka 
    411       1.5   njoly static void
    412       1.5   njoly create_nametoolong(const atf_tc_t *tc, const char *mp)
    413       1.5   njoly {
    414       1.5   njoly 	char *name;
    415       1.5   njoly 	int fd;
    416       1.5   njoly 	long val;
    417       1.5   njoly 	size_t len;
    418       1.5   njoly 
    419       1.5   njoly 	if (rump_sys_chdir(mp) == -1)
    420       1.5   njoly 		atf_tc_fail_errno("chdir mountpoint");
    421       1.5   njoly 
    422       1.5   njoly 	val = rump_sys_pathconf(".", _PC_NAME_MAX);
    423       1.5   njoly 	if (val == -1)
    424       1.5   njoly 		atf_tc_fail_errno("pathconf");
    425       1.5   njoly 
    426       1.5   njoly 	len = val + 1;
    427       1.5   njoly 	name = malloc(len+1);
    428       1.5   njoly 	if (name == NULL)
    429       1.5   njoly 		atf_tc_fail_errno("malloc");
    430       1.5   njoly 
    431       1.5   njoly 	memset(name, 'a', len);
    432       1.5   njoly 	*(name+len) = '\0';
    433       1.5   njoly 
    434       1.5   njoly 	val = rump_sys_pathconf(".", _PC_NO_TRUNC);
    435       1.5   njoly 	if (val == -1)
    436       1.5   njoly 		atf_tc_fail_errno("pathconf");
    437       1.5   njoly 
    438       1.5   njoly 	if (FSTYPE_MSDOS(tc))
    439       1.5   njoly 		atf_tc_expect_fail("PR kern/43670");
    440       1.5   njoly 	fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666);
    441       1.5   njoly 	if (val != 0 && (fd != -1 || errno != ENAMETOOLONG))
    442       1.5   njoly 		atf_tc_fail_errno("open");
    443       1.5   njoly 
    444       1.5   njoly 	if (val == 0 && rump_sys_close(fd) == -1)
    445       1.5   njoly 		atf_tc_fail_errno("close");
    446       1.5   njoly 	if (val == 0 && rump_sys_unlink(name) == -1)
    447       1.5   njoly 		atf_tc_fail_errno("unlink");
    448       1.5   njoly 
    449       1.5   njoly 	free(name);
    450       1.5   njoly 
    451       1.5   njoly 	rump_sys_chdir("/");
    452       1.5   njoly }
    453       1.5   njoly 
    454       1.5   njoly static void
    455  1.12.2.2  bouyer create_exist(const atf_tc_t *tc, const char *mp)
    456  1.12.2.2  bouyer {
    457  1.12.2.2  bouyer 	const char *name = "hoge";
    458  1.12.2.2  bouyer 	int fd;
    459  1.12.2.2  bouyer 
    460  1.12.2.2  bouyer 	RL(rump_sys_chdir(mp));
    461  1.12.2.2  bouyer 	RL(fd = rump_sys_open(name, O_RDWR|O_CREAT|O_EXCL, 0666));
    462  1.12.2.2  bouyer 	RL(rump_sys_close(fd));
    463  1.12.2.2  bouyer 	RL(rump_sys_unlink(name));
    464  1.12.2.2  bouyer 	RL(fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666));
    465  1.12.2.2  bouyer 	RL(rump_sys_close(fd));
    466  1.12.2.2  bouyer 	RL(fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666));
    467  1.12.2.2  bouyer 	RL(rump_sys_close(fd));
    468  1.12.2.2  bouyer 	ATF_REQUIRE_ERRNO(EEXIST,
    469  1.12.2.2  bouyer 	    (fd = rump_sys_open(name, O_RDWR|O_CREAT|O_EXCL, 0666)));
    470  1.12.2.2  bouyer 	RL(rump_sys_unlink(name));
    471  1.12.2.2  bouyer 	RL(rump_sys_chdir("/"));
    472  1.12.2.2  bouyer }
    473  1.12.2.2  bouyer 
    474  1.12.2.2  bouyer static void
    475       1.5   njoly rename_nametoolong(const atf_tc_t *tc, const char *mp)
    476       1.5   njoly {
    477       1.5   njoly 	char *name;
    478       1.5   njoly 	int res, fd;
    479       1.5   njoly 	long val;
    480       1.5   njoly 	size_t len;
    481       1.5   njoly 
    482      1.10   pooka 	if (FSTYPE_RUMPFS(tc))
    483      1.10   pooka 		atf_tc_skip("rename not supported by fs");
    484      1.10   pooka 
    485       1.5   njoly 	if (rump_sys_chdir(mp) == -1)
    486       1.5   njoly 		atf_tc_fail_errno("chdir mountpoint");
    487       1.5   njoly 
    488       1.5   njoly 	val = rump_sys_pathconf(".", _PC_NAME_MAX);
    489       1.5   njoly 	if (val == -1)
    490       1.5   njoly 		atf_tc_fail_errno("pathconf");
    491       1.5   njoly 
    492       1.5   njoly 	len = val + 1;
    493       1.5   njoly 	name = malloc(len+1);
    494       1.5   njoly 	if (name == NULL)
    495       1.5   njoly 		atf_tc_fail_errno("malloc");
    496       1.5   njoly 
    497       1.5   njoly 	memset(name, 'a', len);
    498       1.5   njoly 	*(name+len) = '\0';
    499       1.5   njoly 
    500       1.5   njoly 	fd = rump_sys_open("dummy", O_RDWR|O_CREAT, 0666);
    501       1.5   njoly 	if (fd == -1)
    502       1.5   njoly 		atf_tc_fail_errno("open");
    503       1.5   njoly 	if (rump_sys_close(fd) == -1)
    504       1.5   njoly 		atf_tc_fail_errno("close");
    505       1.5   njoly 
    506       1.5   njoly 	val = rump_sys_pathconf(".", _PC_NO_TRUNC);
    507       1.5   njoly 	if (val == -1)
    508       1.5   njoly 		atf_tc_fail_errno("pathconf");
    509       1.5   njoly 
    510       1.5   njoly 	if (FSTYPE_MSDOS(tc))
    511       1.5   njoly 		atf_tc_expect_fail("PR kern/43670");
    512       1.5   njoly 	res = rump_sys_rename("dummy", name);
    513       1.5   njoly 	if (val != 0 && (res != -1 || errno != ENAMETOOLONG))
    514       1.5   njoly 		atf_tc_fail_errno("rename");
    515       1.5   njoly 
    516       1.5   njoly 	if (val == 0 && rump_sys_unlink(name) == -1)
    517       1.5   njoly 		atf_tc_fail_errno("unlink");
    518       1.5   njoly 
    519       1.5   njoly 	free(name);
    520       1.5   njoly 
    521       1.5   njoly 	rump_sys_chdir("/");
    522       1.5   njoly }
    523       1.5   njoly 
    524       1.7   pooka static void
    525       1.7   pooka symlink_zerolen(const atf_tc_t *tc, const char *mp)
    526       1.7   pooka {
    527       1.7   pooka 
    528       1.7   pooka 	USES_SYMLINKS;
    529       1.7   pooka 
    530       1.7   pooka 	RL(rump_sys_chdir(mp));
    531       1.8   pooka 
    532       1.8   pooka 	if (FSTYPE_TMPFS(tc)) {
    533       1.8   pooka 		atf_tc_expect_signal(SIGABRT, "PR kern/43843");
    534       1.8   pooka 	}
    535       1.8   pooka 
    536       1.7   pooka 	RL(rump_sys_symlink("", "afile"));
    537       1.7   pooka 	RL(rump_sys_chdir("/"));
    538       1.7   pooka }
    539       1.7   pooka 
    540      1.11   pooka static void
    541      1.11   pooka attrs(const atf_tc_t *tc, const char *mp)
    542      1.11   pooka {
    543      1.11   pooka 	struct stat sb, sb2;
    544      1.11   pooka 	struct timeval tv[2];
    545      1.11   pooka 	int fd;
    546      1.11   pooka 
    547      1.11   pooka 	FSTEST_ENTER();
    548      1.11   pooka 	RL(fd = rump_sys_open(TESTFILE, O_RDWR | O_CREAT, 0755));
    549      1.11   pooka 	RL(rump_sys_close(fd));
    550      1.11   pooka 	RL(rump_sys_stat(TESTFILE, &sb));
    551      1.11   pooka 	if (!(FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))) {
    552      1.11   pooka 		RL(rump_sys_chown(TESTFILE, 1, 2));
    553      1.11   pooka 		sb.st_uid = 1;
    554      1.11   pooka 		sb.st_gid = 2;
    555      1.11   pooka 		RL(rump_sys_chmod(TESTFILE, 0123));
    556      1.11   pooka 		sb.st_mode = (sb.st_mode & ~ACCESSPERMS) | 0123;
    557      1.11   pooka 	}
    558      1.11   pooka 
    559      1.11   pooka 	tv[0].tv_sec = 1000000000; /* need something >1980 for msdosfs */
    560      1.11   pooka 	tv[0].tv_usec = 1;
    561      1.11   pooka 	tv[1].tv_sec = 1000000002; /* need even seconds for msdosfs */
    562      1.11   pooka 	tv[1].tv_usec = 3;
    563      1.11   pooka 	RL(rump_sys_utimes(TESTFILE, tv));
    564      1.11   pooka 	RL(rump_sys_utimes(TESTFILE, tv)); /* XXX: utimes & birthtime */
    565      1.11   pooka 	sb.st_atimespec.tv_sec = 1000000000;
    566      1.11   pooka 	sb.st_atimespec.tv_nsec = 1000;
    567      1.11   pooka 	sb.st_mtimespec.tv_sec = 1000000002;
    568      1.11   pooka 	sb.st_mtimespec.tv_nsec = 3000;
    569      1.11   pooka 
    570      1.11   pooka 	RL(rump_sys_stat(TESTFILE, &sb2));
    571      1.11   pooka #define CHECK(a) ATF_REQUIRE_EQ(sb.a, sb2.a)
    572      1.11   pooka 	if (!(FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))) {
    573      1.11   pooka 		CHECK(st_uid);
    574      1.11   pooka 		CHECK(st_gid);
    575      1.11   pooka 		CHECK(st_mode);
    576      1.11   pooka 	}
    577      1.11   pooka 	if (!FSTYPE_MSDOS(tc)) {
    578      1.11   pooka 		/* msdosfs has only access date, not time */
    579      1.11   pooka 		CHECK(st_atimespec.tv_sec);
    580      1.11   pooka 	}
    581      1.11   pooka 	CHECK(st_mtimespec.tv_sec);
    582      1.11   pooka 	if (!(FSTYPE_EXT2FS(tc) || FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))) {
    583      1.11   pooka 		CHECK(st_atimespec.tv_nsec);
    584      1.11   pooka 		CHECK(st_mtimespec.tv_nsec);
    585      1.11   pooka 	}
    586      1.11   pooka #undef  CHECK
    587      1.11   pooka 
    588      1.11   pooka 	FSTEST_EXIT();
    589      1.11   pooka }
    590      1.11   pooka 
    591      1.12  kefren static void
    592      1.12  kefren fcntl_lock(const atf_tc_t *tc, const char *mp)
    593      1.12  kefren {
    594      1.12  kefren 	int fd, fd2;
    595      1.12  kefren 	struct flock l;
    596      1.12  kefren 	struct lwp *lwp1, *lwp2;
    597      1.12  kefren 
    598      1.12  kefren 	FSTEST_ENTER();
    599      1.12  kefren 	l.l_pid = 0;
    600      1.12  kefren 	l.l_start = l.l_len = 1024;
    601      1.12  kefren 	l.l_type = F_RDLCK | F_WRLCK;
    602      1.12  kefren 	l.l_whence = SEEK_END;
    603      1.12  kefren 
    604      1.12  kefren 	lwp1 = rump_pub_lwproc_curlwp();
    605      1.12  kefren 	RL(fd = rump_sys_open(TESTFILE, O_RDWR | O_CREAT, 0755));
    606      1.12  kefren 	RL(rump_sys_ftruncate(fd, 8192));
    607      1.12  kefren 
    608      1.12  kefren 	/* PR kern/43321 */
    609      1.12  kefren 	RL(rump_sys_fcntl(fd, F_SETLK, &l));
    610      1.12  kefren 
    611      1.12  kefren 	/* Next, we fork and try to lock the same area */
    612      1.12  kefren 	RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
    613      1.12  kefren 	lwp2 = rump_pub_lwproc_curlwp();
    614      1.12  kefren 	RL(fd2 = rump_sys_open(TESTFILE, O_RDWR, 0));
    615      1.12  kefren 	ATF_REQUIRE_ERRNO(EAGAIN, rump_sys_fcntl(fd2, F_SETLK, &l));
    616      1.12  kefren 
    617      1.12  kefren 	/* Switch back and unlock... */
    618      1.12  kefren 	rump_pub_lwproc_switch(lwp1);
    619      1.12  kefren 	l.l_type = F_UNLCK;
    620      1.12  kefren 	RL(rump_sys_fcntl(fd, F_SETLK, &l));
    621      1.12  kefren 
    622      1.12  kefren 	/* ... and try to lock again */
    623      1.12  kefren 	rump_pub_lwproc_switch(lwp2);
    624      1.12  kefren 	l.l_type = F_RDLCK | F_WRLCK;
    625      1.12  kefren 	RL(rump_sys_fcntl(fd2, F_SETLK, &l));
    626      1.12  kefren 
    627      1.12  kefren 	RL(rump_sys_close(fd2));
    628      1.12  kefren 	rump_pub_lwproc_releaselwp();
    629      1.12  kefren 
    630      1.12  kefren 	RL(rump_sys_close(fd));
    631      1.12  kefren 
    632      1.12  kefren 	FSTEST_EXIT();
    633      1.12  kefren }
    634      1.12  kefren 
    635  1.12.2.1  bouyer static int
    636  1.12.2.1  bouyer flock_compare(const void *p, const void *q)
    637  1.12.2.1  bouyer {
    638  1.12.2.1  bouyer 	int a = ((const struct flock *)p)->l_start;
    639  1.12.2.1  bouyer 	int b = ((const struct flock *)q)->l_start;
    640  1.12.2.1  bouyer 	return a < b ? -1 : (a > b ? 1 : 0);
    641  1.12.2.1  bouyer }
    642  1.12.2.1  bouyer 
    643  1.12.2.1  bouyer static void
    644  1.12.2.1  bouyer fcntl_getlock_pids(const atf_tc_t *tc, const char *mp)
    645  1.12.2.1  bouyer {
    646  1.12.2.1  bouyer 	/* test non-overlaping ranges */
    647  1.12.2.1  bouyer 	struct flock expect[4];
    648  1.12.2.1  bouyer 	const struct flock lock[4] = {
    649  1.12.2.1  bouyer 		{ 0, 2, 0, F_WRLCK, SEEK_SET },
    650  1.12.2.1  bouyer 		{ 2, 1, 0, F_WRLCK, SEEK_SET },
    651  1.12.2.1  bouyer 		{ 7, 5, 0, F_WRLCK, SEEK_SET },
    652  1.12.2.1  bouyer 		{ 4, 3, 0, F_WRLCK, SEEK_SET },
    653  1.12.2.1  bouyer 	};
    654  1.12.2.1  bouyer 
    655  1.12.2.1  bouyer 	int fd[4];
    656  1.12.2.1  bouyer 	struct lwp *lwp[4];
    657  1.12.2.1  bouyer 	pid_t prevpid = 0;
    658  1.12.2.1  bouyer 
    659  1.12.2.1  bouyer 	unsigned int i, j;
    660  1.12.2.1  bouyer 	const off_t sz = 8192;
    661  1.12.2.1  bouyer 	int omode  = 0755;
    662  1.12.2.1  bouyer 	int oflags = O_RDWR | O_CREAT;
    663  1.12.2.1  bouyer 
    664  1.12.2.1  bouyer 	memcpy(expect, lock, sizeof(lock));
    665  1.12.2.1  bouyer 	qsort(expect, __arraycount(expect), sizeof(expect[0]), &flock_compare);
    666  1.12.2.1  bouyer 
    667  1.12.2.1  bouyer 	FSTEST_ENTER();
    668  1.12.2.1  bouyer 
    669  1.12.2.1  bouyer 	/*
    670  1.12.2.1  bouyer 	 * First, we create 4 processes and let each lock a range of the
    671  1.12.2.1  bouyer 	 * file.  Note that the third and fourth processes lock in
    672  1.12.2.1  bouyer 	 * "reverse" order, i.e. the greater pid locks a range before
    673  1.12.2.1  bouyer 	 * the lesser pid.
    674  1.12.2.1  bouyer 	 */
    675  1.12.2.1  bouyer 	for(i = 0; i < __arraycount(lwp); i++) {
    676  1.12.2.1  bouyer 		RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
    677  1.12.2.1  bouyer 
    678  1.12.2.1  bouyer 		lwp[i] = rump_pub_lwproc_curlwp();
    679  1.12.2.1  bouyer 		assert(rump_sys_getpid() > prevpid);
    680  1.12.2.1  bouyer 		prevpid = rump_sys_getpid();
    681  1.12.2.1  bouyer 
    682  1.12.2.1  bouyer 		RL(fd[i] = rump_sys_open(TESTFILE, oflags, omode));
    683  1.12.2.1  bouyer 		oflags = O_RDWR;
    684  1.12.2.1  bouyer 		omode  = 0;
    685  1.12.2.1  bouyer 
    686  1.12.2.1  bouyer 		RL(rump_sys_ftruncate(fd[i], sz));
    687  1.12.2.1  bouyer 		RL(rump_sys_fcntl(fd[i], F_SETLK, &lock[i]));
    688  1.12.2.1  bouyer 	}
    689  1.12.2.1  bouyer 
    690  1.12.2.1  bouyer 	atf_tc_expect_fail("PR kern/44494");
    691  1.12.2.1  bouyer 	/*
    692  1.12.2.1  bouyer 	 * In the context of each pid , do GETLK for a readlock from
    693  1.12.2.1  bouyer 	 * i = [0,__arraycount(locks)].  If we try to lock from the same
    694  1.12.2.1  bouyer 	 * start offset as the lock our current process holds, check
    695  1.12.2.1  bouyer 	 * that we fail on the offset of the next lock ("else if" branch).
    696  1.12.2.1  bouyer 	 * Otherwise, expect to get a lock for the current offset
    697  1.12.2.1  bouyer 	 * ("if" branch).  The "else" branch is purely for the last
    698  1.12.2.1  bouyer 	 * process where we expect no blocking locks.
    699  1.12.2.1  bouyer 	 */
    700  1.12.2.1  bouyer 	for(i = 0; i < __arraycount(lwp); i++) {
    701  1.12.2.1  bouyer 		rump_pub_lwproc_switch(lwp[i]);
    702  1.12.2.1  bouyer 
    703  1.12.2.1  bouyer 		for(j = 0; j < __arraycount(lwp); j++) {
    704  1.12.2.1  bouyer 			struct flock l;
    705  1.12.2.1  bouyer 			l = expect[j];
    706  1.12.2.1  bouyer 			l.l_len = sz;
    707  1.12.2.1  bouyer 			l.l_type = F_RDLCK;
    708  1.12.2.1  bouyer 
    709  1.12.2.1  bouyer 			RL(rump_sys_fcntl(fd[i], F_GETLK, &l));
    710  1.12.2.1  bouyer 
    711  1.12.2.1  bouyer 			if(expect[j].l_start != lock[i].l_start) {
    712  1.12.2.1  bouyer 				/*
    713  1.12.2.1  bouyer 				 * lock set by another process
    714  1.12.2.1  bouyer 				 */
    715  1.12.2.1  bouyer 				ATF_CHECK(l.l_type != F_UNLCK);
    716  1.12.2.1  bouyer 				ATF_CHECK_EQ(l.l_start, expect[j].l_start);
    717  1.12.2.1  bouyer 				ATF_CHECK_EQ(l.l_len,   expect[j].l_len);
    718  1.12.2.1  bouyer 			} else if (j != __arraycount(lwp) - 1) {
    719  1.12.2.1  bouyer 				/*
    720  1.12.2.1  bouyer 				 * lock set by the current process
    721  1.12.2.1  bouyer 				 */
    722  1.12.2.1  bouyer 				ATF_CHECK(l.l_type != F_UNLCK);
    723  1.12.2.1  bouyer 				ATF_CHECK_EQ(l.l_start, expect[j+1].l_start);
    724  1.12.2.1  bouyer 				ATF_CHECK_EQ(l.l_len,   expect[j+1].l_len);
    725  1.12.2.1  bouyer 			} else {
    726  1.12.2.1  bouyer 				/*
    727  1.12.2.1  bouyer 				 * there are no other locks after the
    728  1.12.2.1  bouyer 				 * current process lock
    729  1.12.2.1  bouyer 				 */
    730  1.12.2.1  bouyer 				ATF_CHECK_EQ(l.l_type,   F_UNLCK);
    731  1.12.2.1  bouyer 				ATF_CHECK_EQ(l.l_start,  expect[j].l_start);
    732  1.12.2.1  bouyer 				ATF_CHECK_EQ(l.l_len,    sz);
    733  1.12.2.1  bouyer 				ATF_CHECK_EQ(l.l_pid,    expect[j].l_pid);
    734  1.12.2.1  bouyer 				ATF_CHECK_EQ(l.l_whence, expect[j].l_whence);
    735  1.12.2.1  bouyer 			}
    736  1.12.2.1  bouyer 		}
    737  1.12.2.1  bouyer 	}
    738  1.12.2.1  bouyer 
    739  1.12.2.1  bouyer 	/*
    740  1.12.2.1  bouyer 	 * Release processes.  This also releases the fds and locks
    741  1.12.2.1  bouyer 	 * making fs unmount possible
    742  1.12.2.1  bouyer 	 */
    743  1.12.2.1  bouyer 	for(i = 0; i < __arraycount(lwp); i++) {
    744  1.12.2.1  bouyer 		rump_pub_lwproc_switch(lwp[i]);
    745  1.12.2.1  bouyer 		rump_pub_lwproc_releaselwp();
    746  1.12.2.1  bouyer 	}
    747  1.12.2.1  bouyer 
    748  1.12.2.1  bouyer 	FSTEST_EXIT();
    749  1.12.2.1  bouyer }
    750  1.12.2.1  bouyer 
    751  1.12.2.2  bouyer static void
    752  1.12.2.2  bouyer access_simple(const atf_tc_t *tc, const char *mp)
    753  1.12.2.2  bouyer {
    754  1.12.2.2  bouyer 	int fd;
    755  1.12.2.2  bouyer 	int tmode;
    756  1.12.2.2  bouyer 
    757  1.12.2.2  bouyer 	FSTEST_ENTER();
    758  1.12.2.2  bouyer 	RL(fd = rump_sys_open("tfile", O_CREAT | O_RDWR, 0777));
    759  1.12.2.2  bouyer 	RL(rump_sys_close(fd));
    760  1.12.2.2  bouyer 
    761  1.12.2.2  bouyer #define ALLACC (F_OK | X_OK | W_OK | R_OK)
    762  1.12.2.2  bouyer 	if (FSTYPE_SYSVBFS(tc) || FSTYPE_MSDOS(tc))
    763  1.12.2.2  bouyer 		tmode = F_OK;
    764  1.12.2.2  bouyer 	else
    765  1.12.2.2  bouyer 		tmode = ALLACC;
    766  1.12.2.2  bouyer 
    767  1.12.2.2  bouyer 	RL(rump_sys_access("tfile", tmode));
    768  1.12.2.2  bouyer 
    769  1.12.2.2  bouyer 	/* PR kern/44648 */
    770  1.12.2.2  bouyer 	ATF_REQUIRE_ERRNO(EINVAL, rump_sys_access("tfile", ALLACC+1) == -1);
    771  1.12.2.2  bouyer #undef ALLACC
    772  1.12.2.2  bouyer 	FSTEST_EXIT();
    773  1.12.2.2  bouyer }
    774  1.12.2.2  bouyer 
    775       1.1   pooka ATF_TC_FSAPPLY(lookup_simple, "simple lookup (./.. on root)");
    776       1.1   pooka ATF_TC_FSAPPLY(lookup_complex, "lookup of non-dot entries");
    777       1.1   pooka ATF_TC_FSAPPLY(dir_simple, "mkdir/rmdir");
    778       1.1   pooka ATF_TC_FSAPPLY(dir_notempty, "non-empty directories cannot be removed");
    779  1.12.2.2  bouyer ATF_TC_FSAPPLY(dir_rmdirdotdot, "remove .. and try to cd out");
    780       1.2   pooka ATF_TC_FSAPPLY(rename_dir, "exercise various directory renaming ops");
    781       1.2   pooka ATF_TC_FSAPPLY(rename_dotdot, "rename dir ..");
    782       1.2   pooka ATF_TC_FSAPPLY(rename_reg_nodir, "rename regular files, no subdirectories");
    783       1.5   njoly ATF_TC_FSAPPLY(create_nametoolong, "create file with name too long");
    784  1.12.2.2  bouyer ATF_TC_FSAPPLY(create_exist, "create with O_EXCL");
    785       1.5   njoly ATF_TC_FSAPPLY(rename_nametoolong, "rename to file with name too long");
    786       1.7   pooka ATF_TC_FSAPPLY(symlink_zerolen, "symlink with 0-len target");
    787      1.11   pooka ATF_TC_FSAPPLY(attrs, "check setting attributes works");
    788      1.12  kefren ATF_TC_FSAPPLY(fcntl_lock, "check fcntl F_SETLK");
    789  1.12.2.1  bouyer ATF_TC_FSAPPLY(fcntl_getlock_pids,"fcntl F_GETLK w/ many procs, PR kern/44494");
    790  1.12.2.2  bouyer ATF_TC_FSAPPLY(access_simple, "access(2)");
    791       1.1   pooka 
    792       1.1   pooka ATF_TP_ADD_TCS(tp)
    793       1.1   pooka {
    794       1.1   pooka 
    795       1.1   pooka 	ATF_TP_FSAPPLY(lookup_simple);
    796       1.1   pooka 	ATF_TP_FSAPPLY(lookup_complex);
    797       1.1   pooka 	ATF_TP_FSAPPLY(dir_simple);
    798       1.1   pooka 	ATF_TP_FSAPPLY(dir_notempty);
    799  1.12.2.2  bouyer 	ATF_TP_FSAPPLY(dir_rmdirdotdot);
    800       1.2   pooka 	ATF_TP_FSAPPLY(rename_dir);
    801       1.2   pooka 	ATF_TP_FSAPPLY(rename_dotdot);
    802       1.2   pooka 	ATF_TP_FSAPPLY(rename_reg_nodir);
    803       1.5   njoly 	ATF_TP_FSAPPLY(create_nametoolong);
    804  1.12.2.2  bouyer 	ATF_TP_FSAPPLY(create_exist);
    805       1.5   njoly 	ATF_TP_FSAPPLY(rename_nametoolong);
    806       1.7   pooka 	ATF_TP_FSAPPLY(symlink_zerolen);
    807      1.11   pooka 	ATF_TP_FSAPPLY(attrs);
    808      1.12  kefren 	ATF_TP_FSAPPLY(fcntl_lock);
    809  1.12.2.1  bouyer 	ATF_TP_FSAPPLY(fcntl_getlock_pids);
    810  1.12.2.2  bouyer 	ATF_TP_FSAPPLY(access_simple);
    811       1.1   pooka 
    812       1.1   pooka 	return atf_no_error();
    813       1.1   pooka }
    814