remove quota header, no point keeping syncd anymore.
[xfstests-dev.git] / tools / fs-walk
1 #!/usr/bin/perl -w
2
3 #
4 #  Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
5 #  
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.
9 #  
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.
13 #  
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.
20 #  
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.
24 #  
25 #  Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
26 #  Mountain View, CA  94043, or:
27 #  
28 #  http://www.sgi.com 
29 #  
30 #  For further information regarding this notice, see: 
31 #  
32 #  http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
33 #
34
35 #
36 # traverse the entire filesystem dumping info. 
37 #
38 #                                                       dxm 5/10/00
39 use MD5;
40 use Getopt::Std;
41
42 my %opt;
43
44 sub scan($)
45 {
46     my ($file)=@_;
47     my ($md5)=new MD5;
48     my (@stat);
49
50     unless (@stat=lstat("$file")) {
51         printf("%-" . ($opt{v}?65:32) . "s $file\n", "!!! could not lstat");
52         return;
53     }
54
55     $stat[0]=$stat[8]=""; # wipe the device and access time
56     $md5->reset;
57     $md5->add(join(" ",@stat));
58     
59     print join(" ",@stat), "\n";
60     
61     if ($opt{v}) {
62         print $md5->hexdigest . " ";
63         $md5->reset;
64     }
65
66     if (-l "$file") {
67         if (!defined($link = readlink $file)) {
68             printf("%-32s $file\n", "!!! could not readlink");
69             return;
70         }
71         $md5->add($link);
72     } elsif (-f "$file") {
73         if (!open(FILE, "$file")) {
74             printf("%-32s $file\n", "!!! could not read");
75             return;
76         }
77         $md5->addfile(FILE);
78         close (FILE);
79     }
80     print $md5->hexdigest . " $file\n";
81 }
82
83 getopts('vs', \%opt);
84
85 die "Usage: $0 <dir>\n" unless (@ARGV == 1);
86
87 $dir=shift @ARGV;
88 die "can't read $dir\n" unless (-r $dir);
89 die "$dir is not a directory\n" unless (-d _);
90
91 chomp($HOST = `hostname -s`);
92
93 print "*** fs-walk host $HOST dir $dir\n";
94
95 @todo=$dir;
96 while ($dir = shift @todo) {
97     scan($dir);
98     unless (opendir(DIR,$dir)) {
99         printf("%-" . ($opt{v}?65:32) . "s $dir\n", "!!! could not opendir");
100         next;
101     }
102     unless (@all=readdir(DIR)) {
103         printf("%-" . ($opt{v}?65:32) . "s $dir\n", "!!! could not readdir");
104         next;
105     }
106     closedir(DIR);
107     @dirs=grep(-d "$dir/$_" && !-l "$dir/$_", @all);
108     foreach (@all) {
109         next if /^\.\.?$/;
110         scan("$dir/$_");
111     }
112     
113     foreach (grep(!/^\.\.?$/, @dirs)) {
114         push (@todo,"$dir/$_");
115     }
116 }
117