4 # Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of version 2 of the GNU General Public License as
8 # published by the Free Software Foundation.
10 # This program is distributed in the hope that it would be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 # Further, this software is distributed without any warranty that it is
15 # free of the rightful claim of any third person regarding infringement
16 # or the like. Any license provided herein, whether implied or
17 # otherwise, applies only to this software file. Patent licenses, if
18 # any, provided herein do not apply to combinations of this program with
19 # other software, or any other product whatsoever.
21 # You should have received a copy of the GNU General Public License along
22 # with this program; if not, write the Free Software Foundation, Inc., 59
23 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
25 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
26 # Mountain View, CA 94043, or:
30 # For further information regarding this notice, see:
32 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
36 # use db to try to traverse the entire filesystem starting at the root
55 $ret=`xfs_db -r $args $device 2> /dev/null`;
56 die "ERROR executing xfs_db -r $args $device" if ($?);
66 foreach (split("\n",$text)) {
69 if ($c+length($_) >= 70) {
90 $t=db("-c \"inode $num\" -c \"print\"");
91 print " *** Inode $num\n";
94 ($mode)= $t=~ /^core.mode = (\d+)$/m;
97 bmap("inode $num","attr");
98 foreach (@bmap_blocks) {
102 if (eval "$mode & 040000") {
103 if ( $t=~ /sfdir/m) {
104 while ($t=~ /inumber(?:\.i[48])? = (\d+)$/mg) {
105 push(@dir_inodes,$1);
108 if ( $t=~ /u\.bmx/m) {
109 bmap("inode $num","dir");
110 foreach (@bmap_blocks) {
112 push(@dir_inodes,@block_inodes);
116 bmap("inode $num","file") if ( $t=~ /u\.bmx/m);
127 $flag=($type eq "attr")?"-a":"";
129 $t=db("-c \"$cmd\" -c \"bmap $flag\"");
130 print " *** bmap $type $cmd\n";
133 if ($type eq "dir" || $type eq "attr") {
134 while ($t=~ /startblock (\d+) \(.+\) count (\d+)/mg) {
135 for ($b=$1;$b<$1+$2;$b++) {
136 push(@bmap_blocks,$b);
149 $type=($dir_version==2)?"dir2":"dir";
151 $t=db("-c \"fsblock $num\" -c \"type $type\" -c \"print\"");
152 print " *** $type block $num\n";
153 # need to drop . and ..
154 ($self)= $t=~ /\[(\d+)\].name = \"\.\"/m;
155 ($parent)= $t=~ /\[(\d+)\].name = \"\.\.\"/m;
159 while ($t=~ /\[(\d+)\].inumber = (\d+)/mg) {
160 next if (defined $self && $1 == $self);
161 next if (defined $parent && $1 == $parent);
162 push(@block_inodes, $2);
171 $t=db("-c \"fsblock $num\" -c \"type attr\" -c \"print\"");
172 print " *** attr block $num\n";
182 $t=db("-c \"sb $num\" -c \"print\"");
183 print " *** SB $num\n";
186 ($rootino)= $t=~ /^rootino = (\d+)$/m;
187 ($agcount)= $t=~ /^agcount = (\d+)$/m;
188 ($versionnum)= $t=~ /^versionnum = (0x[\da-f]+)$/m;
189 $dir_version = (eval "$versionnum & 0x2000")?2:1;
192 die "Usage: $0 <XFS device>\n" unless (@ARGV == 1);
195 die "can't read $device\n" unless (-r $device);
196 die "$device is not a block device\n" unless (-b _);
198 chomp($HOST = `hostname -s`);
200 print "*** db-walk host $HOST device $device\n";
203 for ($ag=1;$ag<$agcount;$ag++) {
208 while ($_ = shift @inodes) {
210 push(@inodes,@dir_inodes);