File: fileno-to-pathname.pl

package info (click to toggle)
squid 2.6.5-6etch5
  • links: PTS
  • area: main
  • in suites: etch
  • size: 12,540 kB
  • ctags: 13,801
  • sloc: ansic: 105,278; sh: 6,083; makefile: 1,297; perl: 1,245; awk: 40
file content (45 lines) | stat: -rwxr-xr-x 962 bytes parent folder | download | duplicates (6)
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
#!/usr/local/bin/perl

# $Id: fileno-to-pathname.pl,v 1.4 2005/05/17 16:56:36 hno Exp $
# Convert hexadecimal cache file numbers (from swap log) into full pathnames.  
# Duane Wessels 6/30/97

require 'getopts.pl';

&Getopts('c:');
$L1 = 16;
$L2 = 256;

$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+)/);
}
close(CF);
unless ($ncache_dirs) {
	$CD[$ncache_dirs++] = '/usr/local/squid/cache';
}


while (<>) {
	chop;
	print &storeSwapFullPath(hex($_)), "\n";
}

sub storeSwapFullPath {
	local($fn) = @_;
	sprintf "%s/%02X/%02X/%08X",
		$CD[$fn % $ncache_dirs],
		($fn / $ncache_dirs) % $L1,
		($fn / $ncache_dirs) / $L1 % $L2,
		$fn;
}

sub usage {
	print STDERR "usage: $0 -c config\n";
	print STDERR "hexadecimal file numbers are read from stdin\n";
	exit 1;
}