xref: /csrg-svn/sys/vax/stand/drtest.c (revision 45803)
123224Smckusick /*
229296Smckusick  * Copyright (c) 1982, 1986 Regents of the University of California.
323224Smckusick  * All rights reserved.  The Berkeley software License Agreement
423224Smckusick  * specifies the terms and conditions for redistribution.
523224Smckusick  *
6*45803Sbostic  *	@(#)drtest.c	7.5 (Berkeley) 12/16/90
723224Smckusick  */
89973Ssam 
911360Ssam /*
1011360Ssam  * Standalone program to test a disk and driver
1111368Ssam  * by reading the disk a track at a time.
1211360Ssam  */
13*45803Sbostic #include "sys/param.h"
14*45803Sbostic #include "sys/disklabel.h"
15*45803Sbostic #include "stand/saio.h"
1610354Shelge 
1710354Shelge #define SECTSIZ	512
189973Ssam 
1911368Ssam extern	int end;
2011368Ssam char	*malloc();
2110608Ssam 
main()229973Ssam main()
239973Ssam {
2433649Sbostic 	register int fd, sector, lastsector, tracksize;
2533649Sbostic 	register char *bp;
2633649Sbostic 	struct disklabel dl;
2733649Sbostic 	int debug;
289973Ssam 
2911368Ssam 	printf("Testprogram for stand-alone driver\n\n");
3011368Ssam again:
3133649Sbostic 	debug = getdebug("Enable debugging (0=none, 1=bse, 2=ecc, 3=bse+ecc)? ");
3211368Ssam 	if (debug < 0)
3311368Ssam 		debug = 0;
3433554Sbostic 	fd = getfile("Device to read?", 2);
3533649Sbostic 	ioctl(fd, SAIODEVDATA, &dl);
3610719Shelge 	printf("Device data: #cylinders=%d, #tracks=%d, #sectors=%d\n",
3733649Sbostic 		dl.d_ncylinders, dl.d_ntracks, dl.d_nsectors);
3811634Sroot 	ioctl(fd, SAIODEBUG, (char *)debug);
3933649Sbostic 	tracksize = dl.d_nsectors * SECTSIZ;
4011375Ssam 	bp = malloc(tracksize);
4111368Ssam 	printf("Reading in %d byte records\n", tracksize);
4211368Ssam 	printf("Start ...make sure drive is on-line\n");
4333554Sbostic 	lseek(fd, 0, L_SET);
4433649Sbostic 	lastsector = dl.d_ncylinders * dl.d_secpercyl;
4533649Sbostic 	for (sector = 0; sector < lastsector; sector += dl.d_nsectors) {
4633649Sbostic 		if (sector && (sector % (dl.d_secpercyl * 10)) == 0)
4733649Sbostic 			printf("cylinder %d\n", sector/dl.d_secpercyl);
4811368Ssam 		read(fd, bp, tracksize);
4911368Ssam 	}
5011368Ssam 	goto again;
5133649Sbostic 	/*NOTREACHED*/
5211368Ssam }
5311170Shelge 
5433649Sbostic static
getdebug(msg)5533554Sbostic getdebug(msg)
5611368Ssam 	char *msg;
5711368Ssam {
5833554Sbostic 	char buf[132];
5911368Ssam 
6011368Ssam 	printf("%s", msg);
6111368Ssam 	gets(buf);
6233554Sbostic 	return (atoi(buf));
6311368Ssam }
6411368Ssam 
6511368Ssam /*
6611368Ssam  * Allocate memory on a page-aligned address.
6711368Ssam  * Round allocated chunk to a page multiple to
6811368Ssam  * ease next request.
6911368Ssam  */
7033649Sbostic static char *
malloc(size)7111368Ssam malloc(size)
7211368Ssam 	int size;
7311368Ssam {
7433649Sbostic 	static caddr_t last = 0;
7511368Ssam 	char *result;
7611368Ssam 
7711368Ssam 	if (last == 0)
7811368Ssam 		last = (caddr_t)(((int)&end + 511) & ~0x1ff);
7911368Ssam 	size = (size + 511) & ~0x1ff;
8011368Ssam 	result = (char *)last;
8111368Ssam 	last += size;
8211368Ssam 	return (result);
8311368Ssam }
84