|
|
1.1 root 1: /*
2: * cohpatch.c
3: * 8/19/91
4: * Uses common routines in build0.c: cc -o cohpatch cohpatch.c build0.c
5: * Patch new copy of COHERENT for V3.2.0 update installation.
6: * Hack, hack, hack.
7: */
8:
9: #include "build0.h"
10: #include <l.out.h>
11: #include <sys/hdioctl.h>
12:
13: extern long lseek();
14:
15: #define COH "/coherent"
16: #define COHNEW "/coherent.new"
17: #define COHOLD "/coherent.old"
18: #define KMEM "/dev/kmem"
19: #define NENTRIES (sizeof(nl)/sizeof(nl[0]))
20:
21: char buf[256]; /* temporary buffer */
22: char cmd[512]; /* command buffer */
23: int kfd; /* kernel file desciptor */
24:
25: /* Symbols patched from old /coherent to new /coherent. */
26: struct nlist nl[] = {
27: { "rootdev_", 0, 0 },
28: { "pipedev_", 0, 0 },
29: { "ronflag_", 0, 0 },
30: { "___", 0, 0 },
31: { "_entry_", 0, 0 },
32: { "LPTIME_", 0, 0 },
33: { "LPWAIT_", 0, 0 },
34: { "", 0, 0 }
35: };
36: int nlsizes[NENTRIES] = { /* sizes of preceding, yuk */
37: sizeof (unsigned int),
38: sizeof (unsigned int),
39: sizeof (unsigned int),
40: sizeof (unsigned long),
41: sizeof (unsigned long),
42: sizeof (unsigned int),
43: sizeof (unsigned int),
44: 0
45: };
46:
47: /* Symbol from old /coherent handled specially. */
48: struct nlist nlat[] = {
49: { "atparm_", 0, 0 },
50: { "", 0, 0 }
51: };
52:
53: /* Symbols patched in /drv/al0. */
54: struct nlist nlal0[] = {
55: { "C1BAUD_", 0, 0 },
56: { "C3BAUD_", 0, 0 },
57: { "", 0, 0 }
58: };
59:
60: /* Symbols patched in /drv/al1. */
61: struct nlist nlal1[] = {
62: { "C2BAUD_", 0, 0 },
63: { "C4BAUD_", 0, 0 },
64: { "", 0, 0 }
65: };
66:
67: extern void kread();
68:
69: main(argc, argv) int argc; char *argv[];
70: {
71: register int i;
72: unsigned char ucval;
73: unsigned int uval;
74: unsigned long ulval;
75:
76: argv0 = argv[0];
77: if (argc > 1 && strcmp(argv[1], "-d") == 0) {
78: ++dflag;
79: --argc;
80: ++argv;
81: }
82:
83: if ((kfd = open(KMEM, 0)) < 0)
84: fatal("cannot open \"%s\"", KMEM);
85:
86: /* Search /coherent for current values. */
87: nlist(COH, nl);
88: nlist(COH, nlat);
89: nlist(COH, nlal0);
90: nlist(COH, nlal1);
91:
92: /*
93: * Patch /coherent.new:
94: * root device
95: * pipe device
96: * read-only flag
97: * serial number (twice)
98: * line printer parameters
99: */
100: sprintf(cmd, "/conf/patch %s ", COHNEW);
101: for (i = 0; i < NENTRIES-1; i++) {
102: if (nl[i].n_type == 0)
103: fatal("cannot find symbol \"%s\"", nl[i].n_name);
104: if (nlsizes[i] == sizeof (unsigned int)) {
105: kread(nl[i].n_value, &uval, nlsizes[i]);
106: sprintf(buf, "%s=0x%x ", nl[i].n_name, uval);
107: } else if (nlsizes[i] == sizeof (unsigned long)) {
108: kread(nl[i].n_value, &ulval, nlsizes[i]);
109: sprintf(buf, "%s=%lu:l ", nl[i].n_name, ulval);
110: }
111: strcat(cmd, buf);
112: }
113: sys(cmd, S_FATAL);
114:
115: /* Patch AT device parameters. */
116: sprintf(cmd, "/conf/patch %s ", COHNEW);
117: if (nlat[0].n_type != 0) {
118: for (i = 0; i < sizeof(hdparm_t); i++ ) {
119: kread(nlat[0].n_value+i, &ucval, sizeof(ucval));
120: sprintf(buf, "atparm_+%d=%u:c ", i, ucval);
121: strcat(cmd, buf);
122: }
123: sys(cmd, S_FATAL);
124: }
125:
126: /* Patch baud rates. */
127: sprintf(cmd, "/conf/patch /drv/al0 ");
128: for (i = 0; i < 2; i++) {
129: if (nlal0[i].n_type == 0)
130: fatal("cannot find symbol \"%s\"", nlal0[i].n_name);
131: kread(nlal0[i].n_value, &uval, sizeof(unsigned int));
132: sprintf(buf, "%s=%u ", nlal0[i].n_name, uval);
133: strcat(cmd, buf);
134: }
135: sys(cmd, S_FATAL);
136: sprintf(cmd, "/conf/patch /drv/al1 ");
137: for (i = 0; i < 2; i++) {
138: if (nlal1[i].n_type == 0)
139: fatal("cannot find symbol \"%s\"", nlal1[i].n_name);
140: kread(nlal1[i].n_value, &uval, sizeof(unsigned int));
141: sprintf(buf, "%s=%u ", nlal1[i].n_name, uval);
142: strcat(cmd, buf);
143: }
144: sys(cmd, S_FATAL);
145:
146: /* Move original and patched versions. */
147: sprintf(cmd, "/bin/mv %s %s", COH, COHOLD);
148: sys(cmd, S_FATAL);
149: sprintf(cmd, "/bin/mv %s %s", COHNEW, COH);
150:
151: /* Done. */
152: sys(cmd, S_FATAL);
153: close(kfd);
154: exit(0);
155: }
156:
157: void
158: kread(useek, bp, n) unsigned int useek; char *bp; int n;
159: {
160: if (lseek(kfd, (long)useek, 0) == -1L)
161: fatal("seek error on \"%s\"", KMEM);
162: if (read(kfd, bp, n) != n)
163: fatal("read error on \"%s\"", KMEM);
164: }
165:
166: /* end of cohpatch.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.