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.1 (Berkeley) 6/5/86
   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 "../h/param.h"
  14: #include "../h/inode.h"
  15: #include "../h/fs.h"
  16: #include "saio.h"
  17: 
  18: #define SECTSIZ 512
  19: 
  20: extern  int end;
  21: char    *malloc();
  22: char    *prompt();
  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:     cp = prompt("Enable debugging (1=bse, 2=ecc, 3=bse+ecc)? ");
  34:     debug = atoi(cp);
  35:     if (debug < 0)
  36:         debug = 0;
  37:     fd = getdevice();
  38:     ioctl(fd, SAIODEVDATA, (char *)&st);
  39:     printf("Device data: #cylinders=%d, #tracks=%d, #sectors=%d\n",
  40:         st.ncyl, st.ntrak, st.nsect);
  41:     ioctl(fd, SAIODEBUG, (char *)debug);
  42:     tracksize = st.nsect * SECTSIZ;
  43:     bp = malloc(tracksize);
  44:     printf("Reading in %d byte records\n", tracksize);
  45:     printf("Start ...make sure drive is on-line\n");
  46:     lseek(fd, 0, 0);
  47:     lastsector = st.ncyl * st.nspc;
  48:     for (sector = 0; sector < lastsector; sector += st.nsect) {
  49:         if (sector && (sector % (st.nspc * 10)) == 0)
  50:             printf("cylinder %d\n", sector/st.nspc);
  51:         read(fd, bp, tracksize);
  52:     }
  53:     goto again;
  54: }
  55: 
  56: /*
  57:  * Prompt and verify a device name from the user.
  58:  */
  59: getdevice()
  60: {
  61:     register char *cp;
  62:     register struct devsw *dp;
  63:     int fd;
  64: 
  65: top:
  66:     cp = prompt("Device to read? ");
  67:     if ((fd = open(cp, 2)) < 0) {
  68:         printf("Known devices are: ");
  69:         for (dp = devsw; dp->dv_name; dp++)
  70:             printf("%s ",dp->dv_name);
  71:         printf("\n");
  72:         goto top;
  73:     }
  74:     return (fd);
  75: }
  76: 
  77: char *
  78: prompt(msg)
  79:     char *msg;
  80: {
  81:     static char buf[132];
  82: 
  83:     printf("%s", msg);
  84:     gets(buf);
  85:     return (buf);
  86: }
  87: 
  88: /*
  89:  * Allocate memory on a page-aligned address.
  90:  * Round allocated chunk to a page multiple to
  91:  * ease next request.
  92:  */
  93: char *
  94: malloc(size)
  95:     int size;
  96: {
  97:     char *result;
  98:     static caddr_t last = 0;
  99: 
 100:     if (last == 0)
 101:         last = (caddr_t)(((int)&end + 511) & ~0x1ff);
 102:     size = (size + 511) & ~0x1ff;
 103:     result = (char *)last;
 104:     last += size;
 105:     return (result);
 106: }

Defined functions

getdevice defined in line 59; used 1 times
  • in line 37
main defined in line 24; never used
malloc defined in line 93; used 2 times
prompt defined in line 77; used 3 times

Defined macros

SECTSIZ defined in line 18; used 1 times
  • in line 42
Last modified: 1986-06-05
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 868
Valid CSS Valid XHTML 1.0 Strict