home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / SNIP9404.ZIP / DRIVSRCH.C < prev    next >
C/C++ Source or Header  |  1994-04-03  |  2KB  |  85 lines

  1. /*
  2. **  DRIVSRCH.C - public domain by Marty Connelly, Victoria, BC 1992
  3. **
  4. **  Modified by Bob Stout
  5. **  
  6. **  Routine checks how many valid disk drives are available on machine,
  7. **  both physical and logical drives
  8. */
  9.  
  10. /*
  11. **  Includes drive letters assigned with DOS SUBST command
  12. **
  13. **  Networked drives are left as an exercise as I don't have access
  14. **  to them to check.
  15. **
  16. **  The routine uses undocumented DOS interrupt 32H.
  17. **
  18. **  Compatible with MSC 5 and 6, ZTC++, BC++, other DOS compilers
  19. **
  20. **  DS:BX contains the address of the Disk Parameter Block (DPB) for a
  21. **  requested drive. If the drive letter at offset 0 of the DPB doesn't
  22. **  match the requested drive, then the drive has been SUBST'ed.
  23. */
  24.  
  25. #include <stdio.h>
  26. #include <dos.h>
  27.  
  28. #if !defined(MK_FP)
  29.     #define MK_FP(seg,off) ((void far *)(((long)(seg) << 16)|(unsigned)(off)))
  30. #endif
  31.  
  32. #ifdef __TURBOC__
  33.  #define _far far
  34. #endif
  35.  
  36. void main(void)
  37. {
  38.       int i;
  39.       int unsigned result;
  40.       int drivestatus[26];
  41.       unsigned char _far *DPB;
  42.       union REGS regs;
  43.       struct SREGS sregs;
  44.  
  45.  
  46.       /* routine checks for all valid drive possibilities from A to Z  */
  47.  
  48.       /*
  49.       **    if removeable media drive ie. floppy drive A: has a latch door
  50.       **    open you will get "Abort Retry" panic message
  51.       */
  52.  
  53.       for (i = 0; i < 26; i++)
  54.       {
  55.             /* drive number (0=default, 1=A, 2=B,etc.)*/
  56.  
  57.             regs.h.dl = (unsigned char)(i + 1);
  58.             segread(&sregs);
  59.  
  60.             regs.h.ah=0x32;         /* DOS interrupt 32H */
  61.                                     /* was undocumented for DOS release 3.2 */
  62.  
  63.             intdosx(®s,®s, &sregs);
  64.  
  65.             result=regs.h.al;
  66.             DPB = MK_FP(sregs.ds, regs.x.bx);
  67.  
  68.             /*
  69.             **  result =0  then valid drive
  70.             **         =255 or ff hex then invalid or non-existent drive
  71.             */
  72.  
  73.             if (0 == result && *DPB != (unsigned char)i)
  74.                   drivestatus[i] = 1;
  75.             else  drivestatus[i]=result;
  76.       }
  77.  
  78.       for (i = 0; i < 26; i = i + 2)
  79.       {
  80.             printf("drive %c: status code =%3d drive %c: status code =%3d\n",
  81.                   'A' + i,drivestatus[i],'B' + i,drivestatus[i+1]);
  82.       }
  83.       return;
  84. }
  85.