summaryrefslogtreecommitdiffstats
path: root/perl-install/partition_table_gpt.pm
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2001-10-18 22:09:38 +0000
committerPascal Rigaux <pixel@mandriva.com>2001-10-18 22:09:38 +0000
commitfbdf055c5f169b4605e8c7e3b4142dc92e22baee (patch)
tree15a815c0dec92435c70e853f870b166ed5af2b5f /perl-install/partition_table_gpt.pm
parent86d42155bc11e397d502e9876aad2dd3082946f4 (diff)
downloaddrakx-backup-do-not-use-fbdf055c5f169b4605e8c7e3b4142dc92e22baee.tar
drakx-backup-do-not-use-fbdf055c5f169b4605e8c7e3b4142dc92e22baee.tar.gz
drakx-backup-do-not-use-fbdf055c5f169b4605e8c7e3b4142dc92e22baee.tar.bz2
drakx-backup-do-not-use-fbdf055c5f169b4605e8c7e3b4142dc92e22baee.tar.xz
drakx-backup-do-not-use-fbdf055c5f169b4605e8c7e3b4142dc92e22baee.zip
- add checksum verif on partition entries
- detect the type of partition since the partition table types seem quite poor
Diffstat (limited to 'perl-install/partition_table_gpt.pm')
-rw-r--r--perl-install/partition_table_gpt.pm20
1 files changed, 12 insertions, 8 deletions
diff --git a/perl-install/partition_table_gpt.pm b/perl-install/partition_table_gpt.pm
index d908a8103..55bc1a49f 100644
--- a/perl-install/partition_table_gpt.pm
+++ b/perl-install/partition_table_gpt.pm
@@ -68,14 +68,13 @@ sub crc32 {
}
$crc = ($crc >> 8) ^ $subcrc;
}
- $crc;
+ $crc ^ 0xFFFFFFFF;
}
-sub compute_crc {
+sub compute_headerCRC32 {
my ($info) = @_;
local $info->{headerCRC32} = 0;
- my $tmp = pack($main_format, @$info{@$main_fields});
- crc32($tmp) ^ 0xFFFFFFFF;
+ crc32(pack($main_format, @$info{@$main_fields}));
}
sub read {
@@ -100,12 +99,17 @@ sub read {
$info{partitionEntrySize} == psizeof($partitionEntry_format) or die "bad partitionEntrySize";
$info{revision} <= $current_revision or log::l("oops, this is a new GPT revision ($info{revision} > $current_revision)");
- my $chksum = compute_crc(\%info);
- $chksum == $info{headerCRC32} or die "bad checksum";
+ $info{headerCRC32} == compute_headerCRC32(\%info) or die "bad partition table checksum";
+
+ c::lseek_sector(fileno(F), $info{partitionEntriesLBA}, 0) or die "can't seek to sector partitionEntriesLBA";
+ sysread F, $tmp, psizeof($partitionEntry_format) * $info{nbPartitions} or die "error while reading partition table in sector $sector";
+ $info{partitionEntriesCRC32} == crc32($tmp) or die "bad partition entries checksum";
c::lseek_sector(fileno(F), $info{partitionEntriesLBA}, 0) or die "can't seek to sector partitionEntriesLBA";
my %gpt_types_rev = reverse %gpt_types;
- my @pt = map {
+ my @pt =
+ grep { $_->{size} && $_->{type} } #- compress empty partitions as kernel skip them
+ map {
sysread F, $tmp, psizeof($partitionEntry_format) or die "error while reading partition table in sector $sector";
my %h; @h{@$partitionEntry_fields} = unpack $partitionEntry_format, $tmp;
$h{size} = $h{ending} - $h{start};
@@ -127,7 +131,7 @@ sub write {
foreach (@$pt) {
$_->{ending} = $_->{start} + $_->{size};
- $_->{gpt_type} = $gpt_types{$_->{type}} || $gpt_types{0x83};
+ $_->{gpt_type} = $gpt_types{$_->{type}} || $_->{gpt_type} || $gpt_types{0x83};
}
$info->{csum} = compute_crc($info);