Home | History | Annotate | Line # | Download | only in fsck_ffs
t_extattr.sh revision 1.6
      1  1.6     rin # $NetBSD: t_extattr.sh,v 1.6 2025/04/19 02:07:43 rin Exp $
      2  1.1     chs #
      3  1.1     chs #  Copyright (c) 2021 The NetBSD Foundation, Inc.
      4  1.1     chs #  All rights reserved.
      5  1.1     chs # 
      6  1.1     chs #  Redistribution and use in source and binary forms, with or without
      7  1.1     chs #  modification, are permitted provided that the following conditions
      8  1.1     chs #  are met:
      9  1.1     chs #  1. Redistributions of source code must retain the above copyright
     10  1.1     chs #     notice, this list of conditions and the following disclaimer.
     11  1.1     chs #  2. Redistributions in binary form must reproduce the above copyright
     12  1.1     chs #     notice, this list of conditions and the following disclaimer in the
     13  1.1     chs #     documentation and/or other materials provided with the distribution.
     14  1.1     chs # 
     15  1.1     chs #  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     16  1.1     chs #  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17  1.1     chs #  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18  1.1     chs #  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     19  1.1     chs #  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20  1.1     chs #  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21  1.1     chs #  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22  1.1     chs #  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23  1.1     chs #  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24  1.1     chs #  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25  1.1     chs #  POSSIBILITY OF SUCH DAMAGE.
     26  1.1     chs #
     27  1.1     chs 
     28  1.1     chs VND=vnd0
     29  1.4  martin BDEV=/dev/${VND}
     30  1.4  martin CDEV=/dev/r${VND}
     31  1.1     chs IMG=fsimage
     32  1.1     chs MNT=mnt
     33  1.1     chs 
     34  1.1     chs atf_test_case fsck_extattr_enable cleanup
     35  1.1     chs atf_test_case fsck_extattr_enable_corrupted cleanup
     36  1.1     chs atf_test_case fsck_extattr_disable cleanup
     37  1.1     chs 
     38  1.1     chs cleanup()
     39  1.1     chs {
     40  1.1     chs 	echo in cleanup
     41  1.5     kre 	umount -f "${MNT}" > /dev/null 2>&1 || true
     42  1.5     kre 	vnconfig -u "${VND}" > /dev/null 2>&1 || true
     43  1.1     chs }
     44  1.1     chs 
     45  1.1     chs fsck_extattr_enable_head()
     46  1.1     chs {
     47  1.1     chs 	atf_set "descr" "Checks fsck_ffs enabling extattrs"
     48  1.2  martin 	atf_set "require.user" "root";
     49  1.1     chs }
     50  1.1     chs 
     51  1.1     chs fsck_extattr_enable_body()
     52  1.1     chs {
     53  1.6     rin 	if [ $(uname -p) = vax ]; then
     54  1.6     rin 		atf_skip "port-vax/59287 vnd(4) can cause kernel crash"
     55  1.6     rin 	fi
     56  1.6     rin 
     57  1.5     kre 	atf_check mkdir -p "${MNT}"
     58  1.1     chs 
     59  1.5     kre 	atf_check -o ignore newfs -O2 -s 4m -F "${IMG}"
     60  1.5     kre 	atf_check vnconfig "${VND}" "${IMG}"
     61  1.1     chs 
     62  1.1     chs 	# Verify that extattrs are disabled.
     63  1.1     chs 	atf_check -o ignore -e 'match:POSIX1e ACLs not supported by this fs' \
     64  1.5     kre 		tunefs -p enable "${CDEV}"
     65  1.5     kre 	atf_check mount -t ffs "${BDEV}" "${MNT}"
     66  1.5     kre 	atf_check touch "${MNT}/file"
     67  1.5     kre 	atf_check -s exit:1 -e ignore setextattr user name1 value1 "${MNT}/file"
     68  1.5     kre 	atf_check umount "${MNT}"
     69  1.1     chs 
     70  1.1     chs 	# Enable extattrs.
     71  1.1     chs 	atf_check -o 'match:ENABLING EXTATTR SUPPORT' \
     72  1.5     kre 		fsck_ffs -c ea "${CDEV}"
     73  1.1     chs 
     74  1.1     chs 	# Verify that extattrs are now enabled.
     75  1.1     chs 	atf_check -o 'match:POSIX1e ACLs set' -e ignore \
     76  1.5     kre 		tunefs -p enable "${CDEV}"
     77  1.5     kre 	atf_check mount -t ffs "${BDEV}" "${MNT}"
     78  1.5     kre 	atf_check touch "${MNT}/file"
     79  1.5     kre 	atf_check setextattr user testname testvalue "${MNT}/file"
     80  1.5     kre 	atf_check -o 'match:testvalue' getextattr user testname "${MNT}/file"
     81  1.5     kre 	atf_check umount "${MNT}"
     82  1.5     kre 	atf_check vnconfig -u "${VND}"
     83  1.1     chs }
     84  1.1     chs 
     85  1.1     chs fsck_extattr_enable_cleanup()
     86  1.1     chs {
     87  1.1     chs 	cleanup
     88  1.1     chs }
     89  1.1     chs 
     90  1.1     chs fsck_extattr_enable_corrupted_head()
     91  1.1     chs {
     92  1.1     chs 	atf_set "descr" "Checks fsck_ffs enabling extattrs with corruption"
     93  1.2  martin 	atf_set "require.user" "root";
     94  1.1     chs }
     95  1.1     chs 
     96  1.1     chs fsck_extattr_enable_corrupted_body()
     97  1.1     chs {
     98  1.6     rin 	if [ $(uname -p) = vax ]; then
     99  1.6     rin 		atf_skip "port-vax/59287 vnd(4) can cause kernel crash"
    100  1.6     rin 	fi
    101  1.6     rin 
    102  1.5     kre 	atf_check mkdir -p "${MNT}"
    103  1.1     chs 
    104  1.1     chs 	# Create an fs with extattrs enabled and set an extattr on the test file.
    105  1.5     kre 	atf_check -o ignore newfs -O2ea -b 8k -f 1k -s 4m -F "${IMG}"
    106  1.5     kre 	atf_check vnconfig "${VND}" "${IMG}"
    107  1.1     chs 
    108  1.5     kre 	atf_check mount -t ffs "${BDEV}" "${MNT}"
    109  1.5     kre 	atf_check touch "${MNT}/file"
    110  1.5     kre 	atf_check setextattr user testname testvalue "${MNT}/file"
    111  1.5     kre 	atf_check -o 'match:testvalue' getextattr user testname "${MNT}/file"
    112  1.5     kre 	atf_check umount "${MNT}"
    113  1.1     chs 
    114  1.1     chs 	# Find the location and size of the extattr block.
    115  1.5     kre 	extb0=$(printf 'cd file\niptrs\n' |
    116  1.5     kre 		fsdb -n "$CDEV" |
    117  1.5     kre 		grep 'di_extb 0' |
    118  1.1     chs 		awk '{print $3}')
    119  1.5     kre 	extsize=$(printf 'cd file\n' |
    120  1.5     kre 		fsdb -n "$CDEV" |
    121  1.5     kre 		grep EXTSIZE |
    122  1.5     kre 		tail -n 1 |
    123  1.5     kre 		awk '{print $4}' |
    124  1.5     kre 		sed 's,.*=,,')
    125  1.5     kre 	atf_check [ "$extb0" != 0 ]
    126  1.5     kre 	atf_check [ "$extsize" != 0 ]
    127  1.1     chs 
    128  1.1     chs 	# Recreate the fs with extattrs disabled and set the extattr block
    129  1.1     chs 	# size/location of the new test file to the same values as the old
    130  1.1     chs 	# test file.  This simulates extattrs having been created in a
    131  1.1     chs 	# UFS2-non-ea file system before UFS2ea was invented.
    132  1.5     kre 	atf_check -o ignore newfs -O2 -b 8k -f 1k -s 4m -F "${IMG}"
    133  1.5     kre 	atf_check mount -t ffs "${BDEV}" "${MNT}"
    134  1.5     kre 	atf_check touch "${MNT}/file"
    135  1.5     kre 	atf_check umount "${MNT}"
    136  1.5     kre 	printf "cd file\nchextb 0 $extb0\n" | fsdb -N "$CDEV"
    137  1.5     kre 	printf "cd file\nchextsize $extsize\n" | fsdb -N "$CDEV"
    138  1.1     chs 
    139  1.1     chs 	# Convert to enable extattrs.
    140  1.1     chs 	atf_check -o 'match:CLEAR EXTATTR FIELDS' \
    141  1.1     chs 		  -o 'match:ENABLING EXTATTR SUPPORT' \
    142  1.5     kre 		  fsck_ffs -y -c ea "${CDEV}"
    143  1.1     chs 
    144  1.1     chs 	# Verify that the test file does not have the extattr.
    145  1.5     kre 	atf_check -o ignore fsck_ffs -n "${CDEV}"
    146  1.5     kre 	atf_check mount -t ffs "${BDEV}" "${MNT}"
    147  1.1     chs 	atf_check -s exit:1 -e 'match:Attribute not found' \
    148  1.5     kre 		  getextattr user testname "${MNT}/file"
    149  1.5     kre 	atf_check umount "${MNT}"
    150  1.5     kre 	atf_check vnconfig -u "${VND}"
    151  1.1     chs }
    152  1.1     chs 
    153  1.1     chs fsck_extattr_enable_corrupted_cleanup()
    154  1.1     chs {
    155  1.1     chs 	cleanup
    156  1.1     chs }
    157  1.1     chs 
    158  1.1     chs fsck_extattr_disable_head()
    159  1.1     chs {
    160  1.1     chs 	atf_set "descr" "Checks fsck_ffs disabling extattrs"
    161  1.2  martin 	atf_set "require.user" "root";
    162  1.1     chs }
    163  1.1     chs 
    164  1.1     chs fsck_extattr_disable_body()
    165  1.1     chs {
    166  1.6     rin 	if [ $(uname -p) = vax ]; then
    167  1.6     rin 		atf_skip "port-vax/59287 vnd(4) can cause kernel crash"
    168  1.6     rin 	fi
    169  1.6     rin 
    170  1.5     kre 	atf_check mkdir -p "${MNT}"
    171  1.1     chs 
    172  1.1     chs 	# Create an fs with extattrs enabled and set an extattr on the test file.
    173  1.5     kre 	atf_check -o ignore newfs -O2ea -b 8k -f 1k -s 4m -F "${IMG}"
    174  1.5     kre 	atf_check vnconfig "${VND}" "${IMG}"
    175  1.1     chs 
    176  1.5     kre 	atf_check mount -t ffs "${BDEV}" "${MNT}"
    177  1.5     kre 	atf_check touch "${MNT}/file"
    178  1.5     kre 	atf_check setextattr user testname testvalue "${MNT}/file"
    179  1.5     kre 	atf_check -o 'match:testvalue' getextattr user testname "${MNT}/file"
    180  1.5     kre 	atf_check umount "${MNT}"
    181  1.1     chs 
    182  1.1     chs 	# Convert to disable extattrs.
    183  1.1     chs 	atf_check -o 'match:CLEAR EXTATTR FIELDS' \
    184  1.1     chs 		  -o 'match:DISABLING EXTATTR SUPPORT' \
    185  1.5     kre 		  fsck_ffs -y -c no-ea "${CDEV}"
    186  1.1     chs 
    187  1.1     chs 	# Verify that the test file does not have the test extattr.
    188  1.5     kre 	atf_check -o ignore fsck_ffs -n "${CDEV}"
    189  1.5     kre 	atf_check mount -t ffs "${BDEV}" "${MNT}"
    190  1.5     kre 	atf_check -s exit:1 \
    191  1.5     kre 	    -e 'match:getextattr: mnt/file: failed: Operation not supported' \
    192  1.5     kre 		  getextattr user testname "${MNT}/file"
    193  1.5     kre 	atf_check umount "${MNT}"
    194  1.1     chs 
    195  1.1     chs 	# Convert to enable extattrs again.
    196  1.1     chs 	atf_check -o 'match:ENABLING EXTATTR SUPPORT' \
    197  1.1     chs 		  fsck_ffs -y -c ea ${CDEV}
    198  1.1     chs 
    199  1.1     chs 	# Verify that the test extattr is still gone.
    200  1.5     kre 	atf_check -o ignore fsck_ffs -n "${CDEV}"
    201  1.5     kre 	atf_check mount -t ffs "${BDEV}" "${MNT}"
    202  1.1     chs 	atf_check -s exit:1 -e 'match:Attribute not found' \
    203  1.5     kre 		  getextattr user testname "${MNT}/file"
    204  1.5     kre 	atf_check umount "${MNT}"
    205  1.1     chs 
    206  1.5     kre 	atf_check vnconfig -u "${VND}"
    207  1.1     chs }
    208  1.1     chs 
    209  1.1     chs fsck_extattr_disable_cleanup()
    210  1.1     chs {
    211  1.1     chs 	cleanup
    212  1.1     chs }
    213  1.1     chs 
    214  1.1     chs atf_init_test_cases()
    215  1.1     chs {
    216  1.1     chs 	atf_add_test_case fsck_extattr_enable
    217  1.1     chs 	atf_add_test_case fsck_extattr_enable_corrupted
    218  1.1     chs 	atf_add_test_case fsck_extattr_disable
    219  1.1     chs }
    220