home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Magazin 1995 October / CD_10_95.BIN / share / dos / dtst&cln / dtest.c < prev    next >
C/C++ Source or Header  |  1991-07-30  |  5KB  |  198 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <malloc.h>
  4. #include <io.h>
  5.  
  6. #define TIME    *(long *)0x46cL
  7.  
  8. extern  int     Null(void);
  9.  
  10. char    *Err[] = {
  11.     {"Retries detected"},
  12.     {"bad command"},
  13.     {"address mark not found"},
  14.     {"Data r/w compare error"},
  15.     {"sector not found"},
  16.     {"reset failed (hard disk)"},
  17.     {"diskette changed"},
  18.     {"parameter act. failed (hard disk)"},
  19.     {"DMA overrun (floppy disk)"},
  20.     {"DMA across 64K boundary"},
  21.     {"bad sector detected (hard disk)"},
  22.     {"bad track detected (hard disk)"},
  23.     {"unsupported track"},
  24.     {"invalid number of sectors on format (hard disk)"},
  25.     {"control data address mark detected (hard disk)"},
  26.     {"DMA arbitration error (hard disk)"},
  27.     {"bad CRC/ECC"},
  28.     {"data ECC corrected (hard disk)"},
  29.     {"controller failure"},
  30.     {"seek failed"},
  31.     {"time out"},
  32.     {"drive not ready (hard disk)"},
  33.     {"undefined error (hard disk)"},
  34.     {"write fault (hard disk)"},
  35.     {"status register error (hard disk)"},
  36.     {"sense operation failed (hard disk)"},
  37. };
  38.  
  39. char    *bp;
  40. char    *cp;
  41. char    *buf;
  42.  
  43. void
  44. main(int ac,char **av)
  45. {
  46.     int     cont = 0;
  47.     int     wrt = 0;
  48.     int     hd = 0;
  49.     int     tr = 0;
  50.     int     err = 0;
  51.     int     mhd;
  52.     int     mtr;
  53.     int     str = 1;
  54.     int     rc;
  55.     int     spt;
  56.     long    msec;
  57.     long    rdtm;
  58.     long    reftm;
  59.  
  60.     if (ac == 2) {
  61.         strupr(av[1]);
  62.         if (strchr(av[1],'W'))
  63.             wrt++;
  64.         if (strchr(av[1],'C'))
  65.             cont++;
  66.     }
  67.     bp = (char *)getvect(0x41);
  68.     mtr = *(int *)bp;
  69.     mhd = bp[2];
  70.     spt = bp[0x0e];
  71.     buf = malloc(512);
  72.     bp = malloc(512);
  73.     cp = malloc(512);
  74.     msec = (long)mtr * (long)mhd * (long)spt;
  75.     printf("Disk: %d heads %d tracks %d sectors/track, %ld total secs\n",\
  76.       mhd,mtr,spt,msec);
  77.     spt++;
  78.     if (wrt)
  79.         printf("Read/Write test!\n");
  80.     else
  81.         printf("Read test only!\n");
  82.     ctrlbrk(Null);
  83. loop:;
  84.     for (;;) {
  85.         printf("hd %d  tr %3d  sec %2d ",hd,tr,str);
  86.         rdtm = TIME;
  87.         rc = rdwr(tr,str,hd,buf,2);
  88.         reftm = TIME - rdtm;
  89.         if ((!rc) && (reftm > 1))
  90.             rc = 99;
  91.         if ((!rc) && (wrt))
  92.             rc = testit(tr,str,hd);
  93.         if (rc) {
  94.             err++;
  95.             if (rc == 99)
  96.                 rc = 0;
  97.             printf("Err %d (%s)\n",rc,Err[rc]);
  98.         }
  99.         else
  100.             printf("ok\r");
  101.         str++;
  102.         if (str == spt) {
  103.             str = 1;
  104.             hd++;
  105.         }
  106.         if (hd == mhd) {
  107.             tr++;
  108.             hd = 0;
  109.         }
  110.         if (tr == mtr)
  111.             break;
  112.         if (kbhit()) {
  113.             int     ch = getch();
  114.             if (ch == 27) {
  115.                 printf("\nESC-Abort");
  116.                 cont = 0;
  117.                 break;
  118.             }
  119.             else if (ch == '+')
  120.                 tr++;
  121.             else if (ch == '-')
  122.                 tr--;
  123.         }
  124.     }
  125.     if (cont) {
  126.         printf("\rPass %d Errors %d                         \n",cont++,err);
  127.         err = 0;
  128.         tr = hd = 0;
  129.         str = 1;
  130.         goto loop;
  131.     }
  132.     printf("\nDisk C: tested with %d errors.\n",err);
  133. }
  134.  
  135. int
  136. testit(int track,int sector,int head)
  137. {
  138.     int     i;
  139.     int     rc;
  140.  
  141.     for (i=0; i<512; i+=2) {
  142.         cp[i] = 0x55;
  143.         cp[i+1] = 0xaa;
  144.     }
  145.     rc = rdwr(track,sector,head,cp,3);
  146.     if (!rc) {
  147.         rc = rdwr(track,sector,head,bp,2);
  148.         if (!rc) {
  149.             for (i=0; i<256; i++)
  150.                 if (cp[i] != bp[i])
  151.                     rc = 3;
  152.         }
  153.     }
  154.     if (!rc) {
  155.         for (i=0; i<512; i++)
  156.             cp[i] = rand();
  157.         rc = rdwr(track,sector,head,cp,3);
  158.         if (!rc) {
  159.             rc = rdwr(track,sector,head,bp,2);
  160.             if (!rc) {
  161.                 for (i=0; i<256; i++)
  162.                     if (cp[i] != bp[i])
  163.                         rc = 3;
  164.             }
  165.         }
  166.     }
  167.     i = rdwr(track,sector,head,buf,3);
  168.     if ((i) && (!rc))
  169.         printf(" [SECTOR DESTROYED] ");
  170.     if (!rc)
  171.         rc = i;
  172.     return(rc);
  173. }
  174.  
  175. int
  176. rdwr(int tr,int str,int hd,char *p,int op)
  177. {
  178.     union   REGS    rg;
  179.     struct  SREGS   sr;
  180.  
  181.     rg.h.ah = op;
  182.     rg.h.al = 1;
  183.     rg.h.ch = (char)tr;
  184.     rg.h.cl = str | ((tr >> 2) & 0xc0);
  185.     rg.h.dh = hd;
  186.     rg.h.dl = 0x80;
  187.     rg.x.bx = FP_OFF(p);
  188.     sr.es = FP_SEG(p);
  189.     int86x(0x13,&rg,&rg,&sr);
  190.     return(rg.h.ah);
  191. }
  192.  
  193. int
  194. Null(void)
  195. {
  196.     return(1);
  197. }
  198.