From 61b0cd36577df2a9f86cb2c08d14737f0bbcb557 Mon Sep 17 00:00:00 2001 From: Thierry Vignaud Date: Tue, 23 Jul 2002 11:08:35 +0000 Subject: g Move 2: partition table: hierarchy --- perl-install/Makefile | 6 +- perl-install/Makefile.config | 2 +- perl-install/Makefile.drakxtools | 4 +- perl-install/any.pm | 6 +- perl-install/bootloader.pm | 8 +- perl-install/detect_devices.pm | 4 +- perl-install/diskdrake/hd_gtk.pm | 2 +- perl-install/diskdrake/interactive.pm | 8 +- perl-install/drakxtools.spec | 1 + perl-install/fsedit.pm | 12 +- perl-install/install_any.pm | 6 +- perl-install/install_interactive.pm | 4 +- perl-install/install_steps.pm | 2 +- perl-install/install_steps_interactive.pm | 16 +- perl-install/partition_table.pm | 10 +- perl-install/partition_table/bsd.pm | 147 +++++++++++ perl-install/partition_table/dos.pm | 99 ++++++++ perl-install/partition_table/empty.pm | 36 +++ perl-install/partition_table/gpt.pm | 266 ++++++++++++++++++++ perl-install/partition_table/lvm_PV.pm | 43 ++++ perl-install/partition_table/mac.pm | 398 ++++++++++++++++++++++++++++++ perl-install/partition_table/raw.pm | 192 ++++++++++++++ perl-install/partition_table/sun.pm | 201 +++++++++++++++ perl-install/partition_table_bsd.pm | 147 ----------- perl-install/partition_table_dos.pm | 99 -------- perl-install/partition_table_empty.pm | 36 --- perl-install/partition_table_gpt.pm | 266 -------------------- perl-install/partition_table_lvm_PV.pm | 43 ---- perl-install/partition_table_mac.pm | 398 ------------------------------ perl-install/partition_table_raw.pm | 192 -------------- perl-install/partition_table_sun.pm | 201 --------------- perl-install/standalone.pm | 2 +- 32 files changed, 1429 insertions(+), 1428 deletions(-) create mode 100644 perl-install/partition_table/bsd.pm create mode 100644 perl-install/partition_table/dos.pm create mode 100644 perl-install/partition_table/empty.pm create mode 100644 perl-install/partition_table/gpt.pm create mode 100644 perl-install/partition_table/lvm_PV.pm create mode 100644 perl-install/partition_table/mac.pm create mode 100644 perl-install/partition_table/raw.pm create mode 100644 perl-install/partition_table/sun.pm delete mode 100644 perl-install/partition_table_bsd.pm delete mode 100644 perl-install/partition_table_dos.pm delete mode 100644 perl-install/partition_table_empty.pm delete mode 100644 perl-install/partition_table_gpt.pm delete mode 100644 perl-install/partition_table_lvm_PV.pm delete mode 100644 perl-install/partition_table_mac.pm delete mode 100644 perl-install/partition_table_raw.pm delete mode 100644 perl-install/partition_table_sun.pm diff --git a/perl-install/Makefile b/perl-install/Makefile index 239c4248b..3994a30e7 100644 --- a/perl-install/Makefile +++ b/perl-install/Makefile @@ -7,7 +7,7 @@ include Makefile.config POFILES = $(shell ls share/po/*.po) MOFILES = $(POFILES:%.po=%.mo) -DISTFILES = Makefile Makefile.config Newt apps.net_monitor diskdrake c ddcprobe drakxtools.spec pam.net_monitor serial_probe share/po sbus_probing resize_fat share/diskdrake.rc $(STANDALONEPMS) standalone/icons pixmaps network interactive standalone/interactive_http rpcinfo-flushed.c *.pm security harddrake +DISTFILES = Makefile Makefile.config Newt apps.net_monitor diskdrake c ddcprobe drakxtools.spec pam.net_monitor serial_probe share/po sbus_probing resize_fat share/diskdrake.rc $(STANDALONEPMS) standalone/icons pixmaps network interactive partition_table standalone/interactive_http rpcinfo-flushed.c *.pm security harddrake OTHERS = $(OTHERDIRS) $(OTHERFILES) OTHERDIRS = tools/ddcprobe tools/serial_probe OTHERFILES = tools/rpcinfo-flushed.c @@ -37,8 +37,8 @@ localcopy: clean $(MAKE) -C ../tools clean || : cd .. ; rm -rf $(PACKAGE)-$(PKGVERSION) ; cp -af perl-install $(PACKAGE)-$(PKGVERSION) ; cp -af $(OTHERS) $(PACKAGE)-$(PKGVERSION) cd - find ../$(PACKAGE)-$(PKGVERSION) -name '*.pm' | xargs perl -pi -e 's/\s*use\s+(diagnostics|vars|strict)//g' - find ../$(PACKAGE)-$(PKGVERSION)/standalone -type f | xargs perl -pi -e 's/\s*use\s+(diagnostics|vars|strict)//g' + find ../$(PACKAGE)-$(PKGVERSION) -name '*.pm' | xargs perl -pi -e 's/\s*use\s+(diagnostics|vars|strict).*//g' + find ../$(PACKAGE)-$(PKGVERSION)/standalone -type f | xargs perl -pi -e 's/\s*use\s+(diagnostics|vars|strict).*//g' $(DIRS): diff --git a/perl-install/Makefile.config b/perl-install/Makefile.config index 0081767ac..dabc34066 100644 --- a/perl-install/Makefile.config +++ b/perl-install/Makefile.config @@ -5,7 +5,7 @@ ARCH := $(patsubst sparc%,sparc,$(ARCH)) VERSION = 2.2.10-BOOT SUDO = sudo SO_FILES = c/blib/arch/auto/c/c.so -PMS = *.pm Newt/*.pm c/stuff.pm resize_fat/*.pm sbus_probing/*.pm network/*.pm interactive/*.pm diskdrake/*.pm harddrake/*.pm commands install2 g_auto_install live_install live_install2 share/advertising/*.pl +PMS = *.pm Newt/*.pm c/stuff.pm resize_fat/*.pm sbus_probing/*.pm network/*.pm interactive/*.pm partition_table/*.pm diskdrake/*.pm harddrake/*.pm commands install2 g_auto_install live_install live_install2 share/advertising/*.pl STANDALONEPMS_ = diskdrake XFdrake mousedrake printerdrake logdrake keyboarddrake drakconnect drakbackup drakfont drakproxy localedrake net_monitor drakbug_report tinyfirewall drakxconf drakxservices draksec drakboot adduserdrake drakgw drakautoinst livedrake lsnetdrake scannerdrake fileshareset drakxtv drakfloppy harddrake2 drakTermServ service_harddrake service_harddrake.sh drakbug STANDALONEPMS = $(STANDALONEPMS_:%=standalone/%) ALLPMS = $(PMS) $(STANDALONEPMS) diff --git a/perl-install/Makefile.drakxtools b/perl-install/Makefile.drakxtools index 032556e50..6b6dadfc9 100644 --- a/perl-install/Makefile.drakxtools +++ b/perl-install/Makefile.drakxtools @@ -26,7 +26,7 @@ $(DIRS): [ ! -e $@/Makefile ] || $(MAKE) -C $@ install: - mkdir -p $(BINDEST) $(ETCDEST) $(SBINDEST) $(DATADIR)/{harddrake,pixmaps} $(LIBDEST)/{network,security,harddrake,interactive} $(BINX11DEST) $(LIBX11DEST) $(PIXDIR) $(INITDIR) + mkdir -p $(BINDEST) $(ETCDEST) $(SBINDEST) $(DATADIR)/{harddrake,pixmaps} $(LIBDEST)/{network,security,harddrake,interactive,partition_table} $(BINX11DEST) $(LIBX11DEST) $(PIXDIR) $(INITDIR) install -d $(INLIBDEST_DIRS:%=$(LIBDEST)/%) install $(STANDALONEPMS) $(SBINDEST) install -s rpcinfo-flushed ddcprobe/ddcxinfos serial_probe/serial_probe $(SBINDEST) @@ -35,7 +35,7 @@ install: mv -f $(SBINDEST)/lsnetdrake $(BINDEST)/lsnetdrake install -m 644 *.pm $(LIBDEST) - for i in network harddrake security interactive; do install -m 644 $$i/*.pm $(LIBDEST)/$$i/;done + for i in network harddrake security interactive partition_table; do install -m 644 $$i/*.pm $(LIBDEST)/$$i/;done install -m 644 pixmaps/* $(PIXDIR) install -m 644 share/diskdrake.rc $(DATADIR)/$(NAME) diff --git a/perl-install/any.pm b/perl-install/any.pm index 0f472748c..44d23a204 100644 --- a/perl-install/any.pm +++ b/perl-install/any.pm @@ -122,8 +122,8 @@ sub setupBootloader { _("Where do you want to install the bootloader?"), \@l, $l[$b->{use_partition}]) or return 0; } elsif (arch() =~ /ppc/) { - if (defined $partition_table_mac::bootstrap_part) { - $b->{boot} = $partition_table_mac::bootstrap_part; + if (defined $partition_table::mac::bootstrap_part) { + $b->{boot} = $partition_table::mac::bootstrap_part; log::l("set bootstrap to $b->{boot}"); } else { die "no bootstrap partition - yaboot.conf creation failed"; @@ -195,7 +195,7 @@ sub setupBootloader { } ) or return 0; } else { - $b->{boot} = $partition_table_mac::bootstrap_part; + $b->{boot} = $partition_table::mac::bootstrap_part; $in->ask_from('', _("Bootloader main options"), [ { label => _("Bootloader to use"), val => \$bootloader, list => [ keys(%bootloaders) ], format => \&translate }, { label => _("Init Message"), val => \$b->{'init-message'} }, diff --git a/perl-install/bootloader.pm b/perl-install/bootloader.pm index aa844921c..a0b18f69a 100644 --- a/perl-install/bootloader.pm +++ b/perl-install/bootloader.pm @@ -15,7 +15,7 @@ use fsedit; use devices; use loopback; use detect_devices; -use partition_table_raw; +use partition_table::raw; use run_program; use modules; @@ -126,7 +126,7 @@ sub read($$) { sub suggest_onmbr { my ($hds) = @_; - my $type = partition_table_raw::typeOfMBR($hds->[0]{device}); + my $type = partition_table::raw::typeOfMBR($hds->[0]{device}); !$type || member($type, qw(dos dummy lilo grub empty)), !$type; } @@ -406,11 +406,11 @@ wait %d seconds for default boot. } } elsif (arch() =~ /ppc/) { #- if we identified a MacOS partition earlier - add it - if (defined $partition_table_mac::macos_part) { + if (defined $partition_table::mac::macos_part) { add_entry($lilo->{entries}, { label => "macos", - kernel_or_dev => $partition_table_mac::macos_part + kernel_or_dev => $partition_table::mac::macos_part }); } } elsif (arch() !~ /ia64/) { diff --git a/perl-install/detect_devices.pm b/perl-install/detect_devices.pm index c8fbc762d..f53f4d750 100644 --- a/perl-install/detect_devices.pm +++ b/perl-install/detect_devices.pm @@ -160,8 +160,8 @@ sub isRemovableDrive { &isZipDrive || &isLS120Drive || $_[0]->{media_type} eq 'f sub isFloppyOrHD { my ($dev) = @_; - require partition_table_raw; - my $geom = partition_table_raw::get_geometry(devices::make($dev)); + require partition_table::raw; + my $geom = partition_table::raw::get_geometry(devices::make($dev)); $geom->{totalsectors} < 10 << 11 ? 'fd' : 'hd'; } diff --git a/perl-install/diskdrake/hd_gtk.pm b/perl-install/diskdrake/hd_gtk.pm index 2de971f89..35342c6e3 100644 --- a/perl-install/diskdrake/hd_gtk.pm +++ b/perl-install/diskdrake/hd_gtk.pm @@ -7,7 +7,7 @@ use common; use resize_fat::main; use my_gtk qw(:helpers :wrappers :ask); use partition_table qw(:types); -use partition_table_raw; +use partition_table::raw; use detect_devices; use diskdrake::interactive; use run_program; diff --git a/perl-install/diskdrake/interactive.pm b/perl-install/diskdrake/interactive.pm index 0cefc1d05..7a76ff2e8 100644 --- a/perl-install/diskdrake/interactive.pm +++ b/perl-install/diskdrake/interactive.pm @@ -5,7 +5,7 @@ use strict; use common; use partition_table qw(:types); -use partition_table_raw; +use partition_table::raw; use detect_devices; use run_program; use loopback; @@ -274,7 +274,7 @@ sub Clear_all { if (isLVM($hd)) { lvm::lv_delete($hd, $_) foreach @parts } else { - partition_table_raw::zero_MBR_and_dirty($hd); + partition_table::raw::zero_MBR_and_dirty($hd); } } @@ -488,7 +488,7 @@ sub Delete { fsedit::recompute_loopbacks($all_hds); } else { if (arch() =~ /ppc/) { - undef $partition_table_mac::bootstrap_part if (isAppleBootstrap($part) && ($part->{device} = $partition_table_mac::bootstrap_part)); + undef $partition_table::mac::bootstrap_part if (isAppleBootstrap($part) && ($part->{device} = $partition_table::mac::bootstrap_part)); } partition_table::remove($hd, $part); warn_if_renumbered($in, $hd); @@ -624,7 +624,7 @@ sub Resize { } #- make sure that even after normalizing the size to cylinder boundaries, the minimun will be saved, #- this save at least a cylinder (less than 8Mb). - $min += partition_table_raw::cylinder_size($hd); + $min += partition_table::raw::cylinder_size($hd); $min >= $max and return $in->ask_warn('', _("This partition is not resizeable")); #- for these, we have tools to resize partition table diff --git a/perl-install/drakxtools.spec b/perl-install/drakxtools.spec index ebb084715..2cf4a7a75 100644 --- a/perl-install/drakxtools.spec +++ b/perl-install/drakxtools.spec @@ -248,6 +248,7 @@ done * Tue Jul 23 2002 Thierry Vignaud 1.1.8-9mdk - reorganization cleanup: move interactive_* into interactive::* + move partition_table_* into partition_table::* * Sun Jul 21 2002 Pixel 1.1.8-8mdk - new snapshot (beware of XFdrake) diff --git a/perl-install/fsedit.pm b/perl-install/fsedit.pm index 5b700d387..b1bb6ea6b 100644 --- a/perl-install/fsedit.pm +++ b/perl-install/fsedit.pm @@ -9,7 +9,7 @@ use vars qw(%suggestions); #-###################################################################################### use common; use partition_table qw(:types); -use partition_table_raw; +use partition_table::raw; use detect_devices; use fsedit; use devices; @@ -143,7 +143,7 @@ sub hds { foreach (@$drives) { my $file = devices::make($_->{device}); - my $hd = partition_table_raw::get_geometry($file) or log::l("An error occurred while getting the geometry of block device $file: $!"), next; + my $hd = partition_table::raw::get_geometry($file) or log::l("An error occurred while getting the geometry of block device $file: $!"), next; add2hash_($hd, $_); $hd->{file} = $file; $hd->{prefix} = $hd->{device}; @@ -153,7 +153,7 @@ sub hds { eval { partition_table::read($hd, $flags->{clearall} || member($_->{device}, @{$flags->{clear} || []})) }; if ($@) { cdie "ask_before_blanking:$@"; - partition_table_raw::zero_MBR($hd); + partition_table::raw::zero_MBR($hd); } member($_->{device}, @{$flags->{clear} || []}) and partition_table::remove($hd, $_) foreach partition_table::get_normal_parts($hd); @@ -164,7 +164,7 @@ sub hds { #- special case for type overloading (eg: reiserfs is 0x183) foreach (grep { isExt2($_) } partition_table::get_normal_parts($hd)) { my $type = typeOfPart($_->{device}); - $_->{type} = $type if $type > 0x100 || $type && $hd->isa('partition_table_gpt'); + $_->{type} = $type if $type > 0x100 || $type && $hd->isa('partition_table::gpt'); } push @hds, $hd; } @@ -691,7 +691,7 @@ sub rescuept($) { } close F or die "rescuept failed"; - partition_table_raw::zero_MBR($hd); + partition_table::raw::zero_MBR($hd); foreach (@hd) { my $b = partition_table::verifyInside($_, $ext); if ($b) { @@ -726,7 +726,7 @@ sub verifyHds { if ($readonly && !$ok) { log::l("using /proc/partitions as diskdrake failed :("); foreach my $hd (@$hds) { - partition_table_raw::zero_MBR($hd); + partition_table::raw::zero_MBR($hd); $hd->{primary} = { normal => [ grep { $hd->{device} eq $_->{rootDevice} } @parts ] }; } $ok = 1; diff --git a/perl-install/install_any.pm b/perl-install/install_any.pm index 2a93b2be1..ea78b14aa 100644 --- a/perl-install/install_any.pm +++ b/perl-install/install_any.pm @@ -18,7 +18,7 @@ use MDK::Common::System; use common; use run_program; use partition_table qw(:types); -use partition_table_raw; +use partition_table::raw; use devices; use fsedit; use modules; @@ -989,7 +989,7 @@ sub getHds { my $flags = $o->{partitioning}; my @drives = detect_devices::hds(); -# add2hash_($o->{partitioning}, { readonly => 1 }) if partition_table_raw::typeOfMBR($drives[0]{device}) eq 'system_commander'; +# add2hash_($o->{partitioning}, { readonly => 1 }) if partition_table::raw::typeOfMBR($drives[0]{device}) eq 'system_commander'; getHds: my $all_hds = catch_cdie { fsedit::hds(\@drives, $flags) } @@ -1007,7 +1007,7 @@ sub getHds { goto getHds; } if (!$::testing) { - @$hds = grep { eval { partition_table_raw::test_for_bad_drives($_) }; !$@ } @$hds; + @$hds = grep { eval { partition_table::raw::test_for_bad_drives($_) }; !$@ } @$hds; } $ok = fsedit::verifyHds($hds, $flags->{readonly}, $ok) diff --git a/perl-install/install_interactive.pm b/perl-install/install_interactive.pm index b9ee10de7..53c92d2ed 100644 --- a/perl-install/install_interactive.pm +++ b/perl-install/install_interactive.pm @@ -7,7 +7,7 @@ use vars; use common; use partition_table qw(:types); -use partition_table_raw; +use partition_table::raw; use detect_devices; use install_steps; use devices; @@ -180,7 +180,7 @@ When sure, press Ok.")) or return; \&partition_table::description, $hds) or return; $o->set_help('takeOverHdConfirm'); $o->ask_okcancel('', _("ALL existing partitions and their data will be lost on drive %s", partition_table::description($hd))) or return; - partition_table_raw::zero_MBR($hd); + partition_table::raw::zero_MBR($hd); fsedit::auto_allocate($all_hds); 1; } ]; diff --git a/perl-install/install_steps.pm b/perl-install/install_steps.pm index 53f32a45e..b4f1fb97d 100644 --- a/perl-install/install_steps.pm +++ b/perl-install/install_steps.pm @@ -157,7 +157,7 @@ sub doPartitionDisksAfter { fsedit::get_root_($o->{fstab}) or die "Oops, no root partition"; if (arch() =~ /ppc/ && detect_devices::get_mac_generation =~ /NewWorld/) { - die "Need bootstrap partition to boot system!" if !(defined $partition_table_mac::bootstrap_part); + die "Need bootstrap partition to boot system!" if !(defined $partition_table::mac::bootstrap_part); } if (arch() =~ /ia64/ && !fsedit::has_mntpoint("/boot/efi", $o->{all_hds})) { diff --git a/perl-install/install_steps_interactive.pm b/perl-install/install_steps_interactive.pm index 4f04a8dcb..1ab9bab30 100644 --- a/perl-install/install_steps_interactive.pm +++ b/perl-install/install_steps_interactive.pm @@ -42,7 +42,7 @@ copyright laws applicable to software programs. #-###################################################################################### use common; use partition_table qw(:types); -use partition_table_raw; +use partition_table::raw; use install_steps; use install_interactive; use install_any; @@ -379,16 +379,16 @@ _("DiskDrake failed to read correctly the partition table. Continue at your own risk!")); if (arch() =~ /ppc/ && detect_devices::get_mac_generation =~ /NewWorld/) { #- need to make bootstrap part if NewWorld machine - thx Pixel ;^) - if (defined $partition_table_mac::bootstrap_part) { + if (defined $partition_table::mac::bootstrap_part) { #- don't do anything if we've got the bootstrap setup #- otherwise, go ahead and create one somewhere in the drive free space } else { - if (defined $partition_table_mac::freepart_start && $partition_table_mac::freepart_size >= 1) { - my ($hd) = $partition_table_mac::freepart_device; - log::l("creating bootstrap partition on drive /dev/$hd->{device}, block $partition_table_mac::freepart_start"); - $partition_table_mac::bootstrap_part = $partition_table_mac::freepart_part; - log::l("bootstrap now at $partition_table_mac::bootstrap_part"); - fsedit::add($hd, { start => $partition_table_mac::freepart_start, size => 1 << 11, type => 0x401, mntpoint => '' }, $o->{all_hds}, { force => 1, primaryOrExtended => 'Primary' }); + if (defined $partition_table::mac::freepart_start && $partition_table::mac::freepart_size >= 1) { + my ($hd) = $partition_table::mac::freepart_device; + log::l("creating bootstrap partition on drive /dev/$hd->{device}, block $partition_table::mac::freepart_start"); + $partition_table::mac::bootstrap_part = $partition_table::mac::freepart_part; + log::l("bootstrap now at $partition_table::mac::bootstrap_part"); + fsedit::add($hd, { start => $partition_table::mac::freepart_start, size => 1 << 11, type => 0x401, mntpoint => '' }, $o->{all_hds}, { force => 1, primaryOrExtended => 'Primary' }); $new_bootstrap = 1; } else { $o->ask_warn('',_("No free space for 1MB bootstrap! Install will continue, but to boot your system, you'll need to create the bootstrap partition in DiskDrake")); diff --git a/perl-install/partition_table.pm b/perl-install/partition_table.pm index 0c1fd482c..7452a70cb 100644 --- a/perl-install/partition_table.pm +++ b/perl-install/partition_table.pm @@ -12,7 +12,7 @@ use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK @important_types @important_types2 @fie use common; -use partition_table_raw; +use partition_table::raw; use detect_devices; use log; @@ -462,8 +462,8 @@ sub read_one($$) { foreach ('empty', @parttype, 'lvm_PV', 'unknown') { /unknown/ and die "unknown partition table format on disk " . $hd->{file}; eval { - require("partition_table_$_.pm"); - bless $hd, "partition_table_$_"; + require("partition_table/$_.pm"); + bless $hd, "partition_table::$_"; ($pt, $info) = $hd->read($sector); log::l("found a $_ partition table on $hd->{file} at sector $sector"); }; @@ -486,7 +486,7 @@ sub read_one($$) { sub read($;$) { my ($hd, $clearall) = @_; if ($clearall) { - partition_table_raw::zero_MBR_and_dirty($hd); + partition_table::raw::zero_MBR_and_dirty($hd); return 1; } my $pt = read_one($hd, 0) or return 0; @@ -584,7 +584,7 @@ sub write { if ($hd->{needKernelReread} && ref($hd->{needKernelReread}) eq 'ARRAY' && $::isStandalone) { #- we've only been adding partitions. Try special add_partition (using BLKPG_ADD_PARTITION) local *F; - partition_table_raw::openit($hd, *F) or goto force_reread; + partition_table::raw::openit($hd, *F) or goto force_reread; foreach (@{$hd->{needKernelReread}}) { c::add_partition(fileno F, $_->{start}, $_->{size}, $_->{device} =~ /(\d+)$/) diff --git a/perl-install/partition_table/bsd.pm b/perl-install/partition_table/bsd.pm new file mode 100644 index 000000000..431d17f1f --- /dev/null +++ b/perl-install/partition_table/bsd.pm @@ -0,0 +1,147 @@ +package partition_table::bsd; # $Id$ + +use diagnostics; +use strict; +use vars qw(@ISA); + +@ISA = qw(partition_table::raw); + +use common; +use partition_table::raw; +use partition_table; +use c; + +#- very bad and rough handling :( +my %typeToDos = ( + 8 => 0x83, + 1 => 0x82, +); +my %typeFromDos = reverse %typeToDos; + +my ($main_format, $main_fields) = list2kv( + I => 'magic', + S => 'type', + S => 'subtype', + a16 => 'typename', + a16 => 'packname', + I => 'secsize', + I => 'nsectors', + I => 'ntracks', + I => 'ncylinders', + I => 'secpercyl', + I => 'secprtunit', + S => 'sparespertrack', + S => 'sparespercyl', + I => 'acylinders', + S => 'rpm', + S => 'interleave', + S => 'trackskew', + S => 'cylskew', + I => 'headswitch', + I => 'trkseek', + I => 'flags', + a20 => 'drivedata', + a20 => 'spare', + I => 'magic2', + S => 'checksum', + S => 'npartitions', + I => 'bbsize', + I => 'sbsize', + a128=> 'partitions', + a236=> 'blank', +); +$main_format = join '', @$main_format; + +my @fields = qw(size start fsize type frag cpg); +my $format = "I I I C C S"; +my $magic = 0x82564557; +my $nb_primary = 8; +my $offset = 0x40; + +sub read($$) { + 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"; + + 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; + + #- TODO verify checksum + + my $size = psizeof($format); + my @pt = map { + my %h; @h{@fields} = unpack $format, $_; + $h{type} = $typeToDos{$h{type}} || $h{type}; + \%h; + } $info{partitions} =~ /(.{$size})/g; + + #- check magic number + $info{magic} == $magic or die "bad magic number on disk $hd->{device}"; + $info{magic2} == $magic or die "bad magic number on disk $hd->{device}"; + + [ @pt ], \%info; +} + +# write the partition table (and extended ones) +# for each entry, it uses fields: start, size, type, active +sub write($$$;$) { + my ($hd, $sector, $pt, $info) = @_; + + #- 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; + } + + #- TODO compute checksum + + $info->{npartitions} = $nb_primary; #- is it ok? + + @$pt == $nb_primary or die "partition table does not have $nb_primary entries"; + $info->{partitions} = join '', map { + local $_->{type} = $typeFromDos{$_->{type}} || $_->{type}; + pack $format, @$_{@fields}; + } @$pt; + + syswrite F, pack($main_format, @$info{@$main_fields}), psizeof($main_format) or return 0; + 1; +} + +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 => $hd->cylinder_size(), + 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) }; +} + +sub first_usable_sector { 2048 } + +1; diff --git a/perl-install/partition_table/dos.pm b/perl-install/partition_table/dos.pm new file mode 100644 index 000000000..a6ad4be76 --- /dev/null +++ b/perl-install/partition_table/dos.pm @@ -0,0 +1,99 @@ +package partition_table::dos; # $Id$ + +use diagnostics; +use strict; +use vars qw(@ISA); + +@ISA = qw(partition_table::raw); + +use common; +use partition_table::raw; +use partition_table; +use c; + +my @fields = qw(active start_head start_sec start_cyl type end_head end_sec end_cyl start size); +my $format = "C8 V2"; +my $magic = "\x55\xAA"; +my $nb_primary = 4; + +my $offset = $common::SECTORSIZE - length($magic) - $nb_primary * common::psizeof($format); + +sub hasExtended { 1 } + +sub compute_CHS($$) { + my ($hd, $e) = @_; + my @l = qw(cyl head sec); + @$e{map { "start_$_" } @l} = $e->{start} || $e->{type} ? CHS2rawCHS($hd, sector2CHS($hd, $e->{start})) : (0,0,0); + @$e{map { "end_$_" } @l} = $e->{start} || $e->{type} ? CHS2rawCHS($hd, sector2CHS($hd, $e->{start} + $e->{size} - 1)) : (0,0,0); + 1; +} + +sub CHS2rawCHS { + my ($hd, $c, $h, $s) = @_; + if ($c > 1023) { + #- no way to have a #cylinder >= 1024 + $c = 1023; + $h = $hd->{geom}{heads} - 1; + $s = $hd->{geom}{sectors}; + } + ($c & 0xff, $h, $s | ($c >> 2 & 0xc0)); +} + +# returns (cylinder, head, sector) +sub sector2CHS { + my ($hd, $start) = @_; + my ($s, $h); + ($start, $s) = divide($start, $hd->{geom}{sectors}); + ($start, $h) = divide($start, $hd->{geom}{heads}); + ($start, $h, $s + 1); +} + +sub read { + 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 @pt = map { + sysread F, $tmp, psizeof($format) or die "error while reading partition table in sector $sector"; + my %h; @h{@fields} = unpack $format, $tmp; + \%h; + } (1..$nb_primary); + + #- check magic number + sysread F, $tmp, length $magic or die "error reading magic number on disk $hd->{device}"; + $tmp eq $magic or die "bad magic number on disk $hd->{device}"; + + [ @pt ]; +} + +# write the partition table (and extended ones) +# for each entry, it uses fields: start, size, type, active +sub write($$$;$) { + my ($hd, $sector, $pt) = @_; + + #- 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; + } + + @$pt == $nb_primary or die "partition table does not have $nb_primary entries"; + foreach (@$pt) { + compute_CHS($hd, $_); + local $_->{start} = $_->{local_start} || 0; + $_->{active} ||= 0; $_->{type} ||= 0; $_->{size} ||= 0; #- for no warning + syswrite F, pack($format, @$_{@fields}), psizeof($format) or return 0; + } + syswrite F, $magic, length $magic or return 0; + 1; +} + +sub clear_raw { { raw => [ ({}) x $nb_primary ] } } + +1; diff --git a/perl-install/partition_table/empty.pm b/perl-install/partition_table/empty.pm new file mode 100644 index 000000000..e90991684 --- /dev/null +++ b/perl-install/partition_table/empty.pm @@ -0,0 +1,36 @@ +package partition_table::empty; # $Id$ + +#- this is a mainly dummy partition table. If we find it's empty, we just call - +#- zero_MBR which will take care of bless'ing us to the partition table type best +#- suited + + +use diagnostics; +use strict; +use vars qw(@ISA); + +@ISA = qw(partition_table::raw); + +use common; +use partition_table::raw; +use partition_table; +use c; + + +sub read($$) { + 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"; + + #- check magic number + sysread F, $tmp, 512 or die "error reading magic number on disk $hd->{device}"; + $tmp eq substr($tmp, 0, 1) x 512 or die "bad magic number on disk $hd->{device}"; + + partition_table::raw::zero_MBR($hd); + + $hd->{primary}{raw}; +} + +1; diff --git a/perl-install/partition_table/gpt.pm b/perl-install/partition_table/gpt.pm new file mode 100644 index 000000000..01de8f8a7 --- /dev/null +++ b/perl-install/partition_table/gpt.pm @@ -0,0 +1,266 @@ +package partition_table::gpt; # $Id$ + +use diagnostics; +use strict; +use vars qw(@ISA); + +@ISA = qw(partition_table::raw); + +use common; +use partition_table::raw; +use partition_table::dos; +use partition_table; +use c; + +my %gpt_types = ( + 0x00 => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + 0x82 => "\x6d\xfd\x57\x06\xab\xa4\xc4\x43\x84\xe5\x09\x33\xc8\x4b\x4f\x4f", + 0x83 => "\xA2\xA0\xD0\xEB\xE5\xB9\x33\x44\x87\xC0\x68\xB6\xB7\x26\x99\xC7", + 0x8e => "\x79\xd3\xd6\xe6\x07\xf5\xc2\x44\xa2\x3c\x23\x8f\x2a\x3d\xf9\x28", + 0xfd => "\x0f\x88\x9d\xa1\xfc\x05\x3b\x4d\xa0\x06\x74\x3f\x0f\x84\x91\x1e", + 0xef => "\x28\x73\x2A\xC1\x1F\xF8\xd2\x11\xBA\x4B\x00\xA0\xC9\x3E\xC9\x3B", + # legacy_partition_table => "\x41\xEE\x4D\x02\xE7\x33\xd3\x11\x9D\x69\x00\x08\xC7\x81\xF3\x9F" + # PARTITION_MSFT_RESERVED_GUID "\x16\xE3\xC9\xE3\x5C\x0B\xB8\x4D\x81\x7D\xF9\x2D\xF0\x02\x15\xAE" + #PARTITION_RESERVED_GUID "\x39\x33\xa6\x8d\x07\x00\xc0\x60\xc4\x36\x08\x3a\xc8\x23\x09\x08" +); + +my $current_revision = 0x00010200; +my ($main_format, $main_fields) = list2kv( + a8 => 'magic', + V => 'revision', + V => 'headerSize', + V => 'headerCRC32', + a4 => 'blank1', + Q => 'myLBA', + Q => 'alternateLBA', + Q => 'firstUsableLBA', + Q => 'lastUsableLBA', + a16 => 'guid', + Q => 'partitionEntriesLBA', + V => 'nbPartitions', + V => 'partitionEntrySize', + V => 'partitionEntriesCRC32', +); + +my ($partitionEntry_format, $partitionEntry_fields) = list2kv( + a16 => 'gpt_type', + a16 => 'guid', + Q => 'start', + Q => 'ending', + a8 => 'efi_attributes', + a72 => 'name', +); + +my ($guid_format, $guid_fields) = list2kv( + N => 'time_low', + n => 'time_mid', + n => 'time_hi_and_version', + n => 'clock_seq', + a6 => 'node', +); + +$_ = join('', @$_) foreach $main_format, $partitionEntry_format, $guid_format; + +my $magic = "EFI PART"; + +sub generate_guid { + my $tmp; + local *F; + open F, devices::make("random") or die "Could not open /dev/random for GUID generation"; + read F, $tmp, psizeof($guid_format); + + my %guid; @guid{@$guid_fields} = unpack $guid_format, $tmp; + $guid{clock_seq} = ($guid{clock_seq} & 0x3fff) | 0x8000; + $guid{time_hi_and_version} = ($guid{time_hi_and_version} & 0x0fff) | 0x4000; + pack($guid_format, @guid{@$guid_fields}); +} + +sub crc32 { + my ($buffer) = @_; + + my $crc = 0xFFFFFFFF; + foreach (unpack "C*", $buffer) { + my $subcrc = ($crc ^ $_) & 0xFF; + for (my $j = 8; $j > 0; $j--){ + my $b = $subcrc & 1; + $subcrc = ($subcrc >> 1) & 0x7FFFFFFF; + $subcrc = $subcrc ^ 0xEDB88320 if $b; + } + $crc = ($crc >> 8) ^ $subcrc; + } + $crc ^ 0xFFFFFFFF; +} + +sub compute_headerCRC32 { + my ($info) = @_; + local $info->{headerCRC32} = 0; + crc32(pack($main_format, @$info{@$main_fields})); +} + +sub read_header { + my ($sector, $F) = @_; + my $tmp; + + c::lseek_sector(fileno($F), $sector, 0) 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"; + my %info; @info{@$main_fields} = unpack $main_format, $tmp; + + $info{magic} eq $magic or die "bad magic number on disk $hd->{device}"; + $info{myLBA} == $sector or die "myLBA is not the same"; + $info{headerSize} == psizeof($main_format) or die "bad partition table header size"; + $info{partitionEntrySize} == psizeof($partitionEntry_format) or die "bad partitionEntrySize"; + $info{revision} <= $current_revision or log::l("oops, this is a new GPT revision ($info{revision} > $current_revision)"); + + $info{headerCRC32} == compute_headerCRC32(\%info) or die "bad partition table checksum"; + \%info +} + +sub read_partitionEntries { + my ($info, $F) = @_; + my $tmp; + + c::lseek_sector(fileno($F), $info->{partitionEntriesLBA}, 0) or die "can't seek to sector partitionEntriesLBA"; + sysread $F, $tmp, psizeof($partitionEntry_format) * $info->{nbPartitions} or die "error while reading partition table in sector $info->{partitionEntriesLBA}"; + $info->{partitionEntriesCRC32} == crc32($tmp) or die "bad partition entries checksum"; + + c::lseek_sector(fileno($F), $info->{partitionEntriesLBA}, 0) or die "can't seek to sector partitionEntriesLBA"; + my %gpt_types_rev = reverse %gpt_types; + my @pt = + map { + sysread $F, $tmp, psizeof($partitionEntry_format) or die "error while reading partition table in sector $info->{partitionEntriesLBA}"; + my %h; @h{@$partitionEntry_fields} = unpack $partitionEntry_format, $tmp; + $h{size} = $h{ending} - $h{start} + 1; + $h{type} = $gpt_types_rev{$h{gpt_type}}; + $h{type} = 0x100 if !defined $h{type}; + \%h; + } (1 .. $info->{nbPartitions}); + \@pt; +} + +sub read { + my ($hd, $sector) = @_; + my $tmp; + + my $l = partition_table::dos::read($hd, $sector); + my @l = grep { $_->{size} && $_->{type} && !partition_table::isExtended($_) } @$l; + @l == 1 or die "bad PMBR"; + $l[0]{type} == 0xee or die "bad PMBR"; + my $myLBA = $l[0]{start}; + + local *F; partition_table::raw::openit($hd, *F) or die "failed to open device"; + my $info1 = eval { read_header($myLBA, *F) }; + my $info2 = eval { read_header($info1->{alternateLBA} || $l[0]{start} + $l[0]{size} - 1, *F) }; #- what about using $hd->{totalsectors} ??? + my $info = $info1 || { %$info2, myLBA => $info2->{alternateLBA}, alternateLBA => $info2->{myLBA}, partitionEntriesLBA => $info2->{alternateLBA} + 1 } or die; + my $pt = $info1 && $info2 ? + eval { $info1 && read_partitionEntries($info1, *F) } || read_partitionEntries($info2, *F) : + read_partitionEntries($info, *F); + $hd->raw_removed($pt); + + $pt, $info; +} + +# write the partition table (and extended ones) +# for each entry, it uses fields: start, size, type, active +sub write { + my ($hd, $sector, $pt, $info) = @_; + + foreach (@$pt) { + $_->{ending} = $_->{start} + $_->{size} - 1; + $_->{guid} ||= generate_guid; + $_->{gpt_type} = $gpt_types{$_->{type}} || $_->{gpt_type} || $gpt_types{0x83}; + } + my $partitionEntries = join('', map { + pack($partitionEntry_format, @$_{@$partitionEntry_fields}) + } (@$pt, ({}) x ($info->{nbPartitions} - @$pt))); + + $info->{partitionEntriesCRC32} = crc32($partitionEntries); + $info->{headerCRC32} = compute_headerCRC32($info); + + my $info2 = { %$info, + myLBA => $info->{alternateLBA}, alternateLBA => $info->{myLBA}, + partitionEntriesLBA => $info->{alternateLBA} - psizeof($partitionEntry_format) * $info->{nbPartitions} / 512, + }; + $info2->{headerCRC32} = compute_headerCRC32($info2); + + { + # write the PMBR + my $pmbr = partition_table::dos::clear_raw(); + $pmbr->{raw}[0] = { type => 0xee, local_start => $info->{myLBA}, size => $info->{alternateLBA} - $info->{myLBA} + 1 }; + partition_table::dos::write($hd, $sector, $pmbr->{raw}); + } + + local *F; + partition_table::raw::openit($hd, *F, 2) or die "error opening device $hd->{device} for writing"; + + c::lseek_sector(fileno(F), $info->{myLBA}, 0) or return 0; + #- pad with 0's + syswrite F, pack($main_format, @$info{@$main_fields}) . "\0" x 512, 512 or return 0; + + c::lseek_sector(fileno(F), $info->{alternateLBA}, 0) or return 0; + #- pad with 0's + syswrite F, pack($main_format, @$info2{@$main_fields}) . "\0" x 512, 512 or return 0; + + c::lseek_sector(fileno(F), $info->{partitionEntriesLBA}, 0) or return 0; + syswrite F, $partitionEntries or return 0; + + c::lseek_sector(fileno(F), $info2->{partitionEntriesLBA}, 0) or return 0; + syswrite F, $partitionEntries or return 0; + + common::sync(); + 1; +} + +sub raw_removed { + my ($hd, $raw) = @_; + @$raw = grep { $_->{size} && $_->{type} } @$raw; +} +sub can_raw_add { + my ($hd) = @_; + @{$hd->{primary}{raw}} < $hd->{primary}{info}{nbPartitions}; +} +sub raw_add { + my ($hd, $raw, $part) = @_; + $hd->can_raw_add or die "raw_add: partition table already full"; + push @$raw, $part; +} + +sub adjustStart {} +sub adjustEnd {} + +sub first_usable_sector { + my ($hd) = @_; + $hd->{primary}{info}{firstUsableLBA}; +} +sub last_usable_sector { + my ($hd) = @_; + $hd->{primary}{info}{lastUsableLBA} + 1; +} + +sub info { + my ($hd) = @_; + my $nb_sect = 32; + + #- build a default suitable partition table, + #- checksum will be built when writing on disk. + { + magic => $magic, + revision => $current_revision, + headerSize => psizeof($main_format), + myLBA => 1, + alternateLBA => $hd->{totalsectors} - 1, + firstUsableLBA => $nb_sect + 2, + lastUsableLBA => $hd->{totalsectors} - $nb_sect - 2, + guid => generate_guid, + partitionEntriesLBA => 2, + nbPartitions => $nb_sect * 512 / psizeof($partitionEntry_format), + partitionEntrySize => psizeof($partitionEntry_format), + }; +} + +sub clear_raw { + my ($hd) = @_; + { raw => [], info => info($hd) }; +} + +1; diff --git a/perl-install/partition_table/lvm_PV.pm b/perl-install/partition_table/lvm_PV.pm new file mode 100644 index 000000000..4a55d3810 --- /dev/null +++ b/perl-install/partition_table/lvm_PV.pm @@ -0,0 +1,43 @@ +package partition_table::lvm; # $Id$ + +use diagnostics; +use strict; + +our @ISA = qw(partition_table::raw); + +use partition_table::raw; +use c; + +my $magic = "HM\1\0"; +my $offset = 0; + + +#- Allows people having PVs on unpartitioned disks to install +#- (but no way to create such beasts) +#- +#- another way to handle them would be to ignore those disks, +#- but this would make those hds unshown in diskdrake, +#- disallowing to zero_MBR, clearing this PV + + +sub read { + my ($hd, $sector) = @_; + + 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"; + + sysread F, my $tmp, length $magic or die "error reading magic number on disk $hd->{file}"; + $tmp eq $magic or die "bad magic number on disk $hd->{file}"; + + [ ]; +} + +sub write { + die "ERROR: should not be writing raw disk lvm PV!!"; +} + +sub clear_raw { + die "ERROR: should not be creating new raw disk lvm PV!!"; +} + +1; diff --git a/perl-install/partition_table/mac.pm b/perl-install/partition_table/mac.pm new file mode 100644 index 000000000..89fb9ceaf --- /dev/null +++ b/perl-install/partition_table/mac.pm @@ -0,0 +1,398 @@ +package partition_table::mac; # $Id$ + +use diagnostics; +#use strict; - fixed other PPC code to comply, but program bails on empty partition table - sbenedict +use vars qw(@ISA $freepart_device $bootstrap_part $freepart_start $freepart_size $freepart_part $macos_part); + +@ISA = qw(partition_table::raw); + +use common; +use partition_table::raw; +use partition_table; +use c; + +my %typeToDos = ( + "Apple_partition_map" => 0x401, + "Apple_Bootstrap" => 0x401, + "Apple_Driver43" => 0x401, + "Apple_Driver_IOKit" => 0x401, + "Apple_Patches" => 0x401, + "Apple_HFS" => 0x402, + "Apple_UNIX_SVR2" => 0x83, + "Apple_UNIX_SVR2" => 0x183, + "Apple_UNIX_SVR2" => 0x283, + "Apple_UNIX_SVR2" => 0x383, + "Apple_UNIX_SVR2" => 0x483, + "Apple_Free" => 0x0, +); +my %typeFromDos = reverse %typeToDos; + + +my ($bz_format, $bz_fields) = list2kv( + n => 'bzSig', + n => 'bzBlkSize', + N => 'bzBlkCnt', + n => 'bzDevType', + n => 'bzDevID', + N => 'bzReserved', + n => 'bzDrvrCnt', +); +$bz_format = join '', @$bz_format; + + +my ($dd_format, $dd_fields) = list2kv( + N => 'ddBlock', + n => 'ddSize', + n => 'ddType', +); +$dd_format = join '', @$dd_format; + + +my ($p_format, $p_fields) = list2kv( + n => 'pSig', + n => 'pSigPad', + N => 'pMapEntry', + N => 'pPBlockStart', + N => 'pPBlocks', + + a32 => 'pName', + a32 => 'pType', + + N => 'pLBlockStart', + N => 'pLBlocks', + N => 'pFlags', + N => 'pBootBlock', + N => 'pBootBytes', + + N => 'pAddrs1', + N => 'pAddrs2', + N => 'pAddrs3', + N => 'pAddrs4', + N => 'pChecksum', + + a16 => 'pProcID', + a128 => 'pBootArgs', + a248 => 'pReserved', +); +$p_format = join '', @$p_format; + +my $magic = 0x4552; +my $pmagic = 0x504D; + +sub first_usable_sector { 1 } + +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) = @_; +} + +sub read($$) { + 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"; + + 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"; + my %dd; @dd{@$dd_fields} = unpack $dd_format, $tmp; + push @{$info{ddMap}}, \%dd; + } + + #- check magic number + $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"; + $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"; + $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"; + + my @pt; + for ($i=0;$i<$partmapsize;$i++) { + my $part; + 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; + if ($i < $numparts && $h{pSig} eq $pmagic) { + + $h{size} = ($h{pPBlocks} * $info{bzBlkSize}) / 512; + $h{start} = ($h{pPBlockStart} * $info{bzBlkSize}) / 512; + + if ($h{pType} =~ /^Apple_UNIX_SVR2/i) { + $h{pName} =~ /swap/i ? ($h{type} = 0x82) : ($h{type} = 0x83); + } elsif ($h{pType} =~ /^Apple_Free/i) { + #- need to locate a 1MB partition to setup a bootstrap on + if (defined $freepart_start && $freepart_size >= 1) { + #- already found a suitable partition + } else { + $freepart_start = $h{start}; + $freepart_size = $h{size}/2048; + $freepart_device = $hd; + $freepart_part = "/dev/" . $hd->{device} . ($i+1); + log::l("free apple partition found on drive /dev/$freepart_device->{device}, block $freepart_start, size $freepart_size"); + } + $h{type} = 0x0; + $h{pName} = 'Extra'; + } elsif ($h{pType} =~ /^Apple_HFS/i) { + $h{type} = 0x402; + if (defined $macos_part) { + #- swag at identifying MacOS - 1st HFS partition + } else { + $macos_part = "/dev/" . $hd->{device} . ($i+1); + log::l("found MacOS at partition $macos_part"); + } + } elsif ($h{pType} =~ /^Apple_Partition_Map/i) { + $h{type} = 0x401; + $h{isMap} = 1; + } elsif ($h{pType} =~ /^Apple_Bootstrap/i) { + $h{type} = 0x401; + $h{isBoot} = 1; + if (defined $bootstrap_part) { + #found a bootstrap already - use it, but log the find + log::l("found another apple bootstrap at partition /dev/$hd->{device}" . ($i+1)); + } else { + $bootstrap_part = "/dev/" . $hd->{device} . ($i+1); + log::l("found apple bootstrap at partition $bootstrap_part"); + } + } else { + $h{type} = 0x401; + $h{isDriver} = 1; + }; + + # Let's see if this partition is a driver. + foreach (@{$info{ddMap}}) { + $_->{ddBlock} == $h{pPBlockStart} and $h{isDriver} = 1; + } + + } + \%h; + } [ $part ]; + }; + + [ @pt ], \%info; +} + +sub write($$$;$) { + my ($hd, $sector, $pt, $info) = @_; + + #- 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, 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"; + push @partstowrite, $part; + + # Now go thru the partitions, sort and fill gaps. + my $last; + while ($part) { + $last = $part; + $part = &partition_table::next($hd, $part); + $part or last; + + if ($last->{start} + $last->{size} < $part->{start}) { + #There is a gap between partitions. Fill it and move on. + push @partstowrite, { + 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, + 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. + $info->{bzDrvrCnt} = 0; + my @ddstowrite; + my $dd; + foreach $dd (@{$info->{ddMap}}) { + foreach (@partstowrite) { + if ($dd->{ddBlock} == $_->{pPBlockStart}) { + push @ddstowrite, $dd; + $info->{bzDrvrCnt}++; + last; + } + } + } + + # Now let's write our first block. + 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; + } + # zero the rest of the data in the first block. + foreach ( 1 .. (494 - ((@ddstowrite) * 8))) { + syswrite F, "\0", 1 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}) { + # The values we need to write to disk are not defined. Let's make them up. + $_->{pSig} = $pmagic; + $_->{pSigPad} = 0; + $_->{pPBlockStart} = ($_->{start} * 512) / $info->{bzBlkSize}; + $_->{pPBlocks} = ($_->{size} * 512) / $info->{bzBlkSize}; + $_->{pLBlockStart} = 0; + $_->{pLBlocks} = $_->{pPBlocks}; + $_->{pBootBlock} = 0; + $_->{pBootBytes} = 0; + $_->{pAddrs1} = 0; + $_->{pAddrs2} = 0; + $_->{pAddrs3} = 0; + $_->{pAddrs4} = 0; + $_->{pChecksum} = 0; + $_->{pProcID} = "\0"; + $_->{pBootArgs} = "\0"; + $_->{pReserved} = "\0"; + + if ($_->{type} == 0x402) { + $_->{pType} = "Apple_HFS"; + $_->{pName} = "MacOS"; + $_->{pFlags} = 0x4000037F; + } elsif ($_->{type} == 0x401 && $_->{start} == 1) { + $_->{pType} = "Apple_Partition_Map"; + $_->{pName} = "Apple"; + $_->{pFlags} = 0x33; + } elsif ($_->{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); + $bootstrap_part = "/dev/" . $_->{device}; + } elsif ($_->{type} == 0x82) { + $_->{pType} = "Apple_UNIX_SVR2"; + $_->{pName} = "swap"; + $_->{pFlags} = 0x33; + } elsif ($_->{type} == 0x83) { + $_->{pType} = "Apple_UNIX_SVR2"; + $_->{pName} = "Linux Native"; + $_->{pFlags} = 0x33; + } elsif ($_->{type} == 0x183) { + $_->{pType} = "Apple_UNIX_SVR2"; + $_->{pName} = "Linux ReiserFS"; + $_->{pFlags} = 0x33; + } elsif ($_->{type} == 0x283) { + $_->{pType} = "Apple_UNIX_SVR2"; + $_->{pName} = "Linux XFS"; + $_->{pFlags} = 0x33; + } elsif ($_->{type} == 0x383) { + $_->{pType} = "Apple_UNIX_SVR2"; + $_->{pName} = "Linux JFS"; + $_->{pFlags} = 0x33; + } elsif ($_->{type} == 0x483) { + $_->{pType} = "Apple_UNIX_SVR2"; + $_->{pName} = "Linux ext3"; + $_->{pFlags} = 0x33; + } elsif ($_->{type} == 0x0) { + $_->{pType} = "Apple_Free"; + $_->{pName} = "Extra"; + $_->{pFlags} = 0x31; + } + }; + $_->{pMapEntry} = @partstowrite; + syswrite F, pack($p_format, @$_{@$p_fields}), psizeof($p_format) or return 0; + } + + common::sync(); + + 1; +} + +sub info { + my ($hd) = @_; + + # - Build the first block of the drive. + + my $info = { + bzSig => $magic, + bzBlkSize => 512, + bzBlkCnt => $hd->{totalsectors}, + bzDevType => 0, + bzDevID => 0, + bzReserved => 0, + bzDrvrCnt => 0, + }; + + $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. + $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; +} + +1; diff --git a/perl-install/partition_table/raw.pm b/perl-install/partition_table/raw.pm new file mode 100644 index 000000000..3be68fe56 --- /dev/null +++ b/perl-install/partition_table/raw.pm @@ -0,0 +1,192 @@ +package partition_table::raw; # $Id$ + +use diagnostics; +use strict; + +use common; +use devices; +use detect_devices; +use log; +use c; + +my @MBR_signatures = ( +if_(arch() =~ /ppc/, + map { [ 'yaboot', 0, "PM", 0x200 * $_ + 0x10, "bootstrap\0" ] } 0 .. 61 +), + [ 'empty', 0, "\0\0\0\0" ], + [ 'grub', 0, "\xEBG", 0x17d, "stage1 \0" ], + [ 'grub', 0, "\xEBH", 0x17e, "stage1 \0" ], + [ 'grub', 0, "\xEBH", 0x18a, "stage1 \0" ], + [ 'grub', 0, "\xEBH", 0x181, "GRUB \0" ], + [ 'lilo', 0x2, "LILO" ], + [ 'lilo', 0x6, "LILO" ], + [ 'grub', 0x6, "GRUB" ], + [ 'osbs', 0x2, "OSBS" ], #- http://www.prz.tu-berlin.de/~wolf/os-bs.html + [ 'pqmagic', 0xef, "PQV" ], + [ 'BootStar', 0x130, "BootStar:" ], + [ 'DocsBoot', 0x148, 'DocsBoot' ], + [ 'system_commander', 0x1ad, "SYSCMNDRSYS" ], + [ 'Be Os', 0x24, 'Boot Manager' ], + [ 'TimO', 0, 'IBM Thinkpad hibernation partition' ], + [ 'dos', 0xa0, "\x25\x03\x4E\x02\xCD\x13" ], + [ 'dos', 0xa0, "\x00\xB4\x08\xCD\x13\x72" ], #- nt2k's + [ 'dos', 0x60, "\xBB\x00\x7C\xB8\x01\x02\x57\xCD\x13\x5F\x73\x0C\x33\xC0\xCD\x13" ], #- nt's + [ 'dos', 0x70, "\x0C\x33\xC0\xCD\x13\x4F\x75\xED\xBE\xA3" ], + [ 'freebsd', 0xC0, "\x00\x30\xE4\xCD\x16\xCD\x19\xBB\x07\x00\xB4" ], + [ 'freebsd', 0x160, "\x6A\x10\x89\xE6\x48\x80\xCC\x40\xCD\x13" ], + [ 'dummy', 0xAC, "\x0E\xB3\x07\x56\xCD\x10\x5E\xEB" ], #- caldera? + [ 'ranish', 0x100, "\x6A\x10\xB4\x42\x8B\xF4\xCD\x13\x8B\xE5\x73" ], + [ 'os2', 0x1c2, "\xA" ], +); + +sub typeOfMBR($) { typeFromMagic(devices::make($_[0]), @MBR_signatures) } +sub typeOfMBR_($) { typeFromMagic($_[0], @MBR_signatures) } + +sub hasExtended { 0 } + +sub cylinder_size($) { + my ($hd) = @_; + $hd->{geom}{sectors} * $hd->{geom}{heads}; +} +sub first_usable_sector { 1 } +sub last_usable_sector { + my ($hd) = @_; + $hd->{totalsectors}; +} + +#- default method for starting a partition, only head size or twice +#- is allowed for starting a partition after a cylinder boundarie. +sub adjustStart($$) { + my ($hd, $part) = @_; + my $end = $part->{start} + $part->{size}; + + $part->{start} = round_up($part->{start}, + $part->{start} % cylinder_size($hd) < 2 * $hd->{geom}{sectors} ? + $hd->{geom}{sectors} : cylinder_size($hd)); + $part->{size} = $end - $part->{start}; + $part->{size} > 0 or die "adjustStart get a too small partition to handle correctly"; +} +#- adjusting end to match a cylinder boundary, two methods are used and must +#- match at the end, else something is wrong and nothing will be done on +#- partition table. +#- $end2 is computed by removing 2 (or only 1 if only 2 heads on drive) groups +#- of sectors, this is necessary to handle extended partition where logical +#- partition start after 1 (or 2 accepted) groups of sectors (typically 63). +#- $end is floating (is not on cylinder boudary) so we have to choice a good +#- candidate, $end1 or $end2 should always be good except $end1 for small +#- partition size. +sub adjustEnd($$) { + my ($hd, $part) = @_; + my $end = $part->{start} + $part->{size}; + $end > $hd->{geom}{cylinders} * cylinder_size($hd) && $end <= $hd->{totalsectors} and return; + my $end1 = round_down($end, cylinder_size($hd)); + my $end2 = round_up($end - ($hd->{geom}{heads} > 2 ? 2 : 1) * $hd->{geom}{sectors}, cylinder_size($hd)); + $end2 <= $hd->{geom}{cylinders} * cylinder_size($hd) or die "adjustEnd go beyond end of device geometry ($end2 > $hd->{totalsectors})"; + $part->{size} = ($end1 - $part->{start} > cylinder_size($hd) ? $end1 : $end2) - $part->{start}; + $part->{size} > 0 or die "adjustEnd get a too small partition to handle correctly"; +} + +sub get_geometry($) { + my ($dev) = @_; + my $g = ""; + + local *F; sysopen F, $dev, 0 or return; + ioctl(F, c::HDIO_GETGEO(), $g) or return; + my %geom; @geom{qw(heads sectors cylinders start)} = unpack "CCSL", $g; + $geom{totalcylinders} = $geom{cylinders}; + + my $total; + #- $geom{cylinders} is no good (only a ushort, that means less than 2^16 => at best 512MB) + if ($total = c::total_sectors(fileno F)) { + $geom{cylinders} = int $total / $geom{heads} / $geom{sectors}; + } else { + $total = $geom{heads} * $geom{sectors} * $geom{cylinders} + } + + { geom => \%geom, totalsectors => $total }; +} + +sub openit($$;$) { sysopen $_[1], $_[0]{file}, $_[2] || 0; } + +# cause kernel to re-read partition table +sub kernel_read($) { + my ($hd) = @_; + common::sync(); + local *F; openit($hd, *F) or return 0; + common::sync(); sleep(1); + $hd->{rebootNeeded} = !ioctl(F, c::BLKRRPART(), 0); + common::sync(); + close F; + common::sync(); sleep(1); +} + +sub raw_removed { + my ($hd, $raw) = @_; +} +sub can_raw_add { + my ($hd) = @_; + $_->{size} || $_->{type} or return 1 foreach @{$hd->{primary}{raw}}; + 0; +} +sub raw_add { + my ($hd, $raw, $part) = @_; + + foreach (@$raw) { + $_->{size} || $_->{type} and next; + $_ = $part; + return; + } + die "raw_add: partition table already full"; +} + +sub zero_MBR { + my ($hd) = @_; + #- force the standard partition type for the architecture + my $type = arch() =~ /ia64/ ? 'gpt' : arch() eq "alpha" ? "bsd" : arch() =~ /^sparc/ ? "sun" : arch() eq "ppc" ? "mac" : "dos"; + #- override standard mac type on PPC for IBM machines to dos + $type = "dos" if (arch() =~ /ppc/ && detect_devices::get_mac_model() =~ /^IBM/); + require("partition_table/$type.pm"); + bless $hd, "partition_table::$type"; + $hd->{primary} = $hd->clear_raw(); + delete $hd->{extended}; +} + +sub zero_MBR_and_dirty { + my ($hd) = @_; + zero_MBR($hd); + $hd->{isDirty} = $hd->{needKernelReread} = 1; + +} + +#- ugly stuff needed mainly for Western Digital IDE drives +#- try writing what we've just read, yells if it fails +#- testing on last sector of head #0 (unused in 99% cases) +#- +#- return false if the device can't be written to (especially for Smartmedia) +sub test_for_bad_drives { + my ($hd) = @_; + + log::l("test_for_bad_drives($hd->{file})"); + my $sector = $hd->{geom}{sectors} - 1; + + + local *F; openit($hd, *F, 2) or die "can't open device"; + + my $seek = sub { + c::lseek_sector(fileno(F), $sector, 0) or die "seeking to sector $sector failed"; + }; + my $tmp; + + &$seek; sysread F, $tmp, $SECTORSIZE or die "test_for_bad_drives: can't even read ($!)"; + &$seek; syswrite F, $tmp or die "test_for_bad_drives: can't even write ($!)"; + + my $tmp2; + &$seek; sysread F, $tmp2, $SECTORSIZE or die "test_for_bad_drives: can't even read again ($!)"; + $tmp eq $tmp2 or die +_("Something bad is happening on your drive. +A test to check the integrity of data has failed. +It means writing anything on the disk will end up with random trash"); + 1; +} + +1; diff --git a/perl-install/partition_table/sun.pm b/perl-install/partition_table/sun.pm new file mode 100644 index 000000000..6944130dc --- /dev/null +++ b/perl-install/partition_table/sun.pm @@ -0,0 +1,201 @@ +package partition_table::sun; # $Id$ + +use diagnostics; +use strict; +use vars qw(@ISA); + +@ISA = qw(partition_table::raw); + +use common; +use partition_table::raw; +use partition_table; +use c; + +my ($main_format, $main_fields) = list2kv( + a128 => 'info', + a14 => 'spare0', + a32 => 'infos', + a246 => 'spare1', + n => 'rspeed', + n => 'pcylcount', + n => 'sparecyl', + a4 => 'spare2', + n => 'ilfact', + n => 'ncyl', + n => 'nacyl', + n => 'ntrks', + n => 'nsect', + a4 => 'spare3', + a64 => 'partitions', + n => 'magic', + n => 'csum', +); +$main_format = join '', @$main_format; + +my ($fields1, $fields2) = ([ qw(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 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; + + 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"; + + 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 + $info{magic} == $magic or die "bad magic number on disk $hd->{device}"; + + #- 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} ]; + + [ @pt ], \%info; +} + +# write the partition table (and extended ones) +# 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; + } + + ($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; + 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; + + common::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, + }; + + $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; +} + +1; diff --git a/perl-install/partition_table_bsd.pm b/perl-install/partition_table_bsd.pm deleted file mode 100644 index aa9b9eb29..000000000 --- a/perl-install/partition_table_bsd.pm +++ /dev/null @@ -1,147 +0,0 @@ -package partition_table_bsd; # $Id$ - -use diagnostics; -use strict; -use vars qw(@ISA); - -@ISA = qw(partition_table_raw); - -use common; -use partition_table_raw; -use partition_table; -use c; - -#- very bad and rough handling :( -my %typeToDos = ( - 8 => 0x83, - 1 => 0x82, -); -my %typeFromDos = reverse %typeToDos; - -my ($main_format, $main_fields) = list2kv( - I => 'magic', - S => 'type', - S => 'subtype', - a16 => 'typename', - a16 => 'packname', - I => 'secsize', - I => 'nsectors', - I => 'ntracks', - I => 'ncylinders', - I => 'secpercyl', - I => 'secprtunit', - S => 'sparespertrack', - S => 'sparespercyl', - I => 'acylinders', - S => 'rpm', - S => 'interleave', - S => 'trackskew', - S => 'cylskew', - I => 'headswitch', - I => 'trkseek', - I => 'flags', - a20 => 'drivedata', - a20 => 'spare', - I => 'magic2', - S => 'checksum', - S => 'npartitions', - I => 'bbsize', - I => 'sbsize', - a128=> 'partitions', - a236=> 'blank', -); -$main_format = join '', @$main_format; - -my @fields = qw(size start fsize type frag cpg); -my $format = "I I I C C S"; -my $magic = 0x82564557; -my $nb_primary = 8; -my $offset = 0x40; - -sub read($$) { - 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"; - - 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; - - #- TODO verify checksum - - my $size = psizeof($format); - my @pt = map { - my %h; @h{@fields} = unpack $format, $_; - $h{type} = $typeToDos{$h{type}} || $h{type}; - \%h; - } $info{partitions} =~ /(.{$size})/g; - - #- check magic number - $info{magic} == $magic or die "bad magic number on disk $hd->{device}"; - $info{magic2} == $magic or die "bad magic number on disk $hd->{device}"; - - [ @pt ], \%info; -} - -# write the partition table (and extended ones) -# for each entry, it uses fields: start, size, type, active -sub write($$$;$) { - my ($hd, $sector, $pt, $info) = @_; - - #- 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; - } - - #- TODO compute checksum - - $info->{npartitions} = $nb_primary; #- is it ok? - - @$pt == $nb_primary or die "partition table does not have $nb_primary entries"; - $info->{partitions} = join '', map { - local $_->{type} = $typeFromDos{$_->{type}} || $_->{type}; - pack $format, @$_{@fields}; - } @$pt; - - syswrite F, pack($main_format, @$info{@$main_fields}), psizeof($main_format) or return 0; - 1; -} - -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 => $hd->cylinder_size(), - 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) }; -} - -sub first_usable_sector { 2048 } - -1; diff --git a/perl-install/partition_table_dos.pm b/perl-install/partition_table_dos.pm deleted file mode 100644 index ced50826f..000000000 --- a/perl-install/partition_table_dos.pm +++ /dev/null @@ -1,99 +0,0 @@ -package partition_table_dos; # $Id$ - -use diagnostics; -use strict; -use vars qw(@ISA); - -@ISA = qw(partition_table_raw); - -use common; -use partition_table_raw; -use partition_table; -use c; - -my @fields = qw(active start_head start_sec start_cyl type end_head end_sec end_cyl start size); -my $format = "C8 V2"; -my $magic = "\x55\xAA"; -my $nb_primary = 4; - -my $offset = $common::SECTORSIZE - length($magic) - $nb_primary * common::psizeof($format); - -sub hasExtended { 1 } - -sub compute_CHS($$) { - my ($hd, $e) = @_; - my @l = qw(cyl head sec); - @$e{map { "start_$_" } @l} = $e->{start} || $e->{type} ? CHS2rawCHS($hd, sector2CHS($hd, $e->{start})) : (0,0,0); - @$e{map { "end_$_" } @l} = $e->{start} || $e->{type} ? CHS2rawCHS($hd, sector2CHS($hd, $e->{start} + $e->{size} - 1)) : (0,0,0); - 1; -} - -sub CHS2rawCHS { - my ($hd, $c, $h, $s) = @_; - if ($c > 1023) { - #- no way to have a #cylinder >= 1024 - $c = 1023; - $h = $hd->{geom}{heads} - 1; - $s = $hd->{geom}{sectors}; - } - ($c & 0xff, $h, $s | ($c >> 2 & 0xc0)); -} - -# returns (cylinder, head, sector) -sub sector2CHS { - my ($hd, $start) = @_; - my ($s, $h); - ($start, $s) = divide($start, $hd->{geom}{sectors}); - ($start, $h) = divide($start, $hd->{geom}{heads}); - ($start, $h, $s + 1); -} - -sub read { - 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 @pt = map { - sysread F, $tmp, psizeof($format) or die "error while reading partition table in sector $sector"; - my %h; @h{@fields} = unpack $format, $tmp; - \%h; - } (1..$nb_primary); - - #- check magic number - sysread F, $tmp, length $magic or die "error reading magic number on disk $hd->{device}"; - $tmp eq $magic or die "bad magic number on disk $hd->{device}"; - - [ @pt ]; -} - -# write the partition table (and extended ones) -# for each entry, it uses fields: start, size, type, active -sub write($$$;$) { - my ($hd, $sector, $pt) = @_; - - #- 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; - } - - @$pt == $nb_primary or die "partition table does not have $nb_primary entries"; - foreach (@$pt) { - compute_CHS($hd, $_); - local $_->{start} = $_->{local_start} || 0; - $_->{active} ||= 0; $_->{type} ||= 0; $_->{size} ||= 0; #- for no warning - syswrite F, pack($format, @$_{@fields}), psizeof($format) or return 0; - } - syswrite F, $magic, length $magic or return 0; - 1; -} - -sub clear_raw { { raw => [ ({}) x $nb_primary ] } } - -1; diff --git a/perl-install/partition_table_empty.pm b/perl-install/partition_table_empty.pm deleted file mode 100644 index 6c922ffb7..000000000 --- a/perl-install/partition_table_empty.pm +++ /dev/null @@ -1,36 +0,0 @@ -package partition_table_empty; # $Id$ - -#- this is a mainly dummy partition table. If we find it's empty, we just call - -#- zero_MBR which will take care of bless'ing us to the partition table type best -#- suited - - -use diagnostics; -use strict; -use vars qw(@ISA); - -@ISA = qw(partition_table_raw); - -use common; -use partition_table_raw; -use partition_table; -use c; - - -sub read($$) { - 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"; - - #- check magic number - sysread F, $tmp, 512 or die "error reading magic number on disk $hd->{device}"; - $tmp eq substr($tmp, 0, 1) x 512 or die "bad magic number on disk $hd->{device}"; - - partition_table_raw::zero_MBR($hd); - - $hd->{primary}{raw}; -} - -1; diff --git a/perl-install/partition_table_gpt.pm b/perl-install/partition_table_gpt.pm deleted file mode 100644 index d4c873851..000000000 --- a/perl-install/partition_table_gpt.pm +++ /dev/null @@ -1,266 +0,0 @@ -package partition_table_gpt; # $Id$ - -use diagnostics; -use strict; -use vars qw(@ISA); - -@ISA = qw(partition_table_raw); - -use common; -use partition_table_raw; -use partition_table_dos; -use partition_table; -use c; - -my %gpt_types = ( - 0x00 => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", - 0x82 => "\x6d\xfd\x57\x06\xab\xa4\xc4\x43\x84\xe5\x09\x33\xc8\x4b\x4f\x4f", - 0x83 => "\xA2\xA0\xD0\xEB\xE5\xB9\x33\x44\x87\xC0\x68\xB6\xB7\x26\x99\xC7", - 0x8e => "\x79\xd3\xd6\xe6\x07\xf5\xc2\x44\xa2\x3c\x23\x8f\x2a\x3d\xf9\x28", - 0xfd => "\x0f\x88\x9d\xa1\xfc\x05\x3b\x4d\xa0\x06\x74\x3f\x0f\x84\x91\x1e", - 0xef => "\x28\x73\x2A\xC1\x1F\xF8\xd2\x11\xBA\x4B\x00\xA0\xC9\x3E\xC9\x3B", - # legacy_partition_table => "\x41\xEE\x4D\x02\xE7\x33\xd3\x11\x9D\x69\x00\x08\xC7\x81\xF3\x9F" - # PARTITION_MSFT_RESERVED_GUID "\x16\xE3\xC9\xE3\x5C\x0B\xB8\x4D\x81\x7D\xF9\x2D\xF0\x02\x15\xAE" - #PARTITION_RESERVED_GUID "\x39\x33\xa6\x8d\x07\x00\xc0\x60\xc4\x36\x08\x3a\xc8\x23\x09\x08" -); - -my $current_revision = 0x00010200; -my ($main_format, $main_fields) = list2kv( - a8 => 'magic', - V => 'revision', - V => 'headerSize', - V => 'headerCRC32', - a4 => 'blank1', - Q => 'myLBA', - Q => 'alternateLBA', - Q => 'firstUsableLBA', - Q => 'lastUsableLBA', - a16 => 'guid', - Q => 'partitionEntriesLBA', - V => 'nbPartitions', - V => 'partitionEntrySize', - V => 'partitionEntriesCRC32', -); - -my ($partitionEntry_format, $partitionEntry_fields) = list2kv( - a16 => 'gpt_type', - a16 => 'guid', - Q => 'start', - Q => 'ending', - a8 => 'efi_attributes', - a72 => 'name', -); - -my ($guid_format, $guid_fields) = list2kv( - N => 'time_low', - n => 'time_mid', - n => 'time_hi_and_version', - n => 'clock_seq', - a6 => 'node', -); - -$_ = join('', @$_) foreach $main_format, $partitionEntry_format, $guid_format; - -my $magic = "EFI PART"; - -sub generate_guid { - my $tmp; - local *F; - open F, devices::make("random") or die "Could not open /dev/random for GUID generation"; - read F, $tmp, psizeof($guid_format); - - my %guid; @guid{@$guid_fields} = unpack $guid_format, $tmp; - $guid{clock_seq} = ($guid{clock_seq} & 0x3fff) | 0x8000; - $guid{time_hi_and_version} = ($guid{time_hi_and_version} & 0x0fff) | 0x4000; - pack($guid_format, @guid{@$guid_fields}); -} - -sub crc32 { - my ($buffer) = @_; - - my $crc = 0xFFFFFFFF; - foreach (unpack "C*", $buffer) { - my $subcrc = ($crc ^ $_) & 0xFF; - for (my $j = 8; $j > 0; $j--){ - my $b = $subcrc & 1; - $subcrc = ($subcrc >> 1) & 0x7FFFFFFF; - $subcrc = $subcrc ^ 0xEDB88320 if $b; - } - $crc = ($crc >> 8) ^ $subcrc; - } - $crc ^ 0xFFFFFFFF; -} - -sub compute_headerCRC32 { - my ($info) = @_; - local $info->{headerCRC32} = 0; - crc32(pack($main_format, @$info{@$main_fields})); -} - -sub read_header { - my ($sector, $F) = @_; - my $tmp; - - c::lseek_sector(fileno($F), $sector, 0) 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"; - my %info; @info{@$main_fields} = unpack $main_format, $tmp; - - $info{magic} eq $magic or die "bad magic number on disk $hd->{device}"; - $info{myLBA} == $sector or die "myLBA is not the same"; - $info{headerSize} == psizeof($main_format) or die "bad partition table header size"; - $info{partitionEntrySize} == psizeof($partitionEntry_format) or die "bad partitionEntrySize"; - $info{revision} <= $current_revision or log::l("oops, this is a new GPT revision ($info{revision} > $current_revision)"); - - $info{headerCRC32} == compute_headerCRC32(\%info) or die "bad partition table checksum"; - \%info -} - -sub read_partitionEntries { - my ($info, $F) = @_; - my $tmp; - - c::lseek_sector(fileno($F), $info->{partitionEntriesLBA}, 0) or die "can't seek to sector partitionEntriesLBA"; - sysread $F, $tmp, psizeof($partitionEntry_format) * $info->{nbPartitions} or die "error while reading partition table in sector $info->{partitionEntriesLBA}"; - $info->{partitionEntriesCRC32} == crc32($tmp) or die "bad partition entries checksum"; - - c::lseek_sector(fileno($F), $info->{partitionEntriesLBA}, 0) or die "can't seek to sector partitionEntriesLBA"; - my %gpt_types_rev = reverse %gpt_types; - my @pt = - map { - sysread $F, $tmp, psizeof($partitionEntry_format) or die "error while reading partition table in sector $info->{partitionEntriesLBA}"; - my %h; @h{@$partitionEntry_fields} = unpack $partitionEntry_format, $tmp; - $h{size} = $h{ending} - $h{start} + 1; - $h{type} = $gpt_types_rev{$h{gpt_type}}; - $h{type} = 0x100 if !defined $h{type}; - \%h; - } (1 .. $info->{nbPartitions}); - \@pt; -} - -sub read { - my ($hd, $sector) = @_; - my $tmp; - - my $l = partition_table_dos::read($hd, $sector); - my @l = grep { $_->{size} && $_->{type} && !partition_table::isExtended($_) } @$l; - @l == 1 or die "bad PMBR"; - $l[0]{type} == 0xee or die "bad PMBR"; - my $myLBA = $l[0]{start}; - - local *F; partition_table_raw::openit($hd, *F) or die "failed to open device"; - my $info1 = eval { read_header($myLBA, *F) }; - my $info2 = eval { read_header($info1->{alternateLBA} || $l[0]{start} + $l[0]{size} - 1, *F) }; #- what about using $hd->{totalsectors} ??? - my $info = $info1 || { %$info2, myLBA => $info2->{alternateLBA}, alternateLBA => $info2->{myLBA}, partitionEntriesLBA => $info2->{alternateLBA} + 1 } or die; - my $pt = $info1 && $info2 ? - eval { $info1 && read_partitionEntries($info1, *F) } || read_partitionEntries($info2, *F) : - read_partitionEntries($info, *F); - $hd->raw_removed($pt); - - $pt, $info; -} - -# write the partition table (and extended ones) -# for each entry, it uses fields: start, size, type, active -sub write { - my ($hd, $sector, $pt, $info) = @_; - - foreach (@$pt) { - $_->{ending} = $_->{start} + $_->{size} - 1; - $_->{guid} ||= generate_guid; - $_->{gpt_type} = $gpt_types{$_->{type}} || $_->{gpt_type} || $gpt_types{0x83}; - } - my $partitionEntries = join('', map { - pack($partitionEntry_format, @$_{@$partitionEntry_fields}) - } (@$pt, ({}) x ($info->{nbPartitions} - @$pt))); - - $info->{partitionEntriesCRC32} = crc32($partitionEntries); - $info->{headerCRC32} = compute_headerCRC32($info); - - my $info2 = { %$info, - myLBA => $info->{alternateLBA}, alternateLBA => $info->{myLBA}, - partitionEntriesLBA => $info->{alternateLBA} - psizeof($partitionEntry_format) * $info->{nbPartitions} / 512, - }; - $info2->{headerCRC32} = compute_headerCRC32($info2); - - { - # write the PMBR - my $pmbr = partition_table_dos::clear_raw(); - $pmbr->{raw}[0] = { type => 0xee, local_start => $info->{myLBA}, size => $info->{alternateLBA} - $info->{myLBA} + 1 }; - partition_table_dos::write($hd, $sector, $pmbr->{raw}); - } - - local *F; - partition_table_raw::openit($hd, *F, 2) or die "error opening device $hd->{device} for writing"; - - c::lseek_sector(fileno(F), $info->{myLBA}, 0) or return 0; - #- pad with 0's - syswrite F, pack($main_format, @$info{@$main_fields}) . "\0" x 512, 512 or return 0; - - c::lseek_sector(fileno(F), $info->{alternateLBA}, 0) or return 0; - #- pad with 0's - syswrite F, pack($main_format, @$info2{@$main_fields}) . "\0" x 512, 512 or return 0; - - c::lseek_sector(fileno(F), $info->{partitionEntriesLBA}, 0) or return 0; - syswrite F, $partitionEntries or return 0; - - c::lseek_sector(fileno(F), $info2->{partitionEntriesLBA}, 0) or return 0; - syswrite F, $partitionEntries or return 0; - - common::sync(); - 1; -} - -sub raw_removed { - my ($hd, $raw) = @_; - @$raw = grep { $_->{size} && $_->{type} } @$raw; -} -sub can_raw_add { - my ($hd) = @_; - @{$hd->{primary}{raw}} < $hd->{primary}{info}{nbPartitions}; -} -sub raw_add { - my ($hd, $raw, $part) = @_; - $hd->can_raw_add or die "raw_add: partition table already full"; - push @$raw, $part; -} - -sub adjustStart {} -sub adjustEnd {} - -sub first_usable_sector { - my ($hd) = @_; - $hd->{primary}{info}{firstUsableLBA}; -} -sub last_usable_sector { - my ($hd) = @_; - $hd->{primary}{info}{lastUsableLBA} + 1; -} - -sub info { - my ($hd) = @_; - my $nb_sect = 32; - - #- build a default suitable partition table, - #- checksum will be built when writing on disk. - { - magic => $magic, - revision => $current_revision, - headerSize => psizeof($main_format), - myLBA => 1, - alternateLBA => $hd->{totalsectors} - 1, - firstUsableLBA => $nb_sect + 2, - lastUsableLBA => $hd->{totalsectors} - $nb_sect - 2, - guid => generate_guid, - partitionEntriesLBA => 2, - nbPartitions => $nb_sect * 512 / psizeof($partitionEntry_format), - partitionEntrySize => psizeof($partitionEntry_format), - }; -} - -sub clear_raw { - my ($hd) = @_; - { raw => [], info => info($hd) }; -} - -1; diff --git a/perl-install/partition_table_lvm_PV.pm b/perl-install/partition_table_lvm_PV.pm deleted file mode 100644 index f9362a9e5..000000000 --- a/perl-install/partition_table_lvm_PV.pm +++ /dev/null @@ -1,43 +0,0 @@ -package partition_table_lvm; # $Id$ - -use diagnostics; -use strict; - -our @ISA = qw(partition_table_raw); - -use partition_table_raw; -use c; - -my $magic = "HM\1\0"; -my $offset = 0; - - -#- Allows people having PVs on unpartitioned disks to install -#- (but no way to create such beasts) -#- -#- another way to handle them would be to ignore those disks, -#- but this would make those hds unshown in diskdrake, -#- disallowing to zero_MBR, clearing this PV - - -sub read { - my ($hd, $sector) = @_; - - 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"; - - sysread F, my $tmp, length $magic or die "error reading magic number on disk $hd->{file}"; - $tmp eq $magic or die "bad magic number on disk $hd->{file}"; - - [ ]; -} - -sub write { - die "ERROR: should not be writing raw disk lvm PV!!"; -} - -sub clear_raw { - die "ERROR: should not be creating new raw disk lvm PV!!"; -} - -1; diff --git a/perl-install/partition_table_mac.pm b/perl-install/partition_table_mac.pm deleted file mode 100644 index 4a094e92b..000000000 --- a/perl-install/partition_table_mac.pm +++ /dev/null @@ -1,398 +0,0 @@ -package partition_table_mac; # $Id$ - -use diagnostics; -#use strict; - fixed other PPC code to comply, but program bails on empty partition table - sbenedict -use vars qw(@ISA $freepart_device $bootstrap_part $freepart_start $freepart_size $freepart_part $macos_part); - -@ISA = qw(partition_table_raw); - -use common; -use partition_table_raw; -use partition_table; -use c; - -my %typeToDos = ( - "Apple_partition_map" => 0x401, - "Apple_Bootstrap" => 0x401, - "Apple_Driver43" => 0x401, - "Apple_Driver_IOKit" => 0x401, - "Apple_Patches" => 0x401, - "Apple_HFS" => 0x402, - "Apple_UNIX_SVR2" => 0x83, - "Apple_UNIX_SVR2" => 0x183, - "Apple_UNIX_SVR2" => 0x283, - "Apple_UNIX_SVR2" => 0x383, - "Apple_UNIX_SVR2" => 0x483, - "Apple_Free" => 0x0, -); -my %typeFromDos = reverse %typeToDos; - - -my ($bz_format, $bz_fields) = list2kv( - n => 'bzSig', - n => 'bzBlkSize', - N => 'bzBlkCnt', - n => 'bzDevType', - n => 'bzDevID', - N => 'bzReserved', - n => 'bzDrvrCnt', -); -$bz_format = join '', @$bz_format; - - -my ($dd_format, $dd_fields) = list2kv( - N => 'ddBlock', - n => 'ddSize', - n => 'ddType', -); -$dd_format = join '', @$dd_format; - - -my ($p_format, $p_fields) = list2kv( - n => 'pSig', - n => 'pSigPad', - N => 'pMapEntry', - N => 'pPBlockStart', - N => 'pPBlocks', - - a32 => 'pName', - a32 => 'pType', - - N => 'pLBlockStart', - N => 'pLBlocks', - N => 'pFlags', - N => 'pBootBlock', - N => 'pBootBytes', - - N => 'pAddrs1', - N => 'pAddrs2', - N => 'pAddrs3', - N => 'pAddrs4', - N => 'pChecksum', - - a16 => 'pProcID', - a128 => 'pBootArgs', - a248 => 'pReserved', -); -$p_format = join '', @$p_format; - -my $magic = 0x4552; -my $pmagic = 0x504D; - -sub first_usable_sector { 1 } - -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) = @_; -} - -sub read($$) { - 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"; - - 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"; - my %dd; @dd{@$dd_fields} = unpack $dd_format, $tmp; - push @{$info{ddMap}}, \%dd; - } - - #- check magic number - $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"; - $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"; - $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"; - - my @pt; - for ($i=0;$i<$partmapsize;$i++) { - my $part; - 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; - if ($i < $numparts && $h{pSig} eq $pmagic) { - - $h{size} = ($h{pPBlocks} * $info{bzBlkSize}) / 512; - $h{start} = ($h{pPBlockStart} * $info{bzBlkSize}) / 512; - - if ($h{pType} =~ /^Apple_UNIX_SVR2/i) { - $h{pName} =~ /swap/i ? ($h{type} = 0x82) : ($h{type} = 0x83); - } elsif ($h{pType} =~ /^Apple_Free/i) { - #- need to locate a 1MB partition to setup a bootstrap on - if (defined $freepart_start && $freepart_size >= 1) { - #- already found a suitable partition - } else { - $freepart_start = $h{start}; - $freepart_size = $h{size}/2048; - $freepart_device = $hd; - $freepart_part = "/dev/" . $hd->{device} . ($i+1); - log::l("free apple partition found on drive /dev/$freepart_device->{device}, block $freepart_start, size $freepart_size"); - } - $h{type} = 0x0; - $h{pName} = 'Extra'; - } elsif ($h{pType} =~ /^Apple_HFS/i) { - $h{type} = 0x402; - if (defined $macos_part) { - #- swag at identifying MacOS - 1st HFS partition - } else { - $macos_part = "/dev/" . $hd->{device} . ($i+1); - log::l("found MacOS at partition $macos_part"); - } - } elsif ($h{pType} =~ /^Apple_Partition_Map/i) { - $h{type} = 0x401; - $h{isMap} = 1; - } elsif ($h{pType} =~ /^Apple_Bootstrap/i) { - $h{type} = 0x401; - $h{isBoot} = 1; - if (defined $bootstrap_part) { - #found a bootstrap already - use it, but log the find - log::l("found another apple bootstrap at partition /dev/$hd->{device}" . ($i+1)); - } else { - $bootstrap_part = "/dev/" . $hd->{device} . ($i+1); - log::l("found apple bootstrap at partition $bootstrap_part"); - } - } else { - $h{type} = 0x401; - $h{isDriver} = 1; - }; - - # Let's see if this partition is a driver. - foreach (@{$info{ddMap}}) { - $_->{ddBlock} == $h{pPBlockStart} and $h{isDriver} = 1; - } - - } - \%h; - } [ $part ]; - }; - - [ @pt ], \%info; -} - -sub write($$$;$) { - my ($hd, $sector, $pt, $info) = @_; - - #- 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, 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"; - push @partstowrite, $part; - - # Now go thru the partitions, sort and fill gaps. - my $last; - while ($part) { - $last = $part; - $part = &partition_table::next($hd, $part); - $part or last; - - if ($last->{start} + $last->{size} < $part->{start}) { - #There is a gap between partitions. Fill it and move on. - push @partstowrite, { - 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, - 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. - $info->{bzDrvrCnt} = 0; - my @ddstowrite; - my $dd; - foreach $dd (@{$info->{ddMap}}) { - foreach (@partstowrite) { - if ($dd->{ddBlock} == $_->{pPBlockStart}) { - push @ddstowrite, $dd; - $info->{bzDrvrCnt}++; - last; - } - } - } - - # Now let's write our first block. - 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; - } - # zero the rest of the data in the first block. - foreach ( 1 .. (494 - ((@ddstowrite) * 8))) { - syswrite F, "\0", 1 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}) { - # The values we need to write to disk are not defined. Let's make them up. - $_->{pSig} = $pmagic; - $_->{pSigPad} = 0; - $_->{pPBlockStart} = ($_->{start} * 512) / $info->{bzBlkSize}; - $_->{pPBlocks} = ($_->{size} * 512) / $info->{bzBlkSize}; - $_->{pLBlockStart} = 0; - $_->{pLBlocks} = $_->{pPBlocks}; - $_->{pBootBlock} = 0; - $_->{pBootBytes} = 0; - $_->{pAddrs1} = 0; - $_->{pAddrs2} = 0; - $_->{pAddrs3} = 0; - $_->{pAddrs4} = 0; - $_->{pChecksum} = 0; - $_->{pProcID} = "\0"; - $_->{pBootArgs} = "\0"; - $_->{pReserved} = "\0"; - - if ($_->{type} == 0x402) { - $_->{pType} = "Apple_HFS"; - $_->{pName} = "MacOS"; - $_->{pFlags} = 0x4000037F; - } elsif ($_->{type} == 0x401 && $_->{start} == 1) { - $_->{pType} = "Apple_Partition_Map"; - $_->{pName} = "Apple"; - $_->{pFlags} = 0x33; - } elsif ($_->{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); - $bootstrap_part = "/dev/" . $_->{device}; - } elsif ($_->{type} == 0x82) { - $_->{pType} = "Apple_UNIX_SVR2"; - $_->{pName} = "swap"; - $_->{pFlags} = 0x33; - } elsif ($_->{type} == 0x83) { - $_->{pType} = "Apple_UNIX_SVR2"; - $_->{pName} = "Linux Native"; - $_->{pFlags} = 0x33; - } elsif ($_->{type} == 0x183) { - $_->{pType} = "Apple_UNIX_SVR2"; - $_->{pName} = "Linux ReiserFS"; - $_->{pFlags} = 0x33; - } elsif ($_->{type} == 0x283) { - $_->{pType} = "Apple_UNIX_SVR2"; - $_->{pName} = "Linux XFS"; - $_->{pFlags} = 0x33; - } elsif ($_->{type} == 0x383) { - $_->{pType} = "Apple_UNIX_SVR2"; - $_->{pName} = "Linux JFS"; - $_->{pFlags} = 0x33; - } elsif ($_->{type} == 0x483) { - $_->{pType} = "Apple_UNIX_SVR2"; - $_->{pName} = "Linux ext3"; - $_->{pFlags} = 0x33; - } elsif ($_->{type} == 0x0) { - $_->{pType} = "Apple_Free"; - $_->{pName} = "Extra"; - $_->{pFlags} = 0x31; - } - }; - $_->{pMapEntry} = @partstowrite; - syswrite F, pack($p_format, @$_{@$p_fields}), psizeof($p_format) or return 0; - } - - common::sync(); - - 1; -} - -sub info { - my ($hd) = @_; - - # - Build the first block of the drive. - - my $info = { - bzSig => $magic, - bzBlkSize => 512, - bzBlkCnt => $hd->{totalsectors}, - bzDevType => 0, - bzDevID => 0, - bzReserved => 0, - bzDrvrCnt => 0, - }; - - $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. - $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; -} - -1; diff --git a/perl-install/partition_table_raw.pm b/perl-install/partition_table_raw.pm deleted file mode 100644 index 20a883b11..000000000 --- a/perl-install/partition_table_raw.pm +++ /dev/null @@ -1,192 +0,0 @@ -package partition_table_raw; # $Id$ - -use diagnostics; -use strict; - -use common; -use devices; -use detect_devices; -use log; -use c; - -my @MBR_signatures = ( -if_(arch() =~ /ppc/, - map { [ 'yaboot', 0, "PM", 0x200 * $_ + 0x10, "bootstrap\0" ] } 0 .. 61 -), - [ 'empty', 0, "\0\0\0\0" ], - [ 'grub', 0, "\xEBG", 0x17d, "stage1 \0" ], - [ 'grub', 0, "\xEBH", 0x17e, "stage1 \0" ], - [ 'grub', 0, "\xEBH", 0x18a, "stage1 \0" ], - [ 'grub', 0, "\xEBH", 0x181, "GRUB \0" ], - [ 'lilo', 0x2, "LILO" ], - [ 'lilo', 0x6, "LILO" ], - [ 'grub', 0x6, "GRUB" ], - [ 'osbs', 0x2, "OSBS" ], #- http://www.prz.tu-berlin.de/~wolf/os-bs.html - [ 'pqmagic', 0xef, "PQV" ], - [ 'BootStar', 0x130, "BootStar:" ], - [ 'DocsBoot', 0x148, 'DocsBoot' ], - [ 'system_commander', 0x1ad, "SYSCMNDRSYS" ], - [ 'Be Os', 0x24, 'Boot Manager' ], - [ 'TimO', 0, 'IBM Thinkpad hibernation partition' ], - [ 'dos', 0xa0, "\x25\x03\x4E\x02\xCD\x13" ], - [ 'dos', 0xa0, "\x00\xB4\x08\xCD\x13\x72" ], #- nt2k's - [ 'dos', 0x60, "\xBB\x00\x7C\xB8\x01\x02\x57\xCD\x13\x5F\x73\x0C\x33\xC0\xCD\x13" ], #- nt's - [ 'dos', 0x70, "\x0C\x33\xC0\xCD\x13\x4F\x75\xED\xBE\xA3" ], - [ 'freebsd', 0xC0, "\x00\x30\xE4\xCD\x16\xCD\x19\xBB\x07\x00\xB4" ], - [ 'freebsd', 0x160, "\x6A\x10\x89\xE6\x48\x80\xCC\x40\xCD\x13" ], - [ 'dummy', 0xAC, "\x0E\xB3\x07\x56\xCD\x10\x5E\xEB" ], #- caldera? - [ 'ranish', 0x100, "\x6A\x10\xB4\x42\x8B\xF4\xCD\x13\x8B\xE5\x73" ], - [ 'os2', 0x1c2, "\xA" ], -); - -sub typeOfMBR($) { typeFromMagic(devices::make($_[0]), @MBR_signatures) } -sub typeOfMBR_($) { typeFromMagic($_[0], @MBR_signatures) } - -sub hasExtended { 0 } - -sub cylinder_size($) { - my ($hd) = @_; - $hd->{geom}{sectors} * $hd->{geom}{heads}; -} -sub first_usable_sector { 1 } -sub last_usable_sector { - my ($hd) = @_; - $hd->{totalsectors}; -} - -#- default method for starting a partition, only head size or twice -#- is allowed for starting a partition after a cylinder boundarie. -sub adjustStart($$) { - my ($hd, $part) = @_; - my $end = $part->{start} + $part->{size}; - - $part->{start} = round_up($part->{start}, - $part->{start} % cylinder_size($hd) < 2 * $hd->{geom}{sectors} ? - $hd->{geom}{sectors} : cylinder_size($hd)); - $part->{size} = $end - $part->{start}; - $part->{size} > 0 or die "adjustStart get a too small partition to handle correctly"; -} -#- adjusting end to match a cylinder boundary, two methods are used and must -#- match at the end, else something is wrong and nothing will be done on -#- partition table. -#- $end2 is computed by removing 2 (or only 1 if only 2 heads on drive) groups -#- of sectors, this is necessary to handle extended partition where logical -#- partition start after 1 (or 2 accepted) groups of sectors (typically 63). -#- $end is floating (is not on cylinder boudary) so we have to choice a good -#- candidate, $end1 or $end2 should always be good except $end1 for small -#- partition size. -sub adjustEnd($$) { - my ($hd, $part) = @_; - my $end = $part->{start} + $part->{size}; - $end > $hd->{geom}{cylinders} * cylinder_size($hd) && $end <= $hd->{totalsectors} and return; - my $end1 = round_down($end, cylinder_size($hd)); - my $end2 = round_up($end - ($hd->{geom}{heads} > 2 ? 2 : 1) * $hd->{geom}{sectors}, cylinder_size($hd)); - $end2 <= $hd->{geom}{cylinders} * cylinder_size($hd) or die "adjustEnd go beyond end of device geometry ($end2 > $hd->{totalsectors})"; - $part->{size} = ($end1 - $part->{start} > cylinder_size($hd) ? $end1 : $end2) - $part->{start}; - $part->{size} > 0 or die "adjustEnd get a too small partition to handle correctly"; -} - -sub get_geometry($) { - my ($dev) = @_; - my $g = ""; - - local *F; sysopen F, $dev, 0 or return; - ioctl(F, c::HDIO_GETGEO(), $g) or return; - my %geom; @geom{qw(heads sectors cylinders start)} = unpack "CCSL", $g; - $geom{totalcylinders} = $geom{cylinders}; - - my $total; - #- $geom{cylinders} is no good (only a ushort, that means less than 2^16 => at best 512MB) - if ($total = c::total_sectors(fileno F)) { - $geom{cylinders} = int $total / $geom{heads} / $geom{sectors}; - } else { - $total = $geom{heads} * $geom{sectors} * $geom{cylinders} - } - - { geom => \%geom, totalsectors => $total }; -} - -sub openit($$;$) { sysopen $_[1], $_[0]{file}, $_[2] || 0; } - -# cause kernel to re-read partition table -sub kernel_read($) { - my ($hd) = @_; - common::sync(); - local *F; openit($hd, *F) or return 0; - common::sync(); sleep(1); - $hd->{rebootNeeded} = !ioctl(F, c::BLKRRPART(), 0); - common::sync(); - close F; - common::sync(); sleep(1); -} - -sub raw_removed { - my ($hd, $raw) = @_; -} -sub can_raw_add { - my ($hd) = @_; - $_->{size} || $_->{type} or return 1 foreach @{$hd->{primary}{raw}}; - 0; -} -sub raw_add { - my ($hd, $raw, $part) = @_; - - foreach (@$raw) { - $_->{size} || $_->{type} and next; - $_ = $part; - return; - } - die "raw_add: partition table already full"; -} - -sub zero_MBR { - my ($hd) = @_; - #- force the standard partition type for the architecture - my $type = arch() =~ /ia64/ ? 'gpt' : arch() eq "alpha" ? "bsd" : arch() =~ /^sparc/ ? "sun" : arch() eq "ppc" ? "mac" : "dos"; - #- override standard mac type on PPC for IBM machines to dos - $type = "dos" if (arch() =~ /ppc/ && detect_devices::get_mac_model() =~ /^IBM/); - require("partition_table_$type.pm"); - bless $hd, "partition_table_$type"; - $hd->{primary} = $hd->clear_raw(); - delete $hd->{extended}; -} - -sub zero_MBR_and_dirty { - my ($hd) = @_; - zero_MBR($hd); - $hd->{isDirty} = $hd->{needKernelReread} = 1; - -} - -#- ugly stuff needed mainly for Western Digital IDE drives -#- try writing what we've just read, yells if it fails -#- testing on last sector of head #0 (unused in 99% cases) -#- -#- return false if the device can't be written to (especially for Smartmedia) -sub test_for_bad_drives { - my ($hd) = @_; - - log::l("test_for_bad_drives($hd->{file})"); - my $sector = $hd->{geom}{sectors} - 1; - - - local *F; openit($hd, *F, 2) or die "can't open device"; - - my $seek = sub { - c::lseek_sector(fileno(F), $sector, 0) or die "seeking to sector $sector failed"; - }; - my $tmp; - - &$seek; sysread F, $tmp, $SECTORSIZE or die "test_for_bad_drives: can't even read ($!)"; - &$seek; syswrite F, $tmp or die "test_for_bad_drives: can't even write ($!)"; - - my $tmp2; - &$seek; sysread F, $tmp2, $SECTORSIZE or die "test_for_bad_drives: can't even read again ($!)"; - $tmp eq $tmp2 or die -_("Something bad is happening on your drive. -A test to check the integrity of data has failed. -It means writing anything on the disk will end up with random trash"); - 1; -} - -1; diff --git a/perl-install/partition_table_sun.pm b/perl-install/partition_table_sun.pm deleted file mode 100644 index e0cc05265..000000000 --- a/perl-install/partition_table_sun.pm +++ /dev/null @@ -1,201 +0,0 @@ -package partition_table_sun; # $Id$ - -use diagnostics; -use strict; -use vars qw(@ISA); - -@ISA = qw(partition_table_raw); - -use common; -use partition_table_raw; -use partition_table; -use c; - -my ($main_format, $main_fields) = list2kv( - a128 => 'info', - a14 => 'spare0', - a32 => 'infos', - a246 => 'spare1', - n => 'rspeed', - n => 'pcylcount', - n => 'sparecyl', - a4 => 'spare2', - n => 'ilfact', - n => 'ncyl', - n => 'nacyl', - n => 'ntrks', - n => 'nsect', - a4 => 'spare3', - a64 => 'partitions', - n => 'magic', - n => 'csum', -); -$main_format = join '', @$main_format; - -my ($fields1, $fields2) = ([ qw(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 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; - - 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"; - - 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 - $info{magic} == $magic or die "bad magic number on disk $hd->{device}"; - - #- 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} ]; - - [ @pt ], \%info; -} - -# write the partition table (and extended ones) -# 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; - } - - ($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; - 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; - - common::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, - }; - - $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; -} - -1; diff --git a/perl-install/standalone.pm b/perl-install/standalone.pm index 077bbba19..7d405ce5a 100644 --- a/perl-install/standalone.pm +++ b/perl-install/standalone.pm @@ -69,7 +69,7 @@ sub explanations { c::syslog(c::LOG_INFO()|c::LOG_LOCAL1(), "@_") } @common_functs = qw(renamef linkf symlinkf output substInFile mkdir_p rm_rf cp_af touch setVarsInSh setVarsInCsh update_gnomekderc); @builtin_functs = qw(chmod chown unlink link symlink rename system); -@drakx_modules = qw(Xconfig Xconfigurator Xconfigurator_consts any bootloader bootlook c class_discard commands crypto detect_devices devices diskdrake diskdrake::hd_gtk diskdrake::interactive diskdrake::removable diskdrake::removable_gtk diskdrake::smbnfs_gtk fs fsedit http keyboard lang log loopback lvm modparm modules mouse my_gtk network network::adsl network::ethernet network::isdn_consts network::isdn network::modem network::netconnect network::network network::nfs network::smb network::tools partition_table partition_table_bsd partition_table_dos partition_table_empty partition_table_gpt partition_table_mac partition_table_raw partition_table_sun printer printerdrake proxy raid run_program scanner services steps swap timezone tinyfirewall); +@drakx_modules = qw(Xconfig Xconfigurator Xconfigurator_consts any bootloader bootlook c class_discard commands crypto detect_devices devices diskdrake diskdrake::hd_gtk diskdrake::interactive diskdrake::removable diskdrake::removable_gtk diskdrake::smbnfs_gtk fs fsedit http keyboard lang log loopback lvm modparm modules mouse my_gtk network network::adsl network::ethernet network::isdn_consts network::isdn network::modem network::netconnect network::network network::nfs network::smb network::tools partition_table partition_table_bsd partition_table::dos partition_table::empty partition_table::gpt partition_table::mac partition_table::raw partition_table::sun printer printerdrake proxy raid run_program scanner services steps swap timezone tinyfirewall); sub import { -- cgit v1.2.1