t_check_quotas.sh revision 1.3 1 1.3 kre # $NetBSD: t_check_quotas.sh,v 1.3 2023/09/26 12:15:44 kre Exp $
2 1.2 bouyer #
3 1.2 bouyer # Copyright (c) 2011 Manuel Bouyer
4 1.2 bouyer # All rights reserved.
5 1.2 bouyer #
6 1.2 bouyer # Redistribution and use in source and binary forms, with or without
7 1.2 bouyer # modification, are permitted provided that the following conditions
8 1.2 bouyer # are met:
9 1.2 bouyer # 1. Redistributions of source code must retain the above copyright
10 1.2 bouyer # notice, this list of conditions and the following disclaimer.
11 1.2 bouyer # 2. Redistributions in binary form must reproduce the above copyright
12 1.2 bouyer # notice, this list of conditions and the following disclaimer in the
13 1.2 bouyer # documentation and/or other materials provided with the distribution.
14 1.2 bouyer #
15 1.2 bouyer # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 1.2 bouyer # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 1.2 bouyer # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 1.2 bouyer # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 1.2 bouyer # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 1.2 bouyer # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 1.2 bouyer # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 1.2 bouyer # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.2 bouyer # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 1.2 bouyer # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.2 bouyer # POSSIBILITY OF SUCH DAMAGE.
26 1.2 bouyer #
27 1.2 bouyer
28 1.2 bouyer for e in le be; do
29 1.2 bouyer for v in 1 2; do
30 1.3 kre test_case "corrupt_list_${e}_${v}" corrupt_list \
31 1.3 kre "recovery of corrupted free list in" "${e}" "${v}"
32 1.3 kre test_case "expand1_list_${e}_${v}" expand_list \
33 1.3 kre "allocation of direct block in" 40 "${e}" "${v}"
34 1.3 kre test_case "expand2_list_${e}_${v}" expand_list \
35 1.3 kre "allocation of indirect block in" 1000 "${e}" "${v}"
36 1.2 bouyer done
37 1.2 bouyer done
38 1.2 bouyer
39 1.2 bouyer corrupt_list()
40 1.2 bouyer {
41 1.3 kre create_with_quotas "$@"
42 1.3 kre local blkno=$(printf "inode 3\nblks\n" |
43 1.3 kre /sbin/fsdb -nF -f "${IMG}" |
44 1.3 kre awk '$1 == "0:" {print $2}')
45 1.2 bouyer blkno=$(($blkno * 512 + 104))
46 1.2 bouyer #clear the free list
47 1.3 kre atf_check -o ignore -e ignore dd if=/dev/zero "of=${IMG}" bs=1 \
48 1.3 kre count=8 "seek=${blkno}" conv=notrunc
49 1.2 bouyer atf_check -s exit:0 \
50 1.2 bouyer -o "match:QUOTA ENTRY NOT IN LIST \(FIXED\)" \
51 1.3 kre fsck_ffs -fp -F "${IMG}"
52 1.3 kre atf_check -s exit:0 -o "match:3 files" fsck_ffs -nf -F "${IMG}"
53 1.2 bouyer }
54 1.2 bouyer
55 1.2 bouyer expand_list()
56 1.2 bouyer {
57 1.2 bouyer local nuid=$1; shift
58 1.2 bouyer local expected_files=$((nuid + 2))
59 1.2 bouyer echo "/set uid=0 gid=0" > spec
60 1.2 bouyer echo ". type=dir mode=0755" >> spec
61 1.2 bouyer mkdir ${DIR}
62 1.3 kre for i in $(seq "${nuid}"); do
63 1.3 kre touch "${DIR}/f${i}"
64 1.2 bouyer echo "./f$i type=file mode=0600 uid=$i gid=$i" >> spec
65 1.2 bouyer done
66 1.2 bouyer
67 1.3 kre atf_check -o ignore -e ignore makefs -B "$1" -o "version=$2" \
68 1.3 kre -F spec -s 4000b "${IMG}" "${DIR}"
69 1.3 kre atf_check -o ignore -e ignore tunefs -q user -F "${IMG}"
70 1.2 bouyer atf_check -s exit:0 -o 'match:NO USER QUOTA INODE \(CREATED\)' \
71 1.2 bouyer -o 'match:USER QUOTA MISMATCH FOR ID 10: 0/0 SHOULD BE 0/1' \
72 1.3 kre fsck_ffs -p -F "${IMG}"
73 1.2 bouyer atf_check -s exit:0 -o "match:${expected_files} files" \
74 1.3 kre fsck_ffs -nf -F "${IMG}"
75 1.2 bouyer }
76