Home | History | Annotate | Line # | Download | only in vfs
t_vnops.c revision 1.10
      1  1.10  pooka /*	$NetBSD: t_vnops.c,v 1.10 2010/11/11 17:44:44 pooka 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.1  pooka #define USES_DIRS \
     45   1.1  pooka     if (FSTYPE_SYSVBFS(tc)) atf_tc_skip("dirs not supported by file system")
     46   1.1  pooka 
     47   1.7  pooka #define USES_SYMLINKS					\
     48   1.7  pooka     if (FSTYPE_SYSVBFS(tc) || FSTYPE_MSDOS(tc))		\
     49   1.9  njoly 	atf_tc_skip("symlinks not supported by file system")
     50   1.7  pooka 
     51   1.2  pooka static char *
     52   1.2  pooka md(char *buf, const char *base, const char *tail)
     53   1.2  pooka {
     54   1.2  pooka 
     55   1.2  pooka 	sprintf(buf, "%s/%s", base, tail);
     56   1.2  pooka 	return buf;
     57   1.2  pooka }
     58   1.2  pooka 
     59   1.1  pooka static void
     60   1.1  pooka lookup_simple(const atf_tc_t *tc, const char *mountpath)
     61   1.1  pooka {
     62   1.1  pooka 	char pb[MAXPATHLEN], final[MAXPATHLEN];
     63   1.1  pooka 	struct stat sb1, sb2;
     64   1.1  pooka 
     65   1.1  pooka 	strcpy(final, mountpath);
     66   1.1  pooka 	sprintf(pb, "%s/../%s", mountpath, basename(final));
     67   1.1  pooka 	if (rump_sys_stat(pb, &sb1) == -1)
     68   1.1  pooka 		atf_tc_fail_errno("stat 1");
     69   1.1  pooka 
     70   1.1  pooka 	sprintf(pb, "%s/./../%s", mountpath, basename(final));
     71   1.1  pooka 	if (rump_sys_stat(pb, &sb2) == -1)
     72   1.1  pooka 		atf_tc_fail_errno("stat 2");
     73   1.1  pooka 
     74   1.1  pooka 	ATF_REQUIRE(memcmp(&sb1, &sb2, sizeof(sb1)) == 0);
     75   1.1  pooka }
     76   1.1  pooka 
     77   1.1  pooka static void
     78   1.1  pooka lookup_complex(const atf_tc_t *tc, const char *mountpath)
     79   1.1  pooka {
     80   1.1  pooka 	char pb[MAXPATHLEN];
     81   1.1  pooka 	struct stat sb1, sb2;
     82   1.1  pooka 
     83   1.1  pooka 	USES_DIRS;
     84   1.1  pooka 
     85   1.1  pooka 	sprintf(pb, "%s/dir", mountpath);
     86   1.1  pooka 	if (rump_sys_mkdir(pb, 0777) == -1)
     87   1.1  pooka 		atf_tc_fail_errno("mkdir");
     88   1.1  pooka 	if (rump_sys_stat(pb, &sb1) == -1)
     89   1.1  pooka 		atf_tc_fail_errno("stat 1");
     90   1.1  pooka 
     91   1.1  pooka 	sprintf(pb, "%s/./dir/../././dir/.", mountpath);
     92   1.1  pooka 	if (rump_sys_stat(pb, &sb2) == -1)
     93   1.1  pooka 		atf_tc_fail_errno("stat 2");
     94   1.1  pooka 
     95   1.1  pooka 	ATF_REQUIRE(memcmp(&sb1, &sb2, sizeof(sb1)) == 0);
     96   1.1  pooka }
     97   1.1  pooka 
     98   1.1  pooka static void
     99   1.1  pooka dir_simple(const atf_tc_t *tc, const char *mountpath)
    100   1.1  pooka {
    101   1.1  pooka 	char pb[MAXPATHLEN];
    102   1.1  pooka 	struct stat sb;
    103   1.1  pooka 
    104   1.1  pooka 	USES_DIRS;
    105   1.1  pooka 
    106   1.1  pooka 	/* check we can create directories */
    107   1.1  pooka 	sprintf(pb, "%s/dir", mountpath);
    108   1.1  pooka 	if (rump_sys_mkdir(pb, 0777) == -1)
    109   1.1  pooka 		atf_tc_fail_errno("mkdir");
    110   1.1  pooka 	if (rump_sys_stat(pb, &sb) == -1)
    111   1.1  pooka 		atf_tc_fail_errno("stat new directory");
    112   1.1  pooka 
    113   1.1  pooka 	/* check we can remove then and that it makes them unreachable */
    114   1.1  pooka 	if (rump_sys_rmdir(pb) == -1)
    115   1.1  pooka 		atf_tc_fail_errno("rmdir");
    116   1.1  pooka 	if (rump_sys_stat(pb, &sb) != -1 || errno != ENOENT)
    117   1.1  pooka 		atf_tc_fail("ENOENT expected from stat");
    118   1.1  pooka }
    119   1.1  pooka 
    120   1.1  pooka static void
    121   1.1  pooka dir_notempty(const atf_tc_t *tc, const char *mountpath)
    122   1.1  pooka {
    123   1.1  pooka 	char pb[MAXPATHLEN], pb2[MAXPATHLEN];
    124   1.1  pooka 	int fd, rv;
    125   1.1  pooka 
    126   1.1  pooka 	USES_DIRS;
    127   1.1  pooka 
    128   1.1  pooka 	/* check we can create directories */
    129   1.1  pooka 	sprintf(pb, "%s/dir", mountpath);
    130   1.1  pooka 	if (rump_sys_mkdir(pb, 0777) == -1)
    131   1.1  pooka 		atf_tc_fail_errno("mkdir");
    132   1.1  pooka 
    133   1.1  pooka 	sprintf(pb2, "%s/dir/file", mountpath);
    134   1.1  pooka 	fd = rump_sys_open(pb2, O_RDWR | O_CREAT, 0777);
    135   1.1  pooka 	if (fd == -1)
    136   1.1  pooka 		atf_tc_fail_errno("create file");
    137   1.1  pooka 	rump_sys_close(fd);
    138   1.1  pooka 
    139   1.1  pooka 	rv = rump_sys_rmdir(pb);
    140   1.1  pooka 	if (rv != -1 || errno != ENOTEMPTY)
    141   1.1  pooka 		atf_tc_fail("non-empty directory removed succesfully");
    142   1.1  pooka 
    143   1.1  pooka 	if (rump_sys_unlink(pb2) == -1)
    144   1.1  pooka 		atf_tc_fail_errno("cannot remove dir/file");
    145   1.1  pooka 
    146   1.1  pooka 	if (rump_sys_rmdir(pb) == -1)
    147   1.1  pooka 		atf_tc_fail_errno("remove directory");
    148   1.1  pooka }
    149   1.1  pooka 
    150   1.2  pooka static void
    151   1.2  pooka checkfile(const char *path, struct stat *refp)
    152   1.2  pooka {
    153   1.2  pooka 	char buf[MAXPATHLEN];
    154   1.2  pooka 	struct stat sb;
    155   1.2  pooka 	static int n = 1;
    156   1.2  pooka 
    157   1.2  pooka 	md(buf, path, "file");
    158   1.2  pooka 	if (rump_sys_stat(buf, &sb) == -1)
    159   1.2  pooka 		atf_tc_fail_errno("cannot stat file %d (%s)", n, buf);
    160   1.2  pooka 	if (memcmp(&sb, refp, sizeof(sb)) != 0)
    161   1.2  pooka 		atf_tc_fail("stat mismatch %d", n);
    162   1.2  pooka 	n++;
    163   1.2  pooka }
    164   1.2  pooka 
    165   1.2  pooka static void
    166   1.2  pooka rename_dir(const atf_tc_t *tc, const char *mp)
    167   1.2  pooka {
    168   1.2  pooka 	char pb1[MAXPATHLEN], pb2[MAXPATHLEN], pb3[MAXPATHLEN];
    169   1.2  pooka 	struct stat ref;
    170   1.2  pooka 
    171   1.3  pooka 	if (FSTYPE_MSDOS(tc))
    172   1.3  pooka 		atf_tc_skip("test fails in some setups, reason unknown");
    173   1.3  pooka 
    174  1.10  pooka 	if (FSTYPE_RUMPFS(tc))
    175  1.10  pooka 		atf_tc_skip("rename not supported by fs");
    176  1.10  pooka 
    177   1.2  pooka 	USES_DIRS;
    178   1.2  pooka 
    179   1.2  pooka 	md(pb1, mp, "dir1");
    180   1.2  pooka 	if (rump_sys_mkdir(pb1, 0777) == -1)
    181   1.2  pooka 		atf_tc_fail_errno("mkdir 1");
    182   1.2  pooka 
    183   1.2  pooka 	md(pb2, mp, "dir2");
    184   1.2  pooka 	if (rump_sys_mkdir(pb2, 0777) == -1)
    185   1.2  pooka 		atf_tc_fail_errno("mkdir 2");
    186   1.2  pooka 	md(pb2, mp, "dir2/subdir");
    187   1.2  pooka 	if (rump_sys_mkdir(pb2, 0777) == -1)
    188   1.2  pooka 		atf_tc_fail_errno("mkdir 3");
    189   1.2  pooka 
    190   1.2  pooka 	md(pb3, mp, "dir1/file");
    191   1.2  pooka 	if (rump_sys_mknod(pb3, S_IFREG | 0777, -1) == -1)
    192   1.2  pooka 		atf_tc_fail_errno("create file");
    193   1.2  pooka 	if (rump_sys_stat(pb3, &ref) == -1)
    194   1.2  pooka 		atf_tc_fail_errno("stat of file");
    195   1.2  pooka 
    196   1.2  pooka 	/*
    197   1.2  pooka 	 * First try ops which should succeed.
    198   1.2  pooka 	 */
    199   1.2  pooka 
    200   1.2  pooka 	/* rename within directory */
    201   1.2  pooka 	md(pb3, mp, "dir3");
    202   1.2  pooka 	if (rump_sys_rename(pb1, pb3) == -1)
    203   1.2  pooka 		atf_tc_fail_errno("rename 1");
    204   1.2  pooka 	checkfile(pb3, &ref);
    205   1.2  pooka 
    206   1.2  pooka 	/* rename directory onto itself (two ways, should fail) */
    207   1.2  pooka 	md(pb1, mp, "dir3/.");
    208   1.2  pooka 	if (rump_sys_rename(pb1, pb3) != -1 || errno != EINVAL)
    209   1.2  pooka 		atf_tc_fail_errno("rename 2");
    210   1.2  pooka 	if (rump_sys_rename(pb3, pb1) != -1 || errno != EISDIR)
    211   1.2  pooka 		atf_tc_fail_errno("rename 3");
    212   1.2  pooka 
    213   1.2  pooka 	checkfile(pb3, &ref);
    214   1.2  pooka 
    215   1.2  pooka 	/* rename father of directory into directory */
    216   1.2  pooka 	md(pb1, mp, "dir2/dir");
    217   1.2  pooka 	md(pb2, mp, "dir2");
    218   1.2  pooka 	if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL)
    219   1.2  pooka 		atf_tc_fail_errno("rename 4");
    220   1.2  pooka 
    221   1.2  pooka 	/* same for grandfather */
    222   1.2  pooka 	md(pb1, mp, "dir2/subdir/dir2");
    223   1.2  pooka 	if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL)
    224   1.2  pooka 		atf_tc_fail("rename 5");
    225   1.2  pooka 
    226   1.2  pooka 	checkfile(pb3, &ref);
    227   1.2  pooka 
    228   1.2  pooka 	/* rename directory over a non-empty directory */
    229   1.2  pooka 	if (rump_sys_rename(pb2, pb3) != -1 || errno != ENOTEMPTY)
    230   1.2  pooka 		atf_tc_fail("rename 6");
    231   1.2  pooka 
    232   1.2  pooka 	/* cross-directory rename */
    233   1.2  pooka 	md(pb1, mp, "dir3");
    234   1.2  pooka 	md(pb2, mp, "dir2/somedir");
    235   1.2  pooka 	if (rump_sys_rename(pb1, pb2) == -1)
    236   1.2  pooka 		atf_tc_fail_errno("rename 7");
    237   1.2  pooka 	checkfile(pb2, &ref);
    238   1.2  pooka 
    239   1.2  pooka 	/* move to parent directory */
    240   1.2  pooka 	md(pb1, mp, "dir2/somedir/../../dir3");
    241   1.2  pooka 	if (rump_sys_rename(pb2, pb1) == -1)
    242   1.2  pooka 		atf_tc_fail_errno("rename 8");
    243   1.2  pooka 	md(pb1, mp, "dir2/../dir3");
    244   1.2  pooka 	checkfile(pb1, &ref);
    245   1.2  pooka 
    246   1.2  pooka 	/* finally, atomic cross-directory rename */
    247   1.2  pooka 	md(pb3, mp, "dir2/subdir");
    248   1.2  pooka 	if (rump_sys_rename(pb1, pb3) == -1)
    249   1.2  pooka 		atf_tc_fail_errno("rename 9");
    250   1.2  pooka 	checkfile(pb3, &ref);
    251   1.2  pooka }
    252   1.2  pooka 
    253   1.2  pooka static void
    254   1.2  pooka rename_dotdot(const atf_tc_t *tc, const char *mp)
    255   1.2  pooka {
    256   1.2  pooka 
    257  1.10  pooka 	if (FSTYPE_RUMPFS(tc))
    258  1.10  pooka 		atf_tc_skip("rename not supported by fs");
    259  1.10  pooka 
    260   1.2  pooka 	USES_DIRS;
    261   1.2  pooka 
    262   1.2  pooka 	if (rump_sys_chdir(mp) == -1)
    263   1.2  pooka 		atf_tc_fail_errno("chdir mountpoint");
    264   1.2  pooka 
    265   1.2  pooka 	if (rump_sys_mkdir("dir1", 0777) == -1)
    266   1.2  pooka 		atf_tc_fail_errno("mkdir 1");
    267   1.2  pooka 	if (rump_sys_mkdir("dir2", 0777) == -1)
    268   1.2  pooka 		atf_tc_fail_errno("mkdir 2");
    269   1.2  pooka 
    270   1.2  pooka 	if (rump_sys_rename("dir1", "dir1/..") != -1 || errno != EINVAL)
    271   1.2  pooka 		atf_tc_fail_errno("self-dotdot to");
    272   1.2  pooka 
    273   1.2  pooka 	if (rump_sys_rename("dir1/..", "sometarget") != -1 || errno != EINVAL)
    274   1.2  pooka 		atf_tc_fail_errno("self-dotdot from");
    275   1.2  pooka 	atf_tc_expect_pass();
    276   1.2  pooka 
    277   1.2  pooka 	if (FSTYPE_TMPFS(tc)) {
    278   1.2  pooka 		atf_tc_expect_fail("PR kern/43617");
    279   1.2  pooka 	}
    280   1.2  pooka 	if (rump_sys_rename("dir1", "dir2/..") != -1 || errno != EINVAL)
    281   1.2  pooka 		atf_tc_fail("other-dotdot");
    282   1.2  pooka 
    283   1.2  pooka 	rump_sys_chdir("/");
    284   1.2  pooka }
    285   1.2  pooka 
    286   1.2  pooka static void
    287   1.2  pooka rename_reg_nodir(const atf_tc_t *tc, const char *mp)
    288   1.2  pooka {
    289   1.2  pooka 	bool haslinks;
    290   1.2  pooka 	struct stat sb;
    291   1.2  pooka 	ino_t f1ino, f2ino;
    292   1.2  pooka 
    293  1.10  pooka 	if (FSTYPE_RUMPFS(tc))
    294  1.10  pooka 		atf_tc_skip("rename not supported by fs");
    295  1.10  pooka 
    296   1.3  pooka 	if (FSTYPE_MSDOS(tc))
    297   1.3  pooka 		atf_tc_skip("test fails in some setups, reason unknown");
    298   1.3  pooka 
    299   1.2  pooka 	if (rump_sys_chdir(mp) == -1)
    300   1.2  pooka 		atf_tc_fail_errno("chdir mountpoint");
    301   1.2  pooka 
    302   1.2  pooka 	if (FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))
    303   1.2  pooka 		haslinks = false;
    304   1.2  pooka 	else
    305   1.2  pooka 		haslinks = true;
    306   1.2  pooka 
    307   1.2  pooka 	if (rump_sys_mknod("file1", S_IFREG | 0777, -1) == -1)
    308   1.2  pooka 		atf_tc_fail_errno("create file");
    309   1.2  pooka 	if (rump_sys_mknod("file2", S_IFREG | 0777, -1) == -1)
    310   1.2  pooka 		atf_tc_fail_errno("create file");
    311   1.2  pooka 
    312   1.2  pooka 	if (rump_sys_stat("file1", &sb) == -1)
    313   1.2  pooka 		atf_tc_fail_errno("stat");
    314   1.2  pooka 	f1ino = sb.st_ino;
    315   1.2  pooka 
    316   1.2  pooka 	if (haslinks) {
    317   1.2  pooka 		if (rump_sys_link("file1", "file_link") == -1)
    318   1.2  pooka 			atf_tc_fail_errno("link");
    319   1.2  pooka 		if (rump_sys_stat("file_link", &sb) == -1)
    320   1.2  pooka 			atf_tc_fail_errno("stat");
    321   1.2  pooka 		ATF_REQUIRE_EQ(sb.st_ino, f1ino);
    322   1.2  pooka 		ATF_REQUIRE_EQ(sb.st_nlink, 2);
    323   1.2  pooka 	}
    324   1.2  pooka 
    325   1.2  pooka 	if (rump_sys_stat("file2", &sb) == -1)
    326   1.2  pooka 		atf_tc_fail_errno("stat");
    327   1.2  pooka 	f2ino = sb.st_ino;
    328   1.2  pooka 
    329   1.2  pooka 	if (rump_sys_rename("file1", "file3") == -1)
    330   1.2  pooka 		atf_tc_fail_errno("rename 1");
    331   1.2  pooka 	if (rump_sys_stat("file3", &sb) == -1)
    332   1.2  pooka 		atf_tc_fail_errno("stat 1");
    333   1.2  pooka 	if (haslinks) {
    334   1.2  pooka 		ATF_REQUIRE_EQ(sb.st_ino, f1ino);
    335   1.2  pooka 	}
    336   1.2  pooka 	if (rump_sys_stat("file1", &sb) != -1 || errno != ENOENT)
    337   1.2  pooka 		atf_tc_fail_errno("source 1");
    338   1.2  pooka 
    339   1.2  pooka 	if (rump_sys_rename("file3", "file2") == -1)
    340   1.2  pooka 		atf_tc_fail_errno("rename 2");
    341   1.2  pooka 	if (rump_sys_stat("file2", &sb) == -1)
    342   1.2  pooka 		atf_tc_fail_errno("stat 2");
    343   1.2  pooka 	if (haslinks) {
    344   1.2  pooka 		ATF_REQUIRE_EQ(sb.st_ino, f1ino);
    345   1.2  pooka 	}
    346   1.2  pooka 
    347   1.2  pooka 	if (rump_sys_stat("file3", &sb) != -1 || errno != ENOENT)
    348   1.2  pooka 		atf_tc_fail_errno("source 2");
    349   1.2  pooka 
    350   1.2  pooka 	if (haslinks) {
    351   1.2  pooka 		if (rump_sys_rename("file2", "file_link") == -1)
    352   1.2  pooka 			atf_tc_fail_errno("rename hardlink");
    353   1.2  pooka 		if (rump_sys_stat("file2", &sb) != -1 || errno != ENOENT)
    354   1.2  pooka 			atf_tc_fail_errno("source 3");
    355   1.2  pooka 		if (rump_sys_stat("file_link", &sb) == -1)
    356   1.2  pooka 			atf_tc_fail_errno("stat 2");
    357   1.2  pooka 		ATF_REQUIRE_EQ(sb.st_ino, f1ino);
    358   1.2  pooka 		ATF_REQUIRE_EQ(sb.st_nlink, 1);
    359   1.2  pooka 	}
    360   1.2  pooka 
    361   1.2  pooka 	rump_sys_chdir("/");
    362   1.2  pooka }
    363   1.2  pooka 
    364   1.5  njoly static void
    365   1.5  njoly create_nametoolong(const atf_tc_t *tc, const char *mp)
    366   1.5  njoly {
    367   1.5  njoly 	char *name;
    368   1.5  njoly 	int fd;
    369   1.5  njoly 	long val;
    370   1.5  njoly 	size_t len;
    371   1.5  njoly 
    372   1.5  njoly 	if (rump_sys_chdir(mp) == -1)
    373   1.5  njoly 		atf_tc_fail_errno("chdir mountpoint");
    374   1.5  njoly 
    375   1.5  njoly 	val = rump_sys_pathconf(".", _PC_NAME_MAX);
    376   1.5  njoly 	if (val == -1)
    377   1.5  njoly 		atf_tc_fail_errno("pathconf");
    378   1.5  njoly 
    379   1.5  njoly 	len = val + 1;
    380   1.5  njoly 	name = malloc(len+1);
    381   1.5  njoly 	if (name == NULL)
    382   1.5  njoly 		atf_tc_fail_errno("malloc");
    383   1.5  njoly 
    384   1.5  njoly 	memset(name, 'a', len);
    385   1.5  njoly 	*(name+len) = '\0';
    386   1.5  njoly 
    387   1.5  njoly 	val = rump_sys_pathconf(".", _PC_NO_TRUNC);
    388   1.5  njoly 	if (val == -1)
    389   1.5  njoly 		atf_tc_fail_errno("pathconf");
    390   1.5  njoly 
    391   1.5  njoly 	if (FSTYPE_MSDOS(tc))
    392   1.5  njoly 		atf_tc_expect_fail("PR kern/43670");
    393   1.5  njoly 	fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666);
    394   1.5  njoly 	if (val != 0 && (fd != -1 || errno != ENAMETOOLONG))
    395   1.5  njoly 		atf_tc_fail_errno("open");
    396   1.5  njoly 
    397   1.5  njoly 	if (val == 0 && rump_sys_close(fd) == -1)
    398   1.5  njoly 		atf_tc_fail_errno("close");
    399   1.5  njoly 	if (val == 0 && rump_sys_unlink(name) == -1)
    400   1.5  njoly 		atf_tc_fail_errno("unlink");
    401   1.5  njoly 
    402   1.5  njoly 	free(name);
    403   1.5  njoly 
    404   1.5  njoly 	rump_sys_chdir("/");
    405   1.5  njoly }
    406   1.5  njoly 
    407   1.5  njoly static void
    408   1.5  njoly rename_nametoolong(const atf_tc_t *tc, const char *mp)
    409   1.5  njoly {
    410   1.5  njoly 	char *name;
    411   1.5  njoly 	int res, fd;
    412   1.5  njoly 	long val;
    413   1.5  njoly 	size_t len;
    414   1.5  njoly 
    415  1.10  pooka 	if (FSTYPE_RUMPFS(tc))
    416  1.10  pooka 		atf_tc_skip("rename not supported by fs");
    417  1.10  pooka 
    418   1.5  njoly 	if (rump_sys_chdir(mp) == -1)
    419   1.5  njoly 		atf_tc_fail_errno("chdir mountpoint");
    420   1.5  njoly 
    421   1.5  njoly 	val = rump_sys_pathconf(".", _PC_NAME_MAX);
    422   1.5  njoly 	if (val == -1)
    423   1.5  njoly 		atf_tc_fail_errno("pathconf");
    424   1.5  njoly 
    425   1.5  njoly 	len = val + 1;
    426   1.5  njoly 	name = malloc(len+1);
    427   1.5  njoly 	if (name == NULL)
    428   1.5  njoly 		atf_tc_fail_errno("malloc");
    429   1.5  njoly 
    430   1.5  njoly 	memset(name, 'a', len);
    431   1.5  njoly 	*(name+len) = '\0';
    432   1.5  njoly 
    433   1.5  njoly 	fd = rump_sys_open("dummy", O_RDWR|O_CREAT, 0666);
    434   1.5  njoly 	if (fd == -1)
    435   1.5  njoly 		atf_tc_fail_errno("open");
    436   1.5  njoly 	if (rump_sys_close(fd) == -1)
    437   1.5  njoly 		atf_tc_fail_errno("close");
    438   1.5  njoly 
    439   1.5  njoly 	val = rump_sys_pathconf(".", _PC_NO_TRUNC);
    440   1.5  njoly 	if (val == -1)
    441   1.5  njoly 		atf_tc_fail_errno("pathconf");
    442   1.5  njoly 
    443   1.5  njoly 	if (FSTYPE_MSDOS(tc))
    444   1.5  njoly 		atf_tc_expect_fail("PR kern/43670");
    445   1.5  njoly 	res = rump_sys_rename("dummy", name);
    446   1.5  njoly 	if (val != 0 && (res != -1 || errno != ENAMETOOLONG))
    447   1.5  njoly 		atf_tc_fail_errno("rename");
    448   1.5  njoly 
    449   1.5  njoly 	if (val == 0 && rump_sys_unlink(name) == -1)
    450   1.5  njoly 		atf_tc_fail_errno("unlink");
    451   1.5  njoly 
    452   1.5  njoly 	free(name);
    453   1.5  njoly 
    454   1.5  njoly 	rump_sys_chdir("/");
    455   1.5  njoly }
    456   1.5  njoly 
    457   1.7  pooka static void
    458   1.7  pooka symlink_zerolen(const atf_tc_t *tc, const char *mp)
    459   1.7  pooka {
    460   1.7  pooka 
    461   1.7  pooka 	USES_SYMLINKS;
    462   1.7  pooka 
    463   1.7  pooka 	RL(rump_sys_chdir(mp));
    464   1.8  pooka 
    465   1.8  pooka 	if (FSTYPE_TMPFS(tc)) {
    466   1.8  pooka 		atf_tc_expect_signal(SIGABRT, "PR kern/43843");
    467   1.8  pooka 	}
    468   1.8  pooka 
    469   1.7  pooka 	RL(rump_sys_symlink("", "afile"));
    470   1.7  pooka 	RL(rump_sys_chdir("/"));
    471   1.7  pooka }
    472   1.7  pooka 
    473   1.1  pooka ATF_TC_FSAPPLY(lookup_simple, "simple lookup (./.. on root)");
    474   1.1  pooka ATF_TC_FSAPPLY(lookup_complex, "lookup of non-dot entries");
    475   1.1  pooka ATF_TC_FSAPPLY(dir_simple, "mkdir/rmdir");
    476   1.1  pooka ATF_TC_FSAPPLY(dir_notempty, "non-empty directories cannot be removed");
    477   1.2  pooka ATF_TC_FSAPPLY(rename_dir, "exercise various directory renaming ops");
    478   1.2  pooka ATF_TC_FSAPPLY(rename_dotdot, "rename dir ..");
    479   1.2  pooka ATF_TC_FSAPPLY(rename_reg_nodir, "rename regular files, no subdirectories");
    480   1.5  njoly ATF_TC_FSAPPLY(create_nametoolong, "create file with name too long");
    481   1.5  njoly ATF_TC_FSAPPLY(rename_nametoolong, "rename to file with name too long");
    482   1.7  pooka ATF_TC_FSAPPLY(symlink_zerolen, "symlink with 0-len target");
    483   1.1  pooka 
    484   1.1  pooka ATF_TP_ADD_TCS(tp)
    485   1.1  pooka {
    486   1.1  pooka 
    487   1.1  pooka 	ATF_TP_FSAPPLY(lookup_simple);
    488   1.1  pooka 	ATF_TP_FSAPPLY(lookup_complex);
    489   1.1  pooka 	ATF_TP_FSAPPLY(dir_simple);
    490   1.1  pooka 	ATF_TP_FSAPPLY(dir_notempty);
    491   1.2  pooka 	ATF_TP_FSAPPLY(rename_dir);
    492   1.2  pooka 	ATF_TP_FSAPPLY(rename_dotdot);
    493   1.2  pooka 	ATF_TP_FSAPPLY(rename_reg_nodir);
    494   1.5  njoly 	ATF_TP_FSAPPLY(create_nametoolong);
    495   1.5  njoly 	ATF_TP_FSAPPLY(rename_nametoolong);
    496   1.7  pooka 	ATF_TP_FSAPPLY(symlink_zerolen);
    497   1.1  pooka 
    498   1.1  pooka 	return atf_no_error();
    499   1.1  pooka }
    500