1# $NetBSD: t_rename.sh,v 1.2 2008/04/30 13:11:00 martin Exp $ 2# 3# Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc. 4# All rights reserved. 5# 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. 14# 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. 26# 27 28# 29# Verifies that the rename operation works (either by renaming entries or 30# by moving them). 31# 32 33atf_test_case dots 34dots_head() { 35 atf_set "descr" "Tests that '.' and '..' cannot be renamed" 36 atf_set "require.user" "root" 37} 38dots_body() { 39 test_mount 40 41 atf_check 'mkdir a' 0 null null 42 atf_check 'mv a/. c' 1 null ignore 43 atf_check 'mv a/.. c' 1 null ignore 44 atf_check 'rmdir a' 0 null null 45 46 test_unmount 47} 48 49atf_test_case crossdev 50crossdev_head() { 51 atf_set "descr" "Tests that cross-device renames do not work" 52 atf_set "require.user" "root" 53} 54crossdev_body() { 55 test_mount 56 57 atf_check 'mkdir a' 0 null null 58 atf_check '$(atf_get_srcdir)/h_tools rename a /var/tmp/a' \ 59 1 null stderr 60 atf_check 'grep "Cross-device link" ../stderr' 0 ignore null 61 atf_check 'test -d a' 0 null null 62 atf_check 'rmdir a' 0 null null 63 64 test_unmount 65} 66 67atf_test_case basic 68basic_head() { 69 atf_set "descr" "Tests that basic renames work" 70 atf_set "require.user" "root" 71} 72basic_body() { 73 test_mount 74 75 atf_check 'mkdir a' 0 null null 76 atf_check 'mv a c' 0 null null 77 atf_check 'test -d a' 1 null null 78 atf_check 'test -d c' 0 null null 79 atf_check 'rmdir c' 0 null null 80 81 test_unmount 82} 83 84atf_test_case dotdot 85dotdot_head() { 86 atf_set "descr" "Tests that the '..' entry is properly updated" \ 87 "during moves" 88 atf_set "require.user" "root" 89} 90dotdot_body() { 91 test_mount 92 93 echo "Checking if the '..' entry is updated after moves" 94 atf_check 'mkdir a' 0 null null 95 atf_check 'mkdir b' 0 null null 96 atf_check 'mv b a' 0 null null 97 atf_check 'test -d a/b/../b' 0 null null 98 atf_check 'test -d a/b/../../a' 0 null null 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 'rmdir a/b' 0 null null 104 atf_check 'rmdir a' 0 null null 105 106 echo "Checking if the '..' entry is correct after renames" 107 atf_check 'mkdir a' 0 null null 108 atf_check 'mkdir b' 0 null null 109 atf_check 'mv b a' 0 null null 110 atf_check 'mv a c' 0 null null 111 atf_check 'test -d c/b/../b' 0 null null 112 atf_check 'test -d c/b/../../c' 0 null null 113 atf_check 'rmdir c/b' 0 null null 114 atf_check 'rmdir c' 0 null null 115 116 echo "Checking if the '..' entry is correct after multiple moves" 117 atf_check 'mkdir a' 0 null null 118 atf_check 'mkdir b' 0 null null 119 atf_check 'mv b a' 0 null null 120 atf_check 'mv a c' 0 null null 121 atf_check 'mv c/b d' 0 null null 122 atf_check 'test -d d/../c' 0 null null 123 atf_check 'rmdir d' 0 null null 124 atf_check 'rmdir c' 0 null null 125 126 test_unmount 127} 128 129atf_test_case dir_to_emptydir 130dir_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" 134} 135dir_to_emptydir_body() { 136 test_mount 137 138 atf_check 'mkdir a' 0 null null 139 atf_check 'touch a/c' 0 null null 140 atf_check 'mkdir b' 0 null null 141 atf_check '$(atf_get_srcdir)/h_tools rename a b' 0 null null 142 atf_check 'test -e a' 1 null null 143 atf_check 'test -d b' 0 null null 144 atf_check 'test -f b/c' 0 null null 145 rm b/c 146 rmdir b 147 148 test_unmount 149} 150 151atf_test_case dir_to_fulldir 152dir_to_fulldir_head() { 153 atf_set "descr" "Tests that renaming a directory to override a" \ 154 "non-empty directory fails" 155 atf_set "require.user" "root" 156} 157dir_to_fulldir_body() { 158 test_mount 159 160 atf_check 'mkdir a' 0 null null 161 atf_check 'touch a/c' 0 null null 162 atf_check 'mkdir b' 0 null null 163 atf_check 'touch b/d' 0 null null 164 atf_check '$(atf_get_srcdir)/h_tools rename a b' 1 null stderr 165 atf_check 'grep "Directory not empty" ../stderr' 0 ignore null 166 atf_check 'test -d a' 0 null null 167 atf_check 'test -f a/c' 0 null null 168 atf_check 'test -d b' 0 null null 169 atf_check 'test -f b/d' 0 null null 170 rm a/c 171 rm b/d 172 rmdir a 173 rmdir b 174 175 test_unmount 176} 177 178atf_test_case dir_to_file 179dir_to_file_head() { 180 atf_set "descr" "Tests that renaming a directory to override a" \ 181 "file fails" 182 atf_set "require.user" "root" 183} 184dir_to_file_body() { 185 test_mount 186 187 atf_check 'mkdir a' 0 null null 188 atf_check 'touch b' 0 null null 189 atf_check '$(atf_get_srcdir)/h_tools rename a b' 1 null stderr 190 atf_check 'grep "Not a directory" ../stderr' 0 ignore null 191 atf_check 'test -d a' 0 null null 192 atf_check 'test -f b' 0 null null 193 rmdir a 194 rm b 195 196 test_unmount 197} 198 199atf_test_case file_to_dir 200file_to_dir_head() { 201 atf_set "descr" "Tests that renaming a file to override a" \ 202 "directory fails" 203 atf_set "require.user" "root" 204} 205file_to_dir_body() { 206 test_mount 207 208 atf_check 'touch a' 0 null null 209 atf_check 'mkdir b' 0 null null 210 atf_check '$(atf_get_srcdir)/h_tools rename a b' 1 null stderr 211 atf_check 'grep "Is a directory" ../stderr' 0 ignore null 212 atf_check 'test -f a' 0 null null 213 atf_check 'test -d b' 0 null null 214 rm a 215 rmdir b 216 217 test_unmount 218} 219 220atf_test_case kqueue 221kqueue_head() { 222 atf_set "descr" "Tests that moving and renaming files raise the" \ 223 "correct kqueue events" 224 atf_set "require.user" "root" 225} 226kqueue_body() { 227 test_mount 228 229 atf_check 'mkdir dir' 0 null null 230 atf_check 'touch dir/a' 0 null null 231 echo 'mv dir/a dir/b' | kqueue_monitor 2 dir dir/a 232 kqueue_check dir/a NOTE_RENAME 233 kqueue_check dir NOTE_WRITE 234 atf_check 'rm dir/b' 0 null null 235 atf_check 'rmdir dir' 0 null null 236 237 atf_check 'mkdir dir' 0 null null 238 atf_check 'touch dir/a' 0 null null 239 atf_check 'touch dir/b' 0 null null 240 echo 'mv dir/a dir/b' | kqueue_monitor 3 dir dir/a dir/b 241 kqueue_check dir/a NOTE_RENAME 242 kqueue_check dir NOTE_WRITE 243 kqueue_check dir/b NOTE_DELETE 244 atf_check 'rm dir/b' 0 null null 245 atf_check 'rmdir dir' 0 null null 246 247 atf_check 'mkdir dir1' 0 null null 248 atf_check 'mkdir dir2' 0 null null 249 atf_check 'touch dir1/a' 0 null null 250 echo 'mv dir1/a dir2/a' | kqueue_monitor 3 dir1 dir1/a dir2 251 kqueue_check dir1/a NOTE_RENAME 252 kqueue_check dir1 NOTE_WRITE 253 kqueue_check dir2 NOTE_WRITE 254 atf_check 'rm dir2/a' 0 null null 255 atf_check 'rmdir dir1' 0 null null 256 atf_check 'rmdir dir2' 0 null null 257 258 test_unmount 259} 260 261atf_init_test_cases() { 262 . $(atf_get_srcdir)/../h_funcs.subr 263 . $(atf_get_srcdir)/h_funcs.subr 264 265 atf_add_test_case dots 266 atf_add_test_case crossdev 267 atf_add_test_case basic 268 atf_add_test_case dotdot 269 atf_add_test_case dir_to_emptydir 270 atf_add_test_case dir_to_fulldir 271 atf_add_test_case dir_to_file 272 atf_add_test_case file_to_dir 273 atf_add_test_case kqueue 274} 275