From 2fa4d19c2ac9059ebab467632d1f970ff064b748 Mon Sep 17 00:00:00 2001 From: Christian Belisle Date: Fri, 11 Jan 2002 17:54:37 +0000 Subject: Read real partition in partition chooser. --- transfugdrake.pm | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 2 deletions(-) (limited to 'transfugdrake.pm') diff --git a/transfugdrake.pm b/transfugdrake.pm index 8b68101..12ab8d9 100644 --- a/transfugdrake.pm +++ b/transfugdrake.pm @@ -1,10 +1,98 @@ package transfugdrake; +# From pixel and gc +sub arch() { + my $t = `uname -m`; + chomp $t; + $t; +} + +# From pixel and gc +sub cat_ { + local *F; + open F, $_[0] or $_[1] ? die "cat of file $_[0] failed: $!\n" : return; + my @l = ; + wantarray ? @l : join '', @l +} -use log; +# From pixel and gc +sub typeFromMagic { + my $f = shift; + local *F; sysopen F, $f, 0 or return; + my $tmp; + M: foreach (@partitions_signatures) { + my ($name, @l) = @$_; + while (@l) { + my ($offset, $signature) = splice(@l, 0, 2); + sysseek(F, $offset, 0) or next M; + sysread(F, $tmp, length $signature); + $tmp eq $signature or next M; + } + return $name; + } + return -1; +} + sub get_windows_partition { + my $in = $_; + my @partitions_signatures = ( + [ 0x8e, 0, "HM\1\0" ], + [ 0x83, 0x438, "\x53\xEF" ], + [ 0x183, 0x10034, "ReIsErFs" ], + [ 0x183, 0x10034, "ReIsEr2Fs" ], + [ 0x283, 0, 'XFSB', 0x200, 'XAGF', 0x400, 'XAGI' ], + [ 0x383, 0x8000, 'JFS1' ], + [ 0x82, 4086, "SWAP-SPACE" ], + [ 0x82, 4086, "SWAPSPACE2" ], + [ 0x7, 0x1FE, "\x55\xAA", 0x3, "NTFS" ], + [ 0xc, 0x1FE, "\x55\xAA", 0x52, "FAT32" ], + arch() !~ /^sparc/ ? ( [ 0x6, 0x1FE, "\x55\xAA", 0x36, "FAT" ],) : (), + ); + + my %type2name = ( + 0x1 => 'DOS 12-bit FAT', + 0x4 => 'DOS 16-bit FAT (up to 32M)', + 0x5 => 'DOS 3.3+ Extended Partition', + 0x6 => 'DOS FAT16', + 0x7 => 'NTFS (or HPFS)', + 0xb => 'Win98 FAT32', + 0xc => 'Win98 FAT32, LBA-mapped', + 0xe => 'Win95: DOS 16-bit FAT, LBA-mapped', + 0xf => 'Win95: Extended partition, LBA-mapped', + 0x82 => 'Linux Swap', + 0x83 => 'Ext2', + 0x183 => 'ReiserFS', + 0x283 => 'XFS', + 0x383 => 'JFS', + 0x85 => 'Linux extended partition', + 0x87 => 'NTFS volume set', + 0x8e => 'Linux LVM', + -1 => 'unknown' + ); + + my (undef, undef, @parts) = cat_('/proc/partitions'); + my %fat_parts; + + P: foreach (@parts) { + my (undef, undef, $blocks, $dev) = split or next; + my %skip_conditions = ( + "Skipping <$dev> because too little blocks ($blocks)" => ($blocks <= 1), + "Skipping <$dev> because doesn't end with a number (e.g. seems to not be a partition)" => ($dev !~ /\d$/), + ); + $skip_conditions{$_} and ($verbose and print(STDERR $_, "\n")), next P foreach keys %skip_conditions; + my $type = typeFromMagic("/dev/$dev"); + if($type eq "NTFS" || $type eq "FAT32" || $type eq "FAT") { + # printf "$dev: type <0x%0x> (%s)\n", $type, $type2name{$type}; + $fat_parts->{$dev} = $type; + } + + return $in->ask_from_list_(_("Select your windows partition"), + _("Please specify your windows partition from the following list"), + [ %fat_parts ], + $fat_parts->{$dev}) + or quit_global($in, 0); } sub get_windows_version { @@ -14,7 +102,6 @@ sub get_windows_version { sub get_windows_config { my %config; $config->{'partitions'} = get_windows_partition(); - my $windows_version = get_windows_version($ } sub get_linux_config { -- cgit v1.2.1