1272343Sngie# $NetBSD: t_umount.sh,v 1.5 2010/11/07 17:51:19 jmmv Exp $
2272343Sngie#
3272343Sngie# Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
4272343Sngie# All rights reserved.
5272343Sngie#
6272343Sngie# Redistribution and use in source and binary forms, with or without
7272343Sngie# modification, are permitted provided that the following conditions
8272343Sngie# are met:
9272343Sngie# 1. Redistributions of source code must retain the above copyright
10272343Sngie#    notice, this list of conditions and the following disclaimer.
11272343Sngie# 2. Redistributions in binary form must reproduce the above copyright
12272343Sngie#    notice, this list of conditions and the following disclaimer in the
13272343Sngie#    documentation and/or other materials provided with the distribution.
14272343Sngie#
15272343Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16272343Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17272343Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18272343Sngie# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19272343Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20272343Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21272343Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22272343Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23272343Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24272343Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25272343Sngie# POSSIBILITY OF SUCH DAMAGE.
26272343Sngie#
27272343Sngie
28272343SngieTMPMP=umount-f_mount
29272343SngieTMPIM=umount-f.im
30272343Sngie
31272343SngieVND=vnd0
32272343SngieBVND=/dev/${VND}
33272343SngieCVND=/dev/r${VND}
34272343SngieMPART=a
35272343Sngie
36272343Sngieatf_test_case umount cleanup
37272343Sngieumount_head()
38272343Sngie{
39272343Sngie	atf_set "descr" "Checks forced unmounting"
40272343Sngie	atf_set "require.user" "root"
41272343Sngie}
42272343Sngieumount_body()
43272343Sngie{
44272343Sngie	cat >disktab <<EOF
45272343Sngiefloppy288|2.88MB 3.5in Extra High Density Floppy:\
46272343Sngie	:ty=floppy:se#512:nt#2:rm#300:ns#36:nc#80:\
47272343Sngie	:pa#5760:oa#0:ba#4096:fa#512:ta=4.2BSD:\
48272343Sngie	:pb#5760:ob#0:\
49272343Sngie	:pc#5760:oc#0:
50272343SngieEOF
51272343Sngie
52272343Sngie	echo "*** Creating a dummy directory tree at" \
53272343Sngie	     "${TMPMP} mounted on ${TMPIM}"
54272343Sngie
55272343Sngie	atf_check -o ignore -e ignore mkdir ${TMPMP}
56272343Sngie	atf_check -o ignore -e ignore touch ${TMPMP}/under_the_mount
57272343Sngie	atf_check -o ignore -e ignore dd if=/dev/zero of=${TMPIM} count=5860
58272343Sngie	atf_check -o ignore -e ignore vnconfig -v ${VND} ${TMPIM}
59272343Sngie	atf_check -o ignore -e ignore disklabel -f disktab -rw ${VND} floppy288
60272343Sngie	atf_check -o ignore -e ignore newfs -i 500 -b 8192 -f 1024 ${CVND}${MPART}
61272343Sngie	atf_check -o ignore -e ignore mount -o async ${BVND}${MPART} ${TMPMP}
62272343Sngie	atf_check -o ignore -e ignore touch ${TMPMP}/in_mounted_directory
63272343Sngie
64272343Sngie	echo "*** Testing forced unmount"
65272343Sngie	test -e "${TMPMP}/in_mounted_directory" || \
66272343Sngie	    atf_fail "Test file not present in mounted directory!"
67272343Sngie
68272343Sngie	mydir="`pwd`"
69272343Sngie	cd "${TMPMP}"
70272343Sngie	atf_check -o ignore -e ignore umount -f "${BVND}${MPART}"
71272343Sngie
72272343Sngie	atf_check -s ne:0 -e inline:"ls: .: No such file or directory\n" ls .
73272343Sngie	atf_check -s ne:0 -e inline:"ls: ..: No such file or directory\n" ls ..
74272343Sngie
75272343Sngie	atf_check -s ne:0 -e ignore -o inline:"cd: can't cd to .\n" \
76272343Sngie	    -x "cd . 2>&1"
77272343Sngie	atf_check -s ne:0 -e ignore -o inline:"cd: can't cd to ..\n" \
78272343Sngie	    -x "cd .. 2>&1"
79272343Sngie
80272343Sngie	cd "${mydir}"
81272343Sngie
82272343Sngie	test -e "${TMPMP}/under_the_mount" || \
83272343Sngie	    atf_fail "Original mount point dissapeared!"
84272343Sngie}
85272343Sngieumount_cleanup()
86272343Sngie{
87272343Sngie	echo "*** Cleaning up ${TMPMP}, ${TMPIM}."
88272343Sngie	umount -f "${TMPMP}"
89272343Sngie	vnconfig -u "${VND}"
90272343Sngie}
91272343Sngie
92272343Sngieatf_init_test_cases()
93272343Sngie{
94272343Sngie	atf_add_test_case umount
95272343Sngie}
96