summaryrefslogtreecommitdiffstats
path: root/perl-install/partition_table/sun.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/partition_table/sun.pm')
-rw-r--r--perl-install/partition_table/sun.pm70
1 files changed, 37 insertions, 33 deletions
diff --git a/perl-install/partition_table/sun.pm b/perl-install/partition_table/sun.pm
index 6944130dc..e665d0168 100644
--- a/perl-install/partition_table/sun.pm
+++ b/perl-install/partition_table/sun.pm
@@ -1,4 +1,4 @@
-package partition_table::sun; # $Id$
+package partition_table::sun;
use diagnostics;
use strict;
@@ -9,6 +9,7 @@ use vars qw(@ISA);
use common;
use partition_table::raw;
use partition_table;
+use fs::type;
use c;
my ($main_format, $main_fields) = list2kv(
@@ -32,13 +33,14 @@ my ($main_format, $main_fields) = list2kv(
);
$main_format = join '', @$main_format;
-my ($fields1, $fields2) = ([ qw(type flags) ], [ qw(start_cylinder size) ]);
+my ($fields1, $fields2) = ([ qw(pt_type flags) ], [ qw(start_cylinder size) ]);
my ($format1, $format2) = ("xCxC", "N2");
-my ($size1, $size2) = map { psizeof($_) } ($format1, $format2);
my $magic = 0xDABE;
my $nb_primary = 8;
my $offset = 0;
+sub use_pt_type { 1 }
+
sub adjustStart($$) {
my ($hd, $part) = @_;
my $end = $part->{start} + $part->{size};
@@ -47,15 +49,15 @@ sub adjustStart($$) {
#- note that if start sector is on the first cylinder, it is adjusted
#- to 0 and it is valid, cylinder 0 bug is from bad define for sparc
#- compilation of mke2fs combined with a blind kernel...
- $part->{start} = round_down($part->{start}, $hd->cylinder_size());
+ $part->{start} = round_down($part->{start}, $hd->cylinder_size);
$part->{size} = $end - $part->{start};
- $part->{size} = $hd->cylinder_size() if $part->{size} <= 0;
+ $part->{size} = $hd->cylinder_size if $part->{size} <= 0;
}
sub adjustEnd($$) {
my ($hd, $part) = @_;
my $end = $part->{start} + $part->{size};
- my $end2 = round_up($end, $hd->cylinder_size());
- $end2 = $hd->{geom}{cylinders} * $hd->cylinder_size() if $end2 > $hd->{geom}{cylinders} * $hd->cylinder_size();
+ my $end2 = round_up($end, $hd->cylinder_size);
+ $end2 = $hd->{geom}{cylinders} * $hd->cylinder_size if $end2 > $hd->{geom}{cylinders} * $hd->cylinder_size;
$part->{size} = $end2 - $part->{start};
}
@@ -66,19 +68,19 @@ sub compute_crc($) {
my @l2b = unpack "n256", $tmp;
my $crc = 0;
- map { $crc ^= $_ } @l2b;
+ $crc ^= $_ foreach @l2b;
$crc;
}
-sub read($$) {
+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;
#- check magic number
@@ -92,11 +94,12 @@ sub read($$) {
my @pt;
my @infos_up = unpack $format1 x $nb_primary, $info{infos};
my @partitions_up = unpack $format2 x $nb_primary, $info{partitions};
- for (0..$nb_primary-1) {
- my $h = { type => $infos_up[2 * $_], flag => $infos_up[1 + 2 * $_],
+ foreach (0..$nb_primary-1) {
+ my $h = { flag => $infos_up[1 + 2 * $_],
start_cylinder => $partitions_up[2 * $_], size => $partitions_up[1 + 2 * $_] };
- $h->{start} = $sector + $h->{start_cylinder} * $hd->cylinder_size();
- $h->{type} && $h->{size} or $h->{$_} = 0 foreach keys %$h;
+ fs::type::set_pt_type($h, $infos_up[2 * $_]);
+ $h->{start} = $sector + $h->{start_cylinder} * $hd->cylinder_size;
+ $h->{pt_type} && $h->{size} or $h->{$_} = 0 foreach keys %$h;
push @pt, $h;
}
@@ -106,7 +109,7 @@ sub read($$) {
# @h{@$fields1} = unpack $format1, $_[0];
# @h{@$fields2} = unpack $format2, $_[1];
# $h{start} = $sector + $h{start_cylinder} * $hd->cylinder_size();
-# $h{type} && $h{size} or $h{$_} = 0 foreach keys %h;
+# $h{pt_type} && $h{size} or $h{$_} = 0 foreach keys %h;
# \%h;
# } [ grep { $_ } split /(.{$size1})/o, $info{infos} ], [ grep { $_ } split /(.{$size2})/o, $info{partitions} ];
@@ -114,28 +117,28 @@ 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) = @_;
# my ($csize, $wdsize) = (0, 0);
#- 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;
}
($info->{infos}, $info->{partitions}) = map { join '', @$_ } list2kv map {
- $_->{start} % $hd->cylinder_size() == 0 or die "partition not at beginning of cylinder";
-# $csize += $_->{size} if $_->{type} != 5;
-# $wdsize += $_->{size} if $_->{type} == 5;
+ $_->{start} % $hd->cylinder_size == 0 or die "partition not at beginning of cylinder";
+# $csize += $_->{size} if $_->{pt_type} != 5;
+# $wdsize += $_->{size} if $_->{pt_type} == 5;
$_->{flags} |= 0x10 if $_->{mntpoint} eq '/';
- $_->{flags} |= 0x01 if partition_table::isSwap($_);
- local $_->{start_cylinder} = $_->{start} / $hd->cylinder_size() - $sector;
+ $_->{flags} |= 0x01 if !isSwap($_);
+ local $_->{start_cylinder} = $_->{start} / $hd->cylinder_size - $sector;
pack($format1, @$_{@$fields1}), pack($format2, @$_{@$fields2});
} @$pt;
# $csize == $wdsize or die "partitions are not using whole disk space";
@@ -145,7 +148,7 @@ sub write($$$;$) {
$info->{csum} = 0;
$info->{csum} = compute_crc(pack($main_format, @$info{@$main_fields}));
- 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;
common::sync();
@@ -183,19 +186,20 @@ sub info {
$info;
}
-sub clear_raw {
+sub initialize {
my ($hd) = @_;
my $pt = { raw => [ ({}) x $nb_primary ], info => info($hd) };
#- handle special case for partition 2 which is whole disk.
$pt->{raw}[2] = {
- type => 5, #- the whole disk type.
+ pt_type => 5, #- the whole disk type.
flags => 0,
start_cylinder => 0,
- size => $hd->{geom}{cylinders} * $hd->cylinder_size(),
+ size => $hd->{geom}{cylinders} * $hd->cylinder_size,
};
- $pt;
+ $hd->{primary} = $pt;
+ bless $hd, 'partition::sun';
}
1;