3 # Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation.
9 # This program is distributed in the hope that it would be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write the Free Software Foundation,
16 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 # use db to try to traverse the entire filesystem starting at the root
38 $ret=`xfs_db -r $args $device 2> /dev/null`;
39 die "ERROR executing xfs_db -r $args $device" if ($?);
49 foreach (split("\n",$text)) {
52 if ($c+length($_) >= 70) {
73 $t=db("-c \"inode $num\" -c \"print\"");
74 print " *** Inode $num\n";
77 ($mode)= $t=~ /^core.mode = (\d+)$/m;
80 bmap("inode $num","attr");
81 foreach (@bmap_blocks) {
85 if (eval "$mode & 040000") {
87 while ($t=~ /inumber(?:\.i[48])? = (\d+)$/mg) {
91 if ( $t=~ /u\.bmx/m) {
92 bmap("inode $num","dir");
93 foreach (@bmap_blocks) {
95 push(@dir_inodes,@block_inodes);
99 bmap("inode $num","file") if ( $t=~ /u\.bmx/m);
110 $flag=($type eq "attr")?"-a":"";
112 $t=db("-c \"$cmd\" -c \"bmap $flag\"");
113 print " *** bmap $type $cmd\n";
116 if ($type eq "dir" || $type eq "attr") {
117 while ($t=~ /startblock (\d+) \(.+\) count (\d+)/mg) {
118 for ($b=$1;$b<$1+$2;$b++) {
119 push(@bmap_blocks,$b);
132 $type=($dir_version==2)?"dir2":"dir";
134 $t=db("-c \"fsblock $num\" -c \"type $type\" -c \"print\"");
135 print " *** $type block $num\n";
136 # need to drop . and ..
137 ($self)= $t=~ /\[(\d+)\].name = \"\.\"/m;
138 ($parent)= $t=~ /\[(\d+)\].name = \"\.\.\"/m;
142 while ($t=~ /\[(\d+)\].inumber = (\d+)/mg) {
143 next if (defined $self && $1 == $self);
144 next if (defined $parent && $1 == $parent);
145 push(@block_inodes, $2);
154 $t=db("-c \"fsblock $num\" -c \"type attr\" -c \"print\"");
155 print " *** attr block $num\n";
165 $t=db("-c \"sb $num\" -c \"print\"");
166 print " *** SB $num\n";
169 ($rootino)= $t=~ /^rootino = (\d+)$/m;
170 ($agcount)= $t=~ /^agcount = (\d+)$/m;
171 ($versionnum)= $t=~ /^versionnum = (0x[\da-f]+)$/m;
172 $dir_version = (eval "$versionnum & 0x2000")?2:1;
175 die "Usage: $0 <XFS device>\n" unless (@ARGV == 1);
178 die "can't read $device\n" unless (-r $device);
179 die "$device is not a block device\n" unless (-b _);
181 chomp($HOST = `hostname -s`);
183 print "*** db-walk host $HOST device $device\n";
186 for ($ag=1;$ag<$agcount;$ag++) {
191 while ($_ = shift @inodes) {
193 push(@inodes,@dir_inodes);