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