home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD-ROM Magazin 1995 October
/
CD_10_95.BIN
/
share
/
dos
/
dtst&cln
/
dclone.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-08-17
|
4KB
|
183 lines
#include <stdio.h>
#include <dos.h>
#include <malloc.h>
#include <io.h>
#include <stdlib.h>
#include <conio.h>
#define TIME *(long *)0x46cL
extern int Null(void);
char *Err[] = {
{"Retries detected"},
{"bad command"},
{"address mark not found"},
{"Data r/w compare error"},
{"sector not found"},
{"reset failed (hard disk)"},
{"diskette changed"},
{"parameter act. failed (hard disk)"},
{"DMA overrun (floppy disk)"},
{"DMA across 64K boundary"},
{"bad sector detected (hard disk)"},
{"bad track detected (hard disk)"},
{"unsupported track"},
{"invalid number of sectors on format (hard disk)"},
{"control data address mark detected (hard disk)"},
{"DMA arbitration error (hard disk)"},
{"bad CRC/ECC"},
{"data ECC corrected (hard disk)"},
{"controller failure"},
{"seek failed"},
{"time out"},
{"drive not ready (hard disk)"},
{"undefined error (hard disk)"},
{"write fault (hard disk)"},
{"status register error (hard disk)"},
{"sense operation failed (hard disk)"},
{"compare error"}, // internal
};
char *bp;
char *cp;
char *buf;
char *bf1;
int spt;
extern void main(void);
extern int testit(int,int,int);
extern int rdwr(int,int,int,char *,int,int);
extern int Null(void);
void
main(void)
{
int hd = 0;
int tr = 0;
int err = 0;
int mhd;
int mhd1;
int mtr;
int mtr1;
int spt1;
int str = 1;
int rc;
long msec;
long rdtm;
long reftm;
bp = (char *)getvect(0x41);
mtr = *(int *)bp;
mhd = bp[2];
spt = bp[0x0e];
bp = (char *)getvect(0x46);
mtr1 = *(int *)bp;
mhd1 = bp[2];
spt1 = bp[0x0e];
if (spt > 120) {
printf("Cannot handle %d sectors/track!\n",spt);
exit(1);
}
if ((mtr != mtr1) || (mhd != mhd1) || (spt != spt1)) {
printf("ERROR: C: and D: are different types!\n");
exit(1);
}
buf = malloc((spt + 2) * 512);
bf1 = malloc((spt + 2) * 512);
if ((!buf) || (!bf1)) {
printf("not enough memory!\n");
exit(1);
}
msec = (long)mtr * (long)mhd * (long)spt;
printf("\n\n");
printf("Disk: %d heads %d tracks %d sectors/track, %ld total secs\n",\
mhd,mtr,spt,msec);
printf("Copy C: to D:!\n");
printf("Any key to continue, ESC to abort...");
if ((getch() & 0xff) == 27)
exit(1);
printf("\n\n");
ctrlbrk(Null);
loop:;
for (;;) {
printf("hd %3d tr %3d sec %2d ",hd,tr,str);
rdtm = TIME;
rc = rdwr(tr,str,hd,buf,2,0x80);
reftm = TIME - rdtm;
if ((!rc) && (reftm > 1))
rc = 99;
if (!rc)
rc = testit(tr,str,hd);
putch(' ');
if (rc) {
err++;
if (rc == 99)
rc = 0;
printf("Err %d (%s)\n",rc,Err[rc]);
}
else
printf("ok\r");
str = 1;
hd++;
if (hd == mhd) {
tr++;
hd = 0;
}
if (tr == mtr)
break;
if (kbhit()) {
int ch = getch();
if (ch == 27) {
printf("\nESC-Abort!!!!!\n");
break;
}
}
}
printf("\nDisk C: copied to D: with %d errors.\n",err);
}
int
testit(int track,int sector,int head)
{
int i;
int rc;
rc = rdwr(track,sector,head,buf,3,0x81);
if (!rc) {
rdwr(track,sector,head,bf1,2,0x81);
for (i=0; i<(spt*512); i++)
if (buf[i] != bf1[i])
return(26);
}
return(rc);
}
int
rdwr(int tr,int str,int hd,char *p,int op,int disk)
{
union REGS rg;
struct SREGS sr;
if (op == 3)
putch('W');
else
putch('R');
rg.h.ah = op;
rg.h.al = spt;
rg.h.ch = (char)tr;
rg.h.cl = str | ((tr >> 2) & 0xc0);
rg.h.dh = hd;
rg.h.dl = disk;
rg.x.bx = FP_OFF(p);
sr.es = FP_SEG(p);
int86x(0x13,&rg,&rg,&sr);
return(rg.h.ah);
}
int
Null(void)
{
return(1);
}