1# $NetBSD: t_enable_quotas.sh,v 1.4 2023/09/26 12:15:44 kre Exp $ 2# 3# Copyright (c) 2011 Manuel Bouyer 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25# POSSIBILITY OF SUCH DAMAGE. 26# 27 28for e in le be; do 29 for v in 1 2; do 30 test_case "disable_${e}_${v}" disable_quotas \ 31 "creation/removal of" "${e}" "${v}" 32 test_case "corrupt_${e}_${v}" corrupt_quotas \ 33 "repair of corrupted" "${e}" "${v}" 34 test_case "unallocated_${e}_${v}" unallocated_quotas \ 35 "recovery of unallocated" "${e}" "${v}" 36 test_case "dir1_${e}_${v}" dir1_quotas \ 37 "successful clear of wrong type of" "${e}" "${v}" 38 test_case "notreg_${e}_${v}" notreg_quotas \ 39 "successful clear of wrong type of" "${e}" "${v}" 40 done 41done 42 43disable_quotas() 44{ 45 create_with_quotas "$@" 46 47# check that the quota inode creation didn't corrupt the filesystem 48 atf_check -s exit:0 -o "match:already clean" -o "match:3 files" \ 49 fsck_ffs -nf -F "${IMG}" 50#now check fsck can properly clear the quota inode when quota flags are 51# cleared 52 atf_check -o ignore -e ignore tunefs -q nouser -q nogroup -F "${IMG}" 53 atf_check -s exit:0 -o "match:SUPERBLOCK QUOTA FLAG CLEARED" \ 54 fsck_ffs -fp -F "${IMG}" 55 atf_check -s exit:0 -o "match:1 files, 1 used" fsck_ffs -nf -F "${IMG}" 56} 57 58corrupt_quotas() 59{ 60 create_with_quotas "$@" 61 62 local blkno=$(printf "inode 3\nblks\n" | 63 /sbin/fsdb -nF -f "${IMG}" | 64 awk '$1 == "0:" {print $2}') 65 66 atf_check -o ignore -e ignore dd if=/dev/zero "of=${IMG}" bs=512 \ 67 count=1 "seek=${blkno}" conv=notrunc 68 atf_check -s exit:0 \ 69 -o "match:CORRUPTED USER QUOTA INODE 3 \(CLEARED\)" \ 70 -o "match:NO USER QUOTA INODE \(CREATED\)" \ 71 fsck_ffs -fp -F "${IMG}" 72 atf_check -s exit:0 -o "match:3 files" fsck_ffs -nf -F "${IMG}" 73} 74 75unallocated_quotas() 76{ 77 create_with_quotas "$@" 78 79 atf_check -o ignore -e ignore clri "${IMG}" 3 80 atf_check -s exit:0 \ 81 -o "match:UNALLOCATED USER QUOTA INODE 3 \(CLEARED\)" \ 82 -o "match:NO USER QUOTA INODE \(CREATED\)" \ 83 fsck_ffs -fp -F "${IMG}" 84 atf_check -s exit:0 -o "match:3 files" fsck_ffs -nf -F "${IMG}" 85} 86 87dir1_quotas() 88{ 89 create_with_quotas "$@" 90 91 atf_check -s exit:255 -o ignore -e ignore -x \ 92 "printf 'inode 3\nchtype dir\nexit\n' | fsdb -F -f '${IMG}'" 93 atf_check -s exit:0 \ 94 -o "match:DIR I=3 CONNECTED. PARENT WAS I=0" \ 95 -o "match:USER QUOTA INODE 3 IS A DIRECTORY" \ 96 fsck_ffs -y -F "${IMG}" 97} 98 99notreg_quotas() 100{ 101 create_with_quotas "$@" 102 103 atf_check -s exit:255 -o ignore -e ignore -x \ 104 "printf 'inode 3\nchtype fifo\nexit\n' | fsdb -F -f '${IMG}'" 105 atf_check -s exit:0 \ 106 -o "match:WRONG TYPE 4096 for USER QUOTA INODE 3 \(CLEARED\)" \ 107 -o "match:NO USER QUOTA INODE \(CREATED\)" \ 108 fsck_ffs -p -F "${IMG}" 109 atf_check -s exit:0 -o "match:3 files" fsck_ffs -nf -F "${IMG}" 110} 111