xref: /csrg-svn/sys/vax/stand/drtest.c (revision 33554)
1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  *
6  *	@(#)drtest.c	7.2 (Berkeley) 02/24/88
7  */
8 
9 /*
10  * Standalone program to test a disk and driver
11  * by reading the disk a track at a time.
12  */
13 #include "param.h"
14 #include "inode.h"
15 #include "fs.h"
16 
17 #include "saio.h"
18 
19 #define SECTSIZ	512
20 
21 extern	int end;
22 char	*malloc();
23 
24 main()
25 {
26 	char *cp, *bp;
27 	int fd, tracksize, debug;
28 	register int sector, lastsector;
29 	struct st st;
30 
31 	printf("Testprogram for stand-alone driver\n\n");
32 again:
33 	debug = getdebug("Enable debugging (1=bse, 2=ecc, 3=bse+ecc)? ");
34 	if (debug < 0)
35 		debug = 0;
36 	fd = getfile("Device to read?", 2);
37 	ioctl(fd, SAIODEVDATA, (char *)&st);
38 	printf("Device data: #cylinders=%d, #tracks=%d, #sectors=%d\n",
39 		st.ncyl, st.ntrak, st.nsect);
40 	ioctl(fd, SAIODEBUG, (char *)debug);
41 	tracksize = st.nsect * SECTSIZ;
42 	bp = malloc(tracksize);
43 	printf("Reading in %d byte records\n", tracksize);
44 	printf("Start ...make sure drive is on-line\n");
45 	lseek(fd, 0, L_SET);
46 	lastsector = st.ncyl * st.nspc;
47 	for (sector = 0; sector < lastsector; sector += st.nsect) {
48 		if (sector && (sector % (st.nspc * 10)) == 0)
49 			printf("cylinder %d\n", sector/st.nspc);
50 		read(fd, bp, tracksize);
51 	}
52 	goto again;
53 }
54 
55 getdebug(msg)
56 	char *msg;
57 {
58 	char buf[132];
59 
60 	printf("%s", msg);
61 	gets(buf);
62 	return (atoi(buf));
63 }
64 
65 /*
66  * Allocate memory on a page-aligned address.
67  * Round allocated chunk to a page multiple to
68  * ease next request.
69  */
70 char *
71 malloc(size)
72 	int size;
73 {
74 	char *result;
75 	static caddr_t last = 0;
76 
77 	if (last == 0)
78 		last = (caddr_t)(((int)&end + 511) & ~0x1ff);
79 	size = (size + 511) & ~0x1ff;
80 	result = (char *)last;
81 	last += size;
82 	return (result);
83 }
84