[comp.sys.ibm.pc] Magic Number Five in turbo C, MS C, and int 21/0E

wayne@schaefer.MATH.WISC.EDU (Rick Wayne) (10/10/89)

we've run into a little problem here that i find baffling.  we're trying to
determine the number of disk drives on a machine at runtime.  there's a DOS
interrupt service for this: interrupt 0x21, function 0x0E, "set default
disk drive".  it's supposed to return the number of drives in the system.

for all the machines we have here (AST Premium 386, Standard 286, Compaq
Deskpro, Dell 210), we get the answer of...five.  needless to say, these
disparate machines have differing numbers of drives.  the one number we
CANNOT come up with, of course, is five.

well, ok, i can't read, maybe a misprint, i'm reading the register wrong, who
knows.  i'll try using the setdisk() function in turbo C, which is supposed
to return the right value.

Five.

Microsoft C?  Five.  hmm.  a sort of subtle pattern emerges.

have we discovered a secret numerological cabal here?  (i have been approached
in parking lots by religious nuts convinced that the number 666 was being 
seeded millions of times in the nation's computers to assist a Satanic 
takeover).  i am a little frustrated, to say the least.  many of our machines
are using a special disk device driver to allow partitions >32 MB, but not
all of them.

any ideas, troops?

rick wayne
WISPLAN (UW Extension)

ralf@b.gp.cs.cmu.edu (Ralf Brown) (10/11/89)

In article <483@schaefer.MATH.WISC.EDU> wayne@schaefer.MATH.WISC.EDU (Rick Wayne) writes:
}determine the number of disk drives on a machine at runtime.  there's a DOS
}interrupt service for this: interrupt 0x21, function 0x0E, "set default
}disk drive".  it's supposed to return the number of drives in the system.
}
}for all the machines we have here (AST Premium 386, Standard 286, Compaq
}Deskpro, Dell 210), we get the answer of...five.  needless to say, these
}disparate machines have differing numbers of drives.  the one number we
}CANNOT come up with, of course, is five.

The value you are seeing is the value of LASTDRIVE= in CONFIG.SYS, which
defaults to 5 if not present.  The value returned by INT 21/AH=0Eh is the
maximum of
	actual drives in system (including virtual drives)
	value of LASTDRIVE
	5


-- 
{backbone}!cs.cmu.edu!ralf   ARPA: RALF@CS.CMU.EDU   FIDO: Ralf Brown 1:129/46
BITnet: RALF%CS.CMU.EDU@CMUCCVMA   AT&Tnet: (412)268-3053 (school)   FAX: ask
DISCLAIMER? |"Humor is laughing at what you haven't got when you ought to
What's that?| have it."  -- Langston Hughes

src@cup.portal.com (Steve R Calwas) (10/12/89)

In article <483@schaefer.MATH.WISC.EDU> wayne@schaefer.MATH.WISC.EDU (Rick Wayn
e) writes:
}determine the number of disk drives on a machine at runtime.  there's a DOS
}interrupt service for this: interrupt 0x21, function 0x0E, "set default
}disk drive".  it's supposed to return the number of drives in the system.
}
}for all the machines we have here (AST Premium 386, Standard 286, Compaq
}Deskpro, Dell 210), we get the answer of...five.  needless to say, these
}disparate machines have differing numbers of drives.  the one number we
}CANNOT come up with, of course, is five.

RALF@CS.CMU.EDU (Ralf Brown) responds:
>The value you are seeing is the value of LASTDRIVE= in CONFIG.SYS, which
>defaults to 5 if not present.  The value returned by INT 21/AH=0Eh is the
>maximum of
>        actual drives in system (including virtual drives)
>        value of LASTDRIVE
>        5

I would like to add that the problem finding the actual number of drives on
a system began with DOS 3.xx.  Also, one method to determine how many drives
really exist is to take the returned value from the INT 21h/AH=0Eh function
(i.e. the 5 you keep getting) and try to get the current directory for each
drive.  If the drive does not exist, an error will result.

Steve Calwas                    src@cup.portal.com
Santa Clara, CA                 ...!sun!cup.portal.com!src

john@wsl.UUCP (John Allen on wsl) (10/13/89)

In article <483@schaefer.MATH.WISC.EDU> wayne@schaefer.MATH.WISC.EDU (Rick Wayne) writes:
>we've run into a little problem here that i find baffling.  we're trying to
>determine the number of disk drives on a machine at runtime.  there's a DOS
>interrupt service for this: interrupt 0x21, function 0x0E, "set default
>disk drive".  it's supposed to return the number of drives in the system.
>

Try putting the following line in your config.sys and watch the magic
number 5 change completely under your control.

lastdrive=z
lastdrive=p

etc....

By the way the default is lastdrive=e, does this give you any clues.

wew@naucse.UUCP (Bill Wilson) (10/16/89)

From article <483@schaefer.MATH.WISC.EDU>, by wayne@schaefer.MATH.WISC.EDU (Rick Wayne):
> we've run into a little problem here that i find baffling.  we're trying to
> determine the number of disk drives on a machine at runtime.  there's a DOS
> interrupt service for this: interrupt 0x21, function 0x0E, "set default
> disk drive".  it's supposed to return the number of drives in the system.
> 
> for all the machines we have here (AST Premium 386, Standard 286, Compaq
> Deskpro, Dell 210), we get the answer of...five.  needless to say, these
> disparate machines have differing numbers of drives.  the one number we
> CANNOT come up with, of course, is five.
>
I tried out the function and it worked just fine on my system.  The
function returns the number of drives that DOS thinks you have.  Since
I have the following in my config.sys:
   lastdrive=z
the function reports 26.  You may want to check your config for what
is indicated in it.  I used the following code to check:

#include <stdlib.h>
#include <stdio.h>
#include <dir.h>

main()
{
   int ndrvs;

   ndrvs=setdisk(getdisk());
   printf("# of drives is %d\n",ndrvs);
}

I use getdisk so that I do not change the current drive.

 
-- 
Let sleeping dragons lie........               | The Bit Chaser
----------------------------------------------------------------
Bill Wilson             (Bitnet: ucc2wew@nauvm | wilson@nauvax)
Northern AZ Univ  Flagstaff, AZ 86011