aboutsummaryrefslogtreecommitdiffstats
path: root/memdisk/fdgeo.pl
blob: b76727d1057a91d0f7ade2b8a3097bdf6754ad82 (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
#!/usr/bin/perl
#
# Try automatic generation of geometries
#

($k) = @ARGV;
$sec = int($k*2+0.5);

if ($sec < 320*2) {
    $c = 40;
    $h = 1;
    $type = 1;
} elsif ($sec < 640*2) {
    $c = 40;
    $h = 2;
    $type = 1;
} elsif ($sec < 1200*2) {
    $c = 80;
    $h = 2;
    $type = 3;
} elsif ($sec < 1440*2) {
    $c = 80;
    $h = 2;
    $type = 2;
} elsif ($sec < 2880*2) {
    $c = 80;
    $h = 2;
    $type = 4;
} elsif ($sec < 4096*2) {
    $c = 80;
    $h = 2;
    $type = 6;
} else {
    printf "%.1fK, %d sectors: ", $sec/2, $sec;
    print "Considered a hard disk\n";
    exit 2;
}

$ok = 0;
while ($c < 256) {
    $s = int($sec/($c*$h)+0.5);
    if ($s <= 63 && $sec == $c*$h*$s) {
	$ok = 1;
	last;
    }
    $c++;
}

printf "%.1fK, %d sectors: ", $sec/2, $sec;
if ($ok) {
    print "c=$c, h=$h, s=$s, type=$type\n";
    exit 0;
} else {
    print "No valid geometry found (MEMDISK will fake it)\n";
    exit 1;
}