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