3 # Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
5 # use db to try to traverse the entire filesystem starting at the root
24 $ret=`xfs_db -r $args $device 2> /dev/null`;
25 die "ERROR executing xfs_db -r $args $device" if ($?);
35 foreach (split("\n",$text)) {
38 if ($c+length($_) >= 70) {
59 $t=db("-c \"inode $num\" -c \"print\"");
60 print " *** Inode $num\n";
63 ($mode)= $t=~ /^core.mode = (\d+)$/m;
66 bmap("inode $num","attr");
67 foreach (@bmap_blocks) {
71 if (eval "$mode & 040000") {
73 while ($t=~ /inumber(?:\.i[48])? = (\d+)$/mg) {
77 if ( $t=~ /u\.bmx/m) {
78 bmap("inode $num","dir");
79 foreach (@bmap_blocks) {
81 push(@dir_inodes,@block_inodes);
85 bmap("inode $num","file") if ( $t=~ /u\.bmx/m);
96 $flag=($type eq "attr")?"-a":"";
98 $t=db("-c \"$cmd\" -c \"bmap $flag\"");
99 print " *** bmap $type $cmd\n";
102 if ($type eq "dir" || $type eq "attr") {
103 while ($t=~ /startblock (\d+) \(.+\) count (\d+)/mg) {
104 for ($b=$1;$b<$1+$2;$b++) {
105 push(@bmap_blocks,$b);
118 $type=($dir_version==2)?"dir2":"dir";
120 $t=db("-c \"fsblock $num\" -c \"type $type\" -c \"print\"");
121 print " *** $type block $num\n";
122 # need to drop . and ..
123 ($self)= $t=~ /\[(\d+)\].name = \"\.\"/m;
124 ($parent)= $t=~ /\[(\d+)\].name = \"\.\.\"/m;
128 while ($t=~ /\[(\d+)\].inumber = (\d+)/mg) {
129 next if (defined $self && $1 == $self);
130 next if (defined $parent && $1 == $parent);
131 push(@block_inodes, $2);
140 $t=db("-c \"fsblock $num\" -c \"type attr\" -c \"print\"");
141 print " *** attr block $num\n";
151 $t=db("-c \"sb $num\" -c \"print\"");
152 print " *** SB $num\n";
155 ($rootino)= $t=~ /^rootino = (\d+)$/m;
156 ($agcount)= $t=~ /^agcount = (\d+)$/m;
157 ($versionnum)= $t=~ /^versionnum = (0x[\da-f]+)$/m;
158 $dir_version = (eval "$versionnum & 0x2000")?2:1;
161 die "Usage: $0 <XFS device>\n" unless (@ARGV == 1);
164 die "can't read $device\n" unless (-r $device);
165 die "$device is not a block device\n" unless (-b _);
167 chomp($HOST = `hostname -s`);
169 print "*** db-walk host $HOST device $device\n";
172 for ($ag=1;$ag<$agcount;$ag++) {
177 while ($_ = shift @inodes) {
179 push(@inodes,@dir_inodes);