summaryrefslogtreecommitdiffstats
path: root/perl-install/partition_table_sun.pm
diff options
context:
space:
mode:
authorMystery Man <unknown@mandriva.org>2000-11-08 00:01:16 +0000
committerMystery Man <unknown@mandriva.org>2000-11-08 00:01:16 +0000
commitd5c526273db473a7d87a26000585900fc10dda7d (patch)
tree0fdaabe7a00921b6cc556601b103d344fc7ac781 /perl-install/partition_table_sun.pm
parent9c164312d4bfff6d93e1c4529de6b992f2bebc44 (diff)
downloaddrakx-d5c526273db473a7d87a26000585900fc10dda7d.tar
drakx-d5c526273db473a7d87a26000585900fc10dda7d.tar.gz
drakx-d5c526273db473a7d87a26000585900fc10dda7d.tar.bz2
drakx-d5c526273db473a7d87a26000585900fc10dda7d.tar.xz
drakx-d5c526273db473a7d87a26000585900fc10dda7d.zip
This commit was manufactured by cvs2svn to create branch
'unlabeled-1.1.1'.
Diffstat (limited to 'perl-install/partition_table_sun.pm')
-rw-r--r--perl-install/partition_table_sun.pm167
1 files changed, 47 insertions, 120 deletions
diff --git a/perl-install/partition_table_sun.pm b/perl-install/partition_table_sun.pm
index 55c3ab775..5c8fc749f 100644
--- a/perl-install/partition_table_sun.pm
+++ b/perl-install/partition_table_sun.pm
@@ -11,6 +11,12 @@ use partition_table_raw;
use partition_table;
use c;
+#- very bad and rough handling :(
+my %typeToDos = (
+ 5 => 0,
+);
+my %typeFromDos = reverse %typeToDos;
+
my ($main_format, $main_fields) = list2kv(
a128 => 'info',
a14 => 'spare0',
@@ -33,44 +39,12 @@ my ($main_format, $main_fields) = list2kv(
$main_format = join '', @$main_format;
my ($fields1, $fields2) = ([ qw(type flags) ], [ qw(start_cylinder size) ]);
-my ($format1, $format2) = ("xCxC", "N2");
+my ($format1, $format2) = ("x C x C", "N N");
my ($size1, $size2) = map { psizeof($_) } ($format1, $format2);
my $magic = 0xDABE;
my $nb_primary = 8;
my $offset = 0;
-sub adjustStart($$) {
- my ($hd, $part) = @_;
- my $end = $part->{start} + $part->{size};
-
- #- since partition must always start on cylinders boundaries on sparc,
- #- 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->{size} = $end - $part->{start};
- $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();
- $part->{size} = $end2 - $part->{start};
-}
-
-#- compute crc checksum used for Sun Label partition, expect
-#- $tmp to be the 512 bytes buffer to be read/written to MBR.
-sub compute_crc($) {
- my ($tmp) = @_;
- my @l2b = unpack "n256", $tmp;
- my $crc = 0;
-
- map { $crc ^= $_ } @l2b;
-
- $crc;
-}
-
sub read($$) {
my ($hd, $sector) = @_;
my $tmp;
@@ -84,31 +58,18 @@ sub read($$) {
#- check magic number
$info{magic} == $magic or die "bad magic number";
- #- check crc, csum contains the crc so result should be 0.
- compute_crc($tmp) == 0 or die "bad checksum";
-
- @{$hd->{geom}}{qw(cylinders heads sectors)} = @info{qw(ncyl ntrks nsect)};
-
- 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 * $_],
- 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;
- push @pt, $h;
- }
-
-#- this code is completely broken by null char inside strings, it gets completely crazy :-)
-# my @pt = mapn {
-# my %h;
-# @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;
-# } [ grep { $_ } split /(.{$size1})/o, $info{infos} ], [ grep { $_ } split /(.{$size2})/o, $info{partitions} ];
+ @{$hd->{geom}}{qw(cylinders heads sectors)} = @info{qw(ncyl nsect ntrks)};
+
+ #- TODO verify checksum
+ my @pt = mapn {
+ my %h;
+ @h{@$fields1} = unpack $format1, $_[0];
+ @h{@$fields2} = unpack $format2, $_[1];
+ $h{start} = $sector + $h{start_cylinder} * partition_table::cylinder_size($hd);
+ $h{type} = $typeToDos{$h{type}} || $h{type};
+ $h{size} or $h{$_} = 0 foreach keys %h;
+ \%h;
+ } [ $info{infos} =~ /(.{$size1})/g ], [ $info{partitions} =~ /(.{$size2})/g ];
[ @pt ], \%info;
}
@@ -117,85 +78,51 @@ sub read($$) {
# for each entry, it uses fields: start, size, type, active
sub write($$$;$) {
my ($hd, $sector, $pt, $info) = @_;
-# my ($csize, $wdsize) = (0, 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;
- }
+
+ 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->{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;
- $_->{flags} |= 0x10 if $_->{mntpoint} eq '/';
- $_->{flags} |= 0x01 if partition_table::isSwap($_);
- local $_->{start_cylinder} = $_->{start} / $hd->cylinder_size() - $sector;
+ $_->{start} % partition_table::cylinder_size($hd) == 0 or die "partition not at beginning of cylinder";
+ local $_->{type} = $typeFromDos{$_->{type}} || $_->{type};
+ local $_->{start_cylinder} = $_->{start} / partition_table::cylinder_size($hd) - $sector;
pack($format1, @$_{@$fields1}), pack($format2, @$_{@$fields2});
} @$pt;
-# $csize == $wdsize or die "partitions are not using whole disk space";
-
- #- compute the checksum by building the buffer to write and call compute_crc.
- #- set csum to 0 so compute_crc will give the right csum value.
- $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;
- sync();
-
1;
}
sub info {
my ($hd) = @_;
-
- #- take care of reduction of the number of cylinders, avoid loop of reduction!
- unless ($hd->{geom}{totalcylinders} > $hd->{geom}{cylinders}) {
- $hd->{geom}{totalcylinders} = $hd->{geom}{cylinders};
- $hd->{geom}{cylinders} -= 2;
-
- #- rebuild some constants according to number of cylinders.
- $hd->{totalsectors} = $hd->{geom}{heads} * $hd->{geom}{sectors} * $hd->{geom}{cylinders};
- }
-
- #- build a default suitable partition table,
- #- checksum will be built when writing on disk.
- #- note third partition is ALWAYS of type Whole disk.
- my $info = {
- info => "DiskDrake partition table",
- rspeed => 5400,
- pcylcount => $hd->{geom}{totalcylinders},
- sparecyl => 0,
- ilfact => 1,
- ncyl => $hd->{geom}{cylinders},
- nacyl => $hd->{geom}{totalcylinders} - $hd->{geom}{cylinders},
- ntrks => $hd->{geom}{heads},
- nsect => $hd->{geom}{sectors},
- magic => $magic,
+ my $dtype_scsi = 4; #- taken from fdisk, removed unused one,
+ my $dtype_ST506 = 6; #- see fdisk for more
+
+ {
+ magic => $magic,
+ magic2 => $magic,
+ dtype => $hd->{device} =~ /^sd/ ? $dtype_scsi : $dtype_ST506,
+ secsize => $common::SECTORSIZE,
+ ncylinders => $hd->{geom}{cylinders},
+ secpercyl => partition_table::cylinder_size($hd),
+ secprtunit => $hd->{geom}{totalsectors},
+ rpm => 3600,
+ interleave => 1,
+ trackskew => 0,
+ cylskew => 0,
+ headswitch => 0,
+ trkseek => 0,
+ bbsize => 8192, #- size of boot area, with label
+ sbsize => 8192, #- max size of fs superblock
};
-
- $info;
}
sub clear_raw {
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.
- flags => 0,
- start_cylinder => 0,
- size => $hd->{geom}{cylinders} * $hd->cylinder_size(),
- };
-
- $pt;
+ { raw => [ ({}) x $nb_primary ], info => info($hd) };
}
1;