home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / s / snip1292.zip / DRIVSRCH.C < prev    next >
C/C++ Source or Header  |  1992-07-03  |  2KB  |  76 lines

  1. /*
  2. **  DRIVSRCH.C - public domain by Marty Connelly Victoria, BC 1992
  3. **  
  4. **  Routine checks how many valid disk drives are available on machine,
  5. **  both physical and logical drives
  6. */
  7.  
  8. /*
  9.   Includes drive letters assigned with DOS SUBST command
  10.   Networked drives are left as an exercise as I don't have access
  11.   to them to check.
  12.   The routine uses undocumented DOS interrupt 32H.
  13.  
  14.  Compiled Under TC LARGE memory Model
  15.  Compatible with MSC 5 and 6, ZTC++, other DOS compilers
  16.  
  17.    DS:BX contains the address of a Disk Info Block for a requested
  18.  drive. This is useful for applications which perform sector_level
  19.  access of disk drives supported by device drivers. Some disk drives
  20.  (especially non-bootable drives) might not contain valid information
  21.  in the boot record and partion table making it hard to locate the
  22.  root directory size or number of FATs. This info is contained in the
  23.  Disk Info Block Structure
  24. */
  25.  
  26.  
  27. #include <dos.h>
  28.  
  29. union REGS inregs,outregs;
  30.  
  31. void main(void)
  32. {
  33.       int i;
  34.       int unsigned result;
  35.       int drivestatus[27];
  36.  
  37.       char drive [27] ={'0','A','B','C','D','E','F','G','H',
  38.                         'l','J','K','L','M','N','O','P','Q',
  39.                         'R','S','T','U','V','W','X','Y','Z'};
  40.  
  41.       /* routine checks for all valid drive possibilities from A to Z  */
  42.  
  43.       /* 0 indicates current drive */
  44.  
  45.       /*
  46.             if removeable media drive ie. floppy drive A: has a latch door
  47.             open you will get "Abort Retry" panic message
  48.       */
  49.  
  50.       for (i = 0; i <= 26; i++)
  51.       {
  52.             inregs.h.dl=i;    /* drive number (0=default, 1=A, 2=B,etc.)*/
  53.  
  54.             inregs.h.ah=0x32; /* DOS interrupt 32H */
  55.                               /* was undocumented for DOS release 3.2*/
  56.             intdos(&inregs,&outregs);
  57.  
  58.             result=outregs.h.al;
  59.  
  60.             /* result =0  then valid drive
  61.                       =55 then  DOS comand SUBST used on drive
  62.                           such as  SUBST P: C:\DOS\TEST
  63.                       =255 or ff hex then invalid or non-existent drive
  64.                       =??? networked drive
  65.             */
  66.             drivestatus[i]=result;
  67.       }
  68.  
  69.       for (i = 1; i <= 26; i = i + 2)
  70.       {
  71.             printf("drive %c: status code =%d drive %c: status code =%d\r\n",
  72.                   drive[i],drivestatus[i],drive[i+1],drivestatus[i+1]);
  73.       }
  74.       return;
  75. }
  76.