aboutsummaryrefslogtreecommitdiffstats
path: root/old/transfugdrake.pm
blob: b14ec361651ac2a262dffe68302c6c9cbf281b65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package transfugdrake;

use common;

# 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 = <F>; wantarray ? @l : join '', @l }

# From pixel and gc
sub typeFromMagic {
    my $f = shift;
    my $tmp;
    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" ],) : (),
    );

    local *F;
    sysopen F, $f, 0 or return;

 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);
	    if($tmp ne $signature) { next M; }
        }
	return $name;
    }
    return -1;
}

sub get_windows_partition {
    my $in = $_[0];
    
    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;
    my $i = 0;
    my $devname = "";
    my @ls_array;
    my @tmp_array;
    my $fstype;

 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($type2name{$type} =~ /NTFS/ || $type2name{$type} =~ /FAT32/ || $type2name{$type} =~ /FAT/) {
	    $devname = `cd /dev/; ls -l | grep '$dev' ; cd -`;
	    @ls_array = split(' ', $devname);
            $fat_parts[$i] = "/dev/$ls_array[8] ($type2name{$type})";
	    $i++;
        }
    }

    if($fat_parts[0] eq "") { $in->ask_warn(N("No Windows Partition"), N("No Windows Partition found")); quit_global($in, 0); }
    $::Wizard_no_previous = 1;
    my $win_part = $in->ask_from_list_(N("Select your windows partition"),
                        N("Please specify your windows partition from the following list"),
                        [ @fat_parts ],
                        $fat_parts[0])
                        or quit_global($in, 0);
    if($fat_parts[1] eq "") { $in->ask_warn(N("Your Windows Partition"), N("$fat_parts[0] is found as your Windows partition")); }

    if($win_part =~ /NTFS/) { $fstype = "ntfs"; }
    elsif($win_part =~ /FAT32/) {$fstype = "msdos"; }
    elsif($win_part =~ /FAT/) {$fstype = "msdos"; }
    
    @tmp_array = split(' ', $win_part);
    $win_part = $tmp_array[0];
    return ($win_part, $fstype);
}

sub mount_partition {
    my $fstype = $_[0];
    my $win_partition = $_[1];
    my $mountpoint = "/mnt/transfug";
    my @mounts;
    my $mounted = 0;
    my @tmp;
    
    (@mounts) =  cat_('/proc/mounts');
    
    foreach (@mounts) {
        @tmp = split(' ', $_);
        if($tmp[0] eq $win_partition) {
            $mounted = 1;
            $mountpoint = $tmp[1];
        }
    }

    if(!$mounted) {
        mkdir($mountpoint);
    
        print "mount -t $fstype $win_partition $mountpoint\n";
        if(`mount -t $fstype $win_partition $mountpoint`) { print "Error\n:"; }
    }

    return $mountpoint;
}

sub get_windows_config {
    my %config;
    my $in = $_[0];

    # Get the windows partition
    ($config->{partition}, $config->{fstype}) = get_windows_partition($in);
    
    # Mount it
    $config->{mountpoint} = mount_partition($config->{fstype}, $config->{partition});

    # Find where the documents are
    # If possible, get some registry config
    return ($config->{partition}, $config->{fstype}, $config->{mountpoint});
}

sub get_linux_config {
}

1;