t_vnops.c revision 1.1 1 1.1 pooka /* $NetBSD: t_vnops.c,v 1.1 2010/07/13 18:13:10 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.1 pooka #include <unistd.h>
36 1.1 pooka
37 1.1 pooka #include <rump/rump_syscalls.h>
38 1.1 pooka #include <rump/rump.h>
39 1.1 pooka
40 1.1 pooka #include "../common/h_fsmacros.h"
41 1.1 pooka #include "../../h_macros.h"
42 1.1 pooka
43 1.1 pooka /* make work when run with 5.0 userland */
44 1.1 pooka #if defined(__NetBSD_Version__) && (__NetBSD_Version__ < 599000700)
45 1.1 pooka #define rump_sys_stat rump_pub_sys___stat30
46 1.1 pooka #endif
47 1.1 pooka
48 1.1 pooka #define USES_DIRS \
49 1.1 pooka if (FSTYPE_SYSVBFS(tc)) atf_tc_skip("dirs not supported by file system")
50 1.1 pooka
51 1.1 pooka static void
52 1.1 pooka lookup_simple(const atf_tc_t *tc, const char *mountpath)
53 1.1 pooka {
54 1.1 pooka char pb[MAXPATHLEN], final[MAXPATHLEN];
55 1.1 pooka struct stat sb1, sb2;
56 1.1 pooka
57 1.1 pooka strcpy(final, mountpath);
58 1.1 pooka sprintf(pb, "%s/../%s", mountpath, basename(final));
59 1.1 pooka if (rump_sys_stat(pb, &sb1) == -1)
60 1.1 pooka atf_tc_fail_errno("stat 1");
61 1.1 pooka
62 1.1 pooka sprintf(pb, "%s/./../%s", mountpath, basename(final));
63 1.1 pooka if (rump_sys_stat(pb, &sb2) == -1)
64 1.1 pooka atf_tc_fail_errno("stat 2");
65 1.1 pooka
66 1.1 pooka ATF_REQUIRE(memcmp(&sb1, &sb2, sizeof(sb1)) == 0);
67 1.1 pooka }
68 1.1 pooka
69 1.1 pooka static void
70 1.1 pooka lookup_complex(const atf_tc_t *tc, const char *mountpath)
71 1.1 pooka {
72 1.1 pooka char pb[MAXPATHLEN];
73 1.1 pooka struct stat sb1, sb2;
74 1.1 pooka
75 1.1 pooka USES_DIRS;
76 1.1 pooka
77 1.1 pooka sprintf(pb, "%s/dir", mountpath);
78 1.1 pooka if (rump_sys_mkdir(pb, 0777) == -1)
79 1.1 pooka atf_tc_fail_errno("mkdir");
80 1.1 pooka if (rump_sys_stat(pb, &sb1) == -1)
81 1.1 pooka atf_tc_fail_errno("stat 1");
82 1.1 pooka
83 1.1 pooka sprintf(pb, "%s/./dir/../././dir/.", mountpath);
84 1.1 pooka if (rump_sys_stat(pb, &sb2) == -1)
85 1.1 pooka atf_tc_fail_errno("stat 2");
86 1.1 pooka
87 1.1 pooka ATF_REQUIRE(memcmp(&sb1, &sb2, sizeof(sb1)) == 0);
88 1.1 pooka }
89 1.1 pooka
90 1.1 pooka static void
91 1.1 pooka dir_simple(const atf_tc_t *tc, const char *mountpath)
92 1.1 pooka {
93 1.1 pooka char pb[MAXPATHLEN];
94 1.1 pooka struct stat sb;
95 1.1 pooka
96 1.1 pooka USES_DIRS;
97 1.1 pooka
98 1.1 pooka /* check we can create directories */
99 1.1 pooka sprintf(pb, "%s/dir", mountpath);
100 1.1 pooka if (rump_sys_mkdir(pb, 0777) == -1)
101 1.1 pooka atf_tc_fail_errno("mkdir");
102 1.1 pooka if (rump_sys_stat(pb, &sb) == -1)
103 1.1 pooka atf_tc_fail_errno("stat new directory");
104 1.1 pooka
105 1.1 pooka /* check we can remove then and that it makes them unreachable */
106 1.1 pooka if (rump_sys_rmdir(pb) == -1)
107 1.1 pooka atf_tc_fail_errno("rmdir");
108 1.1 pooka if (rump_sys_stat(pb, &sb) != -1 || errno != ENOENT)
109 1.1 pooka atf_tc_fail("ENOENT expected from stat");
110 1.1 pooka }
111 1.1 pooka
112 1.1 pooka static void
113 1.1 pooka dir_notempty(const atf_tc_t *tc, const char *mountpath)
114 1.1 pooka {
115 1.1 pooka char pb[MAXPATHLEN], pb2[MAXPATHLEN];
116 1.1 pooka int fd, rv;
117 1.1 pooka
118 1.1 pooka USES_DIRS;
119 1.1 pooka
120 1.1 pooka /* check we can create directories */
121 1.1 pooka sprintf(pb, "%s/dir", mountpath);
122 1.1 pooka if (rump_sys_mkdir(pb, 0777) == -1)
123 1.1 pooka atf_tc_fail_errno("mkdir");
124 1.1 pooka
125 1.1 pooka sprintf(pb2, "%s/dir/file", mountpath);
126 1.1 pooka fd = rump_sys_open(pb2, O_RDWR | O_CREAT, 0777);
127 1.1 pooka if (fd == -1)
128 1.1 pooka atf_tc_fail_errno("create file");
129 1.1 pooka rump_sys_close(fd);
130 1.1 pooka
131 1.1 pooka rv = rump_sys_rmdir(pb);
132 1.1 pooka if (rv != -1 || errno != ENOTEMPTY)
133 1.1 pooka atf_tc_fail("non-empty directory removed succesfully");
134 1.1 pooka
135 1.1 pooka if (rump_sys_unlink(pb2) == -1)
136 1.1 pooka atf_tc_fail_errno("cannot remove dir/file");
137 1.1 pooka
138 1.1 pooka if (rump_sys_rmdir(pb) == -1)
139 1.1 pooka atf_tc_fail_errno("remove directory");
140 1.1 pooka }
141 1.1 pooka
142 1.1 pooka ATF_TC_FSAPPLY(lookup_simple, "simple lookup (./.. on root)");
143 1.1 pooka ATF_TC_FSAPPLY(lookup_complex, "lookup of non-dot entries");
144 1.1 pooka ATF_TC_FSAPPLY(dir_simple, "mkdir/rmdir");
145 1.1 pooka ATF_TC_FSAPPLY(dir_notempty, "non-empty directories cannot be removed");
146 1.1 pooka
147 1.1 pooka ATF_TP_ADD_TCS(tp)
148 1.1 pooka {
149 1.1 pooka
150 1.1 pooka ATF_TP_FSAPPLY(lookup_simple);
151 1.1 pooka ATF_TP_FSAPPLY(lookup_complex);
152 1.1 pooka ATF_TP_FSAPPLY(dir_simple);
153 1.1 pooka ATF_TP_FSAPPLY(dir_notempty);
154 1.1 pooka
155 1.1 pooka return atf_no_error();
156 1.1 pooka }
157