2 # SPDX-License-Identifier: GPL-2.0
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
22 $ret=`xfs_db -r $args $device 2> /dev/null`;
23 die "ERROR executing xfs_db -r $args $device" if ($?);
33 foreach (split("\n",$text)) {
36 if ($c+length($_) >= 70) {
57 $t=db("-c \"inode $num\" -c \"print\"");
58 print " *** Inode $num\n";
61 ($mode)= $t=~ /^core.mode = (\d+)$/m;
64 bmap("inode $num","attr");
65 foreach (@bmap_blocks) {
69 if (eval "$mode & 040000") {
71 while ($t=~ /inumber(?:\.i[48])? = (\d+)$/mg) {
75 if ( $t=~ /u\.bmx/m) {
76 bmap("inode $num","dir");
77 foreach (@bmap_blocks) {
79 push(@dir_inodes,@block_inodes);
83 bmap("inode $num","file") if ( $t=~ /u\.bmx/m);
94 $flag=($type eq "attr")?"-a":"";
96 $t=db("-c \"$cmd\" -c \"bmap $flag\"");
97 print " *** bmap $type $cmd\n";
100 if ($type eq "dir" || $type eq "attr") {
101 while ($t=~ /startblock (\d+) \(.+\) count (\d+)/mg) {
102 for ($b=$1;$b<$1+$2;$b++) {
103 push(@bmap_blocks,$b);
116 $type=($dir_version==2)?"dir2":"dir";
118 $t=db("-c \"fsblock $num\" -c \"type $type\" -c \"print\"");
119 print " *** $type block $num\n";
120 # need to drop . and ..
121 ($self)= $t=~ /\[(\d+)\].name = \"\.\"/m;
122 ($parent)= $t=~ /\[(\d+)\].name = \"\.\.\"/m;
126 while ($t=~ /\[(\d+)\].inumber = (\d+)/mg) {
127 next if (defined $self && $1 == $self);
128 next if (defined $parent && $1 == $parent);
129 push(@block_inodes, $2);
138 $t=db("-c \"fsblock $num\" -c \"type attr\" -c \"print\"");
139 print " *** attr block $num\n";
149 $t=db("-c \"sb $num\" -c \"print\"");
150 print " *** SB $num\n";
153 ($rootino)= $t=~ /^rootino = (\d+)$/m;
154 ($agcount)= $t=~ /^agcount = (\d+)$/m;
155 ($versionnum)= $t=~ /^versionnum = (0x[\da-f]+)$/m;
156 $dir_version = (eval "$versionnum & 0x2000")?2:1;
159 die "Usage: $0 <XFS device>\n" unless (@ARGV == 1);
162 die "can't read $device\n" unless (-r $device);
163 die "$device is not a block device\n" unless (-b _);
165 chomp($HOST = `hostname -s`);
167 print "*** db-walk host $HOST device $device\n";
170 for ($ag=1;$ag<$agcount;$ag++) {
175 while ($_ = shift @inodes) {
177 push(@inodes,@dir_inodes);