summaryrefslogtreecommitdiffstats
path: root/perl-install/partition_table.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/partition_table.pm')
-rw-r--r--perl-install/partition_table.pm324
1 files changed, 36 insertions, 288 deletions
diff --git a/perl-install/partition_table.pm b/perl-install/partition_table.pm
index c7f968c6f..1d5e87e47 100644
--- a/perl-install/partition_table.pm
+++ b/perl-install/partition_table.pm
@@ -2,283 +2,24 @@ package partition_table; # $Id$
use diagnostics;
use strict;
-use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK @important_types @important_types2 @fields2save @bad_types);
-
-@ISA = qw(Exporter);
-%EXPORT_TAGS = (
- types => [ qw(pt_type2name type2fs name2pt_type fs2pt_type isExtended isExt2 isThisFs isTrueLocalFS isTrueFS isSwap isDos isWin isFat isFat_or_NTFS isSunOS isOtherAvailableFS isPrimary isRawLVM isRawRAID isRAID isLVM isMountableRW isNonMountable isPartOfLVM isPartOfRAID isPartOfLoopback isLoopback isMounted isBusy isSpecial maybeFormatted isApple isAppleBootstrap isEfi) ],
-);
-@EXPORT_OK = map { @$_ } values %EXPORT_TAGS;
-
use common;
+use fs::type;
use partition_table::raw;
use detect_devices;
use log;
-@important_types = ('Linux native', 'Linux swap',
- if_(arch() =~ /i.86/, 'Journalised FS: ext3', 'Journalised FS: ReiserFS', 'Journalised FS: JFS', 'Journalised FS: XFS', 'DOS FAT16', 'FAT32'),
- if_(arch() =~ /ia64/, 'Journalised FS: ext3', 'Journalised FS: ReiserFS', 'Journalised FS: XFS', 'FAT32'),
- if_(arch() =~ /x86_64/, 'Journalised FS: ext3', 'Journalised FS: ReiserFS', 'FAT32'),
- if_(arch() =~ /ppc/, 'Journalised FS: ext3', 'Journalised FS: ReiserFS', 'Journalised FS: JFS', 'Journalised FS: XFS', 'Apple HFS Partition', 'Apple Bootstrap'));
-@important_types2 = ('Linux RAID', 'Linux Logical Volume Manager partition');
-
-@fields2save = qw(primary extended totalsectors isDirty will_tell_kernel);
-
-@bad_types = ('Empty', 'DOS 3.3+ Extended Partition', 'Win95: Extended partition, LBA-mapped', 'Linux extended partition');
-
-my %pt_types = (
- 0x0 => 'Empty',
-if_(arch() =~ /^ppc/,
- 0x183 => 'Journalised FS: ReiserFS',
- 0x283 => 'Journalised FS: XFS',
- 0x383 => 'Journalised FS: JFS',
- 0x483 => 'Journalised FS: ext3',
- 0x401 => 'Apple Partition',
- 0x401 => 'Apple Bootstrap',
- 0x402 => 'Apple HFS Partition',
-), if_(arch() =~ /^i.86/,
- 0x107 => 'NTFS',
- 0x183 => 'Journalised FS: ReiserFS',
- 0x283 => 'Journalised FS: XFS',
- 0x383 => 'Journalised FS: JFS',
- 0x483 => 'Journalised FS: ext3',
-), if_(arch() =~ /^ia64/,
- 0x100 => 'Various',
- 0x183 => 'Journalised FS: ReiserFS',
- 0x283 => 'Journalised FS: XFS',
- 0x483 => 'Journalised FS: ext3',
-), if_(arch() =~ /^x86_64/,
- 0x183 => 'Journalised FS: ReiserFS',
- 0x483 => 'Journalised FS: ext3',
-), if_(arch() =~ /^sparc/,
- 0x1 => 'SunOS boot',
- 0x2 => 'SunOS root',
- 0x3 => 'SunOS swap',
- 0x4 => 'SunOS usr',
- 0x5 => 'Whole disk',
- 0x6 => 'SunOS stand',
- 0x7 => 'SunOS var',
- 0x8 => 'SunOS home',
-), if_(arch() =~ /^i.86/,
- 0x1 => 'DOS 12-bit FAT',
- 0x2 => 'XENIX root',
- 0x3 => 'XENIX /usr',
- 0x4 => 'DOS 16-bit FAT (up to 32M)',
- 0x5 => 'DOS 3.3+ Extended Partition',
- 0x6 => 'DOS FAT16',
- 0x7 => 'NTFS (or HPFS)',
- 0x8 => 'OS/2 (v1.0-1.3 only) / AIX boot partition / SplitDrive / Commodore DOS / DELL partition spanning multiple drives / QNX 1.x and 2.x ("qny")',
-),
- 0x9 => 'AIX data partition / Coherent filesystem / QNX 1.x and 2.x ("qnz")',
- 0xa => 'OS/2 Boot Manager / Coherent swap partition / OPUS',
- 0xb => 'FAT32',
- 0xc => 'Win98 FAT32, LBA-mapped',
- 0xe => 'Win95: DOS 16-bit FAT, LBA-mapped',
- 0xf => 'Win95: Extended partition, LBA-mapped',
- 0x10 => 'OPUS (?)',
- 0x11 => 'Hidden DOS 12-bit FAT',
- 0x12 => 'Compaq/HP config partition',
- 0x14 => 'Hidden DOS 16-bit FAT <32M',
- 0x16 => 'Hidden DOS 16-bit FAT >=32M',
- 0x17 => 'Hidden IFS (e.g., HPFS)',
- 0x18 => 'AST Windows swapfile',
- 0x1b => 'Hidden WIN95 OSR2 32-bit FAT',
- 0x1c => 'Hidden WIN95 OSR2 32-bit FAT, LBA-mapped',
- 0x1e => 'Hidden FAT95',
- 0x22 => 'Used for Oxygen Extended Partition Table by ekstazya@sprint.ca.',
- 0x24 => 'NEC DOS 3.x',
- 0x35 => 'JFS (OS/2)',
- 0x38 => 'THEOS ver 3.2 2gb partition',
- 0x39 => 'THEOS ver 4 spanned partition',
- 0x3a => 'THEOS ver 4 4gb partition',
- 0x3b => 'THEOS ver 4 extended partition',
- 0x3c => 'PartitionMagic recovery partition',
- 0x40 => 'Venix 80286',
- 0x41 => 'Linux/MINIX (sharing disk with DRDOS) / Personal RISC Boot / PPC PReP (Power PC Reference Platform) Boot',
- 0x42 => 'Windows Dynamic Partition',
- 0x43 => 'Linux native (sharing disk with DRDOS)',
- 0x45 => 'EUMEL/Elan',
- 0x46 => 'EUMEL/Elan 0x46',
- 0x47 => 'EUMEL/Elan 0x47',
- 0x48 => 'EUMEL/Elan 0x48',
- 0x4d => 'QNX4.x',
- 0x4e => 'QNX4.x 2nd part',
- 0x4f => 'QNX4.x 3rd part / Oberon partition',
- 0x50 => 'OnTrack Disk Manager (older versions) RO',
- 0x51 => 'OnTrack Disk Manager RW (DM6 Aux1) / Novell',
- 0x52 => 'CP/M / Microport SysV/AT',
- 0x53 => 'Disk Manager 6.0 Aux3',
- 0x54 => 'Disk Manager 6.0 Dynamic Drive Overlay',
- 0x55 => 'EZ-Drive',
- 0x56 => 'Golden Bow VFeature Partitioned Volume. / DM converted to EZ-BIOS',
- 0x57 => 'DrivePro',
- 0x5c => 'Priam EDisk',
- 0x61 => 'SpeedStor',
- 0x63 => 'Unix System V (SCO, ISC Unix, UnixWare, ...), Mach, GNU Hurd',
- 0x64 => 'PC-ARMOUR protected partition / Novell Netware 2.xx',
- 0x65 => 'Novell Netware 3.xx or 4.xx',
- 0x67 => 'Novell',
- 0x68 => 'Novell 0x68',
- 0x69 => 'Novell 0x69',
- 0x70 => 'DiskSecure Multi-Boot',
- 0x75 => 'IBM PC/IX',
- 0x80 => 'MINIX until 1.4a',
- 0x81 => 'MINIX since 1.4b, early Linux / Mitac disk manager',
- 0x82 => 'Linux swap',
- 0x83 => 'Linux native',
- 0x84 => 'OS/2 hidden C: drive / Hibernation partition',
- 0x85 => 'Linux extended partition',
- 0x86 => 'Old Linux RAID partition superblock / NTFS volume set',
- 0x87 => 'NTFS volume set',
- 0x8a => 'Linux Kernel Partition (used by AiR-BOOT)',
- 0x8e => 'Linux Logical Volume Manager partition',
- 0x93 => 'Amoeba',
- 0x94 => 'Amoeba bad block table',
- 0x99 => 'DCE376 logical drive',
- 0xa0 => 'IBM Thinkpad hibernation partition / Phoenix NoteBIOS Power Management "Save-to-Disk" partition',
- 0xa5 => 'BSD/386, 386BSD, NetBSD, FreeBSD',
- 0xa6 => 'OpenBSD',
- 0xa7 => 'NEXTSTEP',
- 0xa9 => 'NetBSD',
- 0xaa => 'Olivetti Fat 12 1.44Mb Service Partition',
- 0xb7 => 'BSDI filesystem',
- 0xb8 => 'BSDI swap partition',
- 0xbe => 'Solaris boot partition',
- 0xc0 => 'CTOS / REAL/32 secure small partition',
- 0xc1 => 'DRDOS/secured (FAT-12)',
- 0xc4 => 'DRDOS/secured (FAT-16, < 32M)',
- 0xc6 => 'DRDOS/secured (FAT-16, >= 32M) / Windows NT corrupted FAT16 volume/stripe set',
- 0xc7 => 'Windows NT corrupted NTFS volume/stripe set / Syrinx boot',
- 0xcb => 'reserved for DRDOS/secured (FAT32)',
- 0xcc => 'reserved for DRDOS/secured (FAT32, LBA)',
- 0xcd => 'CTOS Memdump?',
- 0xce => 'reserved for DRDOS/secured (FAT16, LBA)',
- 0xd0 => 'REAL/32 secure big partition',
- 0xd1 => 'Old Multiuser DOS secured FAT12',
- 0xd4 => 'Old Multiuser DOS secured FAT16 <32M',
- 0xd5 => 'Old Multiuser DOS secured extended partition',
- 0xd6 => 'Old Multiuser DOS secured FAT16 >=32M',
- 0xd8 => 'CP/M-86',
- 0xdb => 'Digital Research CP/M, Concurrent CP/M, Concurrent DOS / CTOS (Convergent Technologies OS -Unisys) / KDG Telemetry SCPU boot',
- 0xdd => 'Hidden CTOS Memdump?',
- 0xe1 => 'DOS access or SpeedStor 12-bit FAT extended partition',
- 0xe3 => 'DOS R/O or SpeedStor',
- 0xe4 => 'SpeedStor 16-bit FAT extended partition < 1024 cyl.',
- 0xeb => 'BeOS',
- 0xee => 'EFI GPT',
- 0xef => 'EFI (FAT-12/16/32)',
- 0xf1 => 'SpeedStor 0xf1',
- 0xf2 => 'DOS 3.3+ secondary partition',
- 0xf4 => 'SpeedStor large partition / Prologue single-volume partition',
- 0xf5 => 'Prologue multi-volume partition',
- 0xfd => 'Linux RAID',
- 0xfe => 'SpeedStor > 1024 cyl. or LANstep / IBM PS/2 IML (Initial Microcode Load) partition, located at the end of the disk. / Windows NT Disk Administrator hidden partition / Linux Logical Volume Manager partition (old)',
- 0xff => 'Xenix Bad Block Table',
-);
-
-my %pt_type2fs = (
-arch() =~ /^ppc/ ? (
- 0x07 => 'hpfs',
-) : (
- 0x07 => 'ntfs',
-),
-arch() !~ /sparc/ ? (
- 0x01 => 'vfat',
- 0x04 => 'vfat',
- 0x05 => 'ignore',
- 0x06 => 'vfat',
-) : (
- 0x01 => 'ufs',
- 0x02 => 'ufs',
- 0x04 => 'ufs',
- 0x06 => 'ufs',
- 0x07 => 'ufs',
- 0x08 => 'ufs',
-),
- 0x0b => 'vfat',
- 0x0c => 'vfat',
- 0x0e => 'vfat',
- 0x1b => 'vfat',
- 0x1c => 'vfat',
- 0x1e => 'vfat',
- 0x82 => 'swap',
- 0x83 => 'ext2',
- 0xeb => 'befs',
- 0xef => 'vfat',
- 0x107 => 'ntfs',
- 0x183 => 'reiserfs',
- 0x283 => 'xfs',
- 0x383 => 'jfs',
- 0x483 => 'ext3',
- 0x401 => 'apple',
- 0x402 => 'hfs',
-);
-
-my %pt_types_rev = reverse %pt_types;
-my %fs2pt_type = reverse %pt_type2fs;
+our @fields2save = qw(primary extended totalsectors isDirty will_tell_kernel);
-1;
-
-sub important_types() {
- my @l = (@important_types, if_($::expert, @important_types2, sort values %pt_types));
- difference2(\@l, \@bad_types);
-}
-
-sub type2fs {
- my ($part, $o_default) = @_;
- my $pt_type = $part->{pt_type};
- $pt_type2fs{$pt_type} || $pt_type =~ /^(\d+)$/ && $o_default || $pt_type;
-}
-sub fs2pt_type { $fs2pt_type{$_[0]} || $_[0] }
-sub pt_type2name { $pt_types{$_[0]} || $_[0] }
-sub name2pt_type {
- local ($_) = @_;
- /0x(.*)/ ? hex $1 : $pt_types_rev{$_} || $_;
-}
-#sub name2type { { pt_type => name2pt_type($_[0]) } }
-
-sub isEfi { arch() =~ /ia64/ && $_[0]{pt_type} == 0xef }
-sub isWholedisk { arch() =~ /^sparc/ && $_[0]{pt_type} == 5 }
-sub isExtended { arch() !~ /^sparc/ && ($_[0]{pt_type} == 5 || $_[0]{pt_type} == 0xf || $_[0]{pt_type} == 0x85) }
-sub isRawLVM { $_[0]{pt_type} == 0x8e }
-sub isRawRAID { $_[0]{pt_type} == 0xfd }
-sub isSwap { type2fs($_[0]) eq 'swap' }
-sub isExt2 { type2fs($_[0]) eq 'ext2' }
-sub isDos { arch() !~ /^sparc/ && ${{ 1 => 1, 4 => 1, 6 => 1 }}{$_[0]{pt_type}} }
-sub isWin { ${{ 0xb => 1, 0xc => 1, 0xe => 1, 0x1b => 1, 0x1c => 1, 0x1e => 1 }}{$_[0]{pt_type}} }
-sub isFat { isDos($_[0]) || isWin($_[0]) }
-sub isFat_or_NTFS { isDos($_[0]) || isWin($_[0]) || $_[0]{pt_type} == 0x107 }
-sub isSunOS { arch() =~ /sparc/ && ${{ 0x1 => 1, 0x2 => 1, 0x4 => 1, 0x6 => 1, 0x7 => 1, 0x8 => 1 }}{$_[0]{pt_type}} }
-sub isApple { type2fs($_[0]) eq 'apple' && defined $_[0]{isDriver} }
-sub isAppleBootstrap { type2fs($_[0]) eq 'apple' && defined $_[0]{isBoot} }
-sub isHiddenMacPart { defined $_[0]{isMap} }
-
-sub isThisFs { type2fs($_[1]) eq $_[0] }
-sub isTrueFS { isTrueLocalFS($_[0]) || member(type2fs($_[0]), qw(nfs)) }
-sub isTrueLocalFS { member(type2fs($_[0]), qw(ext2 reiserfs xfs jfs ext3)) }
-
-sub isOtherAvailableFS { isEfi($_[0]) || isFat_or_NTFS($_[0]) || isSunOS($_[0]) || isThisFs('hfs', $_[0]) } #- other OS that linux can access its filesystem
-sub isMountableRW { (isTrueFS($_[0]) || isOtherAvailableFS($_[0])) && !isThisFs('ntfs', $_[0]) }
-sub isNonMountable {
- my ($part) = @_;
- isRawRAID($part) || isRawLVM($part) || isThisFs("ntfs", $part) && !$part->{isFormatted} && $part->{notFormatted};
+sub hd2minimal_part {
+ my ($hd) = @_;
+ {
+ rootDevice => $hd->{device},
+ if_($hd->{usb_media_type}, is_removable => 1),
+ };
}
-sub isPartOfLVM { defined $_[0]{lvm} }
-sub isPartOfRAID { defined $_[0]{raid} }
-sub isPartOfLoopback { defined $_[0]{loopback} }
-sub isRAID { $_[0]{device} =~ /^md/ }
-sub isUBD { $_[0]{device} =~ /^ubd/ } #- should be always true during an $::uml_install
-sub isLVM { $_[0]{VG_name} }
-sub isLoopback { defined $_[0]{loopback_file} }
-sub isMounted { $_[0]{isMounted} }
-sub isBusy { isMounted($_[0]) || isPartOfRAID($_[0]) || isPartOfLVM($_[0]) || isPartOfLoopback($_[0]) }
-sub isSpecial { isRAID($_[0]) || isLVM($_[0]) || isLoopback($_[0]) || isUBD($_[0]) }
-sub maybeFormatted { $_[0]{isFormatted} || !$_[0]{notFormatted} }
-
-
#- works for both hard drives and partitions ;p
sub description {
my ($hd) = @_;
@@ -290,7 +31,7 @@ sub description {
formatXiB($hd->{totalsectors} || $hd->{size}, 512),
$hd->{info} && ", $hd->{info}",
$hd->{mntpoint} && ", " . $hd->{mntpoint},
- $hd->{pt_type} && ", " . pt_type2name($hd->{pt_type});
+ $hd->{fs_type} && ", $hd->{fs_type}";
}
sub isPrimary {
@@ -345,6 +86,12 @@ sub verifyPrimary {
verifyParts_(@{$pt->{normal}}, $pt->{extended});
}
+sub compute_device_name {
+ my ($part, $hd) = @_;
+ $part->{device} = $hd->{prefix} . $part->{part_number};
+ $part->{devfs_device} = $hd->{devfs_prefix} . '/part' . $part->{part_number};
+}
+
sub assign_device_numbers {
my ($hd) = @_;
@@ -363,15 +110,15 @@ sub assign_device_numbers {
log::l("PPC: found a hole on $hd->{prefix} before $_->{start}, skipping device...");
$i++;
}
- $_->{device} = $hd->{prefix} . $i;
- $_->{devfs_device} = $hd->{devfs_prefix} . '/part' . $i;
+ $_->{part_number} = $i;
+ compute_device_name($_, $hd);
$start = $_->{start} + $_->{size};
$i++;
}
} else {
foreach (@{$hd->{primary}{raw}}) {
- $_->{device} = $hd->{prefix} . $i;
- $_->{devfs_device} = $hd->{devfs_prefix} . '/part' . $i;
+ $_->{part_number} = $i;
+ compute_device_name($_, $hd);
$i++;
}
foreach (map { $_->{normal} } @{$hd->{extended} || []}) {
@@ -383,8 +130,8 @@ sub assign_device_numbers {
will_tell_kernel($hd, del => $_, 'delay_del');
push @{$hd->{partitionsRenumbered}}, [ $_->{device}, $dev ];
}
- $_->{device} = $dev;
- $_->{devfs_device} = $hd->{devfs_prefix} . '/part' . $i;
+ $_->{part_number} = $i;
+ compute_device_name($_, $hd);
if ($renumbered) {
will_tell_kernel($hd, add => $_, 'delay_add');
}
@@ -397,14 +144,11 @@ sub assign_device_numbers {
#- first verify there's at least one primary dos partition, otherwise it
#- means it is a secondary disk and all will be false :(
#-
- #- isFat_or_NTFS isn't true for 0x7 partitions, only for 0x107.
- #- alas 0x107 is not set correctly at this stage
- #- solution: don't bother with 0x7 vs 0x107 here
- my ($c, @others) = grep { isFat_or_NTFS($_) || $_->{pt_type} == 0x7 || $_->{pt_type} == 0x17 } @{$hd->{primary}{normal}};
+ my ($c, @others) = grep { isFat_or_NTFS($_) } @{$hd->{primary}{normal}};
$i = ord 'C';
$c->{device_windobe} = chr($i++) if $c;
- $_->{device_windobe} = chr($i++) foreach grep { isFat_or_NTFS($_) || $_->{pt_type} == 0x7 || $_->{pt_type} == 0x17 } map { $_->{normal} } @{$hd->{extended}};
+ $_->{device_windobe} = chr($i++) foreach grep { isFat_or_NTFS($_) } map { $_->{normal} } @{$hd->{extended}};
$_->{device_windobe} = chr($i++) foreach @others;
}
@@ -472,14 +216,17 @@ sub get_normal_parts_and_holes {
ref($hd) or print("get_normal_parts_and_holes: bad hd" . backtrace(), "\n");
+ my $minimal_hole = put_in_hash({ pt_type => 0 }, hd2minimal_part($hd));
+
my @l = map {
my $current = $start;
$start = $_->{start} + $_->{size};
- my $hole = { start => $current, size => $_->{start} - $current, pt_type => 0, rootDevice => $hd->{device} };
+ my $hole = { start => $current, size => $_->{start} - $current, %$minimal_hole };
+ put_in_hash($hole, hd2minimal_part($hd));
$hole, $_;
} sort { $a->{start} <=> $b->{start} } grep { !isWholedisk($_) } get_normal_parts($hd);
- push @l, { start => $start, size => $last - $start, pt_type => 0, rootDevice => $hd->{device} };
+ push @l, { start => $start, size => $last - $start, %$minimal_hole };
grep { $_->{pt_type} || $_->{size} >= $hd->cylinder_size } @l;
}
@@ -522,7 +269,7 @@ sub read_one($$) {
@extended > 1 and die "more than one extended partition";
- $_->{rootDevice} = $hd->{device} foreach @normal, @extended;
+ put_in_hash($_, hd2minimal_part($hd)) foreach @normal, @extended;
{ raw => $pt, extended => $extended[0], normal => \@normal, info => $info, nb_special_empty => $nb_special_empty };
}
@@ -631,7 +378,7 @@ sub tell_kernel {
} elsif ($action eq 'del') {
$force_reboot ||= !c::del_partition(fileno $F, $part_number);
}
- log::l("tell kernel $action ($part_number $o_start $o_size), rebootNeeded is now " . bool2text($hd->{rebootNeeded}));
+ log::l("tell kernel $action ($hd->{device} $part_number $o_start $o_size), rebootNeeded is now " . bool2text($hd->{rebootNeeded}));
}
}
if ($force_reboot) {
@@ -640,10 +387,10 @@ sub tell_kernel {
syscall_('umount', $_->{real_mntpoint}) or log::l(N("error unmounting %s: %s", $_->{real_mntpoint}, $!));
}
$hd->{rebootNeeded} = !ioctl($F, c::BLKRRPART(), 0);
- log::l("tell kernel force_reboot, rebootNeeded is now $hd->{rebootNeeded}.");
+ log::l("tell kernel force_reboot ($hd->{device}), rebootNeeded is now $hd->{rebootNeeded}.");
foreach (@magic_parts) {
- syscall_('mount', $_->{real_mntpoint}, type2fs($_), c::MS_MGC_VAL()) or log::l(N("mount failed: ") . $!);
+ syscall_('mount', $_->{real_mntpoint}, $_->{fs_type}, c::MS_MGC_VAL()) or log::l(N("mount failed: ") . $!);
}
}
}
@@ -801,9 +548,8 @@ sub add {
get_normal_parts($hd) >= ($hd->{device} =~ /^rd/ ? 7 : $hd->{device} =~ /^(sd|ida|cciss|ataraid)/ ? 15 : 63) and cdie "maximum number of partitions handled by linux reached";
- $part->{notFormatted} = 1;
- $part->{isFormatted} = 0;
- $part->{rootDevice} = $hd->{device};
+ set_isFormatted($part, 0);
+ put_in_hash($part, hd2minimal_part($hd));
$part->{start} ||= 1 if arch() !~ /^sparc/; #- starting at sector 0 is not allowed
adjustStartAndEnd($hd, $part) unless $b_forceNoAdjust;
@@ -877,3 +623,5 @@ sub save {
eval { output($file, Data::Dumper->Dump([\@h], ['$h']), "\0") }
or die N("Error writing to file %s", $file);
}
+
+1;