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