This source file includes following definitions.
- dkcsumattach
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 #include <sys/param.h>
33 #include <sys/buf.h>
34 #include <sys/conf.h>
35 #include <sys/device.h>
36 #include <sys/disklabel.h>
37 #include <sys/fcntl.h>
38 #include <sys/proc.h>
39 #include <sys/reboot.h>
40 #include <sys/stat.h>
41 #include <sys/systm.h>
42
43 #include <machine/biosvar.h>
44
45 #include <lib/libz/zlib.h>
46
47 dev_t dev_rawpart(struct device *);
48
49 extern u_int32_t bios_cksumlen;
50 extern bios_diskinfo_t *bios_diskinfo;
51 extern dev_t bootdev;
52
53 void
54 dkcsumattach(void)
55 {
56 struct device *dv;
57 struct buf *bp;
58 struct bdevsw *bdsw;
59 dev_t dev, pribootdev, altbootdev;
60 int error, picked;
61 u_int32_t csum;
62 bios_diskinfo_t *bdi, *hit;
63
64
65 if (bios_diskinfo == NULL || bios_cksumlen * DEV_BSIZE > MAXBSIZE)
66 return;
67
68 #ifdef DEBUG
69 printf("dkcsum: bootdev=%#x\n", bootdev);
70 for (bdi = bios_diskinfo; bdi->bios_number != -1; bdi++)
71 if (bdi->bios_number & 0x80)
72 printf("dkcsum: BIOS drive %#x checksum is %#x\n",
73 bdi->bios_number, bdi->checksum);
74 #endif
75 pribootdev = altbootdev = 0;
76
77
78
79
80
81
82 bp = geteblk(bios_cksumlen * DEV_BSIZE);
83
84 TAILQ_FOREACH(dv, &alldevs, dv_list) {
85 if (dv->dv_class != DV_DISK)
86 continue;
87 bp->b_dev = dev = dev_rawpart(dv);
88 if (dev == NODEV)
89 continue;
90 bdsw = &bdevsw[major(dev)];
91
92
93
94
95
96 error = (*bdsw->d_open)(dev, FREAD, S_IFCHR, curproc);
97 if (error) {
98
99 #ifdef DEBUG
100 printf("dkcsum: %s open failed (%d)\n",
101 dv->dv_xname, error);
102 #endif
103 continue;
104 }
105
106
107 bp->b_blkno = 0;
108 bp->b_bcount = bios_cksumlen * DEV_BSIZE;
109 bp->b_flags = B_BUSY | B_READ;
110 bp->b_cylinder = 0;
111 (*bdsw->d_strategy)(bp);
112 if ((error = biowait(bp))) {
113
114 #ifdef DEBUG
115 printf("dkcsum: %s read failed (%d)\n",
116 dv->dv_xname, error);
117 #endif
118 error = (*bdsw->d_close)(dev, 0, S_IFCHR, curproc);
119 #ifdef DEBUG
120 if (error)
121 printf("dkcsum: %s close failed (%d)\n",
122 dv->dv_xname, error);
123 #endif
124 continue;
125 }
126 error = (*bdsw->d_close)(dev, FREAD, S_IFCHR, curproc);
127 if (error) {
128
129 #ifdef DEBUG
130 printf("dkcsum: %s closed failed (%d)\n",
131 dv->dv_xname, error);
132 #endif
133 continue;
134 }
135
136 csum = adler32(0, bp->b_data, bios_cksumlen * DEV_BSIZE);
137 #ifdef DEBUG
138 printf("dkcsum: %s checksum is %#x\n", dv->dv_xname, csum);
139 #endif
140
141
142 hit = 0;
143 for (bdi = bios_diskinfo; bdi->bios_number != -1; bdi++) {
144
145 if (!(bdi->bios_number & 0x80))
146 continue;
147 if (bdi->checksum != csum)
148 continue;
149 picked = hit || (bdi->flags & BDI_PICKED);
150 if (!picked)
151 hit = bdi;
152 printf("dkcsum: %s matches BIOS drive %#x%s\n",
153 dv->dv_xname, bdi->bios_number,
154 (picked ? " IGNORED" : ""));
155 }
156
157
158
159
160
161 if (!hit) {
162 #ifdef DEBUG
163 printf("dkcsum: %s has no matching BIOS drive\n",
164 dv->dv_xname);
165 #endif
166 continue;
167 }
168
169
170
171
172
173
174
175
176
177 if ((B_TYPE(bootdev) == B_TYPE(hit->bsd_dev)) &&
178 (B_UNIT(bootdev) == B_UNIT(hit->bsd_dev))) {
179 int type, ctrl, adap, part, unit;
180
181 type = major(bp->b_dev);
182 adap = B_ADAPTOR(bootdev);
183 ctrl = B_CONTROLLER(bootdev);
184 unit = DISKUNIT(bp->b_dev);
185 part = B_PARTITION(bootdev);
186
187 pribootdev = MAKEBOOTDEV(type, ctrl, adap, unit, part);
188 #ifdef DEBUG
189 printf("dkcsum: %s is primary boot disk\n",
190 dv->dv_xname);
191 #endif
192 }
193
194 if (B_UNIT(bootdev) == (hit->bios_number & 0x7F)) {
195 int type, ctrl, adap, part, unit;
196
197 type = major(bp->b_dev);
198 adap = B_ADAPTOR(bootdev);
199 ctrl = B_CONTROLLER(bootdev);
200 unit = DISKUNIT(bp->b_dev);
201 part = B_PARTITION(bootdev);
202
203 altbootdev = MAKEBOOTDEV(type, ctrl, adap, unit, part);
204 #ifdef DEBUG
205 printf("dkcsum: %s is alternate boot disk\n",
206 dv->dv_xname);
207 #endif
208 }
209
210
211 hit->bsd_dev = MAKEBOOTDEV(major(bp->b_dev), 0, 0,
212 DISKUNIT(bp->b_dev), RAW_PART);
213 hit->flags |= BDI_PICKED;
214 }
215 bootdev = pribootdev ? pribootdev : altbootdev ? altbootdev : bootdev;
216
217 bp->b_flags |= B_INVAL;
218 brelse(bp);
219 }