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