summaryrefslogtreecommitdiffstats
path: root/perl-install/partition_table_bsd.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/partition_table_bsd.pm')
-rw-r--r--perl-install/partition_table_bsd.pm17
1 files changed, 11 insertions, 6 deletions
diff --git a/perl-install/partition_table_bsd.pm b/perl-install/partition_table_bsd.pm
index 0b03249c1..f3134f4fb 100644
--- a/perl-install/partition_table_bsd.pm
+++ b/perl-install/partition_table_bsd.pm
@@ -66,16 +66,20 @@ sub read($$) {
sysread F, $tmp, psizeof($main_format) or die "error while reading partition table in sector $sector";
my %info; @info{@$main_fields} = unpack $main_format, $tmp;
+ $info{npartitions} <= $nb_primary or die "too many partitions ($info{npartitions} > $nb_primary) for a bsd disklabel";
+
+ #- check magic number
+ $info{magic} == $magic or die "bad magic number";
+ $info{magic2} == $magic or die "bad magic number";
+
+ #- TODO verify checksum
+
my @pt = map {
sysread F, $tmp, psizeof($format) or die "error while reading partition table in sector $sector";
my %h; @h{@fields} = unpack $format, $tmp;
$h{type} = $typeToDos{$h{type}} || $h{type};
\%h;
- } (1..$nb_primary);
-
- #- check magic number
- $info{magic} == $magic or die "bad magic number";
- $info{magic2} == $magic or die "bad magic number";
+ } (1..$info{npartitions});
[ @pt ], \%info;
}
@@ -85,10 +89,11 @@ sub read($$) {
sub write($$$;$) {
my ($hd, $sector, $pt, $info) = @_;
- print "Her\n";
local *F; partition_table_raw::openit($hd, *F, 2) or die "error opening device $hd->{device} for writing";
c::lseek_sector(fileno(F), $sector, $offset) or return 0;
+ #- TODO compute checksum
+
$info->{npartitions} = $nb_primary; #- is it ok?
syswrite F, pack($main_format, @$info{@$main_fields}), psizeof($main_format) or return 0;