|
|
1.1 root 1: /* drtest.c 6.1 83/07/29 */
2:
3: /*
4: * Standalone program to test a disk and driver
5: * by reading the disk a track at a time.
6: */
7: #include "../h/param.h"
8: #include "../h/inode.h"
9: #include "../h/fs.h"
10: #include "saio.h"
11:
12: #define SECTSIZ 512
13:
14: extern int end;
15: char *malloc();
16: char *prompt();
17:
18: main()
19: {
20: char *cp, *bp;
21: int fd, tracksize, debug;
22: register int sector, lastsector;
23: struct st st;
24:
25: printf("Testprogram for stand-alone driver\n\n");
26: again:
27: cp = prompt("Enable debugging (1=bse, 2=ecc, 3=bse+ecc)? ");
28: debug = atoi(cp);
29: if (debug < 0)
30: debug = 0;
31: fd = getdevice();
32: ioctl(fd, SAIODEVDATA, (char *)&st);
33: printf("Device data: #cylinders=%d, #tracks=%d, #sectors=%d\n",
34: st.ncyl, st.ntrak, st.nsect);
35: ioctl(fd, SAIODEBUG, (char *)debug);
36: tracksize = st.nsect * SECTSIZ;
37: bp = malloc(tracksize);
38: printf("Reading in %d byte records\n", tracksize);
39: printf("Start ...make sure drive is on-line\n");
40: lseek(fd, 0, 0);
41: lastsector = st.ncyl * st.nspc;
42: for (sector = 0; sector < lastsector; sector += st.nsect) {
43: if (sector && (sector % (st.nspc * 10)) == 0)
44: printf("cylinder %d\n", sector/st.nspc);
45: read(fd, bp, tracksize);
46: }
47: goto again;
48: }
49:
50: /*
51: * Prompt and verify a device name from the user.
52: */
53: getdevice()
54: {
55: register char *cp;
56: register struct devsw *dp;
57: int fd;
58:
59: top:
60: cp = prompt("Device to read? ");
61: if ((fd = open(cp, 2)) < 0) {
62: printf("Known devices are: ");
63: for (dp = devsw; dp->dv_name; dp++)
64: printf("%s ",dp->dv_name);
65: printf("\n");
66: goto top;
67: }
68: return (fd);
69: }
70:
71: char *
72: prompt(msg)
73: char *msg;
74: {
75: static char buf[132];
76:
77: printf("%s", msg);
78: gets(buf);
79: return (buf);
80: }
81:
82: /*
83: * Allocate memory on a page-aligned address.
84: * Round allocated chunk to a page multiple to
85: * ease next request.
86: */
87: char *
88: malloc(size)
89: int size;
90: {
91: char *result;
92: static caddr_t last = 0;
93:
94: if (last == 0)
95: last = (caddr_t)(((int)&end + 511) & ~0x1ff);
96: size = (size + 511) & ~0x1ff;
97: result = (char *)last;
98: last += size;
99: return (result);
100: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.