From fbdf055c5f169b4605e8c7e3b4142dc92e22baee Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Thu, 18 Oct 2001 22:09:38 +0000 Subject: - add checksum verif on partition entries - detect the type of partition since the partition table types seem quite poor --- perl-install/partition_table_gpt.pm | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'perl-install/partition_table_gpt.pm') 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); -- cgit v1.2.1