QA test updates - fixes for pquota, extsize, fsstress, and ensure mount options passe...
[xfstests-dev.git] / tools / fs-walk
1 #!/usr/bin/perl -w
2 #
3 #  Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # traverse the entire filesystem dumping info.
6 #
7 #                                                       dxm 5/10/00
8 use MD5;
9 use Getopt::Std;
10
11 my %opt;
12
13 sub scan($)
14 {
15     my ($file)=@_;
16     my ($md5)=new MD5;
17     my (@stat);
18
19     unless (@stat=lstat("$file")) {
20         printf("%-" . ($opt{v}?65:32) . "s $file\n", "!!! could not lstat");
21         return;
22     }
23
24     $stat[0]=$stat[8]=""; # wipe the device and access time
25     $md5->reset;
26     $md5->add(join(" ",@stat));
27     
28     print join(" ",@stat), "\n";
29     
30     if ($opt{v}) {
31         print $md5->hexdigest . " ";
32         $md5->reset;
33     }
34
35     if (-l "$file") {
36         if (!defined($link = readlink $file)) {
37             printf("%-32s $file\n", "!!! could not readlink");
38             return;
39         }
40         $md5->add($link);
41     } elsif (-f "$file") {
42         if (!open(FILE, "$file")) {
43             printf("%-32s $file\n", "!!! could not read");
44             return;
45         }
46         $md5->addfile(FILE);
47         close (FILE);
48     }
49     print $md5->hexdigest . " $file\n";
50 }
51
52 getopts('vs', \%opt);
53
54 die "Usage: $0 <dir>\n" unless (@ARGV == 1);
55
56 $dir=shift @ARGV;
57 die "can't read $dir\n" unless (-r $dir);
58 die "$dir is not a directory\n" unless (-d _);
59
60 chomp($HOST = `hostname -s`);
61
62 print "*** fs-walk host $HOST dir $dir\n";
63
64 @todo=$dir;
65 while ($dir = shift @todo) {
66     scan($dir);
67     unless (opendir(DIR,$dir)) {
68         printf("%-" . ($opt{v}?65:32) . "s $dir\n", "!!! could not opendir");
69         next;
70     }
71     unless (@all=readdir(DIR)) {
72         printf("%-" . ($opt{v}?65:32) . "s $dir\n", "!!! could not readdir");
73         next;
74     }
75     closedir(DIR);
76     @dirs=grep(-d "$dir/$_" && !-l "$dir/$_", @all);
77     foreach (@all) {
78         next if /^\.\.?$/;
79         scan("$dir/$_");
80     }
81     
82     foreach (grep(!/^\.\.?$/, @dirs)) {
83         push (@todo,"$dir/$_");
84     }
85 }
86