2 # fixscript will replace this line with require innshellvars.pl
4 # $Id: cnfsheadconf.in 6727 2004-05-16 21:21:14Z rra $
6 # Copyright Andreas Lamrecht 1998
7 # <Andreas.Lamprect@siemens.at>
9 # Modified by Kjetil T. Homme 1998
10 # <kjetilho@ifi.uio.no>
12 # Modified by Robert R. Collier 1998
15 # bigint support added by Duane Currie (sandman@hub.org) 1998
17 # cnfsheadconf is originally from cnfsstat 1999
20 use vars qw($opt_h $opt_w);
23 # required for >32bit ints
26 my($conffile) = "$inn::pathetc/cycbuff.conf";
27 my($storageconf) = "$inn::pathetc/storage.conf";
29 # Hex to bigint conversion routine
30 # bhex(HEXSTRING) returns BIGINT (with leading + chopped off)
32 # In most langauge, unlimited size integers are done using string math
33 # libraries usually called bigint. (Java, Perl, etc...)
35 # Bigint's are really just strings.
37 # Mathematics routines for bigint's:
39 # bneg(BINT) return BINT negation
40 # babs(BINT) return BINT absolute value
41 # bcmp(BINT,BINT) return CODE compare numbers (undef,<0,=0,>0)
42 # badd(BINT,BINT) return BINT addition
43 # bsub(BINT,BINT) return BINT subtraction
44 # bmul(BINT,BINT) return BINT multiplication
45 # bdiv(BINT,BINT) return (BINT,BINT) division (quo,rem) just quo if scalar
46 # bmod(BINT,BINT) return BINT modulus
47 # bgcd(BINT,BINT) return BINT greatest common divisor
48 # bnorm(BINT) return BINT normalization
54 my $integerValue = '0';
55 for (my $i = 0; $i < length($hexValue); $i+=2) {
56 # Could be more efficient going at larger increments, but byte
57 # by byte is safer for the case of 9 byte values, 11 bytes, etc..
59 my $byte = substr($hexValue,$i,2);
60 my $byteIntValue = hex($byte);
62 $integerValue = bmul($integerValue,'256');
63 $integerValue = badd($integerValue,"$byteIntValue");
66 $integerValue =~ s/^\+//;
75 my $h = bmod("$d",'16');
93 Summary tool for cycbuff header manipulation
96 $0 [-c CYCBUFF] [-h] [-w]
98 If called without args, does a one-time status of all CNFS buffers
99 -c <cycbuff>: prints out status of cycbuff
106 my(@line, %class, %metamode, %buff, %stor, $c, @buffers, $cycbuff);
108 my($gr, $cl, $min, $max, @storsort, $header_printed);
110 GetOptions("-c=s", \$cycbuff, "-w", "-h");
114 unless (&read_cycbuffconf) {
115 print STDERR "Cannot open CycBuff Conffile $conffile ...\n";
119 unless (&read_storageconf) {
120 print STDERR "No valid $storageconf.\n";
124 sub read_cycbuffconf {
125 return 0 unless open (CONFFILE, $conffile);
128 $_ =~ s/^\s*(.*?)\s*$/$1/;
129 # \x23 below is #. Emacs perl-mode gets confused by the "comment"
130 next if($_ =~ /^\s*$/ || $_ =~ /^\x23/);
131 next if($_ =~ /^cycbuffupdate:/ || $_ =~ /^refreshinterval:/);
133 if($_ =~ /^metacycbuff:/) {
134 @line = split(/:/, $_);
135 if($class{$line[1]}) {
136 print STDERR "Class $line[1] more than one time in CycBuff Conffile $conffile ...\n";
140 $class{$line[1]} = $line[2];
141 if ($line[3] ne "") {
142 $metamode{$line[1]} = $line[3];
144 $metamode{$line[1]} = "INTERLEAVE";
149 if ($_ =~ /^cycbuff/) {
150 @line = split(/:/, $_);
151 if($buff{$line[1]}) {
152 print STDERR "Buff $line[1] more than one time in CycBuff Conffile $conffile ...\n";
155 $buff{$line[1]} = $line[2];
159 print STDERR "Unknown config line \"$_\" in CycBuff Conffile $conffile ...\n";
165 sub read_storageconf {
167 return 0 unless open (STOR, $storageconf);
174 %key = ("NEWSGROUPS" => "*",
177 if (/method\s+cnfs\s+\{/) {
182 if (/(\w+):\s+(\S+)/i) {
186 unless (defined $key{'CLASS'} && defined $key{'OPTIONS'}) {
187 print STDERR "storage.conf:$line: ".
188 "Missing 'class' or 'options'\n";
192 $key{'SIZE'} .= ",0" unless $key{'SIZE'} =~ /,/;
193 $key{'SIZE'} =~ s/,/:/;
195 if (defined $stor{$key{'OPTIONS'}}) {
196 print STDERR "storage.conf:$line: ".
197 "Class $key{'CLASS'} has several criteria\n";
199 $stor{$key{'OPTIONS'}} = "$key{'NEWSGROUPS'}:$key{'CLASS'}:" .
200 "$key{'SIZE'}:$key{'OPTIONS'}";
201 push(@storsort, $key{'OPTIONS'});
210 if (! $buff{$cycbuff} ) {
211 print STDERR "No buffer definition for buffer $cycbuff ...\n";
214 &print_cycbuff_head($buff{$cycbuff});
220 my ($sec,$min,$hour,$mday,$mon,$year) =
221 (localtime($t))[0..5];
222 push (@ret, sprintf("%04d-%02d-%02d %2d:%02d:%02d",
223 $year + 1900, $mon + 1, $mday, $hour, $min, $sec));
226 $mday = int($t/86400); $t = $t % 86400;
227 $hour = int($t/3600); $t = $t % 3600;
228 $min = int($t/60); $t = $t % 60;
230 push (@ret, sprintf("%4d days, %2d:%02d:%02d",
231 $mday, $hour, $min, $t));
235 sub print_cycbuff_head {
236 my($buffpath) = $_[0];
241 my($headerlength) = 2 * $CNFSMASIZ + 2 * $CNFSNASIZ + $CNFSPASIZ + (5 * $CNFSLASIZ);
242 my($buff, @entries, $e);
243 my($magic, $name, $path, $lena, $freea, $updatea, $cyclenuma, $metaname, $orderinmeta, $currentbuff);
246 if(! open(BUFF, "+< $buffpath") ) {
247 print STDERR "Cannot open Cycbuff $buffpath ...\n";
251 if(! open(BUFF, "< $buffpath") ) {
252 print STDERR "Cannot open Cycbuff $buffpath ...\n";
258 if(! read(BUFF, $buff, $headerlength) ) {
259 print STDERR "Cannot read $headerlength bytes from file $buffpath...\n";
263 ($magic, $name, $path, $lena, $freea, $updatea, $cyclenuma, $metaname, $orderinmeta, $currentbuff) = unpack("a8 a16 a64 a16 a16 a16 a16 a16 a16 a8", $buff);
266 print STDERR "Error while unpacking header ...\n";
270 my($len) = bhex($lena);
271 my($free) = bhex($freea);
272 my($update) = hex($updatea);
273 my($cyclenum) = hex($cyclenuma) - 1;
275 my ($nupdate_str, $nago_str) = &make_time ($update);
278 print " Buffer $name, len: ";
279 printf("%.2f", $len / (1024 * 1024));
280 print " Mbytes, used: ";
281 printf("%.2f Mbytes", $free / (1024 * 1024));
282 printf(" (%4.1f%%) %3d cycles\n", 100 * $free/$len, $cyclenum);
283 print(" Meta $metaname, order: ");
284 printf("%d", $orderinmeta);
285 print(", current: $currentbuff");
287 print "\n Newest: $nupdate_str, $nago_str ago\n";
290 print "\nBuffer [$name] => ";
294 $name = sprintf("%0.9s\0", $in);
296 print "Path [$path] => ";
300 $path = sprintf("%0.65s\0", $in);
302 print "Length [$len ($lena)] => ";
307 $lena = sprintf("%017.17s\0", $in);
309 print "Free [$free ($freea)] => ";
314 $freea = sprintf("%017.17s\0", $in);
316 print "Meta [$metaname] => ";
320 $metaname = sprintf("%0.17s\0", $in);
322 print "Order [$orderinmeta] => ";
326 $orderinmeta = sprintf("%016d\0", $in);
328 print "Currentbuff [$currentbuff] => ";
331 if ($in eq "TRUE" || $in eq "FALSE") {
332 $currentbuff = sprintf("%0.8s", $in);
334 $buff = pack("a8 a16 a64 a16 a16 a16 a16 a16 a16 a8", $magic, $name, $path, $lena, $freea, $updatea, $cyclenuma, $metaname, $orderinmeta, $currentbuff);
336 if(! syswrite(BUFF, $buff, $headerlength) ) {
337 print STDERR "Cannot write $headerlength bytes to file $buffpath...\n";