1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#!/usr/bin/perl -w
#
## Copyright (C) 1996-2025 The Squid Software Foundation and contributors
##
## Squid software is distributed under GPLv2+ license and includes
## contributions from numerous individuals and organizations.
## Please see the COPYING and CONTRIBUTORS files for details.
##
# Convert hexadecimal cache file numbers (from swap log) into full pathnames.
# Duane Wessels 6/30/97
# 2001-12-18 Adapted for squid-2.x Alain Thivillon <at@rominet.net>
# -w and use strict;
# Getopt::Std
use strict;
use vars qw($opt_c);
use Getopt::Std;
&getopts('c:');
my @L1 = ();
my @L2 = ();
my @CD = ();
my $SWAP_DIR_SHIFT=24;
my $SWAP_FILE_MASK=0x00FFFFFF;
my $CF = $opt_c || '/usr/local/squid/etc/squid.conf';
&usage unless (open (CF,"<$CF"));
my $ncache_dirs = 0;
while (<CF>) {
# Squid 2.3 ===>
# cache_dir ufs path size L1 L2
if (/^cache_dir\s+(\S+)\s+(\S+)\s+\d+\s+(\S+)\s+(\S+)/i) {
$CD[$ncache_dirs] = $2;
$L1[$ncache_dirs] = $3;
$L2[$ncache_dirs++] = $4;
}
}
close(CF);
if ($ncache_dirs == 0) {
print STDERR "No proper cache_dir line found\n";
exit 2;
}
while (<>) {
chop;
print &storeSwapFullPath(hex($_)), "\n";
}
sub storeSwapFullPath {
my($fn) = @_;
my $dirn = ($fn >> $SWAP_DIR_SHIFT) % $ncache_dirs;
my $filn = $fn & $SWAP_FILE_MASK;
sprintf "%s/%02X/%02X/%08X",
$CD[$dirn],
(($fn / $L2[$dirn]) / $L2[$dirn]) % $L1[$dirn],
($fn / $L2[$dirn]) % $L2[$dirn],
$fn;
}
sub usage {
print STDERR "usage: $0 -c config\n";
print STDERR "hexadecimal file numbers are read from stdin\n";
exit 1;
}
|