Home | History | Annotate | Line # | Download | only in fsck_ffs
t_check_quotas.sh revision 1.2
      1  1.2  bouyer # $NetBSD: t_check_quotas.sh,v 1.2 2011/03/06 17:08:41 bouyer 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.2  bouyer     test_case corrupt_list_${e}_${v} corrupt_list \
     31  1.2  bouyer 	"recovery of corrupted free list in" ${e} ${v}
     32  1.2  bouyer     test_case expand1_list_${e}_${v} expand_list \
     33  1.2  bouyer 	"allocation of direct block in" 40 ${e} ${v}
     34  1.2  bouyer     test_case expand2_list_${e}_${v} expand_list \
     35  1.2  bouyer 	"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.2  bouyer 	create_with_quotas $*
     42  1.2  bouyer 	local blkno=$(printf "inode 3\nblks\n" | /sbin/fsdb -nF -f ${IMG} | awk '$1 == "0:" {print $2}')
     43  1.2  bouyer 	blkno=$(($blkno * 512 + 104))
     44  1.2  bouyer 	#clear the free list
     45  1.2  bouyer 	atf_check -o ignore -e ignore dd if=/dev/zero of=${IMG} bs=1 \
     46  1.2  bouyer 		count=8 seek=${blkno} conv=notrunc
     47  1.2  bouyer 	atf_check -s exit:0 \
     48  1.2  bouyer 		-o "match:QUOTA ENTRY NOT IN LIST \(FIXED\)" \
     49  1.2  bouyer 		fsck_ffs -fp -F ${IMG}
     50  1.2  bouyer 	atf_check -s exit:0 -o "match:3 files" fsck_ffs -nf -F ${IMG}
     51  1.2  bouyer }
     52  1.2  bouyer 
     53  1.2  bouyer expand_list()
     54  1.2  bouyer {
     55  1.2  bouyer 	local nuid=$1; shift
     56  1.2  bouyer 	local expected_files=$((nuid + 2))
     57  1.2  bouyer 	echo "/set uid=0 gid=0" > spec
     58  1.2  bouyer 	echo ".		type=dir  mode=0755" >> spec
     59  1.2  bouyer 	mkdir ${DIR}
     60  1.2  bouyer 	for i in $(seq ${nuid}); do
     61  1.2  bouyer 		touch ${DIR}/f${i}
     62  1.2  bouyer 		echo "./f$i	type=file mode=0600 uid=$i gid=$i" >> spec
     63  1.2  bouyer 	done
     64  1.2  bouyer 
     65  1.2  bouyer 	atf_check -o ignore -e ignore makefs -B $1 -o version=$2 \
     66  1.2  bouyer 		-F spec -s 4000b ${IMG} ${DIR}
     67  1.2  bouyer 	atf_check -o ignore -e ignore tunefs -q user -F ${IMG}
     68  1.2  bouyer 	atf_check -s exit:0 -o 'match:NO USER QUOTA INODE \(CREATED\)' \
     69  1.2  bouyer 		-o 'match:USER QUOTA MISMATCH FOR ID 10: 0/0 SHOULD BE 0/1' \
     70  1.2  bouyer 		fsck_ffs -p -F ${IMG}
     71  1.2  bouyer 	atf_check -s exit:0 -o "match:${expected_files} files" \
     72  1.2  bouyer 		fsck_ffs -nf -F ${IMG}
     73  1.2  bouyer }
     74