|
DataMuseum.dkPresents historical artifacts from the history of: Commodore CBM-900 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Commodore CBM-900 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - download
Length: 7164 (0x1bfc) Types: TextFile Notes: UNIX file Names: »BTST.C«, »tst.c«
└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code └─⟦2d53db1df⟧ UNIX Filesystem └─ ⟦this⟧ »frankh/src/BTST.C« └─ ⟦this⟧ »frankh/src/junk/tst.c«
/* * Production burn in. fah 06/25/85 */ #include <sys/timeb.h> #include <stdio.h> #include <time.h> #include <sys/stat.h> #include <access.h> #define VERS "1.0" #define BLKSIZ 512 /* * 31001A04 A badblk int * 31001900 A errors int * 31001696 A pass unsigned int * 310016D8 A timeouts int * * These variables were set by the driver, WDSCAN. Note that a special * version of coherent (md.s) is required to access these locations. * Normally segment 31 is system only. The special version of coherent * lowers the protection level of seg 31 to 0. * The variables are accessed using pointers. */ #define PASS ((unsigned short *)(0x31001696L)) #define ERRORS ((unsigned short *)(0x31001900L)) #define BADBLK ((unsigned short *)(0x31001A04L)) #define TIMEOUTS ((unsigned short *)(0x310016D8L)) extern unsigned char pattern[512]; unsigned char buf[512]; long bgblk, atol(); int errsup; unsigned int *pass; int *errors, *badblk, *timeouts; struct timeb systime; main(argc, argv) int argc; char *argv[]; { register unsigned int errcnt; unsigned int hderr, fderr; long maxblk, blksiz; unsigned long xrand(); char *dev, *num, *bufnum, *itoa(); char *ctime(); FILE *f1, *fopen(); num = " "; errsup = 0; errcnt = 0; srand(0); pass = PASS; errors = ERRORS; badblk = BADBLK; timeouts = TIMEOUTS; printf("\nC900 Production Burnin - Disk Excerciser %s\n\n",VERS); printf("There are %d bad blocks on the hard disk.\n", *badblk); /* * If the file "/DATA.BURN" exists, error counts are read from there. * otherwise, they are initialized to 0 and the file is created. */ geterr(&hderr, &fderr); printf("Cumulative errors:\t%s\t%u\n", "/dev/hdall1", hderr); printf("\t\t\t%s\t%u\n\n", "/dev/fd1", fderr); hderr += bang( "/dev/hdall1", 1L, 31000L, 100); fderr += bang( "/dev/fd1", 1510L, 2300L, 20); if ((f1 = fopen("/tmp/BURN.RESULT", "w")) == NULL) panic(" Can't open data file!\n"); stwrite(f1, "Production Burnin. Date: "); ftime(&systime); stwrite(f1, ctime(&systime)); stwrite(f1, "\n\n"); erwrt(f1, "/dev/hdall1", hderr); erwrt(f1, "/dev/fd1", fderr); stwrite(f1, "\n"); stwrite(f1, "Timeouts during format:\t\t"); stwrite(f1, itoa(*timeouts, num)); stwrite(f1, "\n"); stwrite(f1, "Bad blocks on hard disk:\t"); stwrite(f1, itoa(*badblk, num)); stwrite(f1, "\n\n"); puterr(&hderr, &fderr); /* write error file */ fclose(f1); exit(0); } /* * */ int erwrt( file, dev, err) char *dev; int err; FILE *file; { char *itoa(); char *num; num = " "; stwrite(file, "Device:\t"); stwrite(file, dev); stwrite(file, "\tDisk errors: "); stwrite(file, itoa(err, num)); stwrite(file, "\n"); } /* * write a character string to a file. * */ int stwrite(fd, strng) FILE *fd; char *strng; { register int i; for (i = 0; strng[i] != 0; ++i) if (putc(strng[i], fd) == EOF) panic("stwrite: bad file write!\n"); } /* * block write */ bwrite(fdo, blk, db) long blk, lseek(); unsigned char *db; register int fdo; { lseek(fdo, blk*512L, 0); if (write(fdo, db, BLKSIZ) != BLKSIZ) printf("btst: bwrite: Bad write!\n"); } /* * block read */ bread(fdi, blk, db) long blk, lseek(); unsigned char *db; register int fdi; { lseek(fdi, blk*512L, 0); if (read(fdi, db, BLKSIZ) != BLKSIZ) printf("btst: bread: Bad read!\n"); } unsigned long xrand(min, max) unsigned long min, max; { unsigned long try, t, y; unsigned int rfact; try = 0; rfact = max / 32767L + 1L; while ((min > try) || (try > max)) { try = rand() * rfact; } return(try); } panic(x) { printf("btst: %r", &x); exit(1); } fill(spot) register unsigned char *spot; { register unsigned int count; for (count = 0; count < 512; ++count) *spot++ = pattern[count]; /* *spot++ = pattern[(seedy+count)&511]; ++seedy; */ } clr(spot) register unsigned char *spot; { register unsigned int i; for (i = 0; i < 512; ++i) *spot++ = 0; } check(spot, bn) register unsigned char *spot; long bn; { register int count; register int err = 0; register int loopc; for (count = 0; count < 512; ++count) if (*spot++ != pattern[count]) { /* if (*spot++ != pattern[(seedy+count)&511]) { */ /* *--spot, pattern[(seedy+count)&511], */ eprintf("data err %x != %x ofs=%u b=%u\n", *--spot, pattern[count], count, (int)bn); eprintf("disk: "); for (loopc = -5; loopc <= 5; ++loopc) eprintf("%x ", spot[loopc]); eprintf("\nreal: "); for (loopc = count-5; loopc <= count+5; ++loopc) eprintf("%x ", pattern[loopc]); /* eprintf("%x ", pattern[(seedy+loopc)&511]); */ eprintf("\n"); ++err; break; } /* seedy++; */ return (err); } eprintf(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) { if (errsup) return; printf(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o); } /* * Convert interger to ascii string ( leading zeros ) * five places. */ char *itoa(in, strng) unsigned int in; char *strng; { register int i; unsigned int p; p = 10000; strng[0] = 32; /* lead off with a blank */ for(i = 1; i != 6; ++i) { strng[i] = in / p + 0x30; in = in - ( in / p ) * p; p = p / 10; } return(strng); } bang( dev, sblk, eblk, count) char *dev; unsigned long sblk,eblk; int count; { register int i, fdi, fdo, err; register long blk; /* printf("btst: bang: %s %U %U %u \n", dev, sblk, eblk, count); */ err = 0; if ((fdi = open(dev, 0)) < 0) panic("can't open input device\n"); if ((fdo = open(dev, 1)) < 0) panic("can't open output device\n"); printf("btst: testing:\t%s\n", dev); for (i = 0; i < count; ++i) { blk = xrand(sblk, eblk); /* generate random block number */ bwrite(fdo, blk, pattern); /* write the block with pattern */ clr( buf); /* clear buffer */ bread(fdi, blk, buf); /* read it back */ if (check(buf, sblk)) /* see if ok */ ++err; } printf("btst: device:\t%s\terrors this pass:\t%u\n", dev, err); close(fdi); close(fdo); return(err); } /* * read or create error file * */ geterr( er0, er1) unsigned int *er0, *er1; { register int fd; unsigned char *tmp; long lseek(); tmp = " "; if (access("/tmp/DATA.BURN", AWRITE)) { creat("/tmp/DATA.BURN", S_IFREG | S_IREAD | S_IWRITE); *er0 = 0; *er1 = 0; return; } if ((fd = open("/tmp/DATA.BURN", 0)) < 0) panic("btst: geterr: Can't open file!\n"); lseek(fd, 6L, 0); /* get first number */ if (read(fd, tmp, 6) != 6) panic("geterr: bad read\n"); *er1 = atoi(tmp); lseek(fd, 0L, 0); /* get second number */ if (read(fd, tmp, 6) != 6) panic("geterr: bad read\n"); *er0 = atoi(tmp); close(fd); } /* * */ puterr( er0, er1) unsigned int *er0, *er1; { register int fd; unsigned char *tmp; long lseek(); tmp = " "; if (access("/tmp/DATA.BURN", AWRITE)) { creat("/tmp/DATA.BURN", S_IFREG | S_IREAD | S_IWRITE); printf("puterr: WARNING: Created DATA.BURN!\n"); } if ((fd = open("/tmp/DATA.BURN", 1)) < 0) panic("puterr: Can't open file!\n"); lseek(fd, 0L, 0); tmp = itoa(*er0, tmp); if (write(fd, tmp, 6) != 6) panic("puterr: write error\n"); lseek(fd, 6L, 0); tmp = itoa(*er1, tmp); if (write(fd, tmp, 6) != 6) panic("puterr: write error\n"); close(fd); }