1 # $NetBSD: t_umount.sh,v 1.9 2025/08/18 14:59:51 christos Exp $ 2 # 3 # Copyright (c) 2008, 2009 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 TMPMP=umount-f_mount 29 TMPIM=umount-f.im 30 31 VND=vnd0 32 BVND=/dev/${VND} 33 CVND=/dev/r${VND} 34 MPART=a 35 36 atf_test_case umount cleanup 37 umount_head() 38 { 39 atf_set "descr" "Checks forced unmounting" 40 atf_set "require.user" "root" 41 } 42 umount_body() 43 { 44 if [ $(uname -p) = vax ]; then 45 atf_skip "port-vax/59287 vnd(4) can cause kernel crash" 46 fi 47 48 mydir=$(pwd) 49 cat >disktab <<EOF 50 floppy288|2.88MB 3.5in Extra High Density Floppy:\ 51 :ty=floppy:se#512:nt#2:rm#300:ns#36:nc#80:\ 52 :pa#5760:oa#0:ba#4096:fa#512:ta=4.2BSD:\ 53 :pb#5760:ob#0:\ 54 :pc#5760:oc#0: 55 EOF 56 57 cat << EOF > dot 58 cd: Can't cd to ".": No such file or directory 59 EOF 60 cat << EOF > dotdot 61 cd: Can't cd to "..": No such file or directory 62 EOF 63 echo "*** Creating a dummy directory tree at" \ 64 "${TMPMP} mounted on ${TMPIM}" 65 66 atf_check -o ignore -e ignore mkdir ${TMPMP} 67 atf_check -o ignore -e ignore touch ${TMPMP}/under_the_mount 68 atf_check -o ignore -e ignore dd if=/dev/zero of=${TMPIM} count=5860 69 atf_check -o ignore -e ignore vnconfig -v ${VND} ${TMPIM} 70 atf_check -o ignore -e ignore disklabel -f disktab -rw ${VND} floppy288 71 atf_check -o ignore -e ignore newfs -i 500 -b 8192 -f 1024 ${CVND}${MPART} 72 atf_check -o ignore -e ignore mount -o async ${BVND}${MPART} ${TMPMP} 73 atf_check -o ignore -e ignore touch ${TMPMP}/in_mounted_directory 74 75 echo "*** Testing forced unmount" 76 test -e "${TMPMP}/in_mounted_directory" || \ 77 atf_fail "Test file not present in mounted directory!" 78 79 cd "${TMPMP}" 80 atf_check -o ignore -e ignore umount -f "${BVND}${MPART}" 81 82 atf_check -s ne:0 -e inline:"ls: .: No such file or directory\n" ls . 83 atf_check -s ne:0 -e inline:"ls: ..: No such file or directory\n" ls .. 84 85 atf_check -s ne:0 -e ignore -o file:"${mydir}/dot" -x "cd . 2>&1" 86 atf_check -s ne:0 -e ignore -o file:"${mydir}/dotdot" -x "cd .. 2>&1" 87 88 cd "${mydir}" 89 90 test -e "${TMPMP}/under_the_mount" || \ 91 atf_fail "Original mount point disappeared!" 92 } 93 umount_cleanup() 94 { 95 echo "*** Cleaning up ${TMPMP}, ${TMPIM}." 96 umount -f "${TMPMP}" 97 vnconfig -u "${VND}" 98 } 99 100 atf_init_test_cases() 101 { 102 atf_add_test_case umount 103 } 104