diff options
Diffstat (limited to 'perl-install/partition_table/mac.pm')
-rw-r--r-- | perl-install/partition_table/mac.pm | 127 |
1 files changed, 64 insertions, 63 deletions
diff --git a/perl-install/partition_table/mac.pm b/perl-install/partition_table/mac.pm index 45c614139..78e5469cd 100644 --- a/perl-install/partition_table/mac.pm +++ b/perl-install/partition_table/mac.pm @@ -1,17 +1,18 @@ -package partition_table::mac; # $Id$ +package partition_table::mac; use diagnostics; #use strict; - fixed other PPC code to comply, but program bails on empty partition table - sbenedict -use vars qw(@ISA $freepart $bootstrap_part $macos_part); +use vars qw(@ISA $freepart $bootstrap_part $macos_part $new_bootstrap); @ISA = qw(partition_table::raw); use common; +use fs::type; use partition_table::raw; use partition_table; use c; -my %typeToDos = ( +my %_typeToDos = ( "Apple_partition_map" => 0x401, "Apple_Bootstrap" => 0x401, "Apple_Driver43" => 0x401, @@ -25,7 +26,6 @@ my %typeToDos = ( "Apple_UNIX_SVR2" => 0x483, "Apple_Free" => 0x0, ); -my %typeFromDos = reverse %typeToDos; my ($bz_format, $bz_fields) = list2kv( @@ -79,6 +79,8 @@ $p_format = join '', @$p_format; my $magic = 0x4552; my $pmagic = 0x504D; +sub use_pt_type { 1 } + sub first_usable_sector { 1 } sub adjustStart($$) { @@ -93,22 +95,21 @@ sub adjustStart($$) { } sub adjustEnd($$) { - my ($hd, $part) = @_; + my ($_hd, $_part) = @_; } -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, 0) 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, 0) or die "reading of partition in sector $sector failed"; - sysread F, $tmp, psizeof($bz_format) or die "error while reading bz \(Block Zero\) in sector $sector"; + sysread $F, $tmp, psizeof($bz_format) or die "error while reading bz (Block Zero) in sector $sector"; my %info; @info{@$bz_fields} = unpack $bz_format, $tmp; - my $i; - foreach $i (0 .. $info{bzDrvrCnt}-1) { - sysread F, $tmp, psizeof($dd_format) or die "error while reading driver data in sector $sector"; + foreach (1 .. $info{bzDrvrCnt}) { + sysread $F, $tmp, psizeof($dd_format) or die "error while reading driver data in sector $sector"; my %dd; @dd{@$dd_fields} = unpack $dd_format, $tmp; push @{$info{ddMap}}, \%dd; } @@ -117,21 +118,21 @@ sub read($$) { $info{bzSig} == $magic or die "bad magic number on disk $hd->{device}"; my $numparts; - c::lseek_sector(fileno(F), $sector, 516) or die "reading of partition in sector $sector failed"; - sysread F, $tmp, 4 or die "error while reading partition info in sector $sector"; + c::lseek_sector(fileno($F), $sector, 516) or die "reading of partition in sector $sector failed"; + sysread $F, $tmp, 4 or die "error while reading partition info in sector $sector"; $numparts = unpack "N", $tmp; my $partmapsize; - c::lseek_sector(fileno(F), $sector, 524) or die "reading of partition in sector $sector failed"; - sysread F, $tmp, 4 or die "error while reading partition info in sector $sector"; + c::lseek_sector(fileno($F), $sector, 524) or die "reading of partition in sector $sector failed"; + sysread $F, $tmp, 4 or die "error while reading partition info in sector $sector"; $partmapsize = ((unpack "N", $tmp) * $info{bzBlkSize}) / psizeof($p_format); - c::lseek_sector(fileno(F), $sector, 512) or die "reading of partition in sector $sector failed"; + 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 (my $i = 0; $i < $partmapsize; $i++) { my $part; - sysread F, $part, psizeof($p_format) or die "error while reading partition info in sector $sector"; + sysread $F, $part, psizeof($p_format) or die "error while reading partition info in sector $sector"; push @pt, map { my %h; @h{@$p_fields} = unpack $p_format, $part; @@ -141,7 +142,7 @@ sub read($$) { $h{start} = ($h{pPBlockStart} * $info{bzBlkSize}) / 512; if ($h{pType} =~ /^Apple_UNIX_SVR2/i) { - $h{pName} =~ /swap/i ? ($h{type} = 0x82) : ($h{type} = 0x83); + $h{fs_type} = $h{pName} =~ /swap/i ? 'swap' : 'ext2'; } elsif ($h{pType} =~ /^Apple_Free/i) { #- need to locate a 1MB partition to setup a bootstrap on if ($freepart && $freepart->{size} >= 1) { @@ -150,10 +151,10 @@ sub read($$) { $freepart = { start => $h{start}, size => $h{size}/2048, hd => $hd, part => "/dev/$hd->{device}" . ($i+1) }; log::l("free apple partition found on drive /dev/$freepart->{hd}{device}, block $freepart->{start}, size $freepart->{size}"); } - $h{type} = 0x0; + $h{pt_type} = 0x0; $h{pName} = 'Extra'; } elsif ($h{pType} =~ /^Apple_HFS/i) { - $h{type} = 0x402; + fs::type::set_pt_type(\%h, 0x402); if (defined $macos_part) { #- swag at identifying MacOS - 1st HFS partition } else { @@ -161,10 +162,10 @@ sub read($$) { log::l("found MacOS at partition $macos_part"); } } elsif ($h{pType} =~ /^Apple_Partition_Map/i) { - $h{type} = 0x401; + $h{pt_type} = 0x401; $h{isMap} = 1; } elsif ($h{pType} =~ /^Apple_Bootstrap/i) { - $h{type} = 0x401; + $h{pt_type} = 0x401; $h{isBoot} = 1; if (defined $bootstrap_part) { #found a bootstrap already - use it, but log the find @@ -174,9 +175,9 @@ sub read($$) { log::l("found apple bootstrap at partition $bootstrap_part"); } } else { - $h{type} = 0x401; + $h{pt_type} = 0x401; $h{isDriver} = 1; - }; + } # Let's see if this partition is a driver. foreach (@{$info{ddMap}}) { @@ -186,28 +187,28 @@ sub read($$) { } \%h; } [ $part ]; - }; + } [ @pt ], \%info; } 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, 0) 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, 0) or return 0; } # Find the partition map. my @partstowrite; my $part = $pt->[0]; - (defined $part->{isMap}) or die "the first partition is not the partition map"; + defined $part->{isMap} or die "the first partition is not the partition map"; push @partstowrite, $part; # Now go thru the partitions, sort and fill gaps. @@ -220,28 +221,27 @@ sub write($$$;$) { if ($last->{start} + $last->{size} < $part->{start}) { #There is a gap between partitions. Fill it and move on. push @partstowrite, { - type => 0x0, + pt_type => 0x0, start => $last->{start} + $last->{size}, size => $part->{start} - ($last->{start} + $last->{size}), }; } push @partstowrite, $part; - }; + } # now, fill a gap at the end if there is one. if ($last->{start} + $last->{size} < $hd->{totalsectors}) { push @partstowrite, { - type => 0x0, + pt_type => 0x0, start => $last->{start} + $last->{size}, size => $hd->{totalsectors} - ($last->{start} + $last->{size}), }; } - # 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. + # Since we did not create any new drivers, let's try and match up our driver records with out partitons and see if any are missing. $info->{bzDrvrCnt} = 0; my @ddstowrite; - my $dd; - foreach $dd (@{$info->{ddMap}}) { + foreach my $dd (@{$info->{ddMap}}) { foreach (@partstowrite) { if ($dd->{ddBlock} == $_->{pPBlockStart}) { push @ddstowrite, $dd; @@ -252,17 +252,17 @@ sub write($$$;$) { } # Now let's write our first block. - syswrite F, pack($bz_format, @$info{@$bz_fields}), psizeof($bz_format) or return 0; + syswrite $F, pack($bz_format, @$info{@$bz_fields}), psizeof($bz_format) or return 0; # ...and now the driver information. foreach (@ddstowrite) { - syswrite F, pack($dd_format, @$_{@$dd_fields}), psizeof($dd_format) or return 0; + syswrite $F, pack($dd_format, @$_{@$dd_fields}), psizeof($dd_format) or return 0; } # zero the rest of the data in the first block. - foreach ( 1 .. (494 - ((@ddstowrite) * 8))) { - syswrite F, "\0", 1 or return 0; + foreach (1 .. (494 - ((@ddstowrite) * 8))) { + syswrite $F, "\0", 1 or return 0; } - #c::lseek_sector(fileno(F), $sector, 512) or return 0; + #c::lseek_sector(fileno($F), $sector, 512) or return 0; # Now, we iterate thru the partstowrite and write them. foreach (@partstowrite) { if (!defined $_->{pSig}) { @@ -284,54 +284,54 @@ sub write($$$;$) { $_->{pBootArgs} = "\0"; $_->{pReserved} = "\0"; - if ($_->{type} == 0x402) { + if ($_->{pt_type} == 0x402) { $_->{pType} = "Apple_HFS"; $_->{pName} = "MacOS"; $_->{pFlags} = 0x4000037F; - } elsif ($_->{type} == 0x401 && $_->{start} == 1) { + } elsif ($_->{pt_type} == 0x401 && $_->{start} == 1) { $_->{pType} = "Apple_Partition_Map"; $_->{pName} = "Apple"; $_->{pFlags} = 0x33; - } elsif ($_->{type} == 0x401) { + } elsif ($_->{pt_type} == 0x401) { $_->{pType} = "Apple_Bootstrap"; $_->{pName} = "bootstrap"; $_->{pFlags} = 0x33; $_->{isBoot} = 1; log::l("writing a bootstrap at /dev/$_->{device}"); - $install_steps_interactive::new_bootstrap = 1 if !(defined $partition_table::mac::bootstrap_part); + $new_bootstrap = 1 if !(defined $bootstrap_part); $bootstrap_part = "/dev/" . $_->{device}; - } elsif ($_->{type} == 0x82) { + } elsif (isSwap($_)) { $_->{pType} = "Apple_UNIX_SVR2"; $_->{pName} = "swap"; $_->{pFlags} = 0x33; - } elsif ($_->{type} == 0x83) { + } elsif ($_->{fs_type} eq 'ext2') { $_->{pType} = "Apple_UNIX_SVR2"; $_->{pName} = "Linux Native"; $_->{pFlags} = 0x33; - } elsif ($_->{type} == 0x183) { + } elsif ($_->{fs_type} eq 'reiserfs') { $_->{pType} = "Apple_UNIX_SVR2"; $_->{pName} = "Linux ReiserFS"; $_->{pFlags} = 0x33; - } elsif ($_->{type} == 0x283) { + } elsif ($_->{fs_type} eq 'xfs') { $_->{pType} = "Apple_UNIX_SVR2"; $_->{pName} = "Linux XFS"; $_->{pFlags} = 0x33; - } elsif ($_->{type} == 0x383) { + } elsif ($_->{fs_type} eq 'jfs') { $_->{pType} = "Apple_UNIX_SVR2"; $_->{pName} = "Linux JFS"; $_->{pFlags} = 0x33; - } elsif ($_->{type} == 0x483) { + } elsif ($_->{fs_type} eq 'ext3') { $_->{pType} = "Apple_UNIX_SVR2"; $_->{pName} = "Linux ext3"; $_->{pFlags} = 0x33; - } elsif ($_->{type} == 0x0) { + } elsif ($_->{pt_type} == 0x0) { $_->{pType} = "Apple_Free"; $_->{pName} = "Extra"; $_->{pFlags} = 0x31; } - }; + } $_->{pMapEntry} = @partstowrite; - syswrite F, pack($p_format, @$_{@$p_fields}), psizeof($p_format) or return 0; + syswrite $F, pack($p_format, @$_{@$p_fields}), psizeof($p_format) or return 0; } common::sync(); @@ -357,20 +357,20 @@ sub info { $info; } -sub clear_raw { - my ($hd) = @_; +sub initialize { + my ($class, $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. $pt->{raw}[0] = { - type => 0x401, + pt_type => 0x401, start => 1, size => 63, isMap => 1, }; # $pt->{raw}[1] = { -# type => 0x0, +# pt_type => 0x0, # start => 64, # size => $hd->{totalsectors} - 64, # isMap => 0, @@ -386,10 +386,11 @@ sub clear_raw { push @{$pt->{normal}}, $pt->{raw}[$i]; $i++; } - }; + } @{$pt->{info}{ddMap}} = @{$hd->{primary}{info}{ddMap}}; - $pt; + $hd->{primary} = $pt; + bless $hd, $class; } 1; |