t_vnops.c revision 1.8 1 1.8 pooka /* $NetBSD: t_vnops.c,v 1.8 2010/09/06 15:27:18 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.7 pooka atf_tc_skip("dirs 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.2 pooka USES_DIRS;
175 1.2 pooka
176 1.2 pooka md(pb1, mp, "dir1");
177 1.2 pooka if (rump_sys_mkdir(pb1, 0777) == -1)
178 1.2 pooka atf_tc_fail_errno("mkdir 1");
179 1.2 pooka
180 1.2 pooka md(pb2, mp, "dir2");
181 1.2 pooka if (rump_sys_mkdir(pb2, 0777) == -1)
182 1.2 pooka atf_tc_fail_errno("mkdir 2");
183 1.2 pooka md(pb2, mp, "dir2/subdir");
184 1.2 pooka if (rump_sys_mkdir(pb2, 0777) == -1)
185 1.2 pooka atf_tc_fail_errno("mkdir 3");
186 1.2 pooka
187 1.2 pooka md(pb3, mp, "dir1/file");
188 1.2 pooka if (rump_sys_mknod(pb3, S_IFREG | 0777, -1) == -1)
189 1.2 pooka atf_tc_fail_errno("create file");
190 1.2 pooka if (rump_sys_stat(pb3, &ref) == -1)
191 1.2 pooka atf_tc_fail_errno("stat of file");
192 1.2 pooka
193 1.2 pooka /*
194 1.2 pooka * First try ops which should succeed.
195 1.2 pooka */
196 1.2 pooka
197 1.2 pooka /* rename within directory */
198 1.2 pooka md(pb3, mp, "dir3");
199 1.2 pooka if (rump_sys_rename(pb1, pb3) == -1)
200 1.2 pooka atf_tc_fail_errno("rename 1");
201 1.2 pooka checkfile(pb3, &ref);
202 1.2 pooka
203 1.2 pooka /* rename directory onto itself (two ways, should fail) */
204 1.2 pooka md(pb1, mp, "dir3/.");
205 1.2 pooka if (rump_sys_rename(pb1, pb3) != -1 || errno != EINVAL)
206 1.2 pooka atf_tc_fail_errno("rename 2");
207 1.2 pooka if (rump_sys_rename(pb3, pb1) != -1 || errno != EISDIR)
208 1.2 pooka atf_tc_fail_errno("rename 3");
209 1.2 pooka
210 1.2 pooka checkfile(pb3, &ref);
211 1.2 pooka
212 1.2 pooka /* rename father of directory into directory */
213 1.2 pooka md(pb1, mp, "dir2/dir");
214 1.2 pooka md(pb2, mp, "dir2");
215 1.2 pooka if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL)
216 1.2 pooka atf_tc_fail_errno("rename 4");
217 1.2 pooka
218 1.2 pooka /* same for grandfather */
219 1.2 pooka md(pb1, mp, "dir2/subdir/dir2");
220 1.2 pooka if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL)
221 1.2 pooka atf_tc_fail("rename 5");
222 1.2 pooka
223 1.2 pooka checkfile(pb3, &ref);
224 1.2 pooka
225 1.2 pooka /* rename directory over a non-empty directory */
226 1.2 pooka if (rump_sys_rename(pb2, pb3) != -1 || errno != ENOTEMPTY)
227 1.2 pooka atf_tc_fail("rename 6");
228 1.2 pooka
229 1.2 pooka /* cross-directory rename */
230 1.2 pooka md(pb1, mp, "dir3");
231 1.2 pooka md(pb2, mp, "dir2/somedir");
232 1.2 pooka if (rump_sys_rename(pb1, pb2) == -1)
233 1.2 pooka atf_tc_fail_errno("rename 7");
234 1.2 pooka checkfile(pb2, &ref);
235 1.2 pooka
236 1.2 pooka /* move to parent directory */
237 1.2 pooka md(pb1, mp, "dir2/somedir/../../dir3");
238 1.2 pooka if (rump_sys_rename(pb2, pb1) == -1)
239 1.2 pooka atf_tc_fail_errno("rename 8");
240 1.2 pooka md(pb1, mp, "dir2/../dir3");
241 1.2 pooka checkfile(pb1, &ref);
242 1.2 pooka
243 1.2 pooka /* finally, atomic cross-directory rename */
244 1.2 pooka md(pb3, mp, "dir2/subdir");
245 1.2 pooka if (rump_sys_rename(pb1, pb3) == -1)
246 1.2 pooka atf_tc_fail_errno("rename 9");
247 1.2 pooka checkfile(pb3, &ref);
248 1.2 pooka }
249 1.2 pooka
250 1.2 pooka static void
251 1.2 pooka rename_dotdot(const atf_tc_t *tc, const char *mp)
252 1.2 pooka {
253 1.2 pooka
254 1.2 pooka USES_DIRS;
255 1.2 pooka
256 1.2 pooka if (rump_sys_chdir(mp) == -1)
257 1.2 pooka atf_tc_fail_errno("chdir mountpoint");
258 1.2 pooka
259 1.2 pooka if (rump_sys_mkdir("dir1", 0777) == -1)
260 1.2 pooka atf_tc_fail_errno("mkdir 1");
261 1.2 pooka if (rump_sys_mkdir("dir2", 0777) == -1)
262 1.2 pooka atf_tc_fail_errno("mkdir 2");
263 1.2 pooka
264 1.2 pooka if (rump_sys_rename("dir1", "dir1/..") != -1 || errno != EINVAL)
265 1.2 pooka atf_tc_fail_errno("self-dotdot to");
266 1.2 pooka
267 1.2 pooka if (rump_sys_rename("dir1/..", "sometarget") != -1 || errno != EINVAL)
268 1.2 pooka atf_tc_fail_errno("self-dotdot from");
269 1.2 pooka atf_tc_expect_pass();
270 1.2 pooka
271 1.2 pooka if (FSTYPE_TMPFS(tc)) {
272 1.2 pooka atf_tc_expect_fail("PR kern/43617");
273 1.2 pooka }
274 1.2 pooka if (rump_sys_rename("dir1", "dir2/..") != -1 || errno != EINVAL)
275 1.2 pooka atf_tc_fail("other-dotdot");
276 1.2 pooka
277 1.2 pooka rump_sys_chdir("/");
278 1.2 pooka }
279 1.2 pooka
280 1.2 pooka static void
281 1.2 pooka rename_reg_nodir(const atf_tc_t *tc, const char *mp)
282 1.2 pooka {
283 1.2 pooka bool haslinks;
284 1.2 pooka struct stat sb;
285 1.2 pooka ino_t f1ino, f2ino;
286 1.2 pooka
287 1.3 pooka if (FSTYPE_MSDOS(tc))
288 1.3 pooka atf_tc_skip("test fails in some setups, reason unknown");
289 1.3 pooka
290 1.2 pooka if (rump_sys_chdir(mp) == -1)
291 1.2 pooka atf_tc_fail_errno("chdir mountpoint");
292 1.2 pooka
293 1.2 pooka if (FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))
294 1.2 pooka haslinks = false;
295 1.2 pooka else
296 1.2 pooka haslinks = true;
297 1.2 pooka
298 1.2 pooka if (rump_sys_mknod("file1", S_IFREG | 0777, -1) == -1)
299 1.2 pooka atf_tc_fail_errno("create file");
300 1.2 pooka if (rump_sys_mknod("file2", S_IFREG | 0777, -1) == -1)
301 1.2 pooka atf_tc_fail_errno("create file");
302 1.2 pooka
303 1.2 pooka if (rump_sys_stat("file1", &sb) == -1)
304 1.2 pooka atf_tc_fail_errno("stat");
305 1.2 pooka f1ino = sb.st_ino;
306 1.2 pooka
307 1.2 pooka if (haslinks) {
308 1.2 pooka if (rump_sys_link("file1", "file_link") == -1)
309 1.2 pooka atf_tc_fail_errno("link");
310 1.2 pooka if (rump_sys_stat("file_link", &sb) == -1)
311 1.2 pooka atf_tc_fail_errno("stat");
312 1.2 pooka ATF_REQUIRE_EQ(sb.st_ino, f1ino);
313 1.2 pooka ATF_REQUIRE_EQ(sb.st_nlink, 2);
314 1.2 pooka }
315 1.2 pooka
316 1.2 pooka if (rump_sys_stat("file2", &sb) == -1)
317 1.2 pooka atf_tc_fail_errno("stat");
318 1.2 pooka f2ino = sb.st_ino;
319 1.2 pooka
320 1.2 pooka if (rump_sys_rename("file1", "file3") == -1)
321 1.2 pooka atf_tc_fail_errno("rename 1");
322 1.2 pooka if (rump_sys_stat("file3", &sb) == -1)
323 1.2 pooka atf_tc_fail_errno("stat 1");
324 1.2 pooka if (haslinks) {
325 1.2 pooka ATF_REQUIRE_EQ(sb.st_ino, f1ino);
326 1.2 pooka }
327 1.2 pooka if (rump_sys_stat("file1", &sb) != -1 || errno != ENOENT)
328 1.2 pooka atf_tc_fail_errno("source 1");
329 1.2 pooka
330 1.2 pooka if (rump_sys_rename("file3", "file2") == -1)
331 1.2 pooka atf_tc_fail_errno("rename 2");
332 1.2 pooka if (rump_sys_stat("file2", &sb) == -1)
333 1.2 pooka atf_tc_fail_errno("stat 2");
334 1.2 pooka if (haslinks) {
335 1.2 pooka ATF_REQUIRE_EQ(sb.st_ino, f1ino);
336 1.2 pooka }
337 1.2 pooka
338 1.2 pooka if (rump_sys_stat("file3", &sb) != -1 || errno != ENOENT)
339 1.2 pooka atf_tc_fail_errno("source 2");
340 1.2 pooka
341 1.2 pooka if (haslinks) {
342 1.2 pooka if (rump_sys_rename("file2", "file_link") == -1)
343 1.2 pooka atf_tc_fail_errno("rename hardlink");
344 1.2 pooka if (rump_sys_stat("file2", &sb) != -1 || errno != ENOENT)
345 1.2 pooka atf_tc_fail_errno("source 3");
346 1.2 pooka if (rump_sys_stat("file_link", &sb) == -1)
347 1.2 pooka atf_tc_fail_errno("stat 2");
348 1.2 pooka ATF_REQUIRE_EQ(sb.st_ino, f1ino);
349 1.2 pooka ATF_REQUIRE_EQ(sb.st_nlink, 1);
350 1.2 pooka }
351 1.2 pooka
352 1.2 pooka rump_sys_chdir("/");
353 1.2 pooka }
354 1.2 pooka
355 1.5 njoly static void
356 1.5 njoly create_nametoolong(const atf_tc_t *tc, const char *mp)
357 1.5 njoly {
358 1.5 njoly char *name;
359 1.5 njoly int fd;
360 1.5 njoly long val;
361 1.5 njoly size_t len;
362 1.5 njoly
363 1.5 njoly if (rump_sys_chdir(mp) == -1)
364 1.5 njoly atf_tc_fail_errno("chdir mountpoint");
365 1.5 njoly
366 1.5 njoly val = rump_sys_pathconf(".", _PC_NAME_MAX);
367 1.5 njoly if (val == -1)
368 1.5 njoly atf_tc_fail_errno("pathconf");
369 1.5 njoly
370 1.5 njoly len = val + 1;
371 1.5 njoly name = malloc(len+1);
372 1.5 njoly if (name == NULL)
373 1.5 njoly atf_tc_fail_errno("malloc");
374 1.5 njoly
375 1.5 njoly memset(name, 'a', len);
376 1.5 njoly *(name+len) = '\0';
377 1.5 njoly
378 1.5 njoly val = rump_sys_pathconf(".", _PC_NO_TRUNC);
379 1.5 njoly if (val == -1)
380 1.5 njoly atf_tc_fail_errno("pathconf");
381 1.5 njoly
382 1.5 njoly if (FSTYPE_MSDOS(tc))
383 1.5 njoly atf_tc_expect_fail("PR kern/43670");
384 1.5 njoly fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666);
385 1.5 njoly if (val != 0 && (fd != -1 || errno != ENAMETOOLONG))
386 1.5 njoly atf_tc_fail_errno("open");
387 1.5 njoly
388 1.5 njoly if (val == 0 && rump_sys_close(fd) == -1)
389 1.5 njoly atf_tc_fail_errno("close");
390 1.5 njoly if (val == 0 && rump_sys_unlink(name) == -1)
391 1.5 njoly atf_tc_fail_errno("unlink");
392 1.5 njoly
393 1.5 njoly free(name);
394 1.5 njoly
395 1.5 njoly rump_sys_chdir("/");
396 1.5 njoly }
397 1.5 njoly
398 1.5 njoly static void
399 1.5 njoly rename_nametoolong(const atf_tc_t *tc, const char *mp)
400 1.5 njoly {
401 1.5 njoly char *name;
402 1.5 njoly int res, fd;
403 1.5 njoly long val;
404 1.5 njoly size_t len;
405 1.5 njoly
406 1.5 njoly if (rump_sys_chdir(mp) == -1)
407 1.5 njoly atf_tc_fail_errno("chdir mountpoint");
408 1.5 njoly
409 1.5 njoly val = rump_sys_pathconf(".", _PC_NAME_MAX);
410 1.5 njoly if (val == -1)
411 1.5 njoly atf_tc_fail_errno("pathconf");
412 1.5 njoly
413 1.5 njoly len = val + 1;
414 1.5 njoly name = malloc(len+1);
415 1.5 njoly if (name == NULL)
416 1.5 njoly atf_tc_fail_errno("malloc");
417 1.5 njoly
418 1.5 njoly memset(name, 'a', len);
419 1.5 njoly *(name+len) = '\0';
420 1.5 njoly
421 1.5 njoly fd = rump_sys_open("dummy", O_RDWR|O_CREAT, 0666);
422 1.5 njoly if (fd == -1)
423 1.5 njoly atf_tc_fail_errno("open");
424 1.5 njoly if (rump_sys_close(fd) == -1)
425 1.5 njoly atf_tc_fail_errno("close");
426 1.5 njoly
427 1.5 njoly val = rump_sys_pathconf(".", _PC_NO_TRUNC);
428 1.5 njoly if (val == -1)
429 1.5 njoly atf_tc_fail_errno("pathconf");
430 1.5 njoly
431 1.5 njoly if (FSTYPE_MSDOS(tc))
432 1.5 njoly atf_tc_expect_fail("PR kern/43670");
433 1.5 njoly res = rump_sys_rename("dummy", name);
434 1.5 njoly if (val != 0 && (res != -1 || errno != ENAMETOOLONG))
435 1.5 njoly atf_tc_fail_errno("rename");
436 1.5 njoly
437 1.5 njoly if (val == 0 && rump_sys_unlink(name) == -1)
438 1.5 njoly atf_tc_fail_errno("unlink");
439 1.5 njoly
440 1.5 njoly free(name);
441 1.5 njoly
442 1.5 njoly rump_sys_chdir("/");
443 1.5 njoly }
444 1.5 njoly
445 1.7 pooka static void
446 1.7 pooka symlink_zerolen(const atf_tc_t *tc, const char *mp)
447 1.7 pooka {
448 1.7 pooka
449 1.7 pooka USES_SYMLINKS;
450 1.7 pooka
451 1.7 pooka RL(rump_sys_chdir(mp));
452 1.8 pooka
453 1.8 pooka if (FSTYPE_TMPFS(tc)) {
454 1.8 pooka atf_tc_expect_signal(SIGABRT, "PR kern/43843");
455 1.8 pooka }
456 1.8 pooka
457 1.7 pooka RL(rump_sys_symlink("", "afile"));
458 1.7 pooka RL(rump_sys_chdir("/"));
459 1.7 pooka }
460 1.7 pooka
461 1.1 pooka ATF_TC_FSAPPLY(lookup_simple, "simple lookup (./.. on root)");
462 1.1 pooka ATF_TC_FSAPPLY(lookup_complex, "lookup of non-dot entries");
463 1.1 pooka ATF_TC_FSAPPLY(dir_simple, "mkdir/rmdir");
464 1.1 pooka ATF_TC_FSAPPLY(dir_notempty, "non-empty directories cannot be removed");
465 1.2 pooka ATF_TC_FSAPPLY(rename_dir, "exercise various directory renaming ops");
466 1.2 pooka ATF_TC_FSAPPLY(rename_dotdot, "rename dir ..");
467 1.2 pooka ATF_TC_FSAPPLY(rename_reg_nodir, "rename regular files, no subdirectories");
468 1.5 njoly ATF_TC_FSAPPLY(create_nametoolong, "create file with name too long");
469 1.5 njoly ATF_TC_FSAPPLY(rename_nametoolong, "rename to file with name too long");
470 1.7 pooka ATF_TC_FSAPPLY(symlink_zerolen, "symlink with 0-len target");
471 1.1 pooka
472 1.1 pooka ATF_TP_ADD_TCS(tp)
473 1.1 pooka {
474 1.1 pooka
475 1.1 pooka ATF_TP_FSAPPLY(lookup_simple);
476 1.1 pooka ATF_TP_FSAPPLY(lookup_complex);
477 1.1 pooka ATF_TP_FSAPPLY(dir_simple);
478 1.1 pooka ATF_TP_FSAPPLY(dir_notempty);
479 1.2 pooka ATF_TP_FSAPPLY(rename_dir);
480 1.2 pooka ATF_TP_FSAPPLY(rename_dotdot);
481 1.2 pooka ATF_TP_FSAPPLY(rename_reg_nodir);
482 1.5 njoly ATF_TP_FSAPPLY(create_nametoolong);
483 1.5 njoly ATF_TP_FSAPPLY(rename_nametoolong);
484 1.7 pooka ATF_TP_FSAPPLY(symlink_zerolen);
485 1.1 pooka
486 1.1 pooka return atf_no_error();
487 1.1 pooka }
488