Alain asks:

How can I detect the current setting of LASTDRIVE= ?

I just made a program someone suggested in this list. I liked the idea, but I am sorry I cannot remember who had the idea ;-)

The program is called CALCTDSK. It evaluates how much XMS is available, and how much RamDisk I need if I am to use any RamDisk at all. If evything is ok, it creates a batch file with the correct invocation of TDSK and the loader DEVLOAD.

It tested ok, and then I installed in a client's machine and Gess What? An unexpected problem: He already has 4 partition C: D: E: F: and TDSK could not install. Worse even is that DEVLOAD cannot detect the problem (there is no errorlevel for device drivers) and the driver remains loaded in memory.

How can I detect the current setting of LASTDRIVE= ? Please just send me just a few hints so that I can orient myself in RBIL...

-Alain


Arkady points us to Techhelp:

The undocumented DOS fn 52H (get DOS Vars) returns the address of a DOS Variables Block, one field of which contains the LASTDRIVE= setting and another field points to a pointer to the drive info array.


Bart Oldeman points us to Ralph Brown's Interrupt List:

directly and dirty:

INT 21 U - DOS 2+ internal - "SYSVARS" - GET LIST OF LISTS
        AH = 52h
Return: ES:BX -> DOS list of lists (see #01627)
see offset 21h

or nicer:

INT 21 - DOS 1+ - SELECT DEFAULT DRIVE
        AH = 0Eh
        DL = new default drive (00h = A:, 01h = B:, etc)
Return: AL = number of potentially valid drive letters
Notes:  under Novell NetWare, the return value is always 32, the number of
          drives that NetWare supports
        under DOS 3.0+, the return value is the greatest of 5, the value of
          LASTDRIVE= in CONFIG.SYS, and the number of drives actually present
        on a DOS 1.x/2.x single-floppy system, AL returns 2 since the floppy
          may be accessed as either A: or B:
        otherwise, the return value is the highest drive actually present
        DOS 1.x supports a maximum of 16 drives, 2.x a maximum of 63 drives,
          and 3+ a maximum of 26 drives
        under Novell DOS 7, this function returns the correct LASTDRIVE value
          even when the undocumented LASTDRIVE=27..32 directive was used in
          CONFIG.SYS
        "parse FCB" (see AH=29h) can be used to determine whether a drive
          letter is valid
SeeAlso: AH=19h,AH=3Bh,AH=DBh

Imre Leber provides a little bit of sample code:

Please compile this:

  #include <dir.h>
  
  int main()
  {
    return setdisk(getdisk());
  }

It should return the last drive starting with 0. So if your last drive is d:; it should return 3. So:

  if errorlevel 3 goto highenough
  
  echo Not high enough
  goto theend
  
  :highenough
  rem execute whathever
  
  :theend

should do the trick.