-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExtentParser.pm
executable file
·49 lines (43 loc) · 1.53 KB
/
ExtentParser.pm
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
46
47
48
49
package ExtentParser;
use strict;
use warnings;
sub new { return bless { bitmap=>Bitmap->new() }, $_[0]; }
sub parse {
my %x;
(
$x{forkType},
$x{pad},
$x{fileID},
$x{startBlock},
)= unpack("CCNN", $_[1]);
return \%x if @_==2; # key only
$x{extents}= [ map { CatalogParser::parseExtentDescriptor(substr($_[2], 8*$_,8)) } 0..7 ];
$_[0]{stats}[$x{fileID}] += $_->{blockCount} for @{$x{extents}};
for (@{$x{extents}}) {
next if $_->{startBlock}==0 && $_->{blockCount}==0;
printf("WARN: extent(ZERO, %d)\n", $_->{blockCount}) if ($_->{startBlock}==0);
printf("WARN: extent(%d, ZERO)\n", $_->{startBlock}) if ($_->{blockCount}==0);
$_[0]{bitmap}->set_range($_->{startBlock}, $_->{startBlock}+$_->{blockCount}-1)
}
return \%x;
}
sub dump {
if (exists $_[1]{extents}) {
return sprintf("%02x cnid%08lx:%08lx => %s", $_[1]{forkType}, $_[1]{fileID}, $_[1]{startBlock},
join(",", map { sprintf("blk%08lx:%08lx", $_->{startBlock}, $_->{blockCount}) } grep { $_->{startBlock} || $_->{blockCount} } @{$_[1]{extents}}));
}
else {
return sprintf("%02x cnid%08lx:%08lx", $_[1]{forkType}, $_[1]{fileID}, $_[1]{startBlock});
}
}
sub dumpStats {
for (my $nr=0 ; $nr<@{$_[0]{stats}} ; $nr++) {
if (defined $_[0]{stats}[$nr]) {
printf("cnid%08lx: total %08x blocks\n", $nr, $_[0]{stats}[$nr]);
}
}
}
sub getBlockBitmap {
return $_[0]{bitmap};
}
1;