From 0e215bd9359b82933600adb884b5a71a993a5521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwenol=C3=A9=20Beauchesne?= Date: Fri, 19 Oct 2001 17:21:19 +0000 Subject: - Use /dev/random through devices::make() instead of /dev/urandom - Localize file descriptor - Capitalize error message if no /dev/random found --- perl-install/partition_table_gpt.pm | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/perl-install/partition_table_gpt.pm b/perl-install/partition_table_gpt.pm index 3f30da4b9..7512bb0c2 100644 --- a/perl-install/partition_table_gpt.pm +++ b/perl-install/partition_table_gpt.pm @@ -51,10 +51,30 @@ my ($partitionEntry_format, $partitionEntry_fields) = list2kv( a72 => 'name', ); -$_ = join('', @$_) foreach $main_format, $partitionEntry_format; +my ($guid_format, $guid_fields) = list2kv( + N => 'time_low', + n => 'time_mid', + n => 'time_hi_and_version', + n => 'clock_seq', + a6 => 'node', +); + +$_ = join('', @$_) foreach $main_format, $partitionEntry_format, $guid_format; my $magic = "EFI PART"; +sub generate_guid { + local *F; + open F, devices::make("random") or die "Could not open /dev/random for GUID generation"; + read F, $tmp, psizeof($guid_format); + close F; + + my %guid; @guid{@$guid_fields} = unpack $guid_format, $tmp; + $guid{clock_seq} = ($guid{clock_seq} & 0x3fff) | 0x8000; + $guid{time_hi_and_version} = ($guid{time_hi_and_version} & 0x0fff) | 0x4000; + pack($guid_format, @guid{@$guid_fields}); +} + sub crc32 { my ($buffer) = @_; @@ -147,7 +167,7 @@ sub write { foreach (@$pt) { $_->{ending} = $_->{start} + $_->{size} - 1; - $_->{guid} ||= 'TODO'; + $_->{guid} ||= generate_guid; $_->{gpt_type} = $gpt_types{$_->{type}} || $_->{gpt_type} || $gpt_types{0x83}; } my $partitionEntries = join('', map { @@ -219,8 +239,8 @@ sub info { alternateLBA => $hd->{totalsectors} - 1, firstUsableLBA => $nb_sect + 2, lastUsableLBA => $hd->{totalsectors} - $nb_sect - 2, - guid => 'TODO', - partitionEntriesLBA => 2, + guid => generate_guid, + partitionEntriesLBA => 2, nbPartitions => $nb_sect * 512 / psizeof($partitionEntry_format), partitionEntrySize => psizeof($partitionEntry_format), }; -- cgit v1.2.1