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