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.pm38
1 files changed, 25 insertions, 13 deletions
diff --git a/perl-install/partition_table_bsd.pm b/perl-install/partition_table_bsd.pm
index 0b03249c1..c6cd71394 100644
--- a/perl-install/partition_table_bsd.pm
+++ b/perl-install/partition_table_bsd.pm
@@ -1,4 +1,4 @@
-package partition_table_bsd;
+package partition_table_bsd; # $Id$
use diagnostics;
use strict;
@@ -47,6 +47,8 @@ my ($main_format, $main_fields) = list2kv(
S => 'npartitions',
I => 'bbsize',
I => 'sbsize',
+ a128=> 'partitions',
+ a236=> 'blank',
);
$main_format = join '', @$main_format;
@@ -66,12 +68,14 @@ 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;
+ #- TODO verify checksum
+
+ my $size = psizeof($format);
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;
+ my %h; @h{@fields} = unpack $format, $_;
$h{type} = $typeToDos{$h{type}} || $h{type};
\%h;
- } (1..$nb_primary);
+ } $info{partitions} =~ /(.{$size})/g;
#- check magic number
$info{magic} == $magic or die "bad magic number";
@@ -85,19 +89,27 @@ 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;
+ #- handle testing for writing partition table on file only!
+ local *F;
+ if ($::testing) {
+ my $file = "/tmp/partition_table_$hd->{device}";
+ open F, ">$file" or die "error opening test file $file";
+ } else {
+ 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;
+ }
- $info->{npartitions} = $nb_primary; #- is it ok?
+ #- TODO compute checksum
- syswrite F, pack($main_format, @$info{@$main_fields}), psizeof($main_format) or return 0;
+ $info->{npartitions} = $nb_primary; #- is it ok?
@$pt == $nb_primary or die "partition table does not have $nb_primary entries";
- foreach (@$pt) {
+ $info->{partitions} = join '', map {
local $_->{type} = $typeFromDos{$_->{type}} || $_->{type};
- syswrite F, pack($format, @$_{@fields}), psizeof($format) or return 0;
- }
+ pack $format, @$_{@fields};
+ } @$pt;
+
+ syswrite F, pack($main_format, @$info{@$main_fields}), psizeof($main_format) or return 0;
1;
}
@@ -112,7 +124,7 @@ sub info {
dtype => $hd->{device} =~ /^sd/ ? $dtype_scsi : $dtype_ST506,
secsize => $common::SECTORSIZE,
ncylinders => $hd->{geom}{cylinders},
- secpercyl => partition_table::cylinder_size($hd),
+ secpercyl => $hd->cylinder_size(),
secprtunit => $hd->{geom}{totalsectors},
rpm => 3600,
interleave => 1,