xref: /netbsd-src/tests/sbin/fsck_ffs/t_check_quotas.sh (revision 5ae58755a45df7b6cfbd5803078e0c84e32f69e0)
1*5ae58755Skre# $NetBSD: t_check_quotas.sh,v 1.3 2023/09/26 12:15:44 kre Exp $
2063f96f3Sbouyer#
3063f96f3Sbouyer#  Copyright (c) 2011 Manuel Bouyer
4063f96f3Sbouyer#  All rights reserved.
5063f96f3Sbouyer#
6063f96f3Sbouyer#  Redistribution and use in source and binary forms, with or without
7063f96f3Sbouyer#  modification, are permitted provided that the following conditions
8063f96f3Sbouyer#  are met:
9063f96f3Sbouyer#  1. Redistributions of source code must retain the above copyright
10063f96f3Sbouyer#     notice, this list of conditions and the following disclaimer.
11063f96f3Sbouyer#  2. Redistributions in binary form must reproduce the above copyright
12063f96f3Sbouyer#     notice, this list of conditions and the following disclaimer in the
13063f96f3Sbouyer#     documentation and/or other materials provided with the distribution.
14063f96f3Sbouyer#
15063f96f3Sbouyer#  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16063f96f3Sbouyer#  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17063f96f3Sbouyer#  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18063f96f3Sbouyer#  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19063f96f3Sbouyer#  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20063f96f3Sbouyer#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21063f96f3Sbouyer#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22063f96f3Sbouyer#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23063f96f3Sbouyer#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24063f96f3Sbouyer#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25063f96f3Sbouyer#  POSSIBILITY OF SUCH DAMAGE.
26063f96f3Sbouyer#
27063f96f3Sbouyer
28063f96f3Sbouyerfor e in le be; do
29063f96f3Sbouyer  for v in 1 2; do
30*5ae58755Skre    test_case "corrupt_list_${e}_${v}" corrupt_list \
31*5ae58755Skre	"recovery of corrupted free list in" "${e}" "${v}"
32*5ae58755Skre    test_case "expand1_list_${e}_${v}" expand_list \
33*5ae58755Skre	"allocation of direct block in" 40 "${e}" "${v}"
34*5ae58755Skre    test_case "expand2_list_${e}_${v}" expand_list \
35*5ae58755Skre	"allocation of indirect block in" 1000 "${e}" "${v}"
36063f96f3Sbouyer  done
37063f96f3Sbouyerdone
38063f96f3Sbouyer
39063f96f3Sbouyercorrupt_list()
40063f96f3Sbouyer{
41*5ae58755Skre	create_with_quotas "$@"
42*5ae58755Skre	local blkno=$(printf "inode 3\nblks\n" |
43*5ae58755Skre		/sbin/fsdb -nF -f "${IMG}" |
44*5ae58755Skre		awk '$1 == "0:" {print $2}')
45063f96f3Sbouyer	blkno=$(($blkno * 512 + 104))
46063f96f3Sbouyer	#clear the free list
47*5ae58755Skre	atf_check -o ignore -e ignore dd if=/dev/zero "of=${IMG}" bs=1 \
48*5ae58755Skre		count=8 "seek=${blkno}" conv=notrunc
49063f96f3Sbouyer	atf_check -s exit:0 \
50063f96f3Sbouyer		-o "match:QUOTA ENTRY NOT IN LIST \(FIXED\)" \
51*5ae58755Skre		fsck_ffs -fp -F "${IMG}"
52*5ae58755Skre	atf_check -s exit:0 -o "match:3 files" fsck_ffs -nf -F "${IMG}"
53063f96f3Sbouyer}
54063f96f3Sbouyer
55063f96f3Sbouyerexpand_list()
56063f96f3Sbouyer{
57063f96f3Sbouyer	local nuid=$1; shift
58063f96f3Sbouyer	local expected_files=$((nuid + 2))
59063f96f3Sbouyer	echo "/set uid=0 gid=0" > spec
60063f96f3Sbouyer	echo ".		type=dir  mode=0755" >> spec
61063f96f3Sbouyer	mkdir ${DIR}
62*5ae58755Skre	for i in $(seq "${nuid}"); do
63*5ae58755Skre		touch "${DIR}/f${i}"
64063f96f3Sbouyer		echo "./f$i	type=file mode=0600 uid=$i gid=$i" >> spec
65063f96f3Sbouyer	done
66063f96f3Sbouyer
67*5ae58755Skre	atf_check -o ignore -e ignore makefs -B "$1" -o "version=$2" \
68*5ae58755Skre		-F spec -s 4000b "${IMG}" "${DIR}"
69*5ae58755Skre	atf_check -o ignore -e ignore tunefs -q user -F "${IMG}"
70063f96f3Sbouyer	atf_check -s exit:0 -o 'match:NO USER QUOTA INODE \(CREATED\)' \
71063f96f3Sbouyer		-o 'match:USER QUOTA MISMATCH FOR ID 10: 0/0 SHOULD BE 0/1' \
72*5ae58755Skre		fsck_ffs -p -F "${IMG}"
73063f96f3Sbouyer	atf_check -s exit:0 -o "match:${expected_files} files" \
74*5ae58755Skre		fsck_ffs -nf -F "${IMG}"
75063f96f3Sbouyer}
76