old-www/LDP/LG/issue37/ramirez.cylcalc

51 lines
781 B
Plaintext

/*
cylcalc
-------
Calculate the cylinders needed to format X MB on the hard drive.
Gilbert Ramirez
Technical Services
University Health System
$Id: ramirez.cylcalc,v 1.1.1.1 2002/08/14 22:27:25 dan Exp $
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int megs;
int heads;
int sectors;
int bytes;
int cyl;
int calc_bytes;
if (argc != 4) {
fprintf(stderr, "\nusage: %s megabytes heads sectors\n"
"\tcalculates cylinders needed for such a format.\n",
argv[0]);
exit(-1);
}
megs = atoi(argv[1]);
heads = atoi(argv[2]);
sectors = atoi(argv[3]);
bytes = megs * 1024 * 1024;
cyl = 0;
do {
cyl++;
calc_bytes = heads * sectors * 512 * cyl;
} while (calc_bytes < bytes);
printf("%d\n", cyl);
return 0;
}