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