1*5ae58755Skre# $NetBSD: t_extattr.sh,v 1.5 2023/09/26 12:15:44 kre Exp $ 287ba0e2aSchs# 387ba0e2aSchs# Copyright (c) 2021 The NetBSD Foundation, Inc. 487ba0e2aSchs# All rights reserved. 587ba0e2aSchs# 687ba0e2aSchs# Redistribution and use in source and binary forms, with or without 787ba0e2aSchs# modification, are permitted provided that the following conditions 887ba0e2aSchs# are met: 987ba0e2aSchs# 1. Redistributions of source code must retain the above copyright 1087ba0e2aSchs# notice, this list of conditions and the following disclaimer. 1187ba0e2aSchs# 2. Redistributions in binary form must reproduce the above copyright 1287ba0e2aSchs# notice, this list of conditions and the following disclaimer in the 1387ba0e2aSchs# documentation and/or other materials provided with the distribution. 1487ba0e2aSchs# 1587ba0e2aSchs# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1687ba0e2aSchs# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1787ba0e2aSchs# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1887ba0e2aSchs# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 1987ba0e2aSchs# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2087ba0e2aSchs# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2187ba0e2aSchs# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2287ba0e2aSchs# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2387ba0e2aSchs# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2487ba0e2aSchs# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2587ba0e2aSchs# POSSIBILITY OF SUCH DAMAGE. 2687ba0e2aSchs# 2787ba0e2aSchs 2887ba0e2aSchsVND=vnd0 292e1faf8fSmartinBDEV=/dev/${VND} 302e1faf8fSmartinCDEV=/dev/r${VND} 3187ba0e2aSchsIMG=fsimage 3287ba0e2aSchsMNT=mnt 3387ba0e2aSchs 3487ba0e2aSchsatf_test_case fsck_extattr_enable cleanup 3587ba0e2aSchsatf_test_case fsck_extattr_enable_corrupted cleanup 3687ba0e2aSchsatf_test_case fsck_extattr_disable cleanup 3787ba0e2aSchs 3887ba0e2aSchscleanup() 3987ba0e2aSchs{ 4087ba0e2aSchs echo in cleanup 41*5ae58755Skre umount -f "${MNT}" > /dev/null 2>&1 || true 42*5ae58755Skre vnconfig -u "${VND}" > /dev/null 2>&1 || true 4387ba0e2aSchs} 4487ba0e2aSchs 4587ba0e2aSchsfsck_extattr_enable_head() 4687ba0e2aSchs{ 4787ba0e2aSchs atf_set "descr" "Checks fsck_ffs enabling extattrs" 48f202639dSmartin atf_set "require.user" "root"; 4987ba0e2aSchs} 5087ba0e2aSchs 5187ba0e2aSchsfsck_extattr_enable_body() 5287ba0e2aSchs{ 53*5ae58755Skre atf_check mkdir -p "${MNT}" 5487ba0e2aSchs 55*5ae58755Skre atf_check -o ignore newfs -O2 -s 4m -F "${IMG}" 56*5ae58755Skre atf_check vnconfig "${VND}" "${IMG}" 5787ba0e2aSchs 5887ba0e2aSchs # Verify that extattrs are disabled. 5987ba0e2aSchs atf_check -o ignore -e 'match:POSIX1e ACLs not supported by this fs' \ 60*5ae58755Skre tunefs -p enable "${CDEV}" 61*5ae58755Skre atf_check mount -t ffs "${BDEV}" "${MNT}" 62*5ae58755Skre atf_check touch "${MNT}/file" 63*5ae58755Skre atf_check -s exit:1 -e ignore setextattr user name1 value1 "${MNT}/file" 64*5ae58755Skre atf_check umount "${MNT}" 6587ba0e2aSchs 6687ba0e2aSchs # Enable extattrs. 6787ba0e2aSchs atf_check -o 'match:ENABLING EXTATTR SUPPORT' \ 68*5ae58755Skre fsck_ffs -c ea "${CDEV}" 6987ba0e2aSchs 7087ba0e2aSchs # Verify that extattrs are now enabled. 7187ba0e2aSchs atf_check -o 'match:POSIX1e ACLs set' -e ignore \ 72*5ae58755Skre tunefs -p enable "${CDEV}" 73*5ae58755Skre atf_check mount -t ffs "${BDEV}" "${MNT}" 74*5ae58755Skre atf_check touch "${MNT}/file" 75*5ae58755Skre atf_check setextattr user testname testvalue "${MNT}/file" 76*5ae58755Skre atf_check -o 'match:testvalue' getextattr user testname "${MNT}/file" 77*5ae58755Skre atf_check umount "${MNT}" 78*5ae58755Skre atf_check vnconfig -u "${VND}" 7987ba0e2aSchs} 8087ba0e2aSchs 8187ba0e2aSchsfsck_extattr_enable_cleanup() 8287ba0e2aSchs{ 8387ba0e2aSchs cleanup 8487ba0e2aSchs} 8587ba0e2aSchs 8687ba0e2aSchsfsck_extattr_enable_corrupted_head() 8787ba0e2aSchs{ 8887ba0e2aSchs atf_set "descr" "Checks fsck_ffs enabling extattrs with corruption" 89f202639dSmartin atf_set "require.user" "root"; 9087ba0e2aSchs} 9187ba0e2aSchs 9287ba0e2aSchsfsck_extattr_enable_corrupted_body() 9387ba0e2aSchs{ 94*5ae58755Skre atf_check mkdir -p "${MNT}" 9587ba0e2aSchs 9687ba0e2aSchs # Create an fs with extattrs enabled and set an extattr on the test file. 97*5ae58755Skre atf_check -o ignore newfs -O2ea -b 8k -f 1k -s 4m -F "${IMG}" 98*5ae58755Skre atf_check vnconfig "${VND}" "${IMG}" 9987ba0e2aSchs 100*5ae58755Skre atf_check mount -t ffs "${BDEV}" "${MNT}" 101*5ae58755Skre atf_check touch "${MNT}/file" 102*5ae58755Skre atf_check setextattr user testname testvalue "${MNT}/file" 103*5ae58755Skre atf_check -o 'match:testvalue' getextattr user testname "${MNT}/file" 104*5ae58755Skre atf_check umount "${MNT}" 10587ba0e2aSchs 10687ba0e2aSchs # Find the location and size of the extattr block. 107*5ae58755Skre extb0=$(printf 'cd file\niptrs\n' | 108*5ae58755Skre fsdb -n "$CDEV" | 109*5ae58755Skre grep 'di_extb 0' | 11087ba0e2aSchs awk '{print $3}') 111*5ae58755Skre extsize=$(printf 'cd file\n' | 112*5ae58755Skre fsdb -n "$CDEV" | 113*5ae58755Skre grep EXTSIZE | 114*5ae58755Skre tail -n 1 | 115*5ae58755Skre awk '{print $4}' | 116*5ae58755Skre sed 's,.*=,,') 117*5ae58755Skre atf_check [ "$extb0" != 0 ] 118*5ae58755Skre atf_check [ "$extsize" != 0 ] 11987ba0e2aSchs 12087ba0e2aSchs # Recreate the fs with extattrs disabled and set the extattr block 12187ba0e2aSchs # size/location of the new test file to the same values as the old 12287ba0e2aSchs # test file. This simulates extattrs having been created in a 12387ba0e2aSchs # UFS2-non-ea file system before UFS2ea was invented. 124*5ae58755Skre atf_check -o ignore newfs -O2 -b 8k -f 1k -s 4m -F "${IMG}" 125*5ae58755Skre atf_check mount -t ffs "${BDEV}" "${MNT}" 126*5ae58755Skre atf_check touch "${MNT}/file" 127*5ae58755Skre atf_check umount "${MNT}" 128*5ae58755Skre printf "cd file\nchextb 0 $extb0\n" | fsdb -N "$CDEV" 129*5ae58755Skre printf "cd file\nchextsize $extsize\n" | fsdb -N "$CDEV" 13087ba0e2aSchs 13187ba0e2aSchs # Convert to enable extattrs. 13287ba0e2aSchs atf_check -o 'match:CLEAR EXTATTR FIELDS' \ 13387ba0e2aSchs -o 'match:ENABLING EXTATTR SUPPORT' \ 134*5ae58755Skre fsck_ffs -y -c ea "${CDEV}" 13587ba0e2aSchs 13687ba0e2aSchs # Verify that the test file does not have the extattr. 137*5ae58755Skre atf_check -o ignore fsck_ffs -n "${CDEV}" 138*5ae58755Skre atf_check mount -t ffs "${BDEV}" "${MNT}" 13987ba0e2aSchs atf_check -s exit:1 -e 'match:Attribute not found' \ 140*5ae58755Skre getextattr user testname "${MNT}/file" 141*5ae58755Skre atf_check umount "${MNT}" 142*5ae58755Skre atf_check vnconfig -u "${VND}" 14387ba0e2aSchs} 14487ba0e2aSchs 14587ba0e2aSchsfsck_extattr_enable_corrupted_cleanup() 14687ba0e2aSchs{ 14787ba0e2aSchs cleanup 14887ba0e2aSchs} 14987ba0e2aSchs 15087ba0e2aSchsfsck_extattr_disable_head() 15187ba0e2aSchs{ 15287ba0e2aSchs atf_set "descr" "Checks fsck_ffs disabling extattrs" 153f202639dSmartin atf_set "require.user" "root"; 15487ba0e2aSchs} 15587ba0e2aSchs 15687ba0e2aSchsfsck_extattr_disable_body() 15787ba0e2aSchs{ 158*5ae58755Skre atf_check mkdir -p "${MNT}" 15987ba0e2aSchs 16087ba0e2aSchs # Create an fs with extattrs enabled and set an extattr on the test file. 161*5ae58755Skre atf_check -o ignore newfs -O2ea -b 8k -f 1k -s 4m -F "${IMG}" 162*5ae58755Skre atf_check vnconfig "${VND}" "${IMG}" 16387ba0e2aSchs 164*5ae58755Skre atf_check mount -t ffs "${BDEV}" "${MNT}" 165*5ae58755Skre atf_check touch "${MNT}/file" 166*5ae58755Skre atf_check setextattr user testname testvalue "${MNT}/file" 167*5ae58755Skre atf_check -o 'match:testvalue' getextattr user testname "${MNT}/file" 168*5ae58755Skre atf_check umount "${MNT}" 16987ba0e2aSchs 17087ba0e2aSchs # Convert to disable extattrs. 17187ba0e2aSchs atf_check -o 'match:CLEAR EXTATTR FIELDS' \ 17287ba0e2aSchs -o 'match:DISABLING EXTATTR SUPPORT' \ 173*5ae58755Skre fsck_ffs -y -c no-ea "${CDEV}" 17487ba0e2aSchs 17587ba0e2aSchs # Verify that the test file does not have the test extattr. 176*5ae58755Skre atf_check -o ignore fsck_ffs -n "${CDEV}" 177*5ae58755Skre atf_check mount -t ffs "${BDEV}" "${MNT}" 178*5ae58755Skre atf_check -s exit:1 \ 179*5ae58755Skre -e 'match:getextattr: mnt/file: failed: Operation not supported' \ 180*5ae58755Skre getextattr user testname "${MNT}/file" 181*5ae58755Skre atf_check umount "${MNT}" 18287ba0e2aSchs 18387ba0e2aSchs # Convert to enable extattrs again. 18487ba0e2aSchs atf_check -o 'match:ENABLING EXTATTR SUPPORT' \ 18587ba0e2aSchs fsck_ffs -y -c ea ${CDEV} 18687ba0e2aSchs 18787ba0e2aSchs # Verify that the test extattr is still gone. 188*5ae58755Skre atf_check -o ignore fsck_ffs -n "${CDEV}" 189*5ae58755Skre atf_check mount -t ffs "${BDEV}" "${MNT}" 19087ba0e2aSchs atf_check -s exit:1 -e 'match:Attribute not found' \ 191*5ae58755Skre getextattr user testname "${MNT}/file" 192*5ae58755Skre atf_check umount "${MNT}" 19387ba0e2aSchs 194*5ae58755Skre atf_check vnconfig -u "${VND}" 19587ba0e2aSchs} 19687ba0e2aSchs 19787ba0e2aSchsfsck_extattr_disable_cleanup() 19887ba0e2aSchs{ 19987ba0e2aSchs cleanup 20087ba0e2aSchs} 20187ba0e2aSchs 20287ba0e2aSchsatf_init_test_cases() 20387ba0e2aSchs{ 20487ba0e2aSchs atf_add_test_case fsck_extattr_enable 20587ba0e2aSchs atf_add_test_case fsck_extattr_enable_corrupted 20687ba0e2aSchs atf_add_test_case fsck_extattr_disable 20787ba0e2aSchs} 208