]> git.ipfire.org Git - thirdparty/squid.git/blob - scripts/fileno-to-pathname.pl
Cleanup: zap CVS Id tags
[thirdparty/squid.git] / scripts / fileno-to-pathname.pl
1 #!/usr/bin/perl -w
2
3 # $Id$
4 # Convert hexadecimal cache file numbers (from swap log) into full pathnames.
5 # Duane Wessels 6/30/97
6
7 # 2001-12-18 Adapted for squid-2.x Alain Thivillon <at@rominet.net>
8 # -w and use strict;
9 # Getopt::Std
10
11 use strict;
12 use vars qw($opt_c);
13 use Getopt::Std;
14
15 &getopts('c:');
16
17 my @L1 = ();
18 my @L2 = ();
19 my @CD = ();
20
21 my $SWAP_DIR_SHIFT=24;
22 my $SWAP_FILE_MASK=0x00FFFFFF;
23
24 my $CF = $opt_c || '/usr/local/squid/etc/squid.conf';
25 &usage unless (open (CF,"<$CF"));
26
27 my $ncache_dirs = 0;
28
29 while (<CF>) {
30 # Squid 2.3 ===>
31 # cache_dir ufs path size L1 L2
32 if (/^cache_dir\s+(\S+)\s+(\S+)\s+\d+\s+(\S+)\s+(\S+)/i) {
33 $CD[$ncache_dirs] = $2;
34 $L1[$ncache_dirs] = $3;
35 $L2[$ncache_dirs++] = $4;
36 }
37 }
38 close(CF);
39
40 if ($ncache_dirs == 0) {
41 print STDERR "No proper cache_dir line found\n";
42 exit 2;
43 }
44
45 while (<>) {
46 chop;
47 print &storeSwapFullPath(hex($_)), "\n";
48 }
49
50 sub storeSwapFullPath {
51 my($fn) = @_;
52
53 my $dirn = ($fn >> $SWAP_DIR_SHIFT) % $ncache_dirs;
54 my $filn = $fn & $SWAP_FILE_MASK;
55
56 sprintf "%s/%02X/%02X/%08X",
57 $CD[$dirn],
58 (($fn / $L2[$dirn]) / $L2[$dirn]) % $L1[$dirn],
59 ($fn / $L2[$dirn]) % $L2[$dirn],
60 $fn;
61 }
62
63 sub usage {
64 print STDERR "usage: $0 -c config\n";
65 print STDERR "hexadecimal file numbers are read from stdin\n";
66 exit 1;
67 }