xref: /csrg-svn/sys/vax/stand/drtest.c (revision 23224)
1*23224Smckusick /*
2*23224Smckusick  * Copyright (c) 1982 Regents of the University of California.
3*23224Smckusick  * All rights reserved.  The Berkeley software License Agreement
4*23224Smckusick  * specifies the terms and conditions for redistribution.
5*23224Smckusick  *
6*23224Smckusick  *	@(#)drtest.c	6.2 (Berkeley) 06/08/85
7*23224Smckusick  */
89973Ssam 
911360Ssam /*
1011360Ssam  * Standalone program to test a disk and driver
1111368Ssam  * by reading the disk a track at a time.
1211360Ssam  */
1310354Shelge #include "../h/param.h"
1410354Shelge #include "../h/inode.h"
1510354Shelge #include "../h/fs.h"
1610354Shelge #include "saio.h"
1710354Shelge 
1810354Shelge #define SECTSIZ	512
199973Ssam 
2011368Ssam extern	int end;
2111368Ssam char	*malloc();
2211368Ssam char	*prompt();
2310608Ssam 
249973Ssam main()
259973Ssam {
2611368Ssam 	char *cp, *bp;
2711368Ssam 	int fd, tracksize, debug;
2811368Ssam 	register int sector, lastsector;
2910354Shelge 	struct st st;
309973Ssam 
3111368Ssam 	printf("Testprogram for stand-alone driver\n\n");
3211368Ssam again:
3311368Ssam 	cp = prompt("Enable debugging (1=bse, 2=ecc, 3=bse+ecc)? ");
3411368Ssam 	debug = atoi(cp);
3511368Ssam 	if (debug < 0)
3611368Ssam 		debug = 0;
3711368Ssam 	fd = getdevice();
3811634Sroot 	ioctl(fd, SAIODEVDATA, (char *)&st);
3910719Shelge 	printf("Device data: #cylinders=%d, #tracks=%d, #sectors=%d\n",
4010726Ssam 		st.ncyl, st.ntrak, st.nsect);
4111634Sroot 	ioctl(fd, SAIODEBUG, (char *)debug);
4211368Ssam 	tracksize = st.nsect * SECTSIZ;
4311375Ssam 	bp = malloc(tracksize);
4411368Ssam 	printf("Reading in %d byte records\n", tracksize);
4511368Ssam 	printf("Start ...make sure drive is on-line\n");
4611170Shelge 	lseek(fd, 0, 0);
4711375Ssam 	lastsector = st.ncyl * st.nspc;
4811375Ssam 	for (sector = 0; sector < lastsector; sector += st.nsect) {
4911368Ssam 		if (sector && (sector % (st.nspc * 10)) == 0)
5012176Shelge 			printf("cylinder %d\n", sector/st.nspc);
5111368Ssam 		read(fd, bp, tracksize);
5211368Ssam 	}
5311368Ssam 	goto again;
5411368Ssam }
5511170Shelge 
5611368Ssam /*
5711368Ssam  * Prompt and verify a device name from the user.
5811368Ssam  */
5911368Ssam getdevice()
6011368Ssam {
6111368Ssam 	register char *cp;
6211368Ssam 	register struct devsw *dp;
6311368Ssam 	int fd;
6411368Ssam 
6511368Ssam top:
6611368Ssam 	cp = prompt("Device to read? ");
6711368Ssam 	if ((fd = open(cp, 2)) < 0) {
6811368Ssam 		printf("Known devices are: ");
6911368Ssam 		for (dp = devsw; dp->dv_name; dp++)
7011368Ssam 			printf("%s ",dp->dv_name);
7111368Ssam 		printf("\n");
7211368Ssam 		goto top;
739973Ssam 	}
7411368Ssam 	return (fd);
759973Ssam }
7611368Ssam 
7711368Ssam char *
7811368Ssam prompt(msg)
7911368Ssam 	char *msg;
8011368Ssam {
8111368Ssam 	static char buf[132];
8211368Ssam 
8311368Ssam 	printf("%s", msg);
8411368Ssam 	gets(buf);
8511368Ssam 	return (buf);
8611368Ssam }
8711368Ssam 
8811368Ssam /*
8911368Ssam  * Allocate memory on a page-aligned address.
9011368Ssam  * Round allocated chunk to a page multiple to
9111368Ssam  * ease next request.
9211368Ssam  */
9311368Ssam char *
9411368Ssam malloc(size)
9511368Ssam 	int size;
9611368Ssam {
9711368Ssam 	char *result;
9811368Ssam 	static caddr_t last = 0;
9911368Ssam 
10011368Ssam 	if (last == 0)
10111368Ssam 		last = (caddr_t)(((int)&end + 511) & ~0x1ff);
10211368Ssam 	size = (size + 511) & ~0x1ff;
10311368Ssam 	result = (char *)last;
10411368Ssam 	last += size;
10511368Ssam 	return (result);
10611368Ssam }
107