@@ -30,6 +30,8 @@ binmode FILE;
30
30
31
31
my $ps= $ENV{PAGE_SIZE};
32
32
my $page;
33
+ die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
34
+ my $full_crc32 = unpack("N",substr($page,54,4)) & 0x10; # FIL_SPACE_FLAGS
33
35
sysseek(FILE, 3*$ps, 0) || die "Unable to seek $file\n";
34
36
die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
35
37
#In this case the first record should be at offset 135
@@ -38,10 +40,18 @@ die unless unpack("n", substr($page, 99, 2)) == 135;
38
40
substr($page,135+6,6) = "\xff" x 6;
39
41
40
42
my $polynomial = 0x82f63b78; # CRC-32C
41
- my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
43
+ if ($full_crc32)
44
+ {
45
+ my $ck = mycrc32(substr($page, 0, $ps - 4), 0, $polynomial);
46
+ substr($page, $ps - 4, 4) = pack("N", $ck);
47
+ }
48
+ else
49
+ {
50
+ my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
42
51
mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
43
- substr($page,0,4)=$ck;
44
- substr($page,$ps-8,4)=$ck;
52
+ substr($page,0,4)=$ck;
53
+ substr($page,$ps-8,4)=$ck;
54
+ }
45
55
sysseek(FILE, 3*$ps, 0) || die "Unable to rewind $file\n";
46
56
syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
47
57
close(FILE) || die "Unable to close $file";
0 commit comments