Home | History | Annotate | Line # | Download | only in fsck_ffs
t_enable_quotas.sh revision 1.2
      1  1.2  bouyer # $NetBSD: t_enable_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 disable_${e}_${v} disable_quotas "creation/removal of" ${e} ${v}
     31  1.2  bouyer     test_case corrupt_${e}_${v} corrupt_quotas "repair of corrupted" ${e} ${v}
     32  1.2  bouyer     test_case unallocated_${e}_${v} unallocated_quotas \
     33  1.2  bouyer 		"recovery of unallocated" ${e} ${v}
     34  1.2  bouyer     test_case dir1_${e}_${v} dir1_quotas \
     35  1.2  bouyer 		"successfull clear of wrong type of" ${e} ${v}
     36  1.2  bouyer     test_case notreg_${e}_${v} notreg_quotas \
     37  1.2  bouyer 		"successfull clear of wrong type of" ${e} ${v}
     38  1.2  bouyer   done
     39  1.2  bouyer done
     40  1.2  bouyer 
     41  1.2  bouyer disable_quotas()
     42  1.2  bouyer {
     43  1.2  bouyer 	create_with_quotas $*
     44  1.2  bouyer 	
     45  1.2  bouyer # check that the quota inode creation didn't corrupt the filesystem
     46  1.2  bouyer 	atf_check -s exit:0 -o "match:already clean" -o  "match:3 files" \
     47  1.2  bouyer 		fsck_ffs -nf -F ${IMG}
     48  1.2  bouyer #now check fsck can properly clear the quota inode when quota flags are
     49  1.2  bouyer # cleared
     50  1.2  bouyer 	atf_check -o ignore -e ignore tunefs -q nouser -q nogroup -F ${IMG}
     51  1.2  bouyer 	atf_check -s exit:0 -o "match:SUPERBLOCK QUOTA FLAG CLEARED" \
     52  1.2  bouyer 		fsck_ffs -fp -F ${IMG}
     53  1.2  bouyer 	atf_check -s exit:0 -o "match:1 files, 1 used" fsck_ffs -nf -F ${IMG}
     54  1.2  bouyer }
     55  1.2  bouyer 
     56  1.2  bouyer corrupt_quotas()
     57  1.2  bouyer {
     58  1.2  bouyer 	create_with_quotas $*
     59  1.2  bouyer 
     60  1.2  bouyer 	local blkno=$(printf "inode 3\nblks\n" | /sbin/fsdb -nF -f ${IMG} | awk '$1 == "0:" {print $2}')
     61  1.2  bouyer 	atf_check -o ignore -e ignore dd if=/dev/zero of=${IMG} bs=512 \
     62  1.2  bouyer 		count=1 seek=${blkno} conv=notrunc
     63  1.2  bouyer 	atf_check -s exit:0 \
     64  1.2  bouyer 		-o "match:CORRUPTED USER QUOTA INODE 3 \(CLEARED\)" \
     65  1.2  bouyer 		-o "match:NO USER QUOTA INODE \(CREATED\)" \
     66  1.2  bouyer 		fsck_ffs -fp -F ${IMG}
     67  1.2  bouyer 	atf_check -s exit:0 -o "match:3 files" fsck_ffs -nf -F ${IMG}
     68  1.2  bouyer }
     69  1.2  bouyer 
     70  1.2  bouyer unallocated_quotas()
     71  1.2  bouyer {
     72  1.2  bouyer 	create_with_quotas $*
     73  1.2  bouyer 
     74  1.2  bouyer 	atf_check -o ignore -e ignore clri ${IMG} 3
     75  1.2  bouyer 	atf_check -s exit:0 \
     76  1.2  bouyer 		-o "match:UNALLOCATED USER QUOTA INODE 3 \(CLEARED\)" \
     77  1.2  bouyer 		-o "match:NO USER QUOTA INODE \(CREATED\)" \
     78  1.2  bouyer 		fsck_ffs -fp -F ${IMG}
     79  1.2  bouyer 	atf_check -s exit:0 -o "match:3 files" fsck_ffs -nf -F ${IMG}
     80  1.2  bouyer }
     81  1.2  bouyer 
     82  1.2  bouyer dir1_quotas()
     83  1.2  bouyer {
     84  1.2  bouyer 	create_with_quotas $*
     85  1.2  bouyer 
     86  1.2  bouyer 	atf_check -s exit:255 -o ignore -e ignore -x \
     87  1.2  bouyer 		"printf 'inode 3\nchtype dir\nexit\n' | fsdb -F -f ${IMG}"
     88  1.2  bouyer 	atf_check -s exit:0 \
     89  1.2  bouyer 		-o "match:DIR I=3 CONNECTED. PARENT WAS I=0" \
     90  1.2  bouyer 		-o "match:USER QUOTA INODE 3 IS A DIRECTORY" \
     91  1.2  bouyer 		fsck_ffs -y -F ${IMG}
     92  1.2  bouyer }
     93  1.2  bouyer 
     94  1.2  bouyer notreg_quotas()
     95  1.2  bouyer {
     96  1.2  bouyer 	create_with_quotas $*
     97  1.2  bouyer 
     98  1.2  bouyer 	atf_check -s exit:255 -o ignore -e ignore -x \
     99  1.2  bouyer 		"printf 'inode 3\nchtype fifo\nexit\n' | fsdb -F -f ${IMG}"
    100  1.2  bouyer 	atf_check -s exit:0 \
    101  1.2  bouyer 		-o "match:WRONG TYPE 4096 for USER QUOTA INODE 3 \(CLEARED\)" \
    102  1.2  bouyer 		-o "match:NO USER QUOTA INODE \(CREATED\)" \
    103  1.2  bouyer 		fsck_ffs -p -F ${IMG}
    104  1.2  bouyer 	atf_check -s exit:0 -o "match:3 files" fsck_ffs -nf -F ${IMG}
    105  1.2  bouyer }
    106