home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / SNPD9404.ZIP / DRIVSRCH.C < prev    next >
Text File  |  1994-04-03  |  2KB  |  70 lines

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