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