diff options
Diffstat (limited to 'perl-install/partition_table/bsd.pm')
-rw-r--r-- | perl-install/partition_table/bsd.pm | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/perl-install/partition_table/bsd.pm b/perl-install/partition_table/bsd.pm index 431d17f1f..ec2a2edf4 100644 --- a/perl-install/partition_table/bsd.pm +++ b/perl-install/partition_table/bsd.pm @@ -1,4 +1,4 @@ -package partition_table::bsd; # $Id$ +package partition_table::bsd; use diagnostics; use strict; @@ -12,11 +12,11 @@ use partition_table; use c; #- very bad and rough handling :( -my %typeToDos = ( +my %pt_typeToDos = ( 8 => 0x83, 1 => 0x82, ); -my %typeFromDos = reverse %typeToDos; +my %pt_typeFromDos = reverse %pt_typeToDos; my ($main_format, $main_fields) = list2kv( I => 'magic', @@ -47,25 +47,28 @@ my ($main_format, $main_fields) = list2kv( S => 'npartitions', I => 'bbsize', I => 'sbsize', - a128=> 'partitions', - a236=> 'blank', + a128 => 'partitions', + a236 => 'blank', ); $main_format = join '', @$main_format; -my @fields = qw(size start fsize type frag cpg); +my @fields = qw(size start fsize pt_type frag cpg); my $format = "I I I C C S"; my $magic = 0x82564557; my $nb_primary = 8; my $offset = 0x40; -sub read($$) { + +sub use_pt_type { 1 } + +sub read_one { my ($hd, $sector) = @_; my $tmp; - local *F; partition_table::raw::openit($hd, *F) or die "failed to open device"; - c::lseek_sector(fileno(F), $sector, $offset) or die "reading of partition in sector $sector failed"; + my $F = partition_table::raw::openit($hd) or die "failed to open device"; + c::lseek_sector(fileno($F), $sector, $offset) or die "reading of partition in sector $sector failed"; - sysread F, $tmp, psizeof($main_format) or die "error while reading partition table in sector $sector"; + 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 @@ -73,7 +76,7 @@ sub read($$) { my $size = psizeof($format); my @pt = map { my %h; @h{@fields} = unpack $format, $_; - $h{type} = $typeToDos{$h{type}} || $h{type}; + fs::type::set_pt_type(\%h, $pt_typeToDos{$h{pt_type}} || $h{pt_type}); \%h; } $info{partitions} =~ /(.{$size})/g; @@ -85,18 +88,18 @@ sub read($$) { } # write the partition table (and extended ones) -# for each entry, it uses fields: start, size, type, active +# for each entry, it uses fields: start, size, pt_type, active sub write($$$;$) { - my ($hd, $sector, $pt, $info) = @_; + my ($hd, $_handle, $sector, $pt, $info) = @_; #- handle testing for writing partition table on file only! - local *F; + my $F; if ($::testing) { my $file = "/tmp/partition_table_$hd->{device}"; - open F, ">$file" or die "error opening test file $file"; + 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; + $F = partition_table::raw::openit($hd, 2) or die "error opening device $hd->{device} for writing"; + c::lseek_sector(fileno($F), $sector, $offset) or return 0; } #- TODO compute checksum @@ -105,11 +108,11 @@ sub write($$$;$) { @$pt == $nb_primary or die "partition table does not have $nb_primary entries"; $info->{partitions} = join '', map { - local $_->{type} = $typeFromDos{$_->{type}} || $_->{type}; + local $_->{pt_type} = $pt_typeFromDos{$_->{pt_type}} || $_->{pt_type}; pack $format, @$_{@fields}; } @$pt; - syswrite F, pack($main_format, @$info{@$main_fields}), psizeof($main_format) or return 0; + syswrite $F, pack($main_format, @$info{@$main_fields}), psizeof($main_format) or return 0; 1; } @@ -124,7 +127,7 @@ sub info { dtype => $hd->{device} =~ /^sd/ ? $dtype_scsi : $dtype_ST506, secsize => $common::SECTORSIZE, ncylinders => $hd->{geom}{cylinders}, - secpercyl => $hd->cylinder_size(), + secpercyl => $hd->cylinder_size, secprtunit => $hd->{geom}{totalsectors}, rpm => 3600, interleave => 1, @@ -137,9 +140,10 @@ sub info { }; } -sub clear_raw { - my ($hd) = @_; - { raw => [ ({}) x $nb_primary ], info => info($hd) }; +sub initialize { + my ($class, $hd) = @_; + $hd->{primary} = { raw => [ ({}) x $nb_primary ], info => info($hd) }; + bless $hd, $class; } sub first_usable_sector { 2048 } |