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