home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Magazin 1995 October / CD_10_95.BIN / share / dos / dtst&cln / dclone.c < prev    next >
C/C++ Source or Header  |  1995-08-17  |  4KB  |  183 lines

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