1*11634Sroot /* drtest.c 4.12 83/03/20 */ 29973Ssam 311360Ssam /* 411360Ssam * Standalone program to test a disk and driver 511368Ssam * by reading the disk a track at a time. 611360Ssam */ 710354Shelge #include "../h/param.h" 810354Shelge #include "../h/inode.h" 910354Shelge #include "../h/fs.h" 1010354Shelge #include "saio.h" 1110354Shelge 1210354Shelge #define SECTSIZ 512 139973Ssam 1411368Ssam extern int end; 1511368Ssam char *malloc(); 1611368Ssam char *prompt(); 1710608Ssam 189973Ssam main() 199973Ssam { 2011368Ssam char *cp, *bp; 2111368Ssam int fd, tracksize, debug; 2211368Ssam register int sector, lastsector; 2310354Shelge struct st st; 249973Ssam 2511368Ssam printf("Testprogram for stand-alone driver\n\n"); 2611368Ssam again: 2711368Ssam cp = prompt("Enable debugging (1=bse, 2=ecc, 3=bse+ecc)? "); 2811368Ssam debug = atoi(cp); 2911368Ssam if (debug < 0) 3011368Ssam debug = 0; 3111368Ssam fd = getdevice(); 32*11634Sroot ioctl(fd, SAIODEVDATA, (char *)&st); 3310719Shelge printf("Device data: #cylinders=%d, #tracks=%d, #sectors=%d\n", 3410726Ssam st.ncyl, st.ntrak, st.nsect); 35*11634Sroot ioctl(fd, SAIODEBUG, (char *)debug); 3611368Ssam tracksize = st.nsect * SECTSIZ; 3711375Ssam bp = malloc(tracksize); 3811368Ssam printf("Reading in %d byte records\n", tracksize); 3911368Ssam printf("Start ...make sure drive is on-line\n"); 4011170Shelge lseek(fd, 0, 0); 4111375Ssam lastsector = st.ncyl * st.nspc; 4211375Ssam for (sector = 0; sector < lastsector; sector += st.nsect) { 4311368Ssam if (sector && (sector % (st.nspc * 10)) == 0) 4411368Ssam printf("sector %d\n", sector); 4511368Ssam read(fd, bp, tracksize); 4611368Ssam } 4711368Ssam goto again; 4811368Ssam } 4911170Shelge 5011368Ssam /* 5111368Ssam * Prompt and verify a device name from the user. 5211368Ssam */ 5311368Ssam getdevice() 5411368Ssam { 5511368Ssam register char *cp; 5611368Ssam register struct devsw *dp; 5711368Ssam int fd; 5811368Ssam 5911368Ssam top: 6011368Ssam cp = prompt("Device to read? "); 6111368Ssam if ((fd = open(cp, 2)) < 0) { 6211368Ssam printf("Known devices are: "); 6311368Ssam for (dp = devsw; dp->dv_name; dp++) 6411368Ssam printf("%s ",dp->dv_name); 6511368Ssam printf("\n"); 6611368Ssam goto top; 679973Ssam } 6811368Ssam return (fd); 699973Ssam } 7011368Ssam 7111368Ssam char * 7211368Ssam prompt(msg) 7311368Ssam char *msg; 7411368Ssam { 7511368Ssam static char buf[132]; 7611368Ssam 7711368Ssam printf("%s", msg); 7811368Ssam gets(buf); 7911368Ssam return (buf); 8011368Ssam } 8111368Ssam 8211368Ssam /* 8311368Ssam * Allocate memory on a page-aligned address. 8411368Ssam * Round allocated chunk to a page multiple to 8511368Ssam * ease next request. 8611368Ssam */ 8711368Ssam char * 8811368Ssam malloc(size) 8911368Ssam int size; 9011368Ssam { 9111368Ssam char *result; 9211368Ssam static caddr_t last = 0; 9311368Ssam 9411368Ssam if (last == 0) 9511368Ssam last = (caddr_t)(((int)&end + 511) & ~0x1ff); 9611368Ssam size = (size + 511) & ~0x1ff; 9711368Ssam result = (char *)last; 9811368Ssam last += size; 9911368Ssam return (result); 10011368Ssam } 101