xref: /csrg-svn/sys/vax/stand/drtest.c (revision 11368)
1 /*	drtest.c	4.10	83/03/01	*/
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, &st);
33 	printf("Device data: #cylinders=%d, #tracks=%d, #sectors=%d\n",
34 		st.ncyl, st.ntrak, st.nsect);
35 	ioctl(fd, SAIODEBUG, &debug);
36 	tracksize = st.nsect * SECTSIZ;
37 	printf("Reading in %d byte records\n", tracksize);
38 	printf("Start ...make sure drive is on-line\n");
39 	lseek(fd, 0, 0);
40 	lastsector = st.ncyl * st.ntrak;
41 	for (sector = 0; sector < lastsector; sector++) {
42 		if (sector && (sector % (st.nspc * 10)) == 0)
43 			printf("sector %d\n", sector);
44 		read(fd, bp, tracksize);
45 	}
46 	goto again;
47 }
48 
49 /*
50  * Prompt and verify a device name from the user.
51  */
52 getdevice()
53 {
54 	register char *cp;
55 	register struct devsw *dp;
56 	int fd;
57 
58 top:
59 	cp = prompt("Device to read? ");
60 	if ((fd = open(cp, 2)) < 0) {
61 		printf("Known devices are: ");
62 		for (dp = devsw; dp->dv_name; dp++)
63 			printf("%s ",dp->dv_name);
64 		printf("\n");
65 		goto top;
66 	}
67 	return (fd);
68 }
69 
70 char *
71 prompt(msg)
72 	char *msg;
73 {
74 	static char buf[132];
75 
76 	printf("%s", msg);
77 	gets(buf);
78 	return (buf);
79 }
80 
81 /*
82  * Allocate memory on a page-aligned address.
83  * Round allocated chunk to a page multiple to
84  * ease next request.
85  */
86 char *
87 malloc(size)
88 	int size;
89 {
90 	char *result;
91 	static caddr_t last = 0;
92 
93 	if (last == 0)
94 		last = (caddr_t)(((int)&end + 511) & ~0x1ff);
95 	size = (size + 511) & ~0x1ff;
96 	result = (char *)last;
97 	last += size;
98 	return (result);
99 }
100