Tue Sep 26 12:15:45 2023 UTC ()
Perform quoting of variable expansions, etc correctly.   That includes
(some) removing of quotes from where they're useless (superstition).

This should be NFC for these tests, as the data being quoted doesn't
happen to require it, but depending upon the data not altering, or the
code not being copied to a different environment is unwise, when it is
so easy to simply do it correctly.

A few line wrapping and white space changes as well.

Nothing changed here is intended to alter the way that the tests run,
or results generated.


(kre)
diff -r1.2 -r1.3 src/tests/sbin/fsck_ffs/quotas_common.sh
diff -r1.2 -r1.3 src/tests/sbin/fsck_ffs/t_check_quotas.sh
diff -r1.3 -r1.4 src/tests/sbin/fsck_ffs/t_enable_quotas.sh
diff -r1.4 -r1.5 src/tests/sbin/fsck_ffs/t_extattr.sh

cvs diff -r1.2 -r1.3 src/tests/sbin/fsck_ffs/quotas_common.sh (expand / switch to unified diff)

--- src/tests/sbin/fsck_ffs/quotas_common.sh 2011/03/06 17:08:41 1.2
+++ src/tests/sbin/fsck_ffs/quotas_common.sh 2023/09/26 12:15:44 1.3
@@ -1,44 +1,47 @@ @@ -1,44 +1,47 @@
1# $NetBSD: quotas_common.sh,v 1.2 2011/03/06 17:08:41 bouyer Exp $  1# $NetBSD: quotas_common.sh,v 1.3 2023/09/26 12:15:44 kre Exp $
2 2
3create_with_quotas() 3create_with_quotas()
4{ 4{
5 local endian=$1; shift 5 local endian=$1; shift
6 local vers=$1; shift 6 local vers=$1; shift
7 local uid=$(id -u) 7 local uid=$(id -u)
8 local gid=$(id -g) 8 local gid=$(id -g)
9 9
10 atf_check -o ignore -e ignore newfs -B ${endian} -O ${vers} \ 10 atf_check -o ignore -e ignore newfs -B "${endian}" -O "${vers}" \
11 -s 4000 -F ${IMG} 11 -s 4000 -F "${IMG}"
12 atf_check -o ignore -e ignore tunefs -q user -q group -F ${IMG} 12 atf_check -o ignore -e ignore tunefs -q user -q group -F "${IMG}"
13 atf_check -s exit:0 -o 'match:NO USER QUOTA INODE \(CREATED\)' \ 13 atf_check -s exit:0 -o 'match:NO USER QUOTA INODE \(CREATED\)' \
14 -o 'match:USER QUOTA MISMATCH FOR ID '${uid}': 0/0 SHOULD BE 1/1' \ 14 -o "match:USER QUOTA MISMATCH FOR ID ${uid}: 0/0 SHOULD BE 1/1" \
15 -o 'match:GROUP QUOTA MISMATCH FOR ID '${gid}': 0/0 SHOULD BE 1/1' \ 15 -o "match:GROUP QUOTA MISMATCH FOR ID ${gid}: 0/0 SHOULD BE 1/1" \
16 fsck_ffs -p -F ${IMG} 16 fsck_ffs -p -F "${IMG}"
17} 17}
18 18
19# from tests/ipf/h_common.sh via tests/sbin/resize_ffs 19# from tests/ipf/h_common.sh via tests/sbin/resize_ffs
20test_case() 20test_case()
21{ 21{
22 local name="${1}"; shift 22 local name="${1}"; shift
23 local check_function="${1}"; shift 23 local check_function="${1}"; shift
24 local descr="${1}"; shift 24 local descr="${1}"; shift
25  25
26 atf_test_case "${name}" 26 atf_test_case "${name}"
27 27
28 eval "${name}_head() { \ 28 eval "${name}_head() {
29 atf_set "descr" "Checks ${descr} quotas inodes" 29 atf_set descr 'Checks ${descr} quotas inodes'
30 }" 30 }"
31 eval "${name}_body() { \ 31 eval "${name}_body() {
32 ${check_function} " "${@}" "; \ 32 ${check_function} $*
33 }" 33 }"
34 tests="${tests} ${name}" 34 tests="${tests} '${name}'"
35} 35}
36 36
37atf_init_test_cases() 37atf_init_test_cases()
38{ 38{
39 IMG=fsimage 39 IMG=fsimage
40 DIR=target 40 DIR=target
41 for i in ${tests}; do 41
42 atf_add_test_case $i 42 eval "set -- ${tests}"
 43 for i
 44 do
 45 atf_add_test_case "$i"
43 done 46 done
44} 47}

cvs diff -r1.2 -r1.3 src/tests/sbin/fsck_ffs/t_check_quotas.sh (expand / switch to unified diff)

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

cvs diff -r1.3 -r1.4 src/tests/sbin/fsck_ffs/t_enable_quotas.sh (expand / switch to unified diff)

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

cvs diff -r1.4 -r1.5 src/tests/sbin/fsck_ffs/t_extattr.sh (expand / switch to unified diff)

--- src/tests/sbin/fsck_ffs/t_extattr.sh 2022/11/30 07:20:36 1.4
+++ src/tests/sbin/fsck_ffs/t_extattr.sh 2023/09/26 12:15:44 1.5
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: t_extattr.sh,v 1.4 2022/11/30 07:20:36 martin Exp $ 1# $NetBSD: t_extattr.sh,v 1.5 2023/09/26 12:15:44 kre Exp $
2# 2#
3# Copyright (c) 2021 The NetBSD Foundation, Inc. 3# Copyright (c) 2021 The NetBSD Foundation, Inc.
4# All rights reserved. 4# All rights reserved.
5#  5#
6# Redistribution and use in source and binary forms, with or without 6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions 7# modification, are permitted provided that the following conditions
8# are met: 8# are met:
9# 1. Redistributions of source code must retain the above copyright 9# 1. Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer. 10# notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright 11# 2. Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the 12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution. 13# documentation and/or other materials provided with the distribution.
14#  14#
@@ -28,173 +28,180 @@ @@ -28,173 +28,180 @@
28VND=vnd0 28VND=vnd0
29BDEV=/dev/${VND} 29BDEV=/dev/${VND}
30CDEV=/dev/r${VND} 30CDEV=/dev/r${VND}
31IMG=fsimage 31IMG=fsimage
32MNT=mnt 32MNT=mnt
33 33
34atf_test_case fsck_extattr_enable cleanup 34atf_test_case fsck_extattr_enable cleanup
35atf_test_case fsck_extattr_enable_corrupted cleanup 35atf_test_case fsck_extattr_enable_corrupted cleanup
36atf_test_case fsck_extattr_disable cleanup 36atf_test_case fsck_extattr_disable cleanup
37 37
38cleanup() 38cleanup()
39{ 39{
40 echo in cleanup 40 echo in cleanup
41 umount -f ${MNT} > /dev/null 2>&1 || true 41 umount -f "${MNT}" > /dev/null 2>&1 || true
42 vnconfig -u ${VND} > /dev/null 2>&1 || true 42 vnconfig -u "${VND}" > /dev/null 2>&1 || true
43} 43}
44 44
45fsck_extattr_enable_head() 45fsck_extattr_enable_head()
46{ 46{
47 atf_set "descr" "Checks fsck_ffs enabling extattrs" 47 atf_set "descr" "Checks fsck_ffs enabling extattrs"
48 atf_set "require.user" "root"; 48 atf_set "require.user" "root";
49} 49}
50 50
51fsck_extattr_enable_body() 51fsck_extattr_enable_body()
52{ 52{
53 atf_check mkdir -p ${MNT} 53 atf_check mkdir -p "${MNT}"
54 54
55 atf_check -o ignore newfs -O2 -s 4m -F ${IMG} 55 atf_check -o ignore newfs -O2 -s 4m -F "${IMG}"
56 atf_check vnconfig ${VND} ${IMG} 56 atf_check vnconfig "${VND}" "${IMG}"
57 57
58 # Verify that extattrs are disabled. 58 # Verify that extattrs are disabled.
59 atf_check -o ignore -e 'match:POSIX1e ACLs not supported by this fs' \ 59 atf_check -o ignore -e 'match:POSIX1e ACLs not supported by this fs' \
60 tunefs -p enable ${CDEV} 60 tunefs -p enable "${CDEV}"
61 atf_check mount -t ffs ${BDEV} ${MNT} 61 atf_check mount -t ffs "${BDEV}" "${MNT}"
62 atf_check touch ${MNT}/file 62 atf_check touch "${MNT}/file"
63 atf_check -s exit:1 -e ignore setextattr user name1 value1 ${MNT}/file 63 atf_check -s exit:1 -e ignore setextattr user name1 value1 "${MNT}/file"
64 atf_check umount ${MNT} 64 atf_check umount "${MNT}"
65 65
66 # Enable extattrs. 66 # Enable extattrs.
67 atf_check -o 'match:ENABLING EXTATTR SUPPORT' \ 67 atf_check -o 'match:ENABLING EXTATTR SUPPORT' \
68 fsck_ffs -c ea ${CDEV} 68 fsck_ffs -c ea "${CDEV}"
69 69
70 # Verify that extattrs are now enabled. 70 # Verify that extattrs are now enabled.
71 atf_check -o 'match:POSIX1e ACLs set' -e ignore \ 71 atf_check -o 'match:POSIX1e ACLs set' -e ignore \
72 tunefs -p enable ${CDEV} 72 tunefs -p enable "${CDEV}"
73 atf_check mount -t ffs ${BDEV} ${MNT} 73 atf_check mount -t ffs "${BDEV}" "${MNT}"
74 atf_check touch ${MNT}/file 74 atf_check touch "${MNT}/file"
75 atf_check setextattr user testname testvalue ${MNT}/file 75 atf_check setextattr user testname testvalue "${MNT}/file"
76 atf_check -o 'match:testvalue' getextattr user testname ${MNT}/file 76 atf_check -o 'match:testvalue' getextattr user testname "${MNT}/file"
77 atf_check umount ${MNT} 77 atf_check umount "${MNT}"
78 atf_check vnconfig -u ${VND} 78 atf_check vnconfig -u "${VND}"
79} 79}
80 80
81fsck_extattr_enable_cleanup() 81fsck_extattr_enable_cleanup()
82{ 82{
83 cleanup 83 cleanup
84} 84}
85 85
86fsck_extattr_enable_corrupted_head() 86fsck_extattr_enable_corrupted_head()
87{ 87{
88 atf_set "descr" "Checks fsck_ffs enabling extattrs with corruption" 88 atf_set "descr" "Checks fsck_ffs enabling extattrs with corruption"
89 atf_set "require.user" "root"; 89 atf_set "require.user" "root";
90} 90}
91 91
92fsck_extattr_enable_corrupted_body() 92fsck_extattr_enable_corrupted_body()
93{ 93{
94 atf_check mkdir -p ${MNT} 94 atf_check mkdir -p "${MNT}"
95 95
96 # Create an fs with extattrs enabled and set an extattr on the test file. 96 # Create an fs with extattrs enabled and set an extattr on the test file.
97 atf_check -o ignore newfs -O2ea -b 8k -f 1k -s 4m -F ${IMG} 97 atf_check -o ignore newfs -O2ea -b 8k -f 1k -s 4m -F "${IMG}"
98 atf_check vnconfig ${VND} ${IMG} 98 atf_check vnconfig "${VND}" "${IMG}"
99 99
100 atf_check mount -t ffs ${BDEV} ${MNT} 100 atf_check mount -t ffs "${BDEV}" "${MNT}"
101 atf_check touch ${MNT}/file 101 atf_check touch "${MNT}/file"
102 atf_check setextattr user testname testvalue ${MNT}/file 102 atf_check setextattr user testname testvalue "${MNT}/file"
103 atf_check -o 'match:testvalue' getextattr user testname ${MNT}/file 103 atf_check -o 'match:testvalue' getextattr user testname "${MNT}/file"
104 atf_check umount ${MNT} 104 atf_check umount "${MNT}"
105 105
106 # Find the location and size of the extattr block. 106 # Find the location and size of the extattr block.
107 extb0=$(printf 'cd file\niptrs\n' | fsdb -n $CDEV | grep 'di_extb 0' | 107 extb0=$(printf 'cd file\niptrs\n' |
 108 fsdb -n "$CDEV" |
 109 grep 'di_extb 0' |
108 awk '{print $3}') 110 awk '{print $3}')
109 extsize=$(printf 'cd file\n' | fsdb -n $CDEV | grep EXTSIZE | tail -1 | 111 extsize=$(printf 'cd file\n' |
110 awk '{print $4}' | sed 's,.*=,,') 112 fsdb -n "$CDEV" |
111 atf_check [ $extb0 != 0 ] 113 grep EXTSIZE |
112 atf_check [ $extsize != 0 ] 114 tail -n 1 |
 115 awk '{print $4}' |
 116 sed 's,.*=,,')
 117 atf_check [ "$extb0" != 0 ]
 118 atf_check [ "$extsize" != 0 ]
113 119
114 # Recreate the fs with extattrs disabled and set the extattr block 120 # Recreate the fs with extattrs disabled and set the extattr block
115 # size/location of the new test file to the same values as the old 121 # size/location of the new test file to the same values as the old
116 # test file. This simulates extattrs having been created in a 122 # test file. This simulates extattrs having been created in a
117 # UFS2-non-ea file system before UFS2ea was invented. 123 # UFS2-non-ea file system before UFS2ea was invented.
118 atf_check -o ignore newfs -O2 -b 8k -f 1k -s 4m -F ${IMG} 124 atf_check -o ignore newfs -O2 -b 8k -f 1k -s 4m -F "${IMG}"
119 atf_check mount -t ffs ${BDEV} ${MNT} 125 atf_check mount -t ffs "${BDEV}" "${MNT}"
120 atf_check touch ${MNT}/file 126 atf_check touch "${MNT}/file"
121 atf_check umount ${MNT} 127 atf_check umount "${MNT}"
122 printf "cd file\nchextb 0 $extb0\n" | fsdb -N $CDEV 128 printf "cd file\nchextb 0 $extb0\n" | fsdb -N "$CDEV"
123 printf "cd file\nchextsize $extsize\n" | fsdb -N $CDEV 129 printf "cd file\nchextsize $extsize\n" | fsdb -N "$CDEV"
124 130
125 # Convert to enable extattrs. 131 # Convert to enable extattrs.
126 atf_check -o 'match:CLEAR EXTATTR FIELDS' \ 132 atf_check -o 'match:CLEAR EXTATTR FIELDS' \
127 -o 'match:ENABLING EXTATTR SUPPORT' \ 133 -o 'match:ENABLING EXTATTR SUPPORT' \
128 fsck_ffs -y -c ea ${CDEV} 134 fsck_ffs -y -c ea "${CDEV}"
129 135
130 # Verify that the test file does not have the extattr. 136 # Verify that the test file does not have the extattr.
131 atf_check -o ignore fsck_ffs -n ${CDEV} 137 atf_check -o ignore fsck_ffs -n "${CDEV}"
132 atf_check mount -t ffs ${BDEV} ${MNT} 138 atf_check mount -t ffs "${BDEV}" "${MNT}"
133 atf_check -s exit:1 -e 'match:Attribute not found' \ 139 atf_check -s exit:1 -e 'match:Attribute not found' \
134 getextattr user testname ${MNT}/file 140 getextattr user testname "${MNT}/file"
135 atf_check umount ${MNT} 141 atf_check umount "${MNT}"
136 atf_check vnconfig -u ${VND} 142 atf_check vnconfig -u "${VND}"
137} 143}
138 144
139fsck_extattr_enable_corrupted_cleanup() 145fsck_extattr_enable_corrupted_cleanup()
140{ 146{
141 cleanup 147 cleanup
142} 148}
143 149
144fsck_extattr_disable_head() 150fsck_extattr_disable_head()
145{ 151{
146 atf_set "descr" "Checks fsck_ffs disabling extattrs" 152 atf_set "descr" "Checks fsck_ffs disabling extattrs"
147 atf_set "require.user" "root"; 153 atf_set "require.user" "root";
148} 154}
149 155
150fsck_extattr_disable_body() 156fsck_extattr_disable_body()
151{ 157{
152 atf_check mkdir -p ${MNT} 158 atf_check mkdir -p "${MNT}"
153 159
154 # Create an fs with extattrs enabled and set an extattr on the test file. 160 # Create an fs with extattrs enabled and set an extattr on the test file.
155 atf_check -o ignore newfs -O2ea -b 8k -f 1k -s 4m -F ${IMG} 161 atf_check -o ignore newfs -O2ea -b 8k -f 1k -s 4m -F "${IMG}"
156 atf_check vnconfig ${VND} ${IMG} 162 atf_check vnconfig "${VND}" "${IMG}"
157 163
158 atf_check mount -t ffs ${BDEV} ${MNT} 164 atf_check mount -t ffs "${BDEV}" "${MNT}"
159 atf_check touch ${MNT}/file 165 atf_check touch "${MNT}/file"
160 atf_check setextattr user testname testvalue ${MNT}/file 166 atf_check setextattr user testname testvalue "${MNT}/file"
161 atf_check -o 'match:testvalue' getextattr user testname ${MNT}/file 167 atf_check -o 'match:testvalue' getextattr user testname "${MNT}/file"
162 atf_check umount ${MNT} 168 atf_check umount "${MNT}"
163 169
164 # Convert to disable extattrs. 170 # Convert to disable extattrs.
165 atf_check -o 'match:CLEAR EXTATTR FIELDS' \ 171 atf_check -o 'match:CLEAR EXTATTR FIELDS' \
166 -o 'match:DISABLING EXTATTR SUPPORT' \ 172 -o 'match:DISABLING EXTATTR SUPPORT' \
167 fsck_ffs -y -c no-ea ${CDEV} 173 fsck_ffs -y -c no-ea "${CDEV}"
168 174
169 # Verify that the test file does not have the test extattr. 175 # Verify that the test file does not have the test extattr.
170 atf_check -o ignore fsck_ffs -n ${CDEV} 176 atf_check -o ignore fsck_ffs -n "${CDEV}"
171 atf_check mount -t ffs ${BDEV} ${MNT} 177 atf_check mount -t ffs "${BDEV}" "${MNT}"
172 atf_check -s exit:1 -e 'match:getextattr: mnt/file: failed: Operation not supported' \ 178 atf_check -s exit:1 \
173 getextattr user testname ${MNT}/file 179 -e 'match:getextattr: mnt/file: failed: Operation not supported' \
174 atf_check umount ${MNT} 180 getextattr user testname "${MNT}/file"
 181 atf_check umount "${MNT}"
175 182
176 # Convert to enable extattrs again. 183 # Convert to enable extattrs again.
177 atf_check -o 'match:ENABLING EXTATTR SUPPORT' \ 184 atf_check -o 'match:ENABLING EXTATTR SUPPORT' \
178 fsck_ffs -y -c ea ${CDEV} 185 fsck_ffs -y -c ea ${CDEV}
179 186
180 # Verify that the test extattr is still gone. 187 # Verify that the test extattr is still gone.
181 atf_check -o ignore fsck_ffs -n ${CDEV} 188 atf_check -o ignore fsck_ffs -n "${CDEV}"
182 atf_check mount -t ffs ${BDEV} ${MNT} 189 atf_check mount -t ffs "${BDEV}" "${MNT}"
183 atf_check -s exit:1 -e 'match:Attribute not found' \ 190 atf_check -s exit:1 -e 'match:Attribute not found' \
184 getextattr user testname ${MNT}/file 191 getextattr user testname "${MNT}/file"
185 atf_check umount ${MNT} 192 atf_check umount "${MNT}"
186 193
187 atf_check vnconfig -u ${VND} 194 atf_check vnconfig -u "${VND}"
188} 195}
189 196
190fsck_extattr_disable_cleanup() 197fsck_extattr_disable_cleanup()
191{ 198{
192 cleanup 199 cleanup
193} 200}
194 201
195atf_init_test_cases() 202atf_init_test_cases()
196{ 203{
197 atf_add_test_case fsck_extattr_enable 204 atf_add_test_case fsck_extattr_enable
198 atf_add_test_case fsck_extattr_enable_corrupted 205 atf_add_test_case fsck_extattr_enable_corrupted
199 atf_add_test_case fsck_extattr_disable 206 atf_add_test_case fsck_extattr_disable
200} 207}