[net.micro.pc] How does a program detect disks on a PC?

lisa@phs.UUCP (Jeffrey William Gillette) (09/23/85)

[]

I have a program that needs to know how many disk drives [block devices] are 
present on an IBM PC / compatible.  I know that interrupt 11h (equipment 
check) will tell me about diskette drives, but I also need to find out about 
fixed diskes (which may be partitioned into more than one logical device) 
and other device drivers which are loaded through config.sys (e.g. Iomega 
Bernoulle boxes).  

Does anyone know of a way to check for the presence of block devices without
either asking the user (who in this case will probably not know the answer),
or making calls to DOS that will put strange error messages on the screen.

Jeffrey William Gillette		uucp: duke!phys!lisa
The Divinity School			bitnet: DYBBUK @ TUCCVM
Duke University

bet@ecsvax.UUCP (Bennett E. Todd III) (09/23/85)

(I'm moving this discussion to net.micro.pc -- that's where it belongs).
It appears to me, from reading the documentation, that the correct way
to determine how many disks DOS thinks there are is through the DOS
function call Select Disk (0E hex).
	mov	ah,19h	; Current disk -- returned in AL
	int	21h
	mov	dl,al
	mov	ah,0Eh	; set disk to that in DL -- returns total
	int	21h	; number available in AL
Unfortunately, the number DOS is returning seems to bear little
relationship to the number of disk devices DOS currently knows about.
Running DOS 3.10 on an IBM-PC/XT I get 5 drives. This doesn't change
whether or not I have my ramdisk device driver installed. Does this call
work correctly in any version of DOS? Is the number it returns useful
for anything? Is there a correct way to find out how many disk devices
DOS knows about? And what about ... Naomi!!!

-Bennett
-- 

"Hypocrisy is the vaseline of social intercourse." (Who said that?)

Bennett Todd -- Duke Computation Center, Durham, NC 27706-7756; (919) 684-3695
UUCP: ...{decvax,seismo,philabs,ihnp4,akgua}!mcnc!ecsvax!duccpc!bet

gbs@voder.UUCP (George Smith) (09/26/85)

> 
> It appears to me, from reading the documentation, that the correct way
> to determine how many disks DOS thinks there are is through the DOS
> function call Select Disk (0E hex).
> Unfortunately, the number DOS is returning seems to bear little
> relationship to the number of disk devices DOS currently knows about.
> Running DOS 3.10 on an IBM-PC/XT I get 5 drives. This doesn't change
> whether or not I have my ramdisk device driver installed.
> 
> -Bennett

The IBM DOS Technical Reference Manual for DOS 2.1 might lead you to
believe that the Select Disk Function (0EH) will supply you with the
information you want.  However, the Microsoft MS-DOS Programmers
Reference Manual includes the following large notice on the page
describing function 0EH:

	+----------------------------------------------------------+
	|                                                          |
	|                         NOTICE                           |
	|                                                          |
	| For future compatibility, treat the value returned in    |
	| AL with care.  For example, if AL returns 5, it is not   |
	| safe to assume drives A, B, C, D, and E are all valid    |
	| drive designators.                                       |
	|                                                          |
	+----------------------------------------------------------+

If anyone knows how to find out the number of drives currently
available to running software, please post this information to the
net.

-- 
George B. Smith
National Semiconductor
...!{ihnp4!nsc | decvax!decwrl!nsc | ucbvax}!voder!gbs

shanks@teneron.UUCP (Dave Shanks) (09/26/85)

In article <1053@phs.UUCP> lisa@phs.UUCP (Jeffrey William Gillette) writes:
>
>Does anyone know of a way to check for the presence of block devices without
>either asking the user (who in this case will probably not know the answer),
>or making calls to DOS that will put strange error messages on the screen.

The May 1985 issue of PC Tech Journal (vol. 3, no. 5, pp. 76-87) has an
article that describes how to get your hands on the linked list of
MS-DOS device drivers.  After the system is running this list will have
all drivers in it, both those that are loaded by default, and those
that are loaded via the config.sys mechanism.

Basically you open NUL: (guaranteed to be the first device in the list)
using an FCB.  One of the reserved fields in the FCB will then contain
the address of the device header for NUL:.  Each device header has
three fields which may be used to count all the block devices.  The
first is the attribute field which tells (among other things) whether
this is a block or character device.  The second is the device name
field which, for block devices, contains the number of units that this
driver controls.  The final field needed is the next header field which
contains the address of the next device header in the linked list.

Warning:  As far as I know, the method for finding the address of the
first device header is not documented either by Microsoft or by IBM.
The article states that this method will work for PC-DOS versions 2.0,
2.1, and 3.0.  I have not attempted to use this information with any
version of MS-DOS.

-- 
Dave Shanks	..!tektronix!reed!teneron!shanks
Teneron Corp.
6700 SW 105th   Suite 200
Beaverton, OR  97005
(503) 646-1599

dan@gumby.UUCP (09/27/85)

> Unfortunately, the number DOS is returning seems to bear little
> relationship to the number of disk devices DOS currently knows about.
> Running DOS 3.10 on an IBM-PC/XT I get 5 drives. This doesn't change
> whether or not I have my ramdisk device driver installed. Does this call
> work correctly in any version of DOS? Is the number it returns useful
> for anything?

I suspect the number you are getting is the number of the highest
available drive letter.  Huh?, you ask?  As of version 3.1, DOS
reserves some extra drive letters for you to assign to pathnames
using the subst command.  The default highest drive letter is E:,
thus the number 5.  There is a command for the config.sys file to
raise or lower that number; it cannot be made lower than the number
of installed drives (including RAM drives, I think).

Check page 4-24 of the DOS 3.1 manual for a description of the 
LASTDRIVE command.