summaryrefslogtreecommitdiffstats
path: root/mysql-test/suite/innodb/include
diff options
context:
space:
mode:
Diffstat (limited to 'mysql-test/suite/innodb/include')
-rw-r--r--mysql-test/suite/innodb/include/crc32.pl23
-rw-r--r--mysql-test/suite/innodb/include/innodb-util.pl19
2 files changed, 42 insertions, 0 deletions
diff --git a/mysql-test/suite/innodb/include/crc32.pl b/mysql-test/suite/innodb/include/crc32.pl
index c2bce09d..b26f1057 100644
--- a/mysql-test/suite/innodb/include/crc32.pl
+++ b/mysql-test/suite/innodb/include/crc32.pl
@@ -31,3 +31,26 @@ sub mycrc32 {
return $crc;
}
+
+
+# Fix the checksum of an InnoDB tablespace page.
+# Inputs:
+# $page A bytestring with the page data.
+# $full_crc32 Checksum type, see get_full_crc32() in innodb-util.pl
+# Returns: the modified page as a bytestring.
+sub fix_page_crc {
+ my ($page, $full_crc32)= @_;
+ my $ps= length($page);
+ my $polynomial = 0x82f63b78; # CRC-32C
+ if ($full_crc32) {
+ my $ck = mycrc32(substr($page, 0, $ps - 4), 0, $polynomial);
+ substr($page, $ps - 4, 4) = pack("N", $ck);
+ } else {
+ my $ck= pack("N",
+ mycrc32(substr($page, 4, 22), 0, $polynomial) ^
+ mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
+ substr($page, 0, 4)= $ck;
+ substr($page, $ps-8, 4)= $ck;
+ }
+ return $page;
+}
diff --git a/mysql-test/suite/innodb/include/innodb-util.pl b/mysql-test/suite/innodb/include/innodb-util.pl
index 241545da..328ce5c7 100644
--- a/mysql-test/suite/innodb/include/innodb-util.pl
+++ b/mysql-test/suite/innodb/include/innodb-util.pl
@@ -124,3 +124,22 @@ sub ib_restore_ibd_files {
ib_restore_ibd_file($tmpd, $datadir, $db, $table);
}
}
+
+# Read the flag whether a tablespace is using full_crc32.
+# Input: filehandle opened on the tablespace.
+sub get_full_crc32 {
+ my ($TBLSPC)= @_;
+ my $old_pos= sysseek($TBLSPC, 0, 1);
+ die "tell() failed on tablespace filehandle: $!\n"
+ unless defined($old_pos);
+ sysseek($TBLSPC, 0, 0)
+ or die "sysseek() failed on tablespace filehandle: $!\n";
+ my $tblspc_hdr;
+ sysread($TBLSPC, $tblspc_hdr, 58)
+ or die "Cannot read tablespace header: $!\n";
+ sysseek($TBLSPC, $old_pos, 0)
+ or die "sysseek() failed on tablespace filehandle: $!\n";
+ my $full_crc32=
+ unpack("N", substr($tblspc_hdr, 54, 4)) & 0x10; # FIL_SPACE_FLAGS
+ return $full_crc32;
+}