Detect the DOS disk

From: Michele Andreoli ([email protected])
Date: Mon Dec 18 2000 - 17:55:02 CET


This is a little C program compiled for DOS. The intention is to
put this command in every .bat in the dosinstaller, helping muLinux
to find the disk where the user located the images.

The command (called diskinfo.exe) simply outputs a string like:

        diskinfo=disk_id,disk_label,dir,tot,avail

Example (for my Win98) is:

        diskinfo=2,C,MU,1839168,348288

It meas: disk number 2, label C, directory c:\mu, total kB and
free KB on the hard-disk

The string has the right syntax to be passed, via loadlin, to
the linux kernel and parsed by the boot scripts.

You know, currently muLinux scan every disk and every directory
searching for its images! Using this trick, the boot script can
detect the exact directory and the exact disk the user
issued the command "boot.bat" from.

The values are parsed, then compared with info found using fdisk
in muLinux. I do not know if someone on the list know some more
smart solution.

How to find the right disk? The dos label "C" is unknow to Linux,
obiously. But, if we are lucky, the total disk space is the same
in the two world, or I'm wrong?

It it works, we need to parse the "fdisk -l" output, converting
cylinder boundary and block's sizes in Kb, finding the best
(or exact) match. Can we trust in the poor muLinux fdisk output?

Michele

===============================================================
#include <stdio.h>
#include <dos.h>
#include <dir.h>

/*
  diskinfo.c (C) 2000 Michele Andreoli, for muLinux
  output: diskinfo=current-disk,disk-label,
                current-dir,disk-size K,disk-free K
*/

char disks[40]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char buf[1024];
double sclus;
int cdisk;
double tot,avail;

main()
{
struct dfree df;
cdisk=getdisk();
getdfree(0,&df);
sclus=(double)df.df_sclus;
getcurdir(0,buf);

tot=sclus*512*df.df_total;
avail=sclus*512*df.df_avail;

printf ("diskinfo=%d,%c,%s,%.0f,%.0f\n",cdisk,disks[cdisk], buf,
                tot/1024,avail/1024);
}
===============================================================

-- 
In summing up, I wish I had some kind of affirmative message to leave
you with, I don't. Would you take two negative messages? - Woody Allen
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


This archive was generated by hypermail 2.1.6 : Sat Feb 08 2003 - 15:27:17 CET