etc/services - sync with NetBSD-8
[minix.git] / tests / fs / tmpfs / t_rename.sh
blob7613f1f493a8e133508dbc329d9d889a1adef796
1 # $NetBSD: t_rename.sh,v 1.5 2010/11/07 17:51:18 jmmv Exp $
3 # Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
4 # All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
29 # Verifies that the rename operation works (either by renaming entries or
30 # by moving them).
33 atf_test_case dots
34 dots_head() {
35 atf_set "descr" "Tests that '.' and '..' cannot be renamed"
36 atf_set "require.user" "root"
38 dots_body() {
39 test_mount
41 atf_check -s eq:0 -o empty -e empty mkdir a
42 atf_check -s eq:1 -o empty -e ignore mv a/. c
43 atf_check -s eq:1 -o empty -e ignore mv a/.. c
44 atf_check -s eq:0 -o empty -e empty rmdir a
46 test_unmount
49 atf_test_case crossdev
50 crossdev_head() {
51 atf_set "descr" "Tests that cross-device renames do not work"
52 atf_set "require.user" "root"
54 crossdev_body() {
55 test_mount
57 atf_check -s eq:0 -o empty -e empty mkdir a
58 atf_check -s eq:1 -o empty -e save:stderr \
59 $(atf_get_srcdir)/h_tools rename a /var/tmp/a
60 atf_check -s eq:0 -o ignore -e empty grep "Cross-device link" stderr
61 atf_check -s eq:0 -o empty -e empty test -d a
62 atf_check -s eq:0 -o empty -e empty rmdir a
64 test_unmount
67 atf_test_case basic
68 basic_head() {
69 atf_set "descr" "Tests that basic renames work"
70 atf_set "require.user" "root"
72 basic_body() {
73 test_mount
75 atf_check -s eq:0 -o empty -e empty mkdir a
76 atf_check -s eq:0 -o empty -e empty mv a c
77 atf_check -s eq:1 -o empty -e empty test -d a
78 atf_check -s eq:0 -o empty -e empty test -d c
79 atf_check -s eq:0 -o empty -e empty rmdir c
81 test_unmount
84 atf_test_case dotdot
85 dotdot_head() {
86 atf_set "descr" "Tests that the '..' entry is properly updated" \
87 "during moves"
88 atf_set "require.user" "root"
90 dotdot_body() {
91 test_mount
93 echo "Checking if the '..' entry is updated after moves"
94 atf_check -s eq:0 -o empty -e empty mkdir a
95 atf_check -s eq:0 -o empty -e empty mkdir b
96 atf_check -s eq:0 -o empty -e empty mv b a
97 atf_check -s eq:0 -o empty -e empty test -d a/b/../b
98 atf_check -s eq:0 -o empty -e empty test -d a/b/../../a
99 eval $(stat -s a/b)
100 [ ${st_nlink} = 2 ] || atf_fail "Incorrect number of links"
101 eval $(stat -s a)
102 [ ${st_nlink} = 3 ] || atf_fail "Incorrect number of links"
103 atf_check -s eq:0 -o empty -e empty rmdir a/b
104 atf_check -s eq:0 -o empty -e empty rmdir a
106 echo "Checking if the '..' entry is correct after renames"
107 atf_check -s eq:0 -o empty -e empty mkdir a
108 atf_check -s eq:0 -o empty -e empty mkdir b
109 atf_check -s eq:0 -o empty -e empty mv b a
110 atf_check -s eq:0 -o empty -e empty mv a c
111 atf_check -s eq:0 -o empty -e empty test -d c/b/../b
112 atf_check -s eq:0 -o empty -e empty test -d c/b/../../c
113 atf_check -s eq:0 -o empty -e empty rmdir c/b
114 atf_check -s eq:0 -o empty -e empty rmdir c
116 echo "Checking if the '..' entry is correct after multiple moves"
117 atf_check -s eq:0 -o empty -e empty mkdir a
118 atf_check -s eq:0 -o empty -e empty mkdir b
119 atf_check -s eq:0 -o empty -e empty mv b a
120 atf_check -s eq:0 -o empty -e empty mv a c
121 atf_check -s eq:0 -o empty -e empty mv c/b d
122 atf_check -s eq:0 -o empty -e empty test -d d/../c
123 atf_check -s eq:0 -o empty -e empty rmdir d
124 atf_check -s eq:0 -o empty -e empty rmdir c
126 test_unmount
129 atf_test_case dir_to_emptydir
130 dir_to_emptydir_head() {
131 atf_set "descr" "Tests that renaming a directory to override an" \
132 "empty directory works"
133 atf_set "require.user" "root"
135 dir_to_emptydir_body() {
136 test_mount
138 atf_check -s eq:0 -o empty -e empty mkdir a
139 atf_check -s eq:0 -o empty -e empty touch a/c
140 atf_check -s eq:0 -o empty -e empty mkdir b
141 atf_check -s eq:0 -o empty -e empty \
142 $(atf_get_srcdir)/h_tools rename a b
143 atf_check -s eq:1 -o empty -e empty test -e a
144 atf_check -s eq:0 -o empty -e empty test -d b
145 atf_check -s eq:0 -o empty -e empty test -f b/c
146 rm b/c
147 rmdir b
149 test_unmount
152 atf_test_case dir_to_fulldir
153 dir_to_fulldir_head() {
154 atf_set "descr" "Tests that renaming a directory to override a" \
155 "non-empty directory fails"
156 atf_set "require.user" "root"
158 dir_to_fulldir_body() {
159 test_mount
161 atf_check -s eq:0 -o empty -e empty mkdir a
162 atf_check -s eq:0 -o empty -e empty touch a/c
163 atf_check -s eq:0 -o empty -e empty mkdir b
164 atf_check -s eq:0 -o empty -e empty touch b/d
165 atf_check -s eq:1 -o empty -e save:stderr \
166 $(atf_get_srcdir)/h_tools rename a b
167 atf_check -s eq:0 -o ignore -e empty grep "Directory not empty" stderr
168 atf_check -s eq:0 -o empty -e empty test -d a
169 atf_check -s eq:0 -o empty -e empty test -f a/c
170 atf_check -s eq:0 -o empty -e empty test -d b
171 atf_check -s eq:0 -o empty -e empty test -f b/d
172 rm a/c
173 rm b/d
174 rmdir a
175 rmdir b
177 test_unmount
180 atf_test_case dir_to_file
181 dir_to_file_head() {
182 atf_set "descr" "Tests that renaming a directory to override a" \
183 "file fails"
184 atf_set "require.user" "root"
186 dir_to_file_body() {
187 test_mount
189 atf_check -s eq:0 -o empty -e empty mkdir a
190 atf_check -s eq:0 -o empty -e empty touch b
191 atf_check -s eq:1 -o empty -e save:stderr \
192 $(atf_get_srcdir)/h_tools rename a b
193 atf_check -s eq:0 -o ignore -e empty grep "Not a directory" stderr
194 atf_check -s eq:0 -o empty -e empty test -d a
195 atf_check -s eq:0 -o empty -e empty test -f b
196 rmdir a
197 rm b
199 test_unmount
202 atf_test_case file_to_dir
203 file_to_dir_head() {
204 atf_set "descr" "Tests that renaming a file to override a" \
205 "directory fails"
206 atf_set "require.user" "root"
208 file_to_dir_body() {
209 test_mount
211 atf_check -s eq:0 -o empty -e empty touch a
212 atf_check -s eq:0 -o empty -e empty mkdir b
213 atf_check -s eq:1 -o empty -e save:stderr \
214 $(atf_get_srcdir)/h_tools rename a b
215 atf_check -s eq:0 -o ignore -e empty grep "Is a directory" stderr
216 atf_check -s eq:0 -o empty -e empty test -f a
217 atf_check -s eq:0 -o empty -e empty test -d b
218 rm a
219 rmdir b
221 test_unmount
224 atf_test_case kqueue
225 kqueue_head() {
226 atf_set "descr" "Tests that moving and renaming files raise the" \
227 "correct kqueue events"
228 atf_set "require.user" "root"
230 kqueue_body() {
231 test_mount
233 atf_check -s eq:0 -o empty -e empty mkdir dir
234 atf_check -s eq:0 -o empty -e empty touch dir/a
235 echo 'mv dir/a dir/b' | kqueue_monitor 2 dir dir/a
236 kqueue_check dir/a NOTE_RENAME
237 kqueue_check dir NOTE_WRITE
238 atf_check -s eq:0 -o empty -e empty rm dir/b
239 atf_check -s eq:0 -o empty -e empty rmdir dir
241 atf_check -s eq:0 -o empty -e empty mkdir dir
242 atf_check -s eq:0 -o empty -e empty touch dir/a
243 atf_check -s eq:0 -o empty -e empty touch dir/b
244 echo 'mv dir/a dir/b' | kqueue_monitor 3 dir dir/a dir/b
245 kqueue_check dir/a NOTE_RENAME
246 kqueue_check dir NOTE_WRITE
247 kqueue_check dir/b NOTE_DELETE
248 atf_check -s eq:0 -o empty -e empty rm dir/b
249 atf_check -s eq:0 -o empty -e empty rmdir dir
251 atf_check -s eq:0 -o empty -e empty mkdir dir1
252 atf_check -s eq:0 -o empty -e empty mkdir dir2
253 atf_check -s eq:0 -o empty -e empty touch dir1/a
254 echo 'mv dir1/a dir2/a' | kqueue_monitor 3 dir1 dir1/a dir2
255 kqueue_check dir1/a NOTE_RENAME
256 kqueue_check dir1 NOTE_WRITE
257 kqueue_check dir2 NOTE_WRITE
258 atf_check -s eq:0 -o empty -e empty rm dir2/a
259 atf_check -s eq:0 -o empty -e empty rmdir dir1
260 atf_check -s eq:0 -o empty -e empty rmdir dir2
262 test_unmount
265 atf_init_test_cases() {
266 . $(atf_get_srcdir)/../h_funcs.subr
267 . $(atf_get_srcdir)/h_funcs.subr
269 atf_add_test_case dots
270 atf_add_test_case crossdev
271 atf_add_test_case basic
272 atf_add_test_case dotdot
273 atf_add_test_case dir_to_emptydir
274 atf_add_test_case dir_to_fulldir
275 atf_add_test_case dir_to_file
276 atf_add_test_case file_to_dir
277 atf_add_test_case kqueue