From: hno <> Date: Sun, 7 Apr 2002 09:33:40 +0000 (+0000) Subject: Bugzilla #283: fileno-to-pathname.pl does not work with squid 2.x X-Git-Tag: SQUID_3_0_PRE1~1115 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3de7cabec5d4b3f948933e0568c162fd2a2a374e;p=thirdparty%2Fsquid.git Bugzilla #283: fileno-to-pathname.pl does not work with squid 2.x --- diff --git a/scripts/fileno-to-pathname.pl b/scripts/fileno-to-pathname.pl index 7d2f328806..befae1176f 100755 --- a/scripts/fileno-to-pathname.pl +++ b/scripts/fileno-to-pathname.pl @@ -1,28 +1,46 @@ -#!/usr/local/bin/perl +#!/usr/bin/perl -w -# $Id: fileno-to-pathname.pl,v 1.2 1997/07/16 20:31:55 wessels Exp $ +# $Id: fileno-to-pathname.pl,v 1.3 2002/04/07 02:33:40 hno Exp $ # Convert hexadecimal cache file numbers (from swap log) into full pathnames. # Duane Wessels 6/30/97 -require 'getopts.pl'; +# 2001-12-18 Adapted for squid-2.x Alain Thivillon +# -w and use strict; +# Getopt::Std -&Getopts('c:'); -$L1 = 16; -$L2 = 256; +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; -$CF = $opt_c || '/usr/local/squid/etc/squid.conf'; -&usage unless (open (CF)); -$ncache_dirs = 0; while () { - $CD[$ncache_dirs++] = $1 if (/^cache_dir\s+(\S+)/); - $L1 = $1 if (/^swap_level1_dirs\s+(\d+)/); - $L2 = $1 if (/^swap_level2_dirs\s+(\d+)/); + # 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); -unless ($ncache_dirs) { - $CD[$ncache_dirs++] = '/usr/local/squid/cache'; -} +if ($ncache_dirs == 0) { + print STDERR "No proper cache_dir line found\n"; + exit 2; +} while (<>) { chop; @@ -30,11 +48,15 @@ while (<>) { } sub storeSwapFullPath { - local($fn) = @_; + my($fn) = @_; + + my $dirn = ($fn >> $SWAP_DIR_SHIFT) % $ncache_dirs; + my $filn = $fn & $SWAP_FILE_MASK; + sprintf "%s/%02X/%02X/%08X", - $CD[$fn % $ncache_dirs], - ($fn / $ncache_dirs) % $L1, - ($fn / $ncache_dirs) / $L1 % $L2, + $CD[$dirn], + (($fn / $L2[$dirn]) / $L2[$dirn]) % $L1[$dirn], + ($fn / $L2[$dirn]) % $L2[$dirn], $fn; }