home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / wr_prot.c < prev    next >
C/C++ Source or Header  |  1994-03-04  |  1KB  |  47 lines

  1. /********************************************************************
  2. *  WR_PROT.C
  3. *
  4. *       Check to see if a drive is write protected
  5. *
  6. *       Compiled with MSC 5.1   2/5/90   by Kevin English
  7. *       kje2282@venus.tamu.edu  kje2282@tamvenus.bitnet
  8. *
  9. *       Uses the DOS Interupts 25H and 26H to do an absolute
  10. *       read, then write of logical sector 0 of the drive.
  11. *
  12. *       resultant ERRORLEVELs:
  13. *          2 : error accessing drive
  14. *          1 : write protected
  15. *          0 : writable
  16. */
  17. #include <dos.h>
  18. char buffer[2048];
  19.  
  20. int main()
  21. {
  22.    union REGS inregs, outregs;
  23.    struct SREGS segregs;
  24.    char far *bufferp;
  25.  
  26.    inregs.h.al = 0;   /* drive number 0,1 = a,b: 128,129=c,d */
  27.    inregs.x.cx = 1;   /* sectors to read */
  28.    inregs.x.dx = 0;   /* starting sector number */
  29.    bufferp = buffer;
  30.    inregs.x.bx = FP_OFF(bufferp);
  31.    segregs.ds  = FP_SEG(bufferp);
  32.  
  33.    int86x(0x25, &inregs, &outregs, &segregs);
  34.    if (outregs.x.cflag == 1) {
  35.       printf("error reading drive A\n");
  36.       return 2;
  37.    }
  38.  
  39.    int86x(0x26, &inregs, &outregs, &segregs);
  40.    if (outregs.x.cflag == 1) {
  41.       printf("error writing drive A\n");
  42.       return 1;
  43.    }
  44.  
  45.    return 0;
  46. }
  47.