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