t_vnops.c revision 1.41 1 1.41 gson /* $NetBSD: t_vnops.c,v 1.41 2014/08/12 12:13:09 gson 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.13 pooka #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.13 pooka #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.29 njoly #define USES_DIRS \
49 1.29 njoly if (FSTYPE_SYSVBFS(tc)) \
50 1.29 njoly atf_tc_skip("directories not supported by file system")
51 1.1 pooka
52 1.7 pooka #define USES_SYMLINKS \
53 1.7 pooka if (FSTYPE_SYSVBFS(tc) || FSTYPE_MSDOS(tc)) \
54 1.9 njoly atf_tc_skip("symlinks not supported by file system")
55 1.7 pooka
56 1.2 pooka static char *
57 1.2 pooka md(char *buf, const char *base, const char *tail)
58 1.2 pooka {
59 1.2 pooka
60 1.2 pooka sprintf(buf, "%s/%s", base, tail);
61 1.2 pooka return buf;
62 1.2 pooka }
63 1.2 pooka
64 1.1 pooka static void
65 1.1 pooka lookup_simple(const atf_tc_t *tc, const char *mountpath)
66 1.1 pooka {
67 1.1 pooka char pb[MAXPATHLEN], final[MAXPATHLEN];
68 1.1 pooka struct stat sb1, sb2;
69 1.1 pooka
70 1.1 pooka strcpy(final, mountpath);
71 1.1 pooka sprintf(pb, "%s/../%s", mountpath, basename(final));
72 1.1 pooka if (rump_sys_stat(pb, &sb1) == -1)
73 1.1 pooka atf_tc_fail_errno("stat 1");
74 1.1 pooka
75 1.1 pooka sprintf(pb, "%s/./../%s", mountpath, basename(final));
76 1.1 pooka if (rump_sys_stat(pb, &sb2) == -1)
77 1.1 pooka atf_tc_fail_errno("stat 2");
78 1.1 pooka
79 1.1 pooka ATF_REQUIRE(memcmp(&sb1, &sb2, sizeof(sb1)) == 0);
80 1.1 pooka }
81 1.1 pooka
82 1.1 pooka static void
83 1.1 pooka lookup_complex(const atf_tc_t *tc, const char *mountpath)
84 1.1 pooka {
85 1.1 pooka char pb[MAXPATHLEN];
86 1.1 pooka struct stat sb1, sb2;
87 1.1 pooka
88 1.1 pooka USES_DIRS;
89 1.1 pooka
90 1.41 gson if (FSTYPE_UDF(tc))
91 1.41 gson atf_tc_expect_fail("PR kern/49033");
92 1.41 gson
93 1.1 pooka sprintf(pb, "%s/dir", mountpath);
94 1.1 pooka if (rump_sys_mkdir(pb, 0777) == -1)
95 1.1 pooka atf_tc_fail_errno("mkdir");
96 1.1 pooka if (rump_sys_stat(pb, &sb1) == -1)
97 1.1 pooka atf_tc_fail_errno("stat 1");
98 1.1 pooka
99 1.1 pooka sprintf(pb, "%s/./dir/../././dir/.", mountpath);
100 1.1 pooka if (rump_sys_stat(pb, &sb2) == -1)
101 1.1 pooka atf_tc_fail_errno("stat 2");
102 1.1 pooka
103 1.40 martin if (memcmp(&sb1, &sb2, sizeof(sb1)) != 0) {
104 1.40 martin printf("what\tsb1\t\tsb2\n");
105 1.40 martin
106 1.40 martin #define FIELD(FN) \
107 1.40 martin printf(#FN "\t%lld\t%lld\n", \
108 1.40 martin (long long)sb1.FN, (long long)sb2.FN)
109 1.40 martin #define TIME(FN) \
110 1.40 martin printf(#FN "\t%lld.%ld\t%lld.%ld\n", \
111 1.40 martin (long long)sb1.FN.tv_sec, sb1.FN.tv_nsec, \
112 1.40 martin (long long)sb2.FN.tv_sec, sb2.FN.tv_nsec)
113 1.40 martin
114 1.40 martin FIELD(st_dev);
115 1.40 martin FIELD(st_mode);
116 1.40 martin FIELD(st_ino);
117 1.40 martin FIELD(st_nlink);
118 1.40 martin FIELD(st_uid);
119 1.40 martin FIELD(st_gid);
120 1.40 martin FIELD(st_rdev);
121 1.40 martin TIME(st_atim);
122 1.40 martin TIME(st_mtim);
123 1.40 martin TIME(st_ctim);
124 1.40 martin TIME(st_birthtim);
125 1.40 martin FIELD(st_size);
126 1.40 martin FIELD(st_blocks);
127 1.40 martin FIELD(st_flags);
128 1.40 martin FIELD(st_gen);
129 1.40 martin
130 1.40 martin #undef FIELD
131 1.40 martin #undef TIME
132 1.40 martin
133 1.40 martin atf_tc_fail("stat results differ, see ouput for more details");
134 1.40 martin }
135 1.41 gson if (FSTYPE_UDF(tc))
136 1.41 gson atf_tc_fail("random failure of PR kern/49033 "
137 1.41 gson "did not happen this time");
138 1.1 pooka }
139 1.1 pooka
140 1.1 pooka static void
141 1.1 pooka dir_simple(const atf_tc_t *tc, const char *mountpath)
142 1.1 pooka {
143 1.1 pooka char pb[MAXPATHLEN];
144 1.1 pooka struct stat sb;
145 1.1 pooka
146 1.1 pooka USES_DIRS;
147 1.1 pooka
148 1.1 pooka /* check we can create directories */
149 1.1 pooka sprintf(pb, "%s/dir", mountpath);
150 1.1 pooka if (rump_sys_mkdir(pb, 0777) == -1)
151 1.1 pooka atf_tc_fail_errno("mkdir");
152 1.1 pooka if (rump_sys_stat(pb, &sb) == -1)
153 1.1 pooka atf_tc_fail_errno("stat new directory");
154 1.1 pooka
155 1.1 pooka /* check we can remove then and that it makes them unreachable */
156 1.1 pooka if (rump_sys_rmdir(pb) == -1)
157 1.1 pooka atf_tc_fail_errno("rmdir");
158 1.1 pooka if (rump_sys_stat(pb, &sb) != -1 || errno != ENOENT)
159 1.1 pooka atf_tc_fail("ENOENT expected from stat");
160 1.1 pooka }
161 1.1 pooka
162 1.1 pooka static void
163 1.1 pooka dir_notempty(const atf_tc_t *tc, const char *mountpath)
164 1.1 pooka {
165 1.1 pooka char pb[MAXPATHLEN], pb2[MAXPATHLEN];
166 1.1 pooka int fd, rv;
167 1.1 pooka
168 1.1 pooka USES_DIRS;
169 1.1 pooka
170 1.1 pooka /* check we can create directories */
171 1.1 pooka sprintf(pb, "%s/dir", mountpath);
172 1.1 pooka if (rump_sys_mkdir(pb, 0777) == -1)
173 1.1 pooka atf_tc_fail_errno("mkdir");
174 1.1 pooka
175 1.1 pooka sprintf(pb2, "%s/dir/file", mountpath);
176 1.1 pooka fd = rump_sys_open(pb2, O_RDWR | O_CREAT, 0777);
177 1.1 pooka if (fd == -1)
178 1.1 pooka atf_tc_fail_errno("create file");
179 1.1 pooka rump_sys_close(fd);
180 1.1 pooka
181 1.1 pooka rv = rump_sys_rmdir(pb);
182 1.34 jmmv if (FSTYPE_ZFS(tc))
183 1.34 jmmv atf_tc_expect_fail("PR kern/47656: Test known to be broken");
184 1.1 pooka if (rv != -1 || errno != ENOTEMPTY)
185 1.1 pooka atf_tc_fail("non-empty directory removed succesfully");
186 1.1 pooka
187 1.1 pooka if (rump_sys_unlink(pb2) == -1)
188 1.1 pooka atf_tc_fail_errno("cannot remove dir/file");
189 1.1 pooka
190 1.1 pooka if (rump_sys_rmdir(pb) == -1)
191 1.1 pooka atf_tc_fail_errno("remove directory");
192 1.1 pooka }
193 1.1 pooka
194 1.2 pooka static void
195 1.18 pooka dir_rmdirdotdot(const atf_tc_t *tc, const char *mp)
196 1.18 pooka {
197 1.18 pooka char pb[MAXPATHLEN];
198 1.18 pooka int xerrno;
199 1.18 pooka
200 1.18 pooka USES_DIRS;
201 1.18 pooka
202 1.18 pooka FSTEST_ENTER();
203 1.18 pooka RL(rump_sys_mkdir("test", 0777));
204 1.18 pooka RL(rump_sys_chdir("test"));
205 1.18 pooka
206 1.18 pooka RL(rump_sys_mkdir("subtest", 0777));
207 1.18 pooka RL(rump_sys_chdir("subtest"));
208 1.18 pooka
209 1.18 pooka md(pb, mp, "test/subtest");
210 1.18 pooka RL(rump_sys_rmdir(pb));
211 1.18 pooka md(pb, mp, "test");
212 1.18 pooka RL(rump_sys_rmdir(pb));
213 1.18 pooka
214 1.18 pooka if (FSTYPE_NFS(tc))
215 1.18 pooka xerrno = ESTALE;
216 1.18 pooka else
217 1.18 pooka xerrno = ENOENT;
218 1.18 pooka ATF_REQUIRE_ERRNO(xerrno, rump_sys_chdir("..") == -1);
219 1.18 pooka FSTEST_EXIT();
220 1.18 pooka }
221 1.18 pooka
222 1.18 pooka static void
223 1.2 pooka checkfile(const char *path, struct stat *refp)
224 1.2 pooka {
225 1.2 pooka char buf[MAXPATHLEN];
226 1.2 pooka struct stat sb;
227 1.2 pooka static int n = 1;
228 1.2 pooka
229 1.2 pooka md(buf, path, "file");
230 1.2 pooka if (rump_sys_stat(buf, &sb) == -1)
231 1.2 pooka atf_tc_fail_errno("cannot stat file %d (%s)", n, buf);
232 1.2 pooka if (memcmp(&sb, refp, sizeof(sb)) != 0)
233 1.2 pooka atf_tc_fail("stat mismatch %d", n);
234 1.2 pooka n++;
235 1.2 pooka }
236 1.2 pooka
237 1.2 pooka static void
238 1.2 pooka rename_dir(const atf_tc_t *tc, const char *mp)
239 1.2 pooka {
240 1.2 pooka char pb1[MAXPATHLEN], pb2[MAXPATHLEN], pb3[MAXPATHLEN];
241 1.16 pooka struct stat ref, sb;
242 1.2 pooka
243 1.10 pooka if (FSTYPE_RUMPFS(tc))
244 1.29 njoly atf_tc_skip("rename not supported by file system");
245 1.10 pooka
246 1.2 pooka USES_DIRS;
247 1.2 pooka
248 1.2 pooka md(pb1, mp, "dir1");
249 1.2 pooka if (rump_sys_mkdir(pb1, 0777) == -1)
250 1.2 pooka atf_tc_fail_errno("mkdir 1");
251 1.2 pooka
252 1.2 pooka md(pb2, mp, "dir2");
253 1.2 pooka if (rump_sys_mkdir(pb2, 0777) == -1)
254 1.2 pooka atf_tc_fail_errno("mkdir 2");
255 1.2 pooka md(pb2, mp, "dir2/subdir");
256 1.2 pooka if (rump_sys_mkdir(pb2, 0777) == -1)
257 1.2 pooka atf_tc_fail_errno("mkdir 3");
258 1.2 pooka
259 1.2 pooka md(pb3, mp, "dir1/file");
260 1.2 pooka if (rump_sys_mknod(pb3, S_IFREG | 0777, -1) == -1)
261 1.2 pooka atf_tc_fail_errno("create file");
262 1.2 pooka if (rump_sys_stat(pb3, &ref) == -1)
263 1.2 pooka atf_tc_fail_errno("stat of file");
264 1.2 pooka
265 1.2 pooka /*
266 1.2 pooka * First try ops which should succeed.
267 1.2 pooka */
268 1.2 pooka
269 1.2 pooka /* rename within directory */
270 1.2 pooka md(pb3, mp, "dir3");
271 1.2 pooka if (rump_sys_rename(pb1, pb3) == -1)
272 1.2 pooka atf_tc_fail_errno("rename 1");
273 1.2 pooka checkfile(pb3, &ref);
274 1.2 pooka
275 1.2 pooka /* rename directory onto itself (two ways, should fail) */
276 1.2 pooka md(pb1, mp, "dir3/.");
277 1.2 pooka if (rump_sys_rename(pb1, pb3) != -1 || errno != EINVAL)
278 1.2 pooka atf_tc_fail_errno("rename 2");
279 1.34 jmmv if (FSTYPE_ZFS(tc))
280 1.34 jmmv atf_tc_expect_fail("PR kern/47656: Test known to be broken");
281 1.2 pooka if (rump_sys_rename(pb3, pb1) != -1 || errno != EISDIR)
282 1.2 pooka atf_tc_fail_errno("rename 3");
283 1.2 pooka
284 1.2 pooka checkfile(pb3, &ref);
285 1.2 pooka
286 1.2 pooka /* rename father of directory into directory */
287 1.2 pooka md(pb1, mp, "dir2/dir");
288 1.2 pooka md(pb2, mp, "dir2");
289 1.2 pooka if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL)
290 1.2 pooka atf_tc_fail_errno("rename 4");
291 1.2 pooka
292 1.2 pooka /* same for grandfather */
293 1.2 pooka md(pb1, mp, "dir2/subdir/dir2");
294 1.2 pooka if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL)
295 1.2 pooka atf_tc_fail("rename 5");
296 1.2 pooka
297 1.2 pooka checkfile(pb3, &ref);
298 1.2 pooka
299 1.2 pooka /* rename directory over a non-empty directory */
300 1.2 pooka if (rump_sys_rename(pb2, pb3) != -1 || errno != ENOTEMPTY)
301 1.2 pooka atf_tc_fail("rename 6");
302 1.2 pooka
303 1.2 pooka /* cross-directory rename */
304 1.2 pooka md(pb1, mp, "dir3");
305 1.2 pooka md(pb2, mp, "dir2/somedir");
306 1.2 pooka if (rump_sys_rename(pb1, pb2) == -1)
307 1.2 pooka atf_tc_fail_errno("rename 7");
308 1.2 pooka checkfile(pb2, &ref);
309 1.2 pooka
310 1.2 pooka /* move to parent directory */
311 1.2 pooka md(pb1, mp, "dir2/somedir/../../dir3");
312 1.2 pooka if (rump_sys_rename(pb2, pb1) == -1)
313 1.2 pooka atf_tc_fail_errno("rename 8");
314 1.2 pooka md(pb1, mp, "dir2/../dir3");
315 1.2 pooka checkfile(pb1, &ref);
316 1.2 pooka
317 1.16 pooka /* atomic cross-directory rename */
318 1.2 pooka md(pb3, mp, "dir2/subdir");
319 1.2 pooka if (rump_sys_rename(pb1, pb3) == -1)
320 1.2 pooka atf_tc_fail_errno("rename 9");
321 1.2 pooka checkfile(pb3, &ref);
322 1.16 pooka
323 1.16 pooka /* rename directory over an empty directory */
324 1.16 pooka md(pb1, mp, "parent");
325 1.16 pooka md(pb2, mp, "parent/dir1");
326 1.16 pooka md(pb3, mp, "parent/dir2");
327 1.16 pooka RL(rump_sys_mkdir(pb1, 0777));
328 1.16 pooka RL(rump_sys_mkdir(pb2, 0777));
329 1.16 pooka RL(rump_sys_mkdir(pb3, 0777));
330 1.16 pooka RL(rump_sys_rename(pb2, pb3));
331 1.16 pooka
332 1.16 pooka RL(rump_sys_stat(pb1, &sb));
333 1.22 hannken if (! FSTYPE_MSDOS(tc))
334 1.22 hannken ATF_CHECK_EQ(sb.st_nlink, 3);
335 1.16 pooka RL(rump_sys_rmdir(pb3));
336 1.16 pooka RL(rump_sys_rmdir(pb1));
337 1.2 pooka }
338 1.2 pooka
339 1.2 pooka static void
340 1.2 pooka rename_dotdot(const atf_tc_t *tc, const char *mp)
341 1.2 pooka {
342 1.2 pooka
343 1.10 pooka if (FSTYPE_RUMPFS(tc))
344 1.29 njoly atf_tc_skip("rename not supported by file system");
345 1.10 pooka
346 1.2 pooka USES_DIRS;
347 1.2 pooka
348 1.2 pooka if (rump_sys_chdir(mp) == -1)
349 1.2 pooka atf_tc_fail_errno("chdir mountpoint");
350 1.2 pooka
351 1.2 pooka if (rump_sys_mkdir("dir1", 0777) == -1)
352 1.2 pooka atf_tc_fail_errno("mkdir 1");
353 1.2 pooka if (rump_sys_mkdir("dir2", 0777) == -1)
354 1.2 pooka atf_tc_fail_errno("mkdir 2");
355 1.2 pooka
356 1.2 pooka if (rump_sys_rename("dir1", "dir1/..") != -1 || errno != EINVAL)
357 1.2 pooka atf_tc_fail_errno("self-dotdot to");
358 1.2 pooka
359 1.2 pooka if (rump_sys_rename("dir1/..", "sometarget") != -1 || errno != EINVAL)
360 1.2 pooka atf_tc_fail_errno("self-dotdot from");
361 1.2 pooka
362 1.2 pooka if (rump_sys_rename("dir1", "dir2/..") != -1 || errno != EINVAL)
363 1.2 pooka atf_tc_fail("other-dotdot");
364 1.2 pooka
365 1.2 pooka rump_sys_chdir("/");
366 1.2 pooka }
367 1.2 pooka
368 1.2 pooka static void
369 1.2 pooka rename_reg_nodir(const atf_tc_t *tc, const char *mp)
370 1.2 pooka {
371 1.2 pooka bool haslinks;
372 1.2 pooka struct stat sb;
373 1.38 christos ino_t f1ino;
374 1.2 pooka
375 1.10 pooka if (FSTYPE_RUMPFS(tc))
376 1.29 njoly atf_tc_skip("rename not supported by file system");
377 1.10 pooka
378 1.2 pooka if (rump_sys_chdir(mp) == -1)
379 1.2 pooka atf_tc_fail_errno("chdir mountpoint");
380 1.2 pooka
381 1.2 pooka if (FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))
382 1.2 pooka haslinks = false;
383 1.2 pooka else
384 1.2 pooka haslinks = true;
385 1.2 pooka
386 1.2 pooka if (rump_sys_mknod("file1", S_IFREG | 0777, -1) == -1)
387 1.2 pooka atf_tc_fail_errno("create file");
388 1.2 pooka if (rump_sys_mknod("file2", S_IFREG | 0777, -1) == -1)
389 1.2 pooka atf_tc_fail_errno("create file");
390 1.2 pooka
391 1.2 pooka if (rump_sys_stat("file1", &sb) == -1)
392 1.2 pooka atf_tc_fail_errno("stat");
393 1.2 pooka f1ino = sb.st_ino;
394 1.2 pooka
395 1.2 pooka if (haslinks) {
396 1.2 pooka if (rump_sys_link("file1", "file_link") == -1)
397 1.2 pooka atf_tc_fail_errno("link");
398 1.2 pooka if (rump_sys_stat("file_link", &sb) == -1)
399 1.2 pooka atf_tc_fail_errno("stat");
400 1.2 pooka ATF_REQUIRE_EQ(sb.st_ino, f1ino);
401 1.2 pooka ATF_REQUIRE_EQ(sb.st_nlink, 2);
402 1.2 pooka }
403 1.2 pooka
404 1.2 pooka if (rump_sys_stat("file2", &sb) == -1)
405 1.2 pooka atf_tc_fail_errno("stat");
406 1.2 pooka
407 1.2 pooka if (rump_sys_rename("file1", "file3") == -1)
408 1.2 pooka atf_tc_fail_errno("rename 1");
409 1.2 pooka if (rump_sys_stat("file3", &sb) == -1)
410 1.2 pooka atf_tc_fail_errno("stat 1");
411 1.2 pooka if (haslinks) {
412 1.2 pooka ATF_REQUIRE_EQ(sb.st_ino, f1ino);
413 1.2 pooka }
414 1.2 pooka if (rump_sys_stat("file1", &sb) != -1 || errno != ENOENT)
415 1.2 pooka atf_tc_fail_errno("source 1");
416 1.2 pooka
417 1.2 pooka if (rump_sys_rename("file3", "file2") == -1)
418 1.2 pooka atf_tc_fail_errno("rename 2");
419 1.2 pooka if (rump_sys_stat("file2", &sb) == -1)
420 1.2 pooka atf_tc_fail_errno("stat 2");
421 1.2 pooka if (haslinks) {
422 1.2 pooka ATF_REQUIRE_EQ(sb.st_ino, f1ino);
423 1.2 pooka }
424 1.2 pooka
425 1.2 pooka if (rump_sys_stat("file3", &sb) != -1 || errno != ENOENT)
426 1.2 pooka atf_tc_fail_errno("source 2");
427 1.2 pooka
428 1.2 pooka if (haslinks) {
429 1.2 pooka if (rump_sys_rename("file2", "file_link") == -1)
430 1.2 pooka atf_tc_fail_errno("rename hardlink");
431 1.2 pooka if (rump_sys_stat("file2", &sb) != -1 || errno != ENOENT)
432 1.2 pooka atf_tc_fail_errno("source 3");
433 1.2 pooka if (rump_sys_stat("file_link", &sb) == -1)
434 1.2 pooka atf_tc_fail_errno("stat 2");
435 1.2 pooka ATF_REQUIRE_EQ(sb.st_ino, f1ino);
436 1.2 pooka ATF_REQUIRE_EQ(sb.st_nlink, 1);
437 1.2 pooka }
438 1.2 pooka
439 1.37 njoly ATF_CHECK_ERRNO(EFAULT, rump_sys_rename("file2", NULL) == -1);
440 1.37 njoly ATF_CHECK_ERRNO(EFAULT, rump_sys_rename(NULL, "file2") == -1);
441 1.37 njoly
442 1.2 pooka rump_sys_chdir("/");
443 1.2 pooka }
444 1.2 pooka
445 1.5 njoly static void
446 1.5 njoly create_nametoolong(const atf_tc_t *tc, const char *mp)
447 1.5 njoly {
448 1.5 njoly char *name;
449 1.5 njoly int fd;
450 1.5 njoly long val;
451 1.5 njoly size_t len;
452 1.5 njoly
453 1.5 njoly if (rump_sys_chdir(mp) == -1)
454 1.5 njoly atf_tc_fail_errno("chdir mountpoint");
455 1.5 njoly
456 1.5 njoly val = rump_sys_pathconf(".", _PC_NAME_MAX);
457 1.5 njoly if (val == -1)
458 1.5 njoly atf_tc_fail_errno("pathconf");
459 1.5 njoly
460 1.5 njoly len = val + 1;
461 1.5 njoly name = malloc(len+1);
462 1.5 njoly if (name == NULL)
463 1.5 njoly atf_tc_fail_errno("malloc");
464 1.5 njoly
465 1.5 njoly memset(name, 'a', len);
466 1.5 njoly *(name+len) = '\0';
467 1.5 njoly
468 1.5 njoly val = rump_sys_pathconf(".", _PC_NO_TRUNC);
469 1.5 njoly if (val == -1)
470 1.5 njoly atf_tc_fail_errno("pathconf");
471 1.5 njoly
472 1.5 njoly fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666);
473 1.5 njoly if (val != 0 && (fd != -1 || errno != ENAMETOOLONG))
474 1.5 njoly atf_tc_fail_errno("open");
475 1.5 njoly
476 1.5 njoly if (val == 0 && rump_sys_close(fd) == -1)
477 1.5 njoly atf_tc_fail_errno("close");
478 1.5 njoly if (val == 0 && rump_sys_unlink(name) == -1)
479 1.5 njoly atf_tc_fail_errno("unlink");
480 1.5 njoly
481 1.5 njoly free(name);
482 1.5 njoly
483 1.5 njoly rump_sys_chdir("/");
484 1.5 njoly }
485 1.5 njoly
486 1.5 njoly static void
487 1.14 yamt create_exist(const atf_tc_t *tc, const char *mp)
488 1.14 yamt {
489 1.14 yamt const char *name = "hoge";
490 1.14 yamt int fd;
491 1.14 yamt
492 1.14 yamt RL(rump_sys_chdir(mp));
493 1.14 yamt RL(fd = rump_sys_open(name, O_RDWR|O_CREAT|O_EXCL, 0666));
494 1.14 yamt RL(rump_sys_close(fd));
495 1.14 yamt RL(rump_sys_unlink(name));
496 1.14 yamt RL(fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666));
497 1.14 yamt RL(rump_sys_close(fd));
498 1.14 yamt RL(fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666));
499 1.14 yamt RL(rump_sys_close(fd));
500 1.14 yamt ATF_REQUIRE_ERRNO(EEXIST,
501 1.14 yamt (fd = rump_sys_open(name, O_RDWR|O_CREAT|O_EXCL, 0666)));
502 1.14 yamt RL(rump_sys_unlink(name));
503 1.14 yamt RL(rump_sys_chdir("/"));
504 1.14 yamt }
505 1.14 yamt
506 1.14 yamt static void
507 1.5 njoly rename_nametoolong(const atf_tc_t *tc, const char *mp)
508 1.5 njoly {
509 1.5 njoly char *name;
510 1.5 njoly int res, fd;
511 1.5 njoly long val;
512 1.5 njoly size_t len;
513 1.5 njoly
514 1.10 pooka if (FSTYPE_RUMPFS(tc))
515 1.29 njoly atf_tc_skip("rename not supported by file system");
516 1.10 pooka
517 1.5 njoly if (rump_sys_chdir(mp) == -1)
518 1.5 njoly atf_tc_fail_errno("chdir mountpoint");
519 1.5 njoly
520 1.5 njoly val = rump_sys_pathconf(".", _PC_NAME_MAX);
521 1.5 njoly if (val == -1)
522 1.5 njoly atf_tc_fail_errno("pathconf");
523 1.5 njoly
524 1.5 njoly len = val + 1;
525 1.5 njoly name = malloc(len+1);
526 1.5 njoly if (name == NULL)
527 1.5 njoly atf_tc_fail_errno("malloc");
528 1.5 njoly
529 1.5 njoly memset(name, 'a', len);
530 1.5 njoly *(name+len) = '\0';
531 1.5 njoly
532 1.5 njoly fd = rump_sys_open("dummy", O_RDWR|O_CREAT, 0666);
533 1.5 njoly if (fd == -1)
534 1.5 njoly atf_tc_fail_errno("open");
535 1.5 njoly if (rump_sys_close(fd) == -1)
536 1.5 njoly atf_tc_fail_errno("close");
537 1.5 njoly
538 1.5 njoly val = rump_sys_pathconf(".", _PC_NO_TRUNC);
539 1.5 njoly if (val == -1)
540 1.5 njoly atf_tc_fail_errno("pathconf");
541 1.5 njoly
542 1.5 njoly res = rump_sys_rename("dummy", name);
543 1.5 njoly if (val != 0 && (res != -1 || errno != ENAMETOOLONG))
544 1.5 njoly atf_tc_fail_errno("rename");
545 1.5 njoly
546 1.5 njoly if (val == 0 && rump_sys_unlink(name) == -1)
547 1.5 njoly atf_tc_fail_errno("unlink");
548 1.5 njoly
549 1.5 njoly free(name);
550 1.5 njoly
551 1.5 njoly rump_sys_chdir("/");
552 1.5 njoly }
553 1.5 njoly
554 1.7 pooka static void
555 1.7 pooka symlink_zerolen(const atf_tc_t *tc, const char *mp)
556 1.7 pooka {
557 1.7 pooka
558 1.7 pooka USES_SYMLINKS;
559 1.7 pooka
560 1.7 pooka RL(rump_sys_chdir(mp));
561 1.8 pooka
562 1.7 pooka RL(rump_sys_symlink("", "afile"));
563 1.7 pooka RL(rump_sys_chdir("/"));
564 1.7 pooka }
565 1.7 pooka
566 1.11 pooka static void
567 1.28 riastrad symlink_root(const atf_tc_t *tc, const char *mp)
568 1.28 riastrad {
569 1.28 riastrad
570 1.28 riastrad USES_SYMLINKS;
571 1.28 riastrad
572 1.28 riastrad RL(rump_sys_chdir(mp));
573 1.28 riastrad RL(rump_sys_symlink("/", "foo"));
574 1.28 riastrad RL(rump_sys_chdir("foo"));
575 1.28 riastrad }
576 1.28 riastrad
577 1.28 riastrad static void
578 1.11 pooka attrs(const atf_tc_t *tc, const char *mp)
579 1.11 pooka {
580 1.11 pooka struct stat sb, sb2;
581 1.11 pooka struct timeval tv[2];
582 1.11 pooka int fd;
583 1.11 pooka
584 1.11 pooka FSTEST_ENTER();
585 1.11 pooka RL(fd = rump_sys_open(TESTFILE, O_RDWR | O_CREAT, 0755));
586 1.11 pooka RL(rump_sys_close(fd));
587 1.11 pooka RL(rump_sys_stat(TESTFILE, &sb));
588 1.11 pooka if (!(FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))) {
589 1.11 pooka RL(rump_sys_chown(TESTFILE, 1, 2));
590 1.11 pooka sb.st_uid = 1;
591 1.11 pooka sb.st_gid = 2;
592 1.11 pooka RL(rump_sys_chmod(TESTFILE, 0123));
593 1.11 pooka sb.st_mode = (sb.st_mode & ~ACCESSPERMS) | 0123;
594 1.11 pooka }
595 1.11 pooka
596 1.11 pooka tv[0].tv_sec = 1000000000; /* need something >1980 for msdosfs */
597 1.11 pooka tv[0].tv_usec = 1;
598 1.11 pooka tv[1].tv_sec = 1000000002; /* need even seconds for msdosfs */
599 1.11 pooka tv[1].tv_usec = 3;
600 1.11 pooka RL(rump_sys_utimes(TESTFILE, tv));
601 1.11 pooka RL(rump_sys_utimes(TESTFILE, tv)); /* XXX: utimes & birthtime */
602 1.11 pooka sb.st_atimespec.tv_sec = 1000000000;
603 1.11 pooka sb.st_atimespec.tv_nsec = 1000;
604 1.11 pooka sb.st_mtimespec.tv_sec = 1000000002;
605 1.11 pooka sb.st_mtimespec.tv_nsec = 3000;
606 1.11 pooka
607 1.11 pooka RL(rump_sys_stat(TESTFILE, &sb2));
608 1.11 pooka #define CHECK(a) ATF_REQUIRE_EQ(sb.a, sb2.a)
609 1.34 jmmv if (FSTYPE_ZFS(tc))
610 1.34 jmmv atf_tc_expect_fail("PR kern/47656: Test known to be broken");
611 1.11 pooka if (!(FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))) {
612 1.11 pooka CHECK(st_uid);
613 1.11 pooka CHECK(st_gid);
614 1.11 pooka CHECK(st_mode);
615 1.11 pooka }
616 1.11 pooka if (!FSTYPE_MSDOS(tc)) {
617 1.11 pooka /* msdosfs has only access date, not time */
618 1.11 pooka CHECK(st_atimespec.tv_sec);
619 1.11 pooka }
620 1.11 pooka CHECK(st_mtimespec.tv_sec);
621 1.27 uch if (!(FSTYPE_EXT2FS(tc) || FSTYPE_MSDOS(tc) ||
622 1.27 uch FSTYPE_SYSVBFS(tc) || FSTYPE_V7FS(tc))) {
623 1.11 pooka CHECK(st_atimespec.tv_nsec);
624 1.11 pooka CHECK(st_mtimespec.tv_nsec);
625 1.11 pooka }
626 1.11 pooka #undef CHECK
627 1.11 pooka
628 1.11 pooka FSTEST_EXIT();
629 1.11 pooka }
630 1.11 pooka
631 1.12 kefren static void
632 1.12 kefren fcntl_lock(const atf_tc_t *tc, const char *mp)
633 1.12 kefren {
634 1.12 kefren int fd, fd2;
635 1.12 kefren struct flock l;
636 1.12 kefren struct lwp *lwp1, *lwp2;
637 1.12 kefren
638 1.12 kefren FSTEST_ENTER();
639 1.12 kefren l.l_pid = 0;
640 1.12 kefren l.l_start = l.l_len = 1024;
641 1.12 kefren l.l_type = F_RDLCK | F_WRLCK;
642 1.12 kefren l.l_whence = SEEK_END;
643 1.12 kefren
644 1.12 kefren lwp1 = rump_pub_lwproc_curlwp();
645 1.12 kefren RL(fd = rump_sys_open(TESTFILE, O_RDWR | O_CREAT, 0755));
646 1.12 kefren RL(rump_sys_ftruncate(fd, 8192));
647 1.12 kefren
648 1.12 kefren /* PR kern/43321 */
649 1.34 jmmv if (FSTYPE_ZFS(tc))
650 1.34 jmmv atf_tc_expect_fail("PR kern/47656: Test known to be broken");
651 1.12 kefren RL(rump_sys_fcntl(fd, F_SETLK, &l));
652 1.12 kefren
653 1.12 kefren /* Next, we fork and try to lock the same area */
654 1.12 kefren RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
655 1.12 kefren lwp2 = rump_pub_lwproc_curlwp();
656 1.12 kefren RL(fd2 = rump_sys_open(TESTFILE, O_RDWR, 0));
657 1.12 kefren ATF_REQUIRE_ERRNO(EAGAIN, rump_sys_fcntl(fd2, F_SETLK, &l));
658 1.12 kefren
659 1.12 kefren /* Switch back and unlock... */
660 1.12 kefren rump_pub_lwproc_switch(lwp1);
661 1.12 kefren l.l_type = F_UNLCK;
662 1.12 kefren RL(rump_sys_fcntl(fd, F_SETLK, &l));
663 1.12 kefren
664 1.12 kefren /* ... and try to lock again */
665 1.12 kefren rump_pub_lwproc_switch(lwp2);
666 1.12 kefren l.l_type = F_RDLCK | F_WRLCK;
667 1.12 kefren RL(rump_sys_fcntl(fd2, F_SETLK, &l));
668 1.12 kefren
669 1.12 kefren RL(rump_sys_close(fd2));
670 1.12 kefren rump_pub_lwproc_releaselwp();
671 1.12 kefren
672 1.12 kefren RL(rump_sys_close(fd));
673 1.12 kefren
674 1.12 kefren FSTEST_EXIT();
675 1.12 kefren }
676 1.12 kefren
677 1.13 pooka static int
678 1.13 pooka flock_compare(const void *p, const void *q)
679 1.13 pooka {
680 1.13 pooka int a = ((const struct flock *)p)->l_start;
681 1.13 pooka int b = ((const struct flock *)q)->l_start;
682 1.13 pooka return a < b ? -1 : (a > b ? 1 : 0);
683 1.13 pooka }
684 1.13 pooka
685 1.26 alnsn /*
686 1.26 alnsn * Find all locks set by fcntl_getlock_pids test
687 1.26 alnsn * using GETLK for a range [start, start+end], and,
688 1.26 alnsn * if there is a blocking lock, recursively find
689 1.26 alnsn * all locks to the left (toward the beginning of
690 1.26 alnsn * a file) and to the right of the lock.
691 1.26 alnsn * The function also understands "until end of file"
692 1.26 alnsn * convention when len==0.
693 1.26 alnsn */
694 1.26 alnsn static unsigned int
695 1.26 alnsn fcntl_getlocks(int fildes, off_t start, off_t len,
696 1.26 alnsn struct flock *lock, struct flock *end)
697 1.26 alnsn {
698 1.26 alnsn unsigned int rv = 0;
699 1.26 alnsn const struct flock l = { start, len, 0, F_RDLCK, SEEK_SET };
700 1.26 alnsn
701 1.26 alnsn if (lock == end)
702 1.26 alnsn return rv;
703 1.26 alnsn
704 1.26 alnsn RL(rump_sys_fcntl(fildes, F_GETLK, &l));
705 1.26 alnsn
706 1.26 alnsn if (l.l_type == F_UNLCK)
707 1.26 alnsn return rv;
708 1.26 alnsn
709 1.26 alnsn *lock++ = l;
710 1.26 alnsn rv += 1;
711 1.26 alnsn
712 1.26 alnsn ATF_REQUIRE(l.l_whence == SEEK_SET);
713 1.26 alnsn
714 1.26 alnsn if (l.l_start > start) {
715 1.26 alnsn unsigned int n =
716 1.26 alnsn fcntl_getlocks(fildes, start, l.l_start - start, lock, end);
717 1.26 alnsn rv += n;
718 1.26 alnsn lock += n;
719 1.26 alnsn if (lock == end)
720 1.26 alnsn return rv;
721 1.26 alnsn }
722 1.26 alnsn
723 1.26 alnsn if (l.l_len == 0) /* does l spans until the end? */
724 1.26 alnsn return rv;
725 1.26 alnsn
726 1.26 alnsn if (len == 0) /* are we looking for locks until the end? */ {
727 1.26 alnsn rv += fcntl_getlocks(fildes, l.l_start + l.l_len, len, lock, end);
728 1.26 alnsn } else if (l.l_start + l.l_len < start + len) {
729 1.26 alnsn len -= l.l_start + l.l_len - start;
730 1.26 alnsn rv += fcntl_getlocks(fildes, l.l_start + l.l_len, len, lock, end);
731 1.26 alnsn }
732 1.26 alnsn
733 1.26 alnsn return rv;
734 1.26 alnsn }
735 1.26 alnsn
736 1.13 pooka static void
737 1.13 pooka fcntl_getlock_pids(const atf_tc_t *tc, const char *mp)
738 1.13 pooka {
739 1.13 pooka /* test non-overlaping ranges */
740 1.13 pooka struct flock expect[4];
741 1.13 pooka const struct flock lock[4] = {
742 1.13 pooka { 0, 2, 0, F_WRLCK, SEEK_SET },
743 1.13 pooka { 2, 1, 0, F_WRLCK, SEEK_SET },
744 1.13 pooka { 7, 5, 0, F_WRLCK, SEEK_SET },
745 1.13 pooka { 4, 3, 0, F_WRLCK, SEEK_SET },
746 1.13 pooka };
747 1.13 pooka
748 1.26 alnsn /* Add extra element to make sure recursion does't stop at array end */
749 1.26 alnsn struct flock result[5];
750 1.26 alnsn
751 1.26 alnsn /* Add 5th process */
752 1.26 alnsn int fd[5];
753 1.26 alnsn pid_t pid[5];
754 1.26 alnsn struct lwp *lwp[5];
755 1.13 pooka
756 1.13 pooka unsigned int i, j;
757 1.13 pooka const off_t sz = 8192;
758 1.13 pooka int omode = 0755;
759 1.13 pooka int oflags = O_RDWR | O_CREAT;
760 1.13 pooka
761 1.13 pooka memcpy(expect, lock, sizeof(lock));
762 1.13 pooka
763 1.13 pooka FSTEST_ENTER();
764 1.13 pooka
765 1.13 pooka /*
766 1.13 pooka * First, we create 4 processes and let each lock a range of the
767 1.13 pooka * file. Note that the third and fourth processes lock in
768 1.13 pooka * "reverse" order, i.e. the greater pid locks a range before
769 1.13 pooka * the lesser pid.
770 1.26 alnsn * Then, we create 5th process which doesn't lock anything.
771 1.13 pooka */
772 1.26 alnsn for (i = 0; i < __arraycount(lwp); i++) {
773 1.13 pooka RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
774 1.13 pooka
775 1.13 pooka lwp[i] = rump_pub_lwproc_curlwp();
776 1.26 alnsn pid[i] = rump_sys_getpid();
777 1.13 pooka
778 1.13 pooka RL(fd[i] = rump_sys_open(TESTFILE, oflags, omode));
779 1.13 pooka oflags = O_RDWR;
780 1.13 pooka omode = 0;
781 1.13 pooka
782 1.13 pooka RL(rump_sys_ftruncate(fd[i], sz));
783 1.26 alnsn
784 1.34 jmmv if (FSTYPE_ZFS(tc))
785 1.34 jmmv atf_tc_expect_fail("PR kern/47656: Test known to be "
786 1.34 jmmv "broken");
787 1.26 alnsn if (i < __arraycount(lock)) {
788 1.26 alnsn RL(rump_sys_fcntl(fd[i], F_SETLK, &lock[i]));
789 1.26 alnsn expect[i].l_pid = pid[i];
790 1.26 alnsn }
791 1.13 pooka }
792 1.13 pooka
793 1.26 alnsn qsort(expect, __arraycount(expect), sizeof(expect[0]), &flock_compare);
794 1.26 alnsn
795 1.13 pooka /*
796 1.26 alnsn * In the context of each process, recursively find all locks
797 1.26 alnsn * that would block the current process. Processes 1-4 don't
798 1.26 alnsn * see their own lock, we insert it to simplify checks.
799 1.26 alnsn * Process 5 sees all 4 locks.
800 1.13 pooka */
801 1.26 alnsn for (i = 0; i < __arraycount(lwp); i++) {
802 1.26 alnsn unsigned int nlocks;
803 1.26 alnsn
804 1.13 pooka rump_pub_lwproc_switch(lwp[i]);
805 1.13 pooka
806 1.26 alnsn memset(result, 0, sizeof(result));
807 1.26 alnsn nlocks = fcntl_getlocks(fd[i], 0, sz,
808 1.26 alnsn result, result + __arraycount(result));
809 1.26 alnsn
810 1.26 alnsn if (i < __arraycount(lock)) {
811 1.26 alnsn ATF_REQUIRE(nlocks < __arraycount(result));
812 1.26 alnsn result[nlocks] = lock[i];
813 1.26 alnsn result[nlocks].l_pid = pid[i];
814 1.26 alnsn nlocks++;
815 1.26 alnsn }
816 1.26 alnsn
817 1.26 alnsn ATF_CHECK_EQ(nlocks, __arraycount(expect));
818 1.26 alnsn
819 1.26 alnsn qsort(result, nlocks, sizeof(result[0]), &flock_compare);
820 1.26 alnsn
821 1.26 alnsn for (j = 0; j < nlocks; j++) {
822 1.26 alnsn ATF_CHECK_EQ(result[j].l_start, expect[j].l_start );
823 1.26 alnsn ATF_CHECK_EQ(result[j].l_len, expect[j].l_len );
824 1.26 alnsn ATF_CHECK_EQ(result[j].l_pid, expect[j].l_pid );
825 1.26 alnsn ATF_CHECK_EQ(result[j].l_type, expect[j].l_type );
826 1.26 alnsn ATF_CHECK_EQ(result[j].l_whence, expect[j].l_whence);
827 1.13 pooka }
828 1.13 pooka }
829 1.13 pooka
830 1.13 pooka /*
831 1.13 pooka * Release processes. This also releases the fds and locks
832 1.13 pooka * making fs unmount possible
833 1.13 pooka */
834 1.26 alnsn for (i = 0; i < __arraycount(lwp); i++) {
835 1.13 pooka rump_pub_lwproc_switch(lwp[i]);
836 1.13 pooka rump_pub_lwproc_releaselwp();
837 1.13 pooka }
838 1.13 pooka
839 1.13 pooka FSTEST_EXIT();
840 1.13 pooka }
841 1.13 pooka
842 1.15 pooka static void
843 1.15 pooka access_simple(const atf_tc_t *tc, const char *mp)
844 1.15 pooka {
845 1.15 pooka int fd;
846 1.15 pooka int tmode;
847 1.15 pooka
848 1.15 pooka FSTEST_ENTER();
849 1.15 pooka RL(fd = rump_sys_open("tfile", O_CREAT | O_RDWR, 0777));
850 1.15 pooka RL(rump_sys_close(fd));
851 1.15 pooka
852 1.15 pooka #define ALLACC (F_OK | X_OK | W_OK | R_OK)
853 1.15 pooka if (FSTYPE_SYSVBFS(tc) || FSTYPE_MSDOS(tc))
854 1.15 pooka tmode = F_OK;
855 1.15 pooka else
856 1.15 pooka tmode = ALLACC;
857 1.15 pooka
858 1.15 pooka RL(rump_sys_access("tfile", tmode));
859 1.15 pooka
860 1.15 pooka /* PR kern/44648 */
861 1.15 pooka ATF_REQUIRE_ERRNO(EINVAL, rump_sys_access("tfile", ALLACC+1) == -1);
862 1.15 pooka #undef ALLACC
863 1.15 pooka FSTEST_EXIT();
864 1.15 pooka }
865 1.15 pooka
866 1.30 njoly static void
867 1.30 njoly read_directory(const atf_tc_t *tc, const char *mp)
868 1.30 njoly {
869 1.30 njoly char buf[1024];
870 1.30 njoly int fd, res;
871 1.30 njoly ssize_t size;
872 1.30 njoly
873 1.30 njoly FSTEST_ENTER();
874 1.30 njoly fd = rump_sys_open(".", O_DIRECTORY | O_RDONLY, 0777);
875 1.30 njoly ATF_REQUIRE(fd != -1);
876 1.30 njoly
877 1.30 njoly size = rump_sys_pread(fd, buf, sizeof(buf), 0);
878 1.30 njoly ATF_CHECK(size != -1 || errno == EISDIR);
879 1.30 njoly size = rump_sys_read(fd, buf, sizeof(buf));
880 1.30 njoly ATF_CHECK(size != -1 || errno == EISDIR);
881 1.30 njoly
882 1.30 njoly res = rump_sys_close(fd);
883 1.30 njoly ATF_REQUIRE(res != -1);
884 1.30 njoly FSTEST_EXIT();
885 1.30 njoly }
886 1.30 njoly
887 1.39 njoly static void
888 1.39 njoly lstat_symlink(const atf_tc_t *tc, const char *mp)
889 1.39 njoly {
890 1.39 njoly const char *src, *dst;
891 1.39 njoly int res;
892 1.39 njoly struct stat st;
893 1.39 njoly
894 1.39 njoly USES_SYMLINKS;
895 1.39 njoly FSTEST_ENTER();
896 1.39 njoly
897 1.39 njoly src = "source";
898 1.39 njoly dst = "destination";
899 1.39 njoly
900 1.39 njoly res = rump_sys_symlink(src, dst);
901 1.39 njoly ATF_REQUIRE(res != -1);
902 1.39 njoly res = rump_sys_lstat(dst, &st);
903 1.39 njoly ATF_REQUIRE(res != -1);
904 1.39 njoly
905 1.39 njoly ATF_CHECK(S_ISLNK(st.st_mode) != 0);
906 1.39 njoly ATF_CHECK(st.st_size == (off_t)strlen(src));
907 1.39 njoly
908 1.39 njoly FSTEST_EXIT();
909 1.39 njoly }
910 1.39 njoly
911 1.1 pooka ATF_TC_FSAPPLY(lookup_simple, "simple lookup (./.. on root)");
912 1.1 pooka ATF_TC_FSAPPLY(lookup_complex, "lookup of non-dot entries");
913 1.1 pooka ATF_TC_FSAPPLY(dir_simple, "mkdir/rmdir");
914 1.1 pooka ATF_TC_FSAPPLY(dir_notempty, "non-empty directories cannot be removed");
915 1.31 christos ATF_TC_FSAPPLY(dir_rmdirdotdot, "remove .. and try to cd out (PR kern/44657)");
916 1.31 christos ATF_TC_FSAPPLY(rename_dir, "exercise various directory renaming ops "
917 1.31 christos "(PR kern/44288)");
918 1.31 christos ATF_TC_FSAPPLY(rename_dotdot, "rename dir .. (PR kern/43617)");
919 1.2 pooka ATF_TC_FSAPPLY(rename_reg_nodir, "rename regular files, no subdirectories");
920 1.5 njoly ATF_TC_FSAPPLY(create_nametoolong, "create file with name too long");
921 1.14 yamt ATF_TC_FSAPPLY(create_exist, "create with O_EXCL");
922 1.5 njoly ATF_TC_FSAPPLY(rename_nametoolong, "rename to file with name too long");
923 1.7 pooka ATF_TC_FSAPPLY(symlink_zerolen, "symlink with 0-len target");
924 1.28 riastrad ATF_TC_FSAPPLY(symlink_root, "symlink to root directory");
925 1.11 pooka ATF_TC_FSAPPLY(attrs, "check setting attributes works");
926 1.12 kefren ATF_TC_FSAPPLY(fcntl_lock, "check fcntl F_SETLK");
927 1.13 pooka ATF_TC_FSAPPLY(fcntl_getlock_pids,"fcntl F_GETLK w/ many procs, PR kern/44494");
928 1.15 pooka ATF_TC_FSAPPLY(access_simple, "access(2)");
929 1.30 njoly ATF_TC_FSAPPLY(read_directory, "read(2) on directories");
930 1.39 njoly ATF_TC_FSAPPLY(lstat_symlink, "lstat(2) values for symbolic links");
931 1.1 pooka
932 1.1 pooka ATF_TP_ADD_TCS(tp)
933 1.1 pooka {
934 1.1 pooka
935 1.1 pooka ATF_TP_FSAPPLY(lookup_simple);
936 1.1 pooka ATF_TP_FSAPPLY(lookup_complex);
937 1.1 pooka ATF_TP_FSAPPLY(dir_simple);
938 1.1 pooka ATF_TP_FSAPPLY(dir_notempty);
939 1.18 pooka ATF_TP_FSAPPLY(dir_rmdirdotdot);
940 1.2 pooka ATF_TP_FSAPPLY(rename_dir);
941 1.2 pooka ATF_TP_FSAPPLY(rename_dotdot);
942 1.2 pooka ATF_TP_FSAPPLY(rename_reg_nodir);
943 1.5 njoly ATF_TP_FSAPPLY(create_nametoolong);
944 1.14 yamt ATF_TP_FSAPPLY(create_exist);
945 1.5 njoly ATF_TP_FSAPPLY(rename_nametoolong);
946 1.7 pooka ATF_TP_FSAPPLY(symlink_zerolen);
947 1.28 riastrad ATF_TP_FSAPPLY(symlink_root);
948 1.11 pooka ATF_TP_FSAPPLY(attrs);
949 1.12 kefren ATF_TP_FSAPPLY(fcntl_lock);
950 1.13 pooka ATF_TP_FSAPPLY(fcntl_getlock_pids);
951 1.15 pooka ATF_TP_FSAPPLY(access_simple);
952 1.30 njoly ATF_TP_FSAPPLY(read_directory);
953 1.39 njoly ATF_TP_FSAPPLY(lstat_symlink);
954 1.1 pooka
955 1.1 pooka return atf_no_error();
956 1.1 pooka }
957