-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathcorrupt_ibd2sdi.inc
68 lines (53 loc) · 1.69 KB
/
corrupt_ibd2sdi.inc
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# The following variables should be set before invoking this inc file
# IBD_FILE - file name (including absolute path)
# IBD_PAGE_SIZE - page size
# IBD_PAGE_NO - page number in file
# IBD_OFFSET - offset within the page (optional: default to 0th byte
# in page)
# IBD_CHAR - character to write into page (optional: default char
# written is 0)
# IBD_CHAR_LEN - write IBD_CHARs of this length.
perl;
use strict;
use warnings;
use Fcntl qw(SEEK_SET);
my $ibd_file = $ENV{'IBD_FILE'};
my $ibd_page_size = $ENV{'IBD_PAGE_SIZE'};
my $ibd_page_no = $ENV{'IBD_PAGE_NO'};
my $ibd_offset = $ENV{'IBD_OFFSET'};
my $ibd_char = $ENV{'IBD_CHAR'};
my $ibd_char_len = $ENV{'IBD_CHAR_LEN'};
if (!$ibd_file) {
print "ENV variable IBD_FILE is not set. Use --let IBD_FILE=some_filename_here in test\n";
exit;
}
if (!$ibd_page_size) {
print "ENV variable IBD_PAGE_SIZE is not set. Use --let IBD_PAGE_SIZE=some_size_here in test\n";
exit;
}
if (!$ibd_page_no) {
print "ENV variable IBD_PAGE_NO is not set. Use --let IBD_PAGE_NO=some_number_here in test\n";
exit;
}
if (!$ibd_offset) {
$ibd_offset = 0;
}
my $file_offset = ($ibd_page_size * $ibd_page_no) + $ibd_offset;
open(FILE, "+<", $ibd_file) or die "could not open $ibd_file: $!";
binmode FILE;
seek(FILE, $file_offset, SEEK_SET) or die "could not seek: $!";
my $packed;
if ($ibd_char eq "0") {
$packed = chr($ibd_char);
print FILE $packed x $ibd_char_len;
} elsif ($ibd_char_len == 2) {
# Write 2 bytes in Big-Endian format
$packed = pack "n", $ibd_char;
print FILE $packed;
} elsif($ibd_char_len == 4) {
# Write 4 bytes in Big-Endian format
$packed = pack "N", $ibd_char;
print FILE $packed;
}
close FILE;
EOF