]> git.ipfire.org Git - thirdparty/squid.git/blame - scripts/fileno-to-pathname.pl
SourceFormat Enforcement
[thirdparty/squid.git] / scripts / fileno-to-pathname.pl
CommitLineData
3de7cabe 1#!/usr/bin/perl -w
a151895d 2#
4ac4a490 3## Copyright (C) 1996-2017 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
88738790 10# Convert hexadecimal cache file numbers (from swap log) into full pathnames.
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 17use strict;
18use vars qw($opt_c);
19use Getopt::Std;
20
21&getopts('c:');
22
23my @L1 = ();
24my @L2 = ();
25my @CD = ();
26
27my $SWAP_DIR_SHIFT=24;
28my $SWAP_FILE_MASK=0x00FFFFFF;
29
30my $CF = $opt_c || '/usr/local/squid/etc/squid.conf';
31&usage unless (open (CF,"<$CF"));
32
33my $ncache_dirs = 0;
88738790 34
88738790 35while (<CF>) {
3de7cabe 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}
44close(CF);
88738790 45
3de7cabe 46if ($ncache_dirs == 0) {
47 print STDERR "No proper cache_dir line found\n";
48 exit 2;
49}
88738790 50
51while (<>) {
52 chop;
53 print &storeSwapFullPath(hex($_)), "\n";
54}
55
56sub storeSwapFullPath {
3de7cabe 57 my($fn) = @_;
58
59 my $dirn = ($fn >> $SWAP_DIR_SHIFT) % $ncache_dirs;
60 my $filn = $fn & $SWAP_FILE_MASK;
61
88738790 62 sprintf "%s/%02X/%02X/%08X",
3de7cabe 63 $CD[$dirn],
64 (($fn / $L2[$dirn]) / $L2[$dirn]) % $L1[$dirn],
65 ($fn / $L2[$dirn]) % $L2[$dirn],
88738790 66 $fn;
67}
68
69sub usage {
70 print STDERR "usage: $0 -c config\n";
71 print STDERR "hexadecimal file numbers are read from stdin\n";
72 exit 1;
73}