summaryrefslogtreecommitdiffstats
path: root/perl-install/partition_table_mac.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/partition_table_mac.pm')
-rw-r--r--perl-install/partition_table_mac.pm77
1 files changed, 57 insertions, 20 deletions
diff --git a/perl-install/partition_table_mac.pm b/perl-install/partition_table_mac.pm
index 61e741f4b..91d7cea01 100644
--- a/perl-install/partition_table_mac.pm
+++ b/perl-install/partition_table_mac.pm
@@ -1,4 +1,4 @@
-package partition_table_mac;
+package partition_table_mac; # $Id$
use diagnostics;
use strict;
@@ -76,7 +76,15 @@ my $pmagic = 0x504D;
sub adjustStart($$) {
my ($hd, $part) = @_;
+ my $end = $part->{start} + $part->{size};
+ my $partmap_end = $hd->{primary}{raw}[0]{size};
+
+ if ($part->{start} <= $partmap_end) {
+ $part->{start} = $partmap_end + 1;
+ $part->{size} = $end - $part->{start};
+ }
}
+
sub adjustEnd($$) {
my ($hd, $part) = @_;
}
@@ -94,7 +102,8 @@ sub read($$) {
foreach $i (0 .. $info{bzDrvrCnt}-1) {
sysread F, $tmp, psizeof($dd_format) or die "error while reading driver data in sector $sector";
- $info{ddMap}[$i] = unpack $dd_format, $tmp;
+ my %dd; @dd{@$dd_fields} = unpack $dd_format, $tmp;
+ push @{$info{ddMap}}, \%dd;
}
#- check magic number
@@ -113,7 +122,7 @@ sub read($$) {
c::lseek_sector(fileno(F), $sector, 512) or die "reading of partition in sector $sector failed";
my @pt;
- for($i=0;$i<$partmapsize;$i++) {
+ for ($i=0;$i<$partmapsize;$i++) {
my $part;
sysread F, $part, psizeof($p_format) or die "error while reading partition info in sector $sector";
@@ -127,7 +136,8 @@ sub read($$) {
if ($h{pType} =~ /^Apple_UNIX_SVR2/i) {
$h{pName} =~ /swap/i ? ($h{type} = 0x82) : ($h{type} = 0x83);
} elsif ($h{pType} =~ /^Apple_Free/i) {
- $h{type} = 0x0;
+ next;
+ #$h{type} = 0x0;
} elsif ($h{pType} =~ /^Apple_HFS/i) {
$h{type} = 0x402;
} elsif ($h{pType} =~ /^Apple_Partition_Map/i) {
@@ -136,6 +146,12 @@ sub read($$) {
} else {
$h{type} = 0x401;
};
+
+ # Let's see if this partition is a driver.
+ foreach (@{$info{ddMap}}) {
+ $_->{ddBlock} == $h{pPBlockStart} and $h{isDriver} = 1;
+ }
+
}
\%h;
} [ $part ];
@@ -165,12 +181,12 @@ sub write($$$;$) {
# Now go thru the partitions, sort and fill gaps.
my $last;
- while($part) {
+ while ($part) {
$last = $part;
$part = &partition_table::next($hd, $part);
$part or last;
- if($last->{start} + $last->{size} < $part->{start}) {
+ if ($last->{start} + $last->{size} < $part->{start}) {
#There is a gap between partitions. Fill it and move on.
push @partstowrite, {
type => 0x0,
@@ -182,7 +198,7 @@ sub write($$$;$) {
};
# now, fill a gap at the end if there is one.
- if($last->{start} + $last->{size} < $hd->{totalsectors}) {
+ if ($last->{start} + $last->{size} < $hd->{totalsectors}) {
push @partstowrite, {
type => 0x0,
start => $last->{start} + $last->{size},
@@ -191,13 +207,16 @@ sub write($$$;$) {
}
# Since we didn't create any new drivers, let's try and match up our driver records with out partitons and see if any are missing.
- my $i;
+ $info->{bzDrvrCnt} = 0;
my @ddstowrite;
- foreach $i ( 0 .. $info->{bzDrvrCnt} - 1) {
- my $ddBlock = $_->{ddBlock};
- my $dd = $_;
- foreach(@partstowrite) {
- $ddBlock == $_->{pPBlockStart} and push @ddstowrite, $dd;
+ my $dd;
+ foreach $dd (@{$info->{ddMap}}) {
+ foreach (@partstowrite) {
+ if ($dd->{ddBlock} == $_->{pPBlockStart}) {
+ push @ddstowrite, $dd;
+ $info->{bzDrvrCnt}++;
+ last;
+ }
}
}
@@ -205,11 +224,11 @@ sub write($$$;$) {
syswrite F, pack($bz_format, @$info{@$bz_fields}), psizeof($bz_format) or return 0;
# ...and now the driver information.
- foreach $i ( 0 .. $info->{bzDrvrCnt} - 1) {
- syswrite F, pack($dd_format, $ddstowrite[$i]{@$dd_fields}), psizeof($dd_format) or return 0;
+ foreach (@ddstowrite) {
+ syswrite F, pack($dd_format, @$_{@$dd_fields}), psizeof($dd_format) or return 0;
}
# zero the rest of the data in the first block.
- foreach $i ( 1 .. (494 - ($info->{bzDrvrCnt} * 8))) {
+ foreach ( 1 .. (494 - ((@ddstowrite) * 8))) {
syswrite F, "\0", 1 or return 0;
}
#c::lseek_sector(fileno(F), $sector, 512) or return 0;
@@ -234,7 +253,7 @@ sub write($$$;$) {
$_->{pBootArgs} = "\0";
$_->{pReserved} = "\0";
- if($_->{type} == 0x402) {
+ if ($_->{type} == 0x402) {
$_->{pType} = "Apple_HFS";
$_->{pName} = "MacOS";
$_->{pFlags} = 0x4000037F;
@@ -285,18 +304,36 @@ sub info {
sub clear_raw {
my ($hd) = @_;
+ my @oldraw = @{$hd->{primary}{raw}};
my $pt = { raw => [ ({}) x 63 ], info => info($hd) };
#- handle special case for partition 1 which is the partition map.
- my $part = {
+ $pt->{raw}[0] = {
type => 0x401,
start => 1,
size => 63,
isMap => 1,
};
+# $pt->{raw}[1] = {
+# type => 0x0,
+# start => 64,
+# size => $hd->{totalsectors} - 64,
+# isMap => 0,
+# };
+ push @{$pt->{normal}}, $pt->{raw}[0];
+# push @{$pt->{normal}}, $pt->{raw}[1];
+
+ #- Recover any Apple Drivers, if any.
+ my $i = 1;
+ foreach (@oldraw) {
+ if (defined $_->{isDriver}) {
+ $pt->{raw}[$i] = $_;
+ push @{$pt->{normal}}, $pt->{raw}[$i];
+ $i++;
+ }
+ };
+ @{$pt->{info}{ddMap}} = @{$hd->{primary}{info}{ddMap}};
- $pt->{raw}[0] = $part;
- push @{$pt->{normal}}, $part;
$pt;
}