]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bugzilla #283: fileno-to-pathname.pl does not work with squid 2.x
authorhno <>
Sun, 7 Apr 2002 09:33:40 +0000 (09:33 +0000)
committerhno <>
Sun, 7 Apr 2002 09:33:40 +0000 (09:33 +0000)
scripts/fileno-to-pathname.pl

index 7d2f328806d5aa02c70d2821d52064504b3d52f4..befae1176fe94d13a5970f6bdc3b8d0e31d445af 100755 (executable)
@@ -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 <at@rominet.net>
+#            -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 (<CF>) {
-       $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;
 }