fix references to old directory structure.
[xfstests-dev.git] / common.repair
1 ##/bin/sh
2
3 #
4 # Functions useful for xfs_repair tests
5
6 # Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
7
8 # This program is free software; you can redistribute it and/or modify it
9 # under the terms of version 2 of the GNU General Public License as
10 # published by the Free Software Foundation.
11
12 # This program is distributed in the hope that it would be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
16 # Further, this software is distributed without any warranty that it is
17 # free of the rightful claim of any third person regarding infringement
18 # or the like.  Any license provided herein, whether implied or
19 # otherwise, applies only to this software file.  Patent licenses, if
20 # any, provided herein do not apply to combinations of this program with
21 # other software, or any other product whatsoever.
22
23 # You should have received a copy of the GNU General Public License along
24 # with this program; if not, write the Free Software Foundation, Inc., 59
25 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
26
27 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
28 # Mountain View, CA  94043, or:
29
30 # http://www.sgi.com 
31
32 # For further information regarding this notice, see: 
33
34 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
35 #
36
37 _zero_position()
38 {
39         value=$1
40         struct="$2"
41
42         # set values for off/len variables provided by db
43         eval `xfs_db -r -c "$struct" -c stack $SCRATCH_DEV | perl -ne '
44                 if (/byte offset (\d+), length (\d+)/) {
45                         print "offset=$1\nlength=$2\n"; exit
46                 }'`
47         if [ -z "$offset" -o -z "$length" ]; then
48                 echo "cannot calculate offset ($offset) or length ($length)"
49                 exit
50         fi
51         length=`expr $length / 512`
52         src/devzero -v $value -b 1 -n $length -o $offset $SCRATCH_DEV
53 }
54
55 _filter_repair()
56 {
57         perl -ne '
58 # for sb
59 /- agno = / && next;    # remove each AG line (variable number)
60 s/(pointer to) (\d+)/\1 INO/;
61 s/(sb root inode value) (\d+)/\1 INO/;
62 s/(realtime bitmap inode) (\d+)/\1 INO/;
63 s/(realtime summary inode) (\d+)/\1 INO/;
64 s/(inconsistent with calculated value) (\d+)/\1 INO/;
65 s/\.+(found)/\1/g;      # remove "searching" output
66 # for agf + agi
67 s/(bad length -{0,1}\d+ for ag. 0, should be) (\d+)/\1 LENGTH/;
68 s/(bad length # -{0,1}\d+ for ag. 0, should be) (\d+)/\1 LENGTH/;
69 s/(bad agbno) (\d+)/\1 AGBNO/g;
70 s/(max =) (\d+)/\1 MAX/g;
71 # for root inos
72 s/(on inode) (\d+)/\1 INO/g;
73 s/(imap claims a free inode) (\d+)/\1 INO/;
74 s/(cleared root inode) (\d+)/\1 INO/;
75 s/(resetting inode) (\d+)/\1 INO/;
76 s/(disconnected dir inode) (\d+)/\1 INO/;
77         print;'
78 }
79
80 _filter_dd()
81 {
82         fgrep -v records        # lose records in/out lines
83 }
84
85 # do some controlled corrupting & ensure repair recovers us
86
87 _check_repair()
88 {
89         value=$1
90         structure="$2"
91         _zero_position $value "$structure"
92         xfs_repair $SCRATCH_DEV 2>&1 | _filter_repair
93         # some basic sanity checks...
94         _check_fs $SCRATCH_DEV
95         mount -t xfs $SCRATCH_DEV $SCRATCH_MNT              #mount
96         dd if=/bin/sh of=$SCRATCH_MNT/sh 2>&1 |_filter_dd   #open,write
97         dd if=$SCRATCH_MNT/sh of=/dev/null 2>&1 |_filter_dd #read
98         rm -f $SCRATCH_MNT/sh                               #unlink
99         umount $SCRATCH_MNT                                 #umount
100 }
101
102 # make sure this script returns success
103 /bin/true