1*11368Ssam /* drtest.c 4.10 83/03/01 */ 29973Ssam 311360Ssam /* 411360Ssam * Standalone program to test a disk and driver 5*11368Ssam * 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 14*11368Ssam extern int end; 15*11368Ssam char *malloc(); 16*11368Ssam char *prompt(); 1710608Ssam 189973Ssam main() 199973Ssam { 20*11368Ssam char *cp, *bp; 21*11368Ssam int fd, tracksize, debug; 22*11368Ssam register int sector, lastsector; 2310354Shelge struct st st; 249973Ssam 25*11368Ssam printf("Testprogram for stand-alone driver\n\n"); 26*11368Ssam again: 27*11368Ssam cp = prompt("Enable debugging (1=bse, 2=ecc, 3=bse+ecc)? "); 28*11368Ssam debug = atoi(cp); 29*11368Ssam if (debug < 0) 30*11368Ssam debug = 0; 31*11368Ssam fd = getdevice(); 3211170Shelge ioctl(fd, SAIODEVDATA, &st); 3310719Shelge printf("Device data: #cylinders=%d, #tracks=%d, #sectors=%d\n", 3410726Ssam st.ncyl, st.ntrak, st.nsect); 35*11368Ssam ioctl(fd, SAIODEBUG, &debug); 36*11368Ssam tracksize = st.nsect * SECTSIZ; 37*11368Ssam printf("Reading in %d byte records\n", tracksize); 38*11368Ssam printf("Start ...make sure drive is on-line\n"); 3911170Shelge lseek(fd, 0, 0); 40*11368Ssam lastsector = st.ncyl * st.ntrak; 41*11368Ssam for (sector = 0; sector < lastsector; sector++) { 42*11368Ssam if (sector && (sector % (st.nspc * 10)) == 0) 43*11368Ssam printf("sector %d\n", sector); 44*11368Ssam read(fd, bp, tracksize); 45*11368Ssam } 46*11368Ssam goto again; 47*11368Ssam } 4811170Shelge 49*11368Ssam /* 50*11368Ssam * Prompt and verify a device name from the user. 51*11368Ssam */ 52*11368Ssam getdevice() 53*11368Ssam { 54*11368Ssam register char *cp; 55*11368Ssam register struct devsw *dp; 56*11368Ssam int fd; 57*11368Ssam 58*11368Ssam top: 59*11368Ssam cp = prompt("Device to read? "); 60*11368Ssam if ((fd = open(cp, 2)) < 0) { 61*11368Ssam printf("Known devices are: "); 62*11368Ssam for (dp = devsw; dp->dv_name; dp++) 63*11368Ssam printf("%s ",dp->dv_name); 64*11368Ssam printf("\n"); 65*11368Ssam goto top; 669973Ssam } 67*11368Ssam return (fd); 689973Ssam } 69*11368Ssam 70*11368Ssam char * 71*11368Ssam prompt(msg) 72*11368Ssam char *msg; 73*11368Ssam { 74*11368Ssam static char buf[132]; 75*11368Ssam 76*11368Ssam printf("%s", msg); 77*11368Ssam gets(buf); 78*11368Ssam return (buf); 79*11368Ssam } 80*11368Ssam 81*11368Ssam /* 82*11368Ssam * Allocate memory on a page-aligned address. 83*11368Ssam * Round allocated chunk to a page multiple to 84*11368Ssam * ease next request. 85*11368Ssam */ 86*11368Ssam char * 87*11368Ssam malloc(size) 88*11368Ssam int size; 89*11368Ssam { 90*11368Ssam char *result; 91*11368Ssam static caddr_t last = 0; 92*11368Ssam 93*11368Ssam if (last == 0) 94*11368Ssam last = (caddr_t)(((int)&end + 511) & ~0x1ff); 95*11368Ssam size = (size + 511) & ~0x1ff; 96*11368Ssam result = (char *)last; 97*11368Ssam last += size; 98*11368Ssam return (result); 99*11368Ssam } 100