home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD-ROM Magazin 1995 October
/
CD_10_95.BIN
/
share
/
dos
/
dtst&cln
/
dtest.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-30
|
5KB
|
198 lines
#include <stdio.h>
#include <dos.h>
#include <malloc.h>
#include <io.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)"},
};
char *bp;
char *cp;
char *buf;
void
main(int ac,char **av)
{
int cont = 0;
int wrt = 0;
int hd = 0;
int tr = 0;
int err = 0;
int mhd;
int mtr;
int str = 1;
int rc;
int spt;
long msec;
long rdtm;
long reftm;
if (ac == 2) {
strupr(av[1]);
if (strchr(av[1],'W'))
wrt++;
if (strchr(av[1],'C'))
cont++;
}
bp = (char *)getvect(0x41);
mtr = *(int *)bp;
mhd = bp[2];
spt = bp[0x0e];
buf = malloc(512);
bp = malloc(512);
cp = malloc(512);
msec = (long)mtr * (long)mhd * (long)spt;
printf("Disk: %d heads %d tracks %d sectors/track, %ld total secs\n",\
mhd,mtr,spt,msec);
spt++;
if (wrt)
printf("Read/Write test!\n");
else
printf("Read test only!\n");
ctrlbrk(Null);
loop:;
for (;;) {
printf("hd %d tr %3d sec %2d ",hd,tr,str);
rdtm = TIME;
rc = rdwr(tr,str,hd,buf,2);
reftm = TIME - rdtm;
if ((!rc) && (reftm > 1))
rc = 99;
if ((!rc) && (wrt))
rc = testit(tr,str,hd);
if (rc) {
err++;
if (rc == 99)
rc = 0;
printf("Err %d (%s)\n",rc,Err[rc]);
}
else
printf("ok\r");
str++;
if (str == spt) {
str = 1;
hd++;
}
if (hd == mhd) {
tr++;
hd = 0;
}
if (tr == mtr)
break;
if (kbhit()) {
int ch = getch();
if (ch == 27) {
printf("\nESC-Abort");
cont = 0;
break;
}
else if (ch == '+')
tr++;
else if (ch == '-')
tr--;
}
}
if (cont) {
printf("\rPass %d Errors %d \n",cont++,err);
err = 0;
tr = hd = 0;
str = 1;
goto loop;
}
printf("\nDisk C: tested with %d errors.\n",err);
}
int
testit(int track,int sector,int head)
{
int i;
int rc;
for (i=0; i<512; i+=2) {
cp[i] = 0x55;
cp[i+1] = 0xaa;
}
rc = rdwr(track,sector,head,cp,3);
if (!rc) {
rc = rdwr(track,sector,head,bp,2);
if (!rc) {
for (i=0; i<256; i++)
if (cp[i] != bp[i])
rc = 3;
}
}
if (!rc) {
for (i=0; i<512; i++)
cp[i] = rand();
rc = rdwr(track,sector,head,cp,3);
if (!rc) {
rc = rdwr(track,sector,head,bp,2);
if (!rc) {
for (i=0; i<256; i++)
if (cp[i] != bp[i])
rc = 3;
}
}
}
i = rdwr(track,sector,head,buf,3);
if ((i) && (!rc))
printf(" [SECTOR DESTROYED] ");
if (!rc)
rc = i;
return(rc);
}
int
rdwr(int tr,int str,int hd,char *p,int op)
{
union REGS rg;
struct SREGS sr;
rg.h.ah = op;
rg.h.al = 1;
rg.h.ch = (char)tr;
rg.h.cl = str | ((tr >> 2) & 0xc0);
rg.h.dh = hd;
rg.h.dl = 0x80;
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);
}