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