home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / DRIVSRCH.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  2KB  |  81 lines

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