xfs: fix more xfs_db open-coding instances
[xfstests-dev.git] / tests / xfs / 031
1 #! /bin/bash
2 # FS QA Test No. 031
3 #
4 # exercise xfs_repair - ensure repeated use doesn't corrupt
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #
22 #-----------------------------------------------------------------------
23 #
24
25 seqfull=$0
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
34 rm -f $seqres.full
35
36 # get standard environment, filters and checks
37 . ./common/rc
38 . ./common/repair
39 . ./common/filter
40
41 # link correct .out file
42 _link_out_file
43
44 _check_repair()
45 {
46         echo "Repairing, round 0" >> $seqres.full
47         _scratch_xfs_repair 2>&1 | _filter_repair | tee -a $seqres.full >$tmp.0
48         for i in 1 2 3 4
49         do
50                 echo "Repairing, iteration $i" | tee -a $seqres.full
51                 _scratch_xfs_repair 2>&1 | _filter_repair >$tmp.$i
52                 diff $tmp.0 $tmp.$i >> $seqres.full
53                 if [ $? -ne 0 ]; then
54                         echo "ERROR: repair round $i differs to round 0 (see $seqres.full)" | tee -a $seqres.full
55                         break
56                 fi
57                 # echo all interesting stuff...
58                 perl -ne '
59                         s/(rebuilding directory inode) (\d+)/\1 INO/g;
60                         s/internal log/<TYPEOF> log/g;
61                         s/external log on \S+/<TYPEOF> log/g;
62                         /^\S+/ && print;
63                 ' $tmp.$i
64         done
65         echo
66 }
67
68 # prototype file to create various directory forms
69 _create_proto()
70 {
71         total=$1
72         count=0
73
74         # take inode size into account for non-shortform directories...
75         [ $total -gt 0 ] && total=`expr $total \* $isize / 512`
76
77         cat >$tmp.proto <<EOF
78 DUMMY1
79 0 0
80 : root directory
81 d--777 3 1
82 lost+found d--755 3 1
83 $
84 EOF
85
86         while [ $count -lt $total ]
87         do
88                 let count=$count+1
89                 cat >>$tmp.proto <<EOF
90 ${count}_of_${total}_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ---755 3 1 /bin/true
91 EOF
92         done
93         echo '$' >>$tmp.proto
94 }
95
96 # real QA test starts here
97 _supported_fs xfs
98 _supported_os IRIX Linux
99
100 _require_scratch
101 _require_no_large_scratch_dev
102
103 # sanity test - default + one root directory entry
104 # Note: must do this proto/mkfs now for later inode size calcs
105 _create_proto 0
106 echo "=== one entry (shortform)"
107 _scratch_mkfs_xfs -p $tmp.proto >$tmp.mkfs0 2>&1
108 _filter_mkfs <$tmp.mkfs0 >/dev/null 2>$tmp.mkfs
109 . $tmp.mkfs
110 _check_repair
111
112 # block-form root directory & repeat
113 _create_proto 20
114 echo "=== twenty entries (block form)"
115 _scratch_mkfs_xfs -p $tmp.proto | _filter_mkfs >/dev/null 2>&1
116 _check_repair
117
118 # leaf-form root directory & repeat
119 _create_proto 1000
120 echo "=== thousand entries (leaf form)"
121 _scratch_mkfs_xfs -p $tmp.proto | _filter_mkfs >/dev/null 2>&1
122 _check_repair
123
124 # success, all done
125 status=0
126 exit