[comp.sys.ibm.pc] number of DOS drives

osbook@sdcsvax.UCSD.EDU (osbook) (12/02/86)

References: <8005@watdaisy.UUCP> <1441@isis.UUCP>
Reply-To: osbook@sdcsvax.UUCP (osbook)
Distribution: world
Organization: U.C. San Diego

In article <1441@isis.UUCP> dragheb@isis.UUCP (Darius "OPRDRT" Ragheb) writes:
>In article <8005@watdaisy.UUCP> dvadura@watdaisy.UUCP (Dennis Vadura) writes:
>>
>>Hi there, does anyone out there in net land know how you can find out from
>>DOS what the names of physical drives active in the system are?  I haven't
>
>I think this might work (I have not tried it):
>use function (_FUNCTION_, not interrupt) call Eh. It will do two things:
>make the drive selected in DL the current drive, and
>return the number of drives in AL.
>
If you had tried it, you would have found out it *doesn't* work :-) :-)

DOS always returns a minimum of *5* drives  (this corresponds to the
minimum value of "E" in the LASTDRIVE command in CONFIG.SYS.

Harley Hahn
osbook@sdcsvax.ucsd.edu

madd@bucsb.bu.edu.UUCP (Jim Frost) (12/02/86)

In article <2268@sdcsvax.UCSD.EDU> osbook@sdcsvax.UCSD.EDU (osbook) writes:
>References: <8005@watdaisy.UUCP> <1441@isis.UUCP>
>Reply-To: osbook@sdcsvax.UUCP (osbook)
>Distribution: world
>Organization: U.C. San Diego
>
>In article <1441@isis.UUCP> dragheb@isis.UUCP (Darius "OPRDRT" Ragheb) writes:
>>In article <8005@watdaisy.UUCP> dvadura@watdaisy.UUCP (Dennis Vadura) writes:
>>>
>>>Hi there, does anyone out there in net land know how you can find out from
>>>DOS what the names of physical drives active in the system are?  I haven't
>>
>>I think this might work (I have not tried it):
>>use function (_FUNCTION_, not interrupt) call Eh. It will do two things:
>>make the drive selected in DL the current drive, and
>>return the number of drives in AL.
>>
>If you had tried it, you would have found out it *doesn't* work :-) :-)
>
>DOS always returns a minimum of *5* drives  (this corresponds to the
>minimum value of "E" in the LASTDRIVE command in CONFIG.SYS.
>
>Harley Hahn
>osbook@sdcsvax.ucsd.edu


You're correct.  The only easy way I can determine to do it is to
attempt to switch the default drive to some drive.  If you get back an
error like "invalid drive" or "invalid path" (I don't have my stuff
here, so I can't check which function to call or what error number is
returned, sorry) then you know you have a nonexistent drive.  Now
here's the fun stuff.  Call the DOS function to find out what
LASTDRIVE is (usually E:, or 5), then try each one in decreasing order
until DOS allows you to change to it.  This will find the highest
allowable drive name.  Note that single floppy systems can go nuts
when you try this, since drive B: is faked.

If you want an example, email me and I'll send you a Turbo Pascal
example program (or assembler macro if you like) that does this.

-- 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                   - Jim Frost * The Madd Hacker -
UUCP:  ..!harvard!bu-cs!bucsb!madd | ARPANET: madd@bucsb.bu.edu
CSNET: madd%bucsb@bu-cs            | BITNET:  cscc71c@bostonu
-------------------------------+---+------------------------------------
"Oh beer, oh beer." -- Me      |      [=(BEER) <- Bud the Beer (cheers!)

dragheb@isis.UUCP (Darius "OPRDRT" Ragheb) (12/04/86)

In article <623@bucsb.bu.edu.UUCP> madd@bucsb.bu.edu.UUCP (Jim Frost) writes:
>>
>>In article <1441@isis.UUCP> dragheb@isis.UUCP (Darius "OPRDRT" Ragheb) writes:
>>>
>>>I think this might work (I have not tried it):
>>>use function (_FUNCTION_, not interrupt) call Eh. It will do two things:
>>>make the drive selected in DL the current drive, and
>>>return the number of drives in AL.
>>>
>>If you had tried it, you would have found out it *doesn't* work :-) :-)

I think we have it licked now!  I wrote the following program and tested
it on a PC with 1 drive and  a PC with 2 drives and it returned
the correct number of floppies:


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

main ()
{

	int intnum;
	REGS *regsin, *regsout;

	intnum = 0x11;

	int86 (intnum, regsin, regsout);

	printf ("%d\n",(regsout->ax & 192) +1);
}


What it does is call INT 11h and check bits 6 and 7 in the ax
register.  (0 means 1 drive, etc).

(BTW REGS is a struct of ints)

-- 

UseNet:              {hplabs, seismo}!hao!isis!dragheb 

madd@bucsb.bu.edu.UUCP (Jim "Jack" Frost) (12/05/86)

In article <1450@isis.UUCP> dragheb@isis.UUCP (Darius "OPRDRT" Ragheb) writes:
>In article <623@bucsb.bu.edu.UUCP> madd@bucsb.bu.edu.UUCP (Jim Frost) writes:
>>>
>>>In article <1441@isis.UUCP> dragheb@isis.UUCP (Darius "OPRDRT" Ragheb) writes:
>>>>
>>>>I think this might work (I have not tried it):
>>>>use function (_FUNCTION_, not interrupt) call Eh. It will do two things:
>>>>make the drive selected in DL the current drive, and
>>>>return the number of drives in AL.
>>>>
>>>If you had tried it, you would have found out it *doesn't* work :-) :-)
>
>I think we have it licked now!  I wrote the following program and tested
>it on a PC with 1 drive and  a PC with 2 drives and it returned
>the correct number of floppies:
[ C program deleted ]
>
>What it does is call INT 11h and check bits 6 and 7 in the ax
>register.  (0 means 1 drive, etc).
>
>(BTW REGS is a struct of ints)
>
That's great, but I assumed that they may have at least one hard
drive.  Also, it's at least theoretically possible to have more than 4
floppies (why would you do that?  no idea, but...) so you really can't
trust the configuration bits, which are limited to 4.  Because DOS
allows you to install odd devices (RAM drives, etc) which you might
like to use, you'd probably want to see if there is one available.

I really wish I had my DOS manual, but here is the general idea of how
I would do it (expanded slightly from last time):

* Call DOS to find out how many drives it CAN have (ie LASTDRIVE
  setting).
* Start at LASTDRIVE and request the volume label for all drives down to
  C:.
* If you don't find a drive higher than C:, you could test the
  configuration bits.  This would take care of the nasty "Drive not
  ready error.  Abort, Retry, Ignore?" when you don't have a floppy
  installed.

Come to think of it, you might want to check the bits first to see if
you have an installed floppy that is higher than B:.  This isn't
common, but it's possible.  As for systems with 4+ floppies, well,
tough luck.  Get a hard drive :-).

This is really easy to write if you have the DOS Tech Ref manual
handy, which I don't.  I think that is about as accurate as you could
get without explicitly asking "how many drives/psuedo drives do you
have?"
-- 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                   - Jim Frost * The Madd Hacker -
UUCP:  ..!harvard!bu-cs!bucsb!madd | ARPANET: madd@bucsb.bu.edu
CSNET: madd%bucsb@bu-cs            | BITNET:  cscc71c@bostonu
-------------------------------+---+------------------------------------
"Oh beer, oh beer." -- Me      |      [=(BEER) <- Bud the Beer (cheers!)

rde@ukc.ac.uk (R.D.Eager) (12/06/86)

I  have  been  following  the  discussion  of  how to discover number of
drives, with interest. I may have missed something, and  I  agree  there
are  portability  issues,  but how about using one of the techniques for
looking at the device driver chain (you know, open NUL and grab the link
to the next driver, etc.)?

This  works  even  if  third  party  drives,   20   floppies,   etc. are
fitted. Just count the number of block device drivers...
-- 
           Bob Eager

           rde@ukc.UUCP
           rde@ukc
           ...!mcvax!ukc!rde

           Phone: +44 227 66822 ext 7589

madd@bucsb.bu.edu.UUCP (Jim "Jack" Frost) (12/10/86)

In article <2230@eagle.ukc.ac.uk> rde@ukc.ac.uk (R.D.Eager) writes:
>
>I  have  been  following  the  discussion  of  how to discover number of
>drives, with interest. I may have missed something, and  I  agree  there
>are  portability  issues,  but how about using one of the techniques for
>looking at the device driver chain (you know, open NUL and grab the link
>to the next driver, etc.)?
>
>This  works  even  if  third  party  drives,   20   floppies,   etc. are
>fitted. Just count the number of block device drivers...

Umm...this does work.  Now.  But I wouldn't be counting on it
indefinitely, since MS-DOS does NOT have to put NUL at the beginning
of the list.  Also, you should be careful -- are all "block" device
drivers accessible as drives?  I tend to doubt it -- I think that
several multitasking/multiprocessor cards use a block type device
driver to control the card, or at least to pass it stuff.  On your
average system it should work right now, though.
-- 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                   - Jim Frost * The Madd Hacker -
UUCP:  ..!harvard!bu-cs!bucsb!madd | ARPANET: madd@bucsb.bu.edu
CSNET: madd%bucsb@bu-cs            | BITNET:  cscc71c@bostonu
-------------------------------+---+------------------------------------
"Oh beer, oh beer." -- Me      |      [=(BEER) <- Bud the Beer (cheers!)