summaryrefslogtreecommitdiffstats
path: root/perl-install/partition_table_sun.pm
diff options
context:
space:
mode:
authorFrancois Pons <fpons@mandriva.com>2000-01-24 13:11:27 +0000
committerFrancois Pons <fpons@mandriva.com>2000-01-24 13:11:27 +0000
commitfe0e92f4e338bd3ab690e409ff9ccde6cfe58780 (patch)
tree90162d89089414633e30308971a9e715f1b1363c /perl-install/partition_table_sun.pm
parent9e683c898b6592aaac1196f76dd9321c4426c912 (diff)
downloaddrakx-backup-do-not-use-fe0e92f4e338bd3ab690e409ff9ccde6cfe58780.tar
drakx-backup-do-not-use-fe0e92f4e338bd3ab690e409ff9ccde6cfe58780.tar.gz
drakx-backup-do-not-use-fe0e92f4e338bd3ab690e409ff9ccde6cfe58780.tar.bz2
drakx-backup-do-not-use-fe0e92f4e338bd3ab690e409ff9ccde6cfe58780.tar.xz
drakx-backup-do-not-use-fe0e92f4e338bd3ab690e409ff9ccde6cfe58780.zip
first sparc release of DrakX.
Diffstat (limited to 'perl-install/partition_table_sun.pm')
-rw-r--r--perl-install/partition_table_sun.pm119
1 files changed, 92 insertions, 27 deletions
diff --git a/perl-install/partition_table_sun.pm b/perl-install/partition_table_sun.pm
index 5c8fc749f..808944b8c 100644
--- a/perl-install/partition_table_sun.pm
+++ b/perl-install/partition_table_sun.pm
@@ -45,6 +45,32 @@ 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.
+ $part->{start} = $part->{start} >= partition_table::cylinder_size() ? round_up($part->{start}, partition_table::cylinder_size($hd)) : 0;
+ $part->{size} = $end - $part->{start};
+}
+sub adjustEnd($$) {
+ &partition_table::adjustEnd;
+}
+
+#- 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;
@@ -58,15 +84,17 @@ 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 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{type} = $typeToDos{$h{type}} || $h{type}; #- for rewrite it ?
$h{size} or $h{$_} = 0 foreach keys %h;
\%h;
} [ $info{infos} =~ /(.{$size1})/g ], [ $info{partitions} =~ /(.{$size2})/g ];
@@ -79,18 +107,28 @@ sub read($$) {
sub write($$$;$) {
my ($hd, $sector, $pt, $info) = @_;
- 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
+ #- 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->{infos}, $info->{partitions}) = map { join '', @$_ } list2kv map {
$_->{start} % partition_table::cylinder_size($hd) == 0 or die "partition not at beginning of cylinder";
- local $_->{type} = $typeFromDos{$_->{type}} || $_->{type};
+# local $_->{type} = $typeFromDos{$_->{type}} || $_->{type};
local $_->{start_cylinder} = $_->{start} / partition_table::cylinder_size($hd) - $sector;
pack($format1, @$_{@$fields1}), pack($format2, @$_{@$fields2});
} @$pt;
+ #- 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;
1;
@@ -98,31 +136,58 @@ sub write($$$;$) {
sub info {
my ($hd) = @_;
- 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
+
+ #- 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}{total_cylinders},
+ sparecyl => 0,
+ ilfact => 1,
+ ncyl => $hd->{geom}{cylinders},
+ nacyl => $hd->{geom}{total_cylinders} - $hd->{geom}{cylinders},
+ ntrks => $hd->{geom}{heads},
+ nsect => $hd->{geom}{sectors},
+ magic => $magic,
};
+
+ $info;
+# 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
+# };
}
sub clear_raw {
my ($hd) = @_;
- { raw => [ ({}) x $nb_primary ], info => info($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} * partition_table::cylinder_size($hd),
+ };
+
+ $pt;
}
1;