1272343Sngie# $NetBSD: t_enable_quotas.sh,v 1.2 2011/03/06 17:08:41 bouyer Exp $ 
2272343Sngie#
3272343Sngie#  Copyright (c) 2011 Manuel Bouyer
4272343Sngie#  All rights reserved.
5272343Sngie# 
6272343Sngie#  Redistribution and use in source and binary forms, with or without
7272343Sngie#  modification, are permitted provided that the following conditions
8272343Sngie#  are met:
9272343Sngie#  1. Redistributions of source code must retain the above copyright
10272343Sngie#     notice, this list of conditions and the following disclaimer.
11272343Sngie#  2. Redistributions in binary form must reproduce the above copyright
12272343Sngie#     notice, this list of conditions and the following disclaimer in the
13272343Sngie#     documentation and/or other materials provided with the distribution.
14272343Sngie# 
15272343Sngie#  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16272343Sngie#  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17272343Sngie#  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18272343Sngie#  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19272343Sngie#  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20272343Sngie#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21272343Sngie#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22272343Sngie#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23272343Sngie#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24272343Sngie#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25272343Sngie#  POSSIBILITY OF SUCH DAMAGE.
26272343Sngie#
27272343Sngie
28272343Sngiefor e in le be; do
29272343Sngie  for v in 1 2; do
30272343Sngie    test_case disable_${e}_${v} disable_quotas "creation/removal of" ${e} ${v}
31272343Sngie    test_case corrupt_${e}_${v} corrupt_quotas "repair of corrupted" ${e} ${v}
32272343Sngie    test_case unallocated_${e}_${v} unallocated_quotas \
33272343Sngie		"recovery of unallocated" ${e} ${v}
34272343Sngie    test_case dir1_${e}_${v} dir1_quotas \
35272343Sngie		"successfull clear of wrong type of" ${e} ${v}
36272343Sngie    test_case notreg_${e}_${v} notreg_quotas \
37272343Sngie		"successfull clear of wrong type of" ${e} ${v}
38272343Sngie  done
39272343Sngiedone
40272343Sngie
41272343Sngiedisable_quotas()
42272343Sngie{
43272343Sngie	create_with_quotas $*
44272343Sngie	
45272343Sngie# check that the quota inode creation didn't corrupt the filesystem
46272343Sngie	atf_check -s exit:0 -o "match:already clean" -o  "match:3 files" \
47272343Sngie		fsck_ffs -nf -F ${IMG}
48272343Sngie#now check fsck can properly clear the quota inode when quota flags are
49272343Sngie# cleared
50272343Sngie	atf_check -o ignore -e ignore tunefs -q nouser -q nogroup -F ${IMG}
51272343Sngie	atf_check -s exit:0 -o "match:SUPERBLOCK QUOTA FLAG CLEARED" \
52272343Sngie		fsck_ffs -fp -F ${IMG}
53272343Sngie	atf_check -s exit:0 -o "match:1 files, 1 used" fsck_ffs -nf -F ${IMG}
54272343Sngie}
55272343Sngie
56272343Sngiecorrupt_quotas()
57272343Sngie{
58272343Sngie	create_with_quotas $*
59272343Sngie
60272343Sngie	local blkno=$(printf "inode 3\nblks\n" | /sbin/fsdb -nF -f ${IMG} | awk '$1 == "0:" {print $2}')
61272343Sngie	atf_check -o ignore -e ignore dd if=/dev/zero of=${IMG} bs=512 \
62272343Sngie		count=1 seek=${blkno} conv=notrunc
63272343Sngie	atf_check -s exit:0 \
64272343Sngie		-o "match:CORRUPTED USER QUOTA INODE 3 \(CLEARED\)" \
65272343Sngie		-o "match:NO USER QUOTA INODE \(CREATED\)" \
66272343Sngie		fsck_ffs -fp -F ${IMG}
67272343Sngie	atf_check -s exit:0 -o "match:3 files" fsck_ffs -nf -F ${IMG}
68272343Sngie}
69272343Sngie
70272343Sngieunallocated_quotas()
71272343Sngie{
72272343Sngie	create_with_quotas $*
73272343Sngie
74272343Sngie	atf_check -o ignore -e ignore clri ${IMG} 3
75272343Sngie	atf_check -s exit:0 \
76272343Sngie		-o "match:UNALLOCATED USER QUOTA INODE 3 \(CLEARED\)" \
77272343Sngie		-o "match:NO USER QUOTA INODE \(CREATED\)" \
78272343Sngie		fsck_ffs -fp -F ${IMG}
79272343Sngie	atf_check -s exit:0 -o "match:3 files" fsck_ffs -nf -F ${IMG}
80272343Sngie}
81272343Sngie
82272343Sngiedir1_quotas()
83272343Sngie{
84272343Sngie	create_with_quotas $*
85272343Sngie
86272343Sngie	atf_check -s exit:255 -o ignore -e ignore -x \
87272343Sngie		"printf 'inode 3\nchtype dir\nexit\n' | fsdb -F -f ${IMG}"
88272343Sngie	atf_check -s exit:0 \
89272343Sngie		-o "match:DIR I=3 CONNECTED. PARENT WAS I=0" \
90272343Sngie		-o "match:USER QUOTA INODE 3 IS A DIRECTORY" \
91272343Sngie		fsck_ffs -y -F ${IMG}
92272343Sngie}
93272343Sngie
94272343Sngienotreg_quotas()
95272343Sngie{
96272343Sngie	create_with_quotas $*
97272343Sngie
98272343Sngie	atf_check -s exit:255 -o ignore -e ignore -x \
99272343Sngie		"printf 'inode 3\nchtype fifo\nexit\n' | fsdb -F -f ${IMG}"
100272343Sngie	atf_check -s exit:0 \
101272343Sngie		-o "match:WRONG TYPE 4096 for USER QUOTA INODE 3 \(CLEARED\)" \
102272343Sngie		-o "match:NO USER QUOTA INODE \(CREATED\)" \
103272343Sngie		fsck_ffs -p -F ${IMG}
104272343Sngie	atf_check -s exit:0 -o "match:3 files" fsck_ffs -nf -F ${IMG}
105272343Sngie}
106