fstests: convert remaining tests to SPDX license tags
[xfstests-dev.git] / tests / xfs / 136
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2005 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 136
6 #
7 # Test the attr2 code
8 # Let's look, xfs_db, at the inode and its literal area for the
9 # extents and the attributes 
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22     cd /
23     rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/attr
30
31 # real QA test starts here
32
33 #_notrun "Need to fix up filtering before checkin" 
34
35 # Modify as appropriate.
36 _supported_fs xfs
37 _supported_os Linux
38
39 _require_scratch
40 _require_attrs
41
42 export MKFS_OPTIONS="-i size=512,attr=2"
43 _scratch_mkfs_xfs > /dev/null 2>&1
44 _scratch_mount
45
46 file=$SCRATCH_MNT/file
47 touch $file
48 inum=`ls -i $file | awk '{print $1}'`
49 echo "inum=$inum"
50
51 _filter()
52 {
53     sed -e "s#$tmp#TMP#g"
54 }
55
56 add_eas()
57 {
58     start=$1
59     end=$2
60     echo ""; echo "** add $start..$end EAs **"
61     i=$start
62     while [ $i -le $end ]; do 
63         ${ATTR_PROG} -s name.$i -V value $file >/dev/null
64         let i=$i+1
65     done
66 }
67
68 rm_eas()
69 {
70     start=$1
71     end=$2
72     echo ""; echo "** rm $start..$end EAs **"
73     i=$start
74     while [ $i -le $end ]; do 
75         ${ATTR_PROG} -r name.$i $file >/dev/null
76         let i=$i+1
77     done
78 }
79
80 do_extents()
81 {
82     num=$1
83     echo ""; echo "** $num extents **"
84     src/makeextents -v -p -w -n $num $file
85 }
86
87 _print_inode()
88 {
89     _scratch_unmount
90     _scratch_xfs_db -r -c "inode $inum" -c "print"  |\
91     awk '
92         /nextents/ { print; next }
93         /naextents/ { print; next }
94         /u\./ { print; next }
95         /a\./ { print; next }
96         /forkoff/ { printf("core.forkoff = %d (%d bytes)\n", $3, $3*8); next }
97         /format/ { print; next }
98         /size/ { print; next }
99     '
100     _scratch_mount
101 }
102
103 _print_inode_u()
104 {
105     _scratch_unmount
106     _scratch_xfs_db -r -c "inode $inum" -c "print u"
107     _scratch_mount
108 }
109
110 _print_inode_a()
111 {
112     _scratch_unmount
113     _scratch_xfs_db -r -c "inode $inum" -c "print a"
114     _scratch_mount
115 }
116
117 _test_add_eas()
118 {
119         _print_inode
120
121         add_eas 1 1
122         _print_inode
123
124         add_eas 2 2
125         _print_inode
126
127         add_eas 3 4
128         _print_inode
129
130         add_eas 5 8
131         _print_inode
132
133         add_eas 9 16
134         _print_inode
135
136         add_eas 17 20
137         _print_inode
138
139         add_eas 21 21
140         _print_inode
141
142         add_eas 22 22
143         _print_inode
144
145         add_eas 23 23
146         _print_inode
147
148         add_eas 24 24
149         _print_inode
150
151         add_eas 25 25
152         _print_inode
153
154         add_eas 26 30
155         _print_inode
156
157         add_eas 31 35
158         _print_inode
159
160         rm_eas 1 34
161         _print_inode
162 }
163
164 _test_add_extents()
165 {
166         # now do the extents
167
168         #build up
169         j=1
170         while [ $j -le 30 ]; do
171             do_extents $j
172             _print_inode
173             let j=$j+2
174         done
175
176         #scale down
177         j=30
178         while [ $j -ge 1 ]; do
179             do_extents $j
180             _print_inode
181             let j=$j-2
182         done
183
184         #build up
185         j=1
186         while [ $j -le 30 ]; do
187             do_extents $j
188             _print_inode
189             let j=$j+2
190         done
191 }
192
193 #
194 # Using a nested loop,
195 # for various number of data extents,
196 # try adding EAs and then removing EAs
197 # Check that when we play with the EAs that we don't mess with the extents
198 #
199 _test_extents_eas()
200 {
201         # now do the EAs with the extents
202
203         extents_max=400
204         extents_inc=10
205         EAs_max=100
206         EAs_inc=5
207         for i in `seq 1 $extents_inc $extents_max`; do
208             do_extents $i
209             echo "--- extents: $i ---"
210             _print_inode
211             _print_inode_u > $tmp.u1
212             for j in `seq 1 $EAs_inc $EAs_max`; do
213                 let k=$k+$EAs_inc-1
214                 add_eas $j $k
215             done
216             # should have same extents
217             _print_inode
218             _print_inode_u > $tmp.u2
219             rm_eas 1 $EAs_max
220             _print_inode_u > $tmp.u3
221
222             echo ""
223             echo "*** Extent differences before and after EAs added ***"
224             diff -s $tmp.u1 $tmp.u2 | _filter
225             echo ""
226             if ! diff $tmp.u1 $tmp.u2 >/dev/null; then 
227                 echo "Data extents magically changed"
228                 exit
229             fi
230
231             echo ""
232             echo "*** Extent differences before and after EAs removed ***"
233             diff -s $tmp.u2 $tmp.u3 | _filter
234             echo ""
235             if ! diff $tmp.u2 $tmp.u3 >/dev/null; then 
236                 echo "Data extents magically changed"
237                 exit
238             fi
239         done
240 }
241
242 #
243 # The counterpart of _test_extents_eas
244 # with the nested loops reversed.
245 # For various number of EAs, try adding extents
246 # Check that when we play with the data extents that we don't mess with the EAs
247 #
248 _test_eas_extents()
249 {
250         # now do the EAs with the extents
251
252         extents_max=400
253         extents_inc=10
254         EAs_max=100
255         EAs_inc=5
256         for j in `seq 1 $EAs_inc $EAs_max`; do
257
258             let k=$k+$EAs_inc-1
259             add_eas $j $k
260             echo "--- EAs: $j ---"
261
262             _print_inode
263             _print_inode_a > $tmp.a1
264             for i in `seq 1 $extents_inc $extents_max`; do
265                 do_extents $i
266             done
267
268             # should have same EAs
269             _print_inode
270             _print_inode_a > $tmp.a2
271             >$file 
272             _print_inode_a > $tmp.a3
273
274             echo ""
275             echo "*** EA differences before and after extents added ***"
276             diff -s $tmp.a1 $tmp.a2 | _filter
277             echo ""
278             if ! diff $tmp.a1 $tmp.a2 >/dev/null; then 
279                 echo "EAs magically changed"
280                 exit
281             fi
282
283             echo ""
284             echo "*** EA differences before and after extents removed ***"
285             diff -s $tmp.a2 $tmp.a3 | _filter
286             echo ""
287             if ! diff $tmp.a2 $tmp.a3 >/dev/null; then 
288                 echo "EAs magically changed"
289                 exit
290             fi
291         done
292 }
293
294 #
295 # test to see how we go 
296
297 #
298 # test to ensure it fits a max sf EA
299 #
300 # literal part of inode starts at offset 100 (decimal)
301 # for 512 bytes inode that gives 412 bytes of literal area
302 #
303 # min btree root (numrecs=3) => 3 * 16 + (4 or 8)
304 # for 8 byte alignment => 56 bytes
305 # => 512 - 156 = 356 bytes 
306 #
307 # SF EA of form
308 #   totsize: 2 bytes
309 #   count:   1 byte
310 #   nlen:    1 byte
311 #   vlen:    1 byte
312 #   flags:   1 byte
313 #   name:    nlen
314 #   value:   vlen
315 #
316 # => 6+nlen+vlen
317 #
318 # for nlen=4 "name"
319 # vlen = 356 - (6+4) = 346
320
321 #
322 _test_initial_sf_ea()
323 {
324         rm $file
325         touch $file
326         vlen=402
327         vlen=300
328         dd if=/dev/zero bs=1 count=$vlen | ${ATTR_PROG} -s name $file
329         _print_inode
330 }
331
332 # main
333
334 _test_add_eas
335 _test_add_extents
336 _test_extents_eas
337 _test_eas_extents
338 #_test_initial_sf_ea
339
340 # do a test with a variety of sized EAs
341
342 # success, all done
343 status=0
344 exit