<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
#
# Try automatic generation of geometries
#

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

if ($sec &lt; 320*2) {
    $c = 40;
    $h = 1;
    $type = 1;
} elsif ($sec &lt; 640*2) {
    $c = 40;
    $h = 2;
    $type = 1;
} elsif ($sec &lt; 1200*2) {
    $c = 80;
    $h = 2;
    $type = 3;
} elsif ($sec &lt; 1440*2) {
    $c = 80;
    $h = 2;
    $type = 2;
} elsif ($sec &lt; 2880*2) {
    $c = 80;
    $h = 2;
    $type = 4;
} elsif ($sec &lt; 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 &lt; 256) {
    $s = int($sec/($c*$h)+0.5);
    if ($s &lt;= 63 &amp;&amp; $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;
}
</pre></body></html>