Home | History | Annotate | Line # | Download | only in vfs
t_vnops.c revision 1.12
      1  1.12  kefren /*	$NetBSD: t_vnops.c,v 1.12 2011/01/11 14:03:38 kefren 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.1   pooka #include <atf-c.h>
     33   1.1   pooka #include <fcntl.h>
     34   1.1   pooka #include <libgen.h>
     35   1.5   njoly #include <stdlib.h>
     36   1.1   pooka #include <unistd.h>
     37   1.1   pooka 
     38   1.1   pooka #include <rump/rump_syscalls.h>
     39   1.1   pooka #include <rump/rump.h>
     40   1.1   pooka 
     41   1.1   pooka #include "../common/h_fsmacros.h"
     42   1.1   pooka #include "../../h_macros.h"
     43   1.1   pooka 
     44  1.11   pooka #define TESTFILE "afile"
     45  1.11   pooka 
     46   1.1   pooka #define USES_DIRS \
     47   1.1   pooka     if (FSTYPE_SYSVBFS(tc)) atf_tc_skip("dirs not supported by file system")
     48   1.1   pooka 
     49   1.7   pooka #define USES_SYMLINKS					\
     50   1.7   pooka     if (FSTYPE_SYSVBFS(tc) || FSTYPE_MSDOS(tc))		\
     51   1.9   njoly 	atf_tc_skip("symlinks not supported by file system")
     52   1.7   pooka 
     53   1.2   pooka static char *
     54   1.2   pooka md(char *buf, const char *base, const char *tail)
     55   1.2   pooka {
     56   1.2   pooka 
     57   1.2   pooka 	sprintf(buf, "%s/%s", base, tail);
     58   1.2   pooka 	return buf;
     59   1.2   pooka }
     60   1.2   pooka 
     61   1.1   pooka static void
     62   1.1   pooka lookup_simple(const atf_tc_t *tc, const char *mountpath)
     63   1.1   pooka {
     64   1.1   pooka 	char pb[MAXPATHLEN], final[MAXPATHLEN];
     65   1.1   pooka 	struct stat sb1, sb2;
     66   1.1   pooka 
     67   1.1   pooka 	strcpy(final, mountpath);
     68   1.1   pooka 	sprintf(pb, "%s/../%s", mountpath, basename(final));
     69   1.1   pooka 	if (rump_sys_stat(pb, &sb1) == -1)
     70   1.1   pooka 		atf_tc_fail_errno("stat 1");
     71   1.1   pooka 
     72   1.1   pooka 	sprintf(pb, "%s/./../%s", mountpath, basename(final));
     73   1.1   pooka 	if (rump_sys_stat(pb, &sb2) == -1)
     74   1.1   pooka 		atf_tc_fail_errno("stat 2");
     75   1.1   pooka 
     76   1.1   pooka 	ATF_REQUIRE(memcmp(&sb1, &sb2, sizeof(sb1)) == 0);
     77   1.1   pooka }
     78   1.1   pooka 
     79   1.1   pooka static void
     80   1.1   pooka lookup_complex(const atf_tc_t *tc, const char *mountpath)
     81   1.1   pooka {
     82   1.1   pooka 	char pb[MAXPATHLEN];
     83   1.1   pooka 	struct stat sb1, sb2;
     84   1.1   pooka 
     85   1.1   pooka 	USES_DIRS;
     86   1.1   pooka 
     87   1.1   pooka 	sprintf(pb, "%s/dir", mountpath);
     88   1.1   pooka 	if (rump_sys_mkdir(pb, 0777) == -1)
     89   1.1   pooka 		atf_tc_fail_errno("mkdir");
     90   1.1   pooka 	if (rump_sys_stat(pb, &sb1) == -1)
     91   1.1   pooka 		atf_tc_fail_errno("stat 1");
     92   1.1   pooka 
     93   1.1   pooka 	sprintf(pb, "%s/./dir/../././dir/.", mountpath);
     94   1.1   pooka 	if (rump_sys_stat(pb, &sb2) == -1)
     95   1.1   pooka 		atf_tc_fail_errno("stat 2");
     96   1.1   pooka 
     97   1.1   pooka 	ATF_REQUIRE(memcmp(&sb1, &sb2, sizeof(sb1)) == 0);
     98   1.1   pooka }
     99   1.1   pooka 
    100   1.1   pooka static void
    101   1.1   pooka dir_simple(const atf_tc_t *tc, const char *mountpath)
    102   1.1   pooka {
    103   1.1   pooka 	char pb[MAXPATHLEN];
    104   1.1   pooka 	struct stat sb;
    105   1.1   pooka 
    106   1.1   pooka 	USES_DIRS;
    107   1.1   pooka 
    108   1.1   pooka 	/* check we can create directories */
    109   1.1   pooka 	sprintf(pb, "%s/dir", mountpath);
    110   1.1   pooka 	if (rump_sys_mkdir(pb, 0777) == -1)
    111   1.1   pooka 		atf_tc_fail_errno("mkdir");
    112   1.1   pooka 	if (rump_sys_stat(pb, &sb) == -1)
    113   1.1   pooka 		atf_tc_fail_errno("stat new directory");
    114   1.1   pooka 
    115   1.1   pooka 	/* check we can remove then and that it makes them unreachable */
    116   1.1   pooka 	if (rump_sys_rmdir(pb) == -1)
    117   1.1   pooka 		atf_tc_fail_errno("rmdir");
    118   1.1   pooka 	if (rump_sys_stat(pb, &sb) != -1 || errno != ENOENT)
    119   1.1   pooka 		atf_tc_fail("ENOENT expected from stat");
    120   1.1   pooka }
    121   1.1   pooka 
    122   1.1   pooka static void
    123   1.1   pooka dir_notempty(const atf_tc_t *tc, const char *mountpath)
    124   1.1   pooka {
    125   1.1   pooka 	char pb[MAXPATHLEN], pb2[MAXPATHLEN];
    126   1.1   pooka 	int fd, rv;
    127   1.1   pooka 
    128   1.1   pooka 	USES_DIRS;
    129   1.1   pooka 
    130   1.1   pooka 	/* check we can create directories */
    131   1.1   pooka 	sprintf(pb, "%s/dir", mountpath);
    132   1.1   pooka 	if (rump_sys_mkdir(pb, 0777) == -1)
    133   1.1   pooka 		atf_tc_fail_errno("mkdir");
    134   1.1   pooka 
    135   1.1   pooka 	sprintf(pb2, "%s/dir/file", mountpath);
    136   1.1   pooka 	fd = rump_sys_open(pb2, O_RDWR | O_CREAT, 0777);
    137   1.1   pooka 	if (fd == -1)
    138   1.1   pooka 		atf_tc_fail_errno("create file");
    139   1.1   pooka 	rump_sys_close(fd);
    140   1.1   pooka 
    141   1.1   pooka 	rv = rump_sys_rmdir(pb);
    142   1.1   pooka 	if (rv != -1 || errno != ENOTEMPTY)
    143   1.1   pooka 		atf_tc_fail("non-empty directory removed succesfully");
    144   1.1   pooka 
    145   1.1   pooka 	if (rump_sys_unlink(pb2) == -1)
    146   1.1   pooka 		atf_tc_fail_errno("cannot remove dir/file");
    147   1.1   pooka 
    148   1.1   pooka 	if (rump_sys_rmdir(pb) == -1)
    149   1.1   pooka 		atf_tc_fail_errno("remove directory");
    150   1.1   pooka }
    151   1.1   pooka 
    152   1.2   pooka static void
    153   1.2   pooka checkfile(const char *path, struct stat *refp)
    154   1.2   pooka {
    155   1.2   pooka 	char buf[MAXPATHLEN];
    156   1.2   pooka 	struct stat sb;
    157   1.2   pooka 	static int n = 1;
    158   1.2   pooka 
    159   1.2   pooka 	md(buf, path, "file");
    160   1.2   pooka 	if (rump_sys_stat(buf, &sb) == -1)
    161   1.2   pooka 		atf_tc_fail_errno("cannot stat file %d (%s)", n, buf);
    162   1.2   pooka 	if (memcmp(&sb, refp, sizeof(sb)) != 0)
    163   1.2   pooka 		atf_tc_fail("stat mismatch %d", n);
    164   1.2   pooka 	n++;
    165   1.2   pooka }
    166   1.2   pooka 
    167   1.2   pooka static void
    168   1.2   pooka rename_dir(const atf_tc_t *tc, const char *mp)
    169   1.2   pooka {
    170   1.2   pooka 	char pb1[MAXPATHLEN], pb2[MAXPATHLEN], pb3[MAXPATHLEN];
    171   1.2   pooka 	struct stat ref;
    172   1.2   pooka 
    173   1.3   pooka 	if (FSTYPE_MSDOS(tc))
    174   1.3   pooka 		atf_tc_skip("test fails in some setups, reason unknown");
    175   1.3   pooka 
    176  1.10   pooka 	if (FSTYPE_RUMPFS(tc))
    177  1.10   pooka 		atf_tc_skip("rename not supported by fs");
    178  1.10   pooka 
    179   1.2   pooka 	USES_DIRS;
    180   1.2   pooka 
    181   1.2   pooka 	md(pb1, mp, "dir1");
    182   1.2   pooka 	if (rump_sys_mkdir(pb1, 0777) == -1)
    183   1.2   pooka 		atf_tc_fail_errno("mkdir 1");
    184   1.2   pooka 
    185   1.2   pooka 	md(pb2, mp, "dir2");
    186   1.2   pooka 	if (rump_sys_mkdir(pb2, 0777) == -1)
    187   1.2   pooka 		atf_tc_fail_errno("mkdir 2");
    188   1.2   pooka 	md(pb2, mp, "dir2/subdir");
    189   1.2   pooka 	if (rump_sys_mkdir(pb2, 0777) == -1)
    190   1.2   pooka 		atf_tc_fail_errno("mkdir 3");
    191   1.2   pooka 
    192   1.2   pooka 	md(pb3, mp, "dir1/file");
    193   1.2   pooka 	if (rump_sys_mknod(pb3, S_IFREG | 0777, -1) == -1)
    194   1.2   pooka 		atf_tc_fail_errno("create file");
    195   1.2   pooka 	if (rump_sys_stat(pb3, &ref) == -1)
    196   1.2   pooka 		atf_tc_fail_errno("stat of file");
    197   1.2   pooka 
    198   1.2   pooka 	/*
    199   1.2   pooka 	 * First try ops which should succeed.
    200   1.2   pooka 	 */
    201   1.2   pooka 
    202   1.2   pooka 	/* rename within directory */
    203   1.2   pooka 	md(pb3, mp, "dir3");
    204   1.2   pooka 	if (rump_sys_rename(pb1, pb3) == -1)
    205   1.2   pooka 		atf_tc_fail_errno("rename 1");
    206   1.2   pooka 	checkfile(pb3, &ref);
    207   1.2   pooka 
    208   1.2   pooka 	/* rename directory onto itself (two ways, should fail) */
    209   1.2   pooka 	md(pb1, mp, "dir3/.");
    210   1.2   pooka 	if (rump_sys_rename(pb1, pb3) != -1 || errno != EINVAL)
    211   1.2   pooka 		atf_tc_fail_errno("rename 2");
    212   1.2   pooka 	if (rump_sys_rename(pb3, pb1) != -1 || errno != EISDIR)
    213   1.2   pooka 		atf_tc_fail_errno("rename 3");
    214   1.2   pooka 
    215   1.2   pooka 	checkfile(pb3, &ref);
    216   1.2   pooka 
    217   1.2   pooka 	/* rename father of directory into directory */
    218   1.2   pooka 	md(pb1, mp, "dir2/dir");
    219   1.2   pooka 	md(pb2, mp, "dir2");
    220   1.2   pooka 	if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL)
    221   1.2   pooka 		atf_tc_fail_errno("rename 4");
    222   1.2   pooka 
    223   1.2   pooka 	/* same for grandfather */
    224   1.2   pooka 	md(pb1, mp, "dir2/subdir/dir2");
    225   1.2   pooka 	if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL)
    226   1.2   pooka 		atf_tc_fail("rename 5");
    227   1.2   pooka 
    228   1.2   pooka 	checkfile(pb3, &ref);
    229   1.2   pooka 
    230   1.2   pooka 	/* rename directory over a non-empty directory */
    231   1.2   pooka 	if (rump_sys_rename(pb2, pb3) != -1 || errno != ENOTEMPTY)
    232   1.2   pooka 		atf_tc_fail("rename 6");
    233   1.2   pooka 
    234   1.2   pooka 	/* cross-directory rename */
    235   1.2   pooka 	md(pb1, mp, "dir3");
    236   1.2   pooka 	md(pb2, mp, "dir2/somedir");
    237   1.2   pooka 	if (rump_sys_rename(pb1, pb2) == -1)
    238   1.2   pooka 		atf_tc_fail_errno("rename 7");
    239   1.2   pooka 	checkfile(pb2, &ref);
    240   1.2   pooka 
    241   1.2   pooka 	/* move to parent directory */
    242   1.2   pooka 	md(pb1, mp, "dir2/somedir/../../dir3");
    243   1.2   pooka 	if (rump_sys_rename(pb2, pb1) == -1)
    244   1.2   pooka 		atf_tc_fail_errno("rename 8");
    245   1.2   pooka 	md(pb1, mp, "dir2/../dir3");
    246   1.2   pooka 	checkfile(pb1, &ref);
    247   1.2   pooka 
    248   1.2   pooka 	/* finally, atomic cross-directory rename */
    249   1.2   pooka 	md(pb3, mp, "dir2/subdir");
    250   1.2   pooka 	if (rump_sys_rename(pb1, pb3) == -1)
    251   1.2   pooka 		atf_tc_fail_errno("rename 9");
    252   1.2   pooka 	checkfile(pb3, &ref);
    253   1.2   pooka }
    254   1.2   pooka 
    255   1.2   pooka static void
    256   1.2   pooka rename_dotdot(const atf_tc_t *tc, const char *mp)
    257   1.2   pooka {
    258   1.2   pooka 
    259  1.10   pooka 	if (FSTYPE_RUMPFS(tc))
    260  1.10   pooka 		atf_tc_skip("rename not supported by fs");
    261  1.10   pooka 
    262   1.2   pooka 	USES_DIRS;
    263   1.2   pooka 
    264   1.2   pooka 	if (rump_sys_chdir(mp) == -1)
    265   1.2   pooka 		atf_tc_fail_errno("chdir mountpoint");
    266   1.2   pooka 
    267   1.2   pooka 	if (rump_sys_mkdir("dir1", 0777) == -1)
    268   1.2   pooka 		atf_tc_fail_errno("mkdir 1");
    269   1.2   pooka 	if (rump_sys_mkdir("dir2", 0777) == -1)
    270   1.2   pooka 		atf_tc_fail_errno("mkdir 2");
    271   1.2   pooka 
    272   1.2   pooka 	if (rump_sys_rename("dir1", "dir1/..") != -1 || errno != EINVAL)
    273   1.2   pooka 		atf_tc_fail_errno("self-dotdot to");
    274   1.2   pooka 
    275   1.2   pooka 	if (rump_sys_rename("dir1/..", "sometarget") != -1 || errno != EINVAL)
    276   1.2   pooka 		atf_tc_fail_errno("self-dotdot from");
    277   1.2   pooka 	atf_tc_expect_pass();
    278   1.2   pooka 
    279   1.2   pooka 	if (FSTYPE_TMPFS(tc)) {
    280   1.2   pooka 		atf_tc_expect_fail("PR kern/43617");
    281   1.2   pooka 	}
    282   1.2   pooka 	if (rump_sys_rename("dir1", "dir2/..") != -1 || errno != EINVAL)
    283   1.2   pooka 		atf_tc_fail("other-dotdot");
    284   1.2   pooka 
    285   1.2   pooka 	rump_sys_chdir("/");
    286   1.2   pooka }
    287   1.2   pooka 
    288   1.2   pooka static void
    289   1.2   pooka rename_reg_nodir(const atf_tc_t *tc, const char *mp)
    290   1.2   pooka {
    291   1.2   pooka 	bool haslinks;
    292   1.2   pooka 	struct stat sb;
    293   1.2   pooka 	ino_t f1ino, f2ino;
    294   1.2   pooka 
    295  1.10   pooka 	if (FSTYPE_RUMPFS(tc))
    296  1.10   pooka 		atf_tc_skip("rename not supported by fs");
    297  1.10   pooka 
    298   1.3   pooka 	if (FSTYPE_MSDOS(tc))
    299   1.3   pooka 		atf_tc_skip("test fails in some setups, reason unknown");
    300   1.3   pooka 
    301   1.2   pooka 	if (rump_sys_chdir(mp) == -1)
    302   1.2   pooka 		atf_tc_fail_errno("chdir mountpoint");
    303   1.2   pooka 
    304   1.2   pooka 	if (FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))
    305   1.2   pooka 		haslinks = false;
    306   1.2   pooka 	else
    307   1.2   pooka 		haslinks = true;
    308   1.2   pooka 
    309   1.2   pooka 	if (rump_sys_mknod("file1", S_IFREG | 0777, -1) == -1)
    310   1.2   pooka 		atf_tc_fail_errno("create file");
    311   1.2   pooka 	if (rump_sys_mknod("file2", S_IFREG | 0777, -1) == -1)
    312   1.2   pooka 		atf_tc_fail_errno("create file");
    313   1.2   pooka 
    314   1.2   pooka 	if (rump_sys_stat("file1", &sb) == -1)
    315   1.2   pooka 		atf_tc_fail_errno("stat");
    316   1.2   pooka 	f1ino = sb.st_ino;
    317   1.2   pooka 
    318   1.2   pooka 	if (haslinks) {
    319   1.2   pooka 		if (rump_sys_link("file1", "file_link") == -1)
    320   1.2   pooka 			atf_tc_fail_errno("link");
    321   1.2   pooka 		if (rump_sys_stat("file_link", &sb) == -1)
    322   1.2   pooka 			atf_tc_fail_errno("stat");
    323   1.2   pooka 		ATF_REQUIRE_EQ(sb.st_ino, f1ino);
    324   1.2   pooka 		ATF_REQUIRE_EQ(sb.st_nlink, 2);
    325   1.2   pooka 	}
    326   1.2   pooka 
    327   1.2   pooka 	if (rump_sys_stat("file2", &sb) == -1)
    328   1.2   pooka 		atf_tc_fail_errno("stat");
    329   1.2   pooka 	f2ino = sb.st_ino;
    330   1.2   pooka 
    331   1.2   pooka 	if (rump_sys_rename("file1", "file3") == -1)
    332   1.2   pooka 		atf_tc_fail_errno("rename 1");
    333   1.2   pooka 	if (rump_sys_stat("file3", &sb) == -1)
    334   1.2   pooka 		atf_tc_fail_errno("stat 1");
    335   1.2   pooka 	if (haslinks) {
    336   1.2   pooka 		ATF_REQUIRE_EQ(sb.st_ino, f1ino);
    337   1.2   pooka 	}
    338   1.2   pooka 	if (rump_sys_stat("file1", &sb) != -1 || errno != ENOENT)
    339   1.2   pooka 		atf_tc_fail_errno("source 1");
    340   1.2   pooka 
    341   1.2   pooka 	if (rump_sys_rename("file3", "file2") == -1)
    342   1.2   pooka 		atf_tc_fail_errno("rename 2");
    343   1.2   pooka 	if (rump_sys_stat("file2", &sb) == -1)
    344   1.2   pooka 		atf_tc_fail_errno("stat 2");
    345   1.2   pooka 	if (haslinks) {
    346   1.2   pooka 		ATF_REQUIRE_EQ(sb.st_ino, f1ino);
    347   1.2   pooka 	}
    348   1.2   pooka 
    349   1.2   pooka 	if (rump_sys_stat("file3", &sb) != -1 || errno != ENOENT)
    350   1.2   pooka 		atf_tc_fail_errno("source 2");
    351   1.2   pooka 
    352   1.2   pooka 	if (haslinks) {
    353   1.2   pooka 		if (rump_sys_rename("file2", "file_link") == -1)
    354   1.2   pooka 			atf_tc_fail_errno("rename hardlink");
    355   1.2   pooka 		if (rump_sys_stat("file2", &sb) != -1 || errno != ENOENT)
    356   1.2   pooka 			atf_tc_fail_errno("source 3");
    357   1.2   pooka 		if (rump_sys_stat("file_link", &sb) == -1)
    358   1.2   pooka 			atf_tc_fail_errno("stat 2");
    359   1.2   pooka 		ATF_REQUIRE_EQ(sb.st_ino, f1ino);
    360   1.2   pooka 		ATF_REQUIRE_EQ(sb.st_nlink, 1);
    361   1.2   pooka 	}
    362   1.2   pooka 
    363   1.2   pooka 	rump_sys_chdir("/");
    364   1.2   pooka }
    365   1.2   pooka 
    366   1.5   njoly static void
    367   1.5   njoly create_nametoolong(const atf_tc_t *tc, const char *mp)
    368   1.5   njoly {
    369   1.5   njoly 	char *name;
    370   1.5   njoly 	int fd;
    371   1.5   njoly 	long val;
    372   1.5   njoly 	size_t len;
    373   1.5   njoly 
    374   1.5   njoly 	if (rump_sys_chdir(mp) == -1)
    375   1.5   njoly 		atf_tc_fail_errno("chdir mountpoint");
    376   1.5   njoly 
    377   1.5   njoly 	val = rump_sys_pathconf(".", _PC_NAME_MAX);
    378   1.5   njoly 	if (val == -1)
    379   1.5   njoly 		atf_tc_fail_errno("pathconf");
    380   1.5   njoly 
    381   1.5   njoly 	len = val + 1;
    382   1.5   njoly 	name = malloc(len+1);
    383   1.5   njoly 	if (name == NULL)
    384   1.5   njoly 		atf_tc_fail_errno("malloc");
    385   1.5   njoly 
    386   1.5   njoly 	memset(name, 'a', len);
    387   1.5   njoly 	*(name+len) = '\0';
    388   1.5   njoly 
    389   1.5   njoly 	val = rump_sys_pathconf(".", _PC_NO_TRUNC);
    390   1.5   njoly 	if (val == -1)
    391   1.5   njoly 		atf_tc_fail_errno("pathconf");
    392   1.5   njoly 
    393   1.5   njoly 	if (FSTYPE_MSDOS(tc))
    394   1.5   njoly 		atf_tc_expect_fail("PR kern/43670");
    395   1.5   njoly 	fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666);
    396   1.5   njoly 	if (val != 0 && (fd != -1 || errno != ENAMETOOLONG))
    397   1.5   njoly 		atf_tc_fail_errno("open");
    398   1.5   njoly 
    399   1.5   njoly 	if (val == 0 && rump_sys_close(fd) == -1)
    400   1.5   njoly 		atf_tc_fail_errno("close");
    401   1.5   njoly 	if (val == 0 && rump_sys_unlink(name) == -1)
    402   1.5   njoly 		atf_tc_fail_errno("unlink");
    403   1.5   njoly 
    404   1.5   njoly 	free(name);
    405   1.5   njoly 
    406   1.5   njoly 	rump_sys_chdir("/");
    407   1.5   njoly }
    408   1.5   njoly 
    409   1.5   njoly static void
    410   1.5   njoly rename_nametoolong(const atf_tc_t *tc, const char *mp)
    411   1.5   njoly {
    412   1.5   njoly 	char *name;
    413   1.5   njoly 	int res, fd;
    414   1.5   njoly 	long val;
    415   1.5   njoly 	size_t len;
    416   1.5   njoly 
    417  1.10   pooka 	if (FSTYPE_RUMPFS(tc))
    418  1.10   pooka 		atf_tc_skip("rename not supported by fs");
    419  1.10   pooka 
    420   1.5   njoly 	if (rump_sys_chdir(mp) == -1)
    421   1.5   njoly 		atf_tc_fail_errno("chdir mountpoint");
    422   1.5   njoly 
    423   1.5   njoly 	val = rump_sys_pathconf(".", _PC_NAME_MAX);
    424   1.5   njoly 	if (val == -1)
    425   1.5   njoly 		atf_tc_fail_errno("pathconf");
    426   1.5   njoly 
    427   1.5   njoly 	len = val + 1;
    428   1.5   njoly 	name = malloc(len+1);
    429   1.5   njoly 	if (name == NULL)
    430   1.5   njoly 		atf_tc_fail_errno("malloc");
    431   1.5   njoly 
    432   1.5   njoly 	memset(name, 'a', len);
    433   1.5   njoly 	*(name+len) = '\0';
    434   1.5   njoly 
    435   1.5   njoly 	fd = rump_sys_open("dummy", O_RDWR|O_CREAT, 0666);
    436   1.5   njoly 	if (fd == -1)
    437   1.5   njoly 		atf_tc_fail_errno("open");
    438   1.5   njoly 	if (rump_sys_close(fd) == -1)
    439   1.5   njoly 		atf_tc_fail_errno("close");
    440   1.5   njoly 
    441   1.5   njoly 	val = rump_sys_pathconf(".", _PC_NO_TRUNC);
    442   1.5   njoly 	if (val == -1)
    443   1.5   njoly 		atf_tc_fail_errno("pathconf");
    444   1.5   njoly 
    445   1.5   njoly 	if (FSTYPE_MSDOS(tc))
    446   1.5   njoly 		atf_tc_expect_fail("PR kern/43670");
    447   1.5   njoly 	res = rump_sys_rename("dummy", name);
    448   1.5   njoly 	if (val != 0 && (res != -1 || errno != ENAMETOOLONG))
    449   1.5   njoly 		atf_tc_fail_errno("rename");
    450   1.5   njoly 
    451   1.5   njoly 	if (val == 0 && rump_sys_unlink(name) == -1)
    452   1.5   njoly 		atf_tc_fail_errno("unlink");
    453   1.5   njoly 
    454   1.5   njoly 	free(name);
    455   1.5   njoly 
    456   1.5   njoly 	rump_sys_chdir("/");
    457   1.5   njoly }
    458   1.5   njoly 
    459   1.7   pooka static void
    460   1.7   pooka symlink_zerolen(const atf_tc_t *tc, const char *mp)
    461   1.7   pooka {
    462   1.7   pooka 
    463   1.7   pooka 	USES_SYMLINKS;
    464   1.7   pooka 
    465   1.7   pooka 	RL(rump_sys_chdir(mp));
    466   1.8   pooka 
    467   1.8   pooka 	if (FSTYPE_TMPFS(tc)) {
    468   1.8   pooka 		atf_tc_expect_signal(SIGABRT, "PR kern/43843");
    469   1.8   pooka 	}
    470   1.8   pooka 
    471   1.7   pooka 	RL(rump_sys_symlink("", "afile"));
    472   1.7   pooka 	RL(rump_sys_chdir("/"));
    473   1.7   pooka }
    474   1.7   pooka 
    475  1.11   pooka static void
    476  1.11   pooka attrs(const atf_tc_t *tc, const char *mp)
    477  1.11   pooka {
    478  1.11   pooka 	struct stat sb, sb2;
    479  1.11   pooka 	struct timeval tv[2];
    480  1.11   pooka 	int fd;
    481  1.11   pooka 
    482  1.11   pooka 	FSTEST_ENTER();
    483  1.11   pooka 	RL(fd = rump_sys_open(TESTFILE, O_RDWR | O_CREAT, 0755));
    484  1.11   pooka 	RL(rump_sys_close(fd));
    485  1.11   pooka 	RL(rump_sys_stat(TESTFILE, &sb));
    486  1.11   pooka 	if (!(FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))) {
    487  1.11   pooka 		RL(rump_sys_chown(TESTFILE, 1, 2));
    488  1.11   pooka 		sb.st_uid = 1;
    489  1.11   pooka 		sb.st_gid = 2;
    490  1.11   pooka 		RL(rump_sys_chmod(TESTFILE, 0123));
    491  1.11   pooka 		sb.st_mode = (sb.st_mode & ~ACCESSPERMS) | 0123;
    492  1.11   pooka 	}
    493  1.11   pooka 
    494  1.11   pooka 	tv[0].tv_sec = 1000000000; /* need something >1980 for msdosfs */
    495  1.11   pooka 	tv[0].tv_usec = 1;
    496  1.11   pooka 	tv[1].tv_sec = 1000000002; /* need even seconds for msdosfs */
    497  1.11   pooka 	tv[1].tv_usec = 3;
    498  1.11   pooka 	RL(rump_sys_utimes(TESTFILE, tv));
    499  1.11   pooka 	RL(rump_sys_utimes(TESTFILE, tv)); /* XXX: utimes & birthtime */
    500  1.11   pooka 	sb.st_atimespec.tv_sec = 1000000000;
    501  1.11   pooka 	sb.st_atimespec.tv_nsec = 1000;
    502  1.11   pooka 	sb.st_mtimespec.tv_sec = 1000000002;
    503  1.11   pooka 	sb.st_mtimespec.tv_nsec = 3000;
    504  1.11   pooka 
    505  1.11   pooka 	RL(rump_sys_stat(TESTFILE, &sb2));
    506  1.11   pooka #define CHECK(a) ATF_REQUIRE_EQ(sb.a, sb2.a)
    507  1.11   pooka 	if (!(FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))) {
    508  1.11   pooka 		CHECK(st_uid);
    509  1.11   pooka 		CHECK(st_gid);
    510  1.11   pooka 		CHECK(st_mode);
    511  1.11   pooka 	}
    512  1.11   pooka 	if (!FSTYPE_MSDOS(tc)) {
    513  1.11   pooka 		/* msdosfs has only access date, not time */
    514  1.11   pooka 		CHECK(st_atimespec.tv_sec);
    515  1.11   pooka 	}
    516  1.11   pooka 	CHECK(st_mtimespec.tv_sec);
    517  1.11   pooka 	if (!(FSTYPE_EXT2FS(tc) || FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))) {
    518  1.11   pooka 		CHECK(st_atimespec.tv_nsec);
    519  1.11   pooka 		CHECK(st_mtimespec.tv_nsec);
    520  1.11   pooka 	}
    521  1.11   pooka #undef  CHECK
    522  1.11   pooka 
    523  1.11   pooka 	FSTEST_EXIT();
    524  1.11   pooka }
    525  1.11   pooka 
    526  1.12  kefren static void
    527  1.12  kefren fcntl_lock(const atf_tc_t *tc, const char *mp)
    528  1.12  kefren {
    529  1.12  kefren 	int fd, fd2;
    530  1.12  kefren 	struct flock l;
    531  1.12  kefren 	struct lwp *lwp1, *lwp2;
    532  1.12  kefren 
    533  1.12  kefren 	FSTEST_ENTER();
    534  1.12  kefren 	l.l_pid = 0;
    535  1.12  kefren 	l.l_start = l.l_len = 1024;
    536  1.12  kefren 	l.l_type = F_RDLCK | F_WRLCK;
    537  1.12  kefren 	l.l_whence = SEEK_END;
    538  1.12  kefren 
    539  1.12  kefren 	lwp1 = rump_pub_lwproc_curlwp();
    540  1.12  kefren 	RL(fd = rump_sys_open(TESTFILE, O_RDWR | O_CREAT, 0755));
    541  1.12  kefren 	RL(rump_sys_ftruncate(fd, 8192));
    542  1.12  kefren 
    543  1.12  kefren 	/* PR kern/43321 */
    544  1.12  kefren 	RL(rump_sys_fcntl(fd, F_SETLK, &l));
    545  1.12  kefren 
    546  1.12  kefren 	/* Next, we fork and try to lock the same area */
    547  1.12  kefren 	RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
    548  1.12  kefren 	lwp2 = rump_pub_lwproc_curlwp();
    549  1.12  kefren 	RL(fd2 = rump_sys_open(TESTFILE, O_RDWR, 0));
    550  1.12  kefren 	ATF_REQUIRE_ERRNO(EAGAIN, rump_sys_fcntl(fd2, F_SETLK, &l));
    551  1.12  kefren 
    552  1.12  kefren 	/* Switch back and unlock... */
    553  1.12  kefren 	rump_pub_lwproc_switch(lwp1);
    554  1.12  kefren 	l.l_type = F_UNLCK;
    555  1.12  kefren 	RL(rump_sys_fcntl(fd, F_SETLK, &l));
    556  1.12  kefren 
    557  1.12  kefren 	/* ... and try to lock again */
    558  1.12  kefren 	rump_pub_lwproc_switch(lwp2);
    559  1.12  kefren 	l.l_type = F_RDLCK | F_WRLCK;
    560  1.12  kefren 	RL(rump_sys_fcntl(fd2, F_SETLK, &l));
    561  1.12  kefren 
    562  1.12  kefren 	RL(rump_sys_close(fd2));
    563  1.12  kefren 	rump_pub_lwproc_releaselwp();
    564  1.12  kefren 
    565  1.12  kefren 	RL(rump_sys_close(fd));
    566  1.12  kefren 
    567  1.12  kefren 	FSTEST_EXIT();
    568  1.12  kefren }
    569  1.12  kefren 
    570   1.1   pooka ATF_TC_FSAPPLY(lookup_simple, "simple lookup (./.. on root)");
    571   1.1   pooka ATF_TC_FSAPPLY(lookup_complex, "lookup of non-dot entries");
    572   1.1   pooka ATF_TC_FSAPPLY(dir_simple, "mkdir/rmdir");
    573   1.1   pooka ATF_TC_FSAPPLY(dir_notempty, "non-empty directories cannot be removed");
    574   1.2   pooka ATF_TC_FSAPPLY(rename_dir, "exercise various directory renaming ops");
    575   1.2   pooka ATF_TC_FSAPPLY(rename_dotdot, "rename dir ..");
    576   1.2   pooka ATF_TC_FSAPPLY(rename_reg_nodir, "rename regular files, no subdirectories");
    577   1.5   njoly ATF_TC_FSAPPLY(create_nametoolong, "create file with name too long");
    578   1.5   njoly ATF_TC_FSAPPLY(rename_nametoolong, "rename to file with name too long");
    579   1.7   pooka ATF_TC_FSAPPLY(symlink_zerolen, "symlink with 0-len target");
    580  1.11   pooka ATF_TC_FSAPPLY(attrs, "check setting attributes works");
    581  1.12  kefren ATF_TC_FSAPPLY(fcntl_lock, "check fcntl F_SETLK");
    582   1.1   pooka 
    583   1.1   pooka ATF_TP_ADD_TCS(tp)
    584   1.1   pooka {
    585   1.1   pooka 
    586   1.1   pooka 	ATF_TP_FSAPPLY(lookup_simple);
    587   1.1   pooka 	ATF_TP_FSAPPLY(lookup_complex);
    588   1.1   pooka 	ATF_TP_FSAPPLY(dir_simple);
    589   1.1   pooka 	ATF_TP_FSAPPLY(dir_notempty);
    590   1.2   pooka 	ATF_TP_FSAPPLY(rename_dir);
    591   1.2   pooka 	ATF_TP_FSAPPLY(rename_dotdot);
    592   1.2   pooka 	ATF_TP_FSAPPLY(rename_reg_nodir);
    593   1.5   njoly 	ATF_TP_FSAPPLY(create_nametoolong);
    594   1.5   njoly 	ATF_TP_FSAPPLY(rename_nametoolong);
    595   1.7   pooka 	ATF_TP_FSAPPLY(symlink_zerolen);
    596  1.11   pooka 	ATF_TP_FSAPPLY(attrs);
    597  1.12  kefren 	ATF_TP_FSAPPLY(fcntl_lock);
    598   1.1   pooka 
    599   1.1   pooka 	return atf_no_error();
    600   1.1   pooka }
    601