|
|
1.1 root 1: /*% cc -O -o rarct %
2: *
3: * read the rct and other stuff
4: */
5:
6: #include <stdio.h>
7: #include <sys/param.h>
8: #include <sys/udaioc.h>
9: #include "rct.h"
10:
11: struct ud_unit ud_unit;
12:
13: main(argc, argv)
14: int argc;
15: char **argv;
16: {
17: int hdr = 0;
18: int stat = 0;
19: int nd = 0;
20: int errs = 0;
21:
22: while (--argc > 0) {
23: if (**++argv == '-')
24: switch (argv[0][1]) {
25: case 'h':
26: hdr++;
27: continue;
28:
29: case 'c':
30: stat++;
31: continue;
32:
33: default:
34: fprintf(stderr, "%s ignored\n", *argv);
35: continue;
36: }
37: nd++;
38: errs += dodev(*argv, hdr, stat);
39: }
40: if (nd == 0) {
41: fprintf(stderr, "usage: %s dev\n", argv[0]);
42: exit(1);
43: }
44: exit(errs);
45: }
46:
47: dodev(dev, hdr, stat)
48: char *dev;
49: int hdr, stat;
50: {
51: int fd;
52: daddr_t size;
53: char buf[RBNSEC];
54: register daddr_t i;
55: daddr_t rctmax();
56:
57: if ((fd = open(dev, 0)) < 0) {
58: perror(dev);
59: return (1);
60: }
61: /*
62: * hack to force driver to read status
63: */
64: if (read(fd, buf, RBNSEC) != RBNSEC) {
65: perror("read first block");
66: close(fd);
67: return (1);
68: }
69: if (ioctl(fd, UIOCHAR, &ud_unit) < 0) {
70: perror("ioctl");
71: close(fd);
72: return (1);
73: }
74: if (stat)
75: statput();
76: if (hdr) {
77: rctread(fd, buf, RCTHDR);
78: hdrput(buf);
79: }
80: if (hdr || stat) {
81: close(fd);
82: return (0);
83: }
84: size = rctmax();
85: for (i = RCTTAB; i < size; i++) {
86: rctread(fd, buf, i);
87: rctput(buf, i);
88: }
89: close(fd);
90: return (0);
91: }
92:
93: daddr_t
94: rctmax()
95: {
96: daddr_t nrbns;
97:
98: nrbns = (ud_unit.radsize / ud_unit.tracksz) * ud_unit.rbns;
99: return ((nrbns / RBNPB) + RCTTAB);
100: }
101:
102: rctread(fd, buf, bno)
103: char *buf;
104: daddr_t bno;
105: {
106: struct ud_rctbuf rb;
107: register int i;
108:
109: rb.lbn = bno;
110: rb.buf = buf;
111: if (ioctl(fd, UIORRCT, &rb) < 0) {
112: perror("read rct");
113: fprintf(stderr, "block %d\n", bno);
114: for (i = 0; i < RBNSEC; i++)
115: buf[i] = 0;
116: }
117: }
118:
119: rctput(buf, bno)
120: char *buf;
121: int bno;
122: {
123: register long rbn;
124: register struct rbd *rp;
125: register int i;
126:
127: rbn = (bno - RCTTAB) * RBNPB;
128: rp = (struct rbd *)buf;
129: for (i = 0; i < RBNPB; i++, rp++, rbn++)
130: if (rp->rb_lbn || rp->rb_code)
131: printf("%ld: %o: %ld\n", rbn, rp->rb_code, rp->rb_lbn);
132: }
133:
134: hdrput(buf)
135: char *buf;
136: {
137: register struct rct *rc;
138:
139: rc = (struct rct *)buf;
140: printf("volser x%lx x%lx\n", rc->rc_volser[0], rc->rc_volser[1]);
141: printf("flags 0%x lbn %ld rbn %ld badrbn %ld\n",
142: rc->rc_flags, rc->rc_lbn, rc->rc_rbn, rc->rc_badrbn);
143: }
144:
145: statput()
146: {
147:
148: printf("size %ld\nrctsize %ld\n", ud_unit.radsize, ud_unit.rctsize);
149: printf("medium x%lx\n", ud_unit.medium);
150: printf("tracks %d groups %d cyls %d\n",
151: ud_unit.tracksz, ud_unit.groupsz, ud_unit.cylsz);
152: printf("rbns/track %d\ncopies %d\n", ud_unit.rbns, ud_unit.copies);
153: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.