ofdisk.c revision 1.17.2.1 1 1.17.2.1 fvdl /* $NetBSD: ofdisk.c,v 1.17.2.1 2001/10/10 11:56:56 fvdl Exp $ */
2 1.1 ws
3 1.1 ws /*
4 1.1 ws * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5 1.1 ws * Copyright (C) 1995, 1996 TooLs GmbH.
6 1.1 ws * All rights reserved.
7 1.1 ws *
8 1.1 ws * Redistribution and use in source and binary forms, with or without
9 1.1 ws * modification, are permitted provided that the following conditions
10 1.1 ws * are met:
11 1.1 ws * 1. Redistributions of source code must retain the above copyright
12 1.1 ws * notice, this list of conditions and the following disclaimer.
13 1.1 ws * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 ws * notice, this list of conditions and the following disclaimer in the
15 1.1 ws * documentation and/or other materials provided with the distribution.
16 1.1 ws * 3. All advertising materials mentioning features or use of this software
17 1.1 ws * must display the following acknowledgement:
18 1.1 ws * This product includes software developed by TooLs GmbH.
19 1.1 ws * 4. The name of TooLs GmbH may not be used to endorse or promote products
20 1.1 ws * derived from this software without specific prior written permission.
21 1.1 ws *
22 1.1 ws * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23 1.1 ws * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 ws * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 ws * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 1.1 ws * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 1.1 ws * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 1.1 ws * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 1.1 ws * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 1.1 ws * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 1.1 ws * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 ws */
33 1.1 ws
34 1.1 ws #include <sys/param.h>
35 1.1 ws #include <sys/buf.h>
36 1.1 ws #include <sys/device.h>
37 1.16 matt #include <sys/conf.h>
38 1.1 ws #include <sys/disklabel.h>
39 1.1 ws #include <sys/disk.h>
40 1.1 ws #include <sys/fcntl.h>
41 1.1 ws #include <sys/ioctl.h>
42 1.1 ws #include <sys/stat.h>
43 1.1 ws #include <sys/systm.h>
44 1.6 thorpej #include <sys/proc.h>
45 1.17.2.1 fvdl #include <sys/vnode.h>
46 1.1 ws
47 1.1 ws #include <dev/ofw/openfirm.h>
48 1.1 ws
49 1.10 mycroft struct ofdisk_softc {
50 1.1 ws struct device sc_dev;
51 1.1 ws int sc_phandle;
52 1.1 ws int sc_unit;
53 1.4 thorpej int sc_flags;
54 1.1 ws struct disk sc_dk;
55 1.1 ws int sc_ihandle;
56 1.1 ws u_long max_transfer;
57 1.1 ws char sc_name[16];
58 1.1 ws };
59 1.1 ws
60 1.16 matt bdev_decl(ofdisk_);
61 1.16 matt cdev_decl(ofdisk_);
62 1.16 matt
63 1.4 thorpej /* sc_flags */
64 1.4 thorpej #define OFDF_ISFLOPPY 0x01 /* we are a floppy drive */
65 1.4 thorpej
66 1.17 matt static int ofdisk_match (struct device *, struct cfdata *, void *);
67 1.17 matt static void ofdisk_attach (struct device *, struct device *, void *);
68 1.1 ws
69 1.1 ws struct cfattach ofdisk_ca = {
70 1.10 mycroft sizeof(struct ofdisk_softc), ofdisk_match, ofdisk_attach
71 1.1 ws };
72 1.1 ws
73 1.9 thorpej extern struct cfdriver ofdisk_cd;
74 1.1 ws
75 1.17 matt void ofdisk_strategy (struct buf *);
76 1.1 ws
77 1.10 mycroft struct dkdriver ofdisk_dkdriver = { ofdisk_strategy };
78 1.1 ws
79 1.17 matt void ofdisk_getdefaultlabel (struct ofdisk_softc *, struct disklabel *);
80 1.17.2.1 fvdl void ofdisk_getdisklabel (struct vnode *);
81 1.7 thorpej
82 1.1 ws static int
83 1.17 matt ofdisk_match(struct device *parent, struct cfdata *match, void *aux)
84 1.1 ws {
85 1.10 mycroft struct ofbus_attach_args *oba = aux;
86 1.1 ws char type[8];
87 1.1 ws int l;
88 1.1 ws
89 1.10 mycroft if (strcmp(oba->oba_busname, "ofw"))
90 1.10 mycroft return (0);
91 1.10 mycroft if ((l = OF_getprop(oba->oba_phandle, "device_type", type,
92 1.4 thorpej sizeof type - 1)) < 0)
93 1.1 ws return 0;
94 1.1 ws if (l >= sizeof type)
95 1.1 ws return 0;
96 1.1 ws type[l] = 0;
97 1.1 ws return !strcmp(type, "block");
98 1.1 ws }
99 1.1 ws
100 1.1 ws static void
101 1.17 matt ofdisk_attach(struct device *parent, struct device *self, void *aux)
102 1.1 ws {
103 1.10 mycroft struct ofdisk_softc *of = (void *)self;
104 1.10 mycroft struct ofbus_attach_args *oba = aux;
105 1.4 thorpej char child[64];
106 1.1 ws int l;
107 1.4 thorpej
108 1.10 mycroft if ((l = OF_getprop(oba->oba_phandle, "name", child,
109 1.4 thorpej sizeof child - 1)) < 0)
110 1.4 thorpej panic("device without name?");
111 1.4 thorpej if (l >= sizeof child)
112 1.4 thorpej l = sizeof child - 1;
113 1.4 thorpej child[l] = 0;
114 1.4 thorpej
115 1.4 thorpej of->sc_flags = 0;
116 1.10 mycroft of->sc_phandle = oba->oba_phandle;
117 1.10 mycroft of->sc_unit = oba->oba_unit;
118 1.1 ws of->sc_ihandle = 0;
119 1.10 mycroft of->sc_dk.dk_driver = &ofdisk_dkdriver;
120 1.1 ws of->sc_dk.dk_name = of->sc_name;
121 1.1 ws strcpy(of->sc_name, of->sc_dev.dv_xname);
122 1.1 ws disk_attach(&of->sc_dk);
123 1.13 thorpej #ifdef __BROKEN_DK_ESTABLISH
124 1.1 ws dk_establish(&of->sc_dk, self); /* XXX */
125 1.13 thorpej #endif
126 1.3 christos printf("\n");
127 1.4 thorpej
128 1.4 thorpej if (strcmp(child, "floppy") == 0)
129 1.4 thorpej of->sc_flags |= OFDF_ISFLOPPY;
130 1.1 ws }
131 1.1 ws
132 1.1 ws int
133 1.17.2.1 fvdl ofdisk_open(struct vnode *devvp, int flags, int fmt, struct proc *p)
134 1.1 ws {
135 1.17.2.1 fvdl dev_t dev = vdev_rdev(devvp);
136 1.1 ws int unit = DISKUNIT(dev);
137 1.10 mycroft struct ofdisk_softc *of;
138 1.1 ws char path[256];
139 1.1 ws int l;
140 1.1 ws
141 1.1 ws if (unit >= ofdisk_cd.cd_ndevs)
142 1.1 ws return ENXIO;
143 1.1 ws if (!(of = ofdisk_cd.cd_devs[unit]))
144 1.1 ws return ENXIO;
145 1.1 ws
146 1.17.2.1 fvdl vdev_setprivdata(devvp, of);
147 1.17.2.1 fvdl
148 1.1 ws if (!of->sc_ihandle) {
149 1.4 thorpej if ((l = OF_package_to_path(of->sc_phandle, path,
150 1.11 mycroft sizeof path - 3)) < 0 ||
151 1.11 mycroft l >= sizeof path - 3)
152 1.1 ws return ENXIO;
153 1.1 ws path[l] = 0;
154 1.1 ws
155 1.1 ws /*
156 1.4 thorpej * XXX This is for the benefit of SCSI/IDE disks that don't
157 1.4 thorpej * XXX have all their childs in the device tree.
158 1.4 thorpej * XXX YES, I DO THINK THIS IS A BUG IN OPENFIRMWARE!!!
159 1.4 thorpej * XXX And yes, this is a very gross hack!
160 1.4 thorpej * XXX See also ofscsi.c
161 1.1 ws */
162 1.1 ws if (!strcmp(path + l - 4, "disk")) {
163 1.1 ws path[l++] = '@';
164 1.1 ws path[l++] = '0' + of->sc_unit;
165 1.1 ws path[l] = 0;
166 1.1 ws }
167 1.1 ws
168 1.1 ws strcat(path, ":0");
169 1.1 ws
170 1.1 ws if (!(of->sc_ihandle = OF_open(path)))
171 1.1 ws return ENXIO;
172 1.1 ws
173 1.1 ws /*
174 1.1 ws * Try to get characteristics of the disk.
175 1.1 ws */
176 1.4 thorpej of->max_transfer = OF_call_method_1("max-transfer",
177 1.4 thorpej of->sc_ihandle, 0);
178 1.1 ws if (of->max_transfer > MAXPHYS)
179 1.1 ws of->max_transfer = MAXPHYS;
180 1.4 thorpej
181 1.17.2.1 fvdl ofdisk_getdisklabel(devvp);
182 1.1 ws }
183 1.1 ws
184 1.1 ws switch (fmt) {
185 1.1 ws case S_IFCHR:
186 1.1 ws of->sc_dk.dk_copenmask |= 1 << DISKPART(dev);
187 1.1 ws break;
188 1.1 ws case S_IFBLK:
189 1.1 ws of->sc_dk.dk_bopenmask |= 1 << DISKPART(dev);
190 1.1 ws break;
191 1.1 ws }
192 1.4 thorpej of->sc_dk.dk_openmask =
193 1.4 thorpej of->sc_dk.dk_copenmask | of->sc_dk.dk_bopenmask;
194 1.1 ws
195 1.1 ws return 0;
196 1.1 ws }
197 1.1 ws
198 1.1 ws int
199 1.17.2.1 fvdl ofdisk_close(struct vnode *devvp, int flags, int fmt, struct proc *p)
200 1.1 ws {
201 1.17.2.1 fvdl struct ofdisk_softc *of = vdev_privdata(devvp);
202 1.17.2.1 fvdl dev_t dev = vdev_rdev(devvp);
203 1.1 ws
204 1.1 ws switch (fmt) {
205 1.1 ws case S_IFCHR:
206 1.1 ws of->sc_dk.dk_copenmask &= ~(1 << DISKPART(dev));
207 1.1 ws break;
208 1.1 ws case S_IFBLK:
209 1.1 ws of->sc_dk.dk_bopenmask &= ~(1 << DISKPART(dev));
210 1.1 ws break;
211 1.1 ws }
212 1.1 ws of->sc_dk.dk_openmask = of->sc_dk.dk_copenmask | of->sc_dk.dk_bopenmask;
213 1.1 ws
214 1.4 thorpej #ifdef FIRMWORKSBUGS
215 1.1 ws /*
216 1.1 ws * This is a hack to get the firmware to flush its buffers.
217 1.1 ws */
218 1.1 ws OF_seek(of->sc_ihandle, 0);
219 1.1 ws #endif
220 1.1 ws if (!of->sc_dk.dk_openmask) {
221 1.1 ws OF_close(of->sc_ihandle);
222 1.1 ws of->sc_ihandle = 0;
223 1.1 ws }
224 1.1 ws
225 1.1 ws return 0;
226 1.1 ws }
227 1.1 ws
228 1.1 ws void
229 1.17 matt ofdisk_strategy(struct buf *bp)
230 1.1 ws {
231 1.17.2.1 fvdl struct ofdisk_softc *of = vdev_privdata(bp->b_devvp);
232 1.1 ws struct partition *p;
233 1.1 ws u_quad_t off;
234 1.1 ws int read;
235 1.1 ws int (*OF_io)(int, void *, int);
236 1.1 ws daddr_t blkno = bp->b_blkno;
237 1.17.2.1 fvdl dev_t dev;
238 1.4 thorpej
239 1.17.2.1 fvdl dev = vdev_rdev(bp->b_devvp);
240 1.1 ws bp->b_resid = 0;
241 1.1 ws if (bp->b_bcount == 0)
242 1.1 ws goto done;
243 1.1 ws
244 1.1 ws OF_io = bp->b_flags & B_READ ? OF_read : OF_write;
245 1.1 ws
246 1.17.2.1 fvdl if (DISKPART(dev) != RAW_PART && !(bp->b_flags & B_DKLABEL)) {
247 1.1 ws if (bounds_check_with_label(bp, of->sc_dk.dk_label, 0) <= 0) {
248 1.1 ws bp->b_resid = bp->b_bcount;
249 1.1 ws goto done;
250 1.1 ws }
251 1.17.2.1 fvdl p = &of->sc_dk.dk_label->d_partitions[dev];
252 1.1 ws blkno = bp->b_blkno + p->p_offset;
253 1.1 ws }
254 1.4 thorpej
255 1.1 ws disk_busy(&of->sc_dk);
256 1.1 ws
257 1.1 ws off = (u_quad_t)blkno * DEV_BSIZE;
258 1.1 ws read = -1;
259 1.1 ws do {
260 1.1 ws if (OF_seek(of->sc_ihandle, off) < 0)
261 1.1 ws break;
262 1.1 ws read = OF_io(of->sc_ihandle, bp->b_data, bp->b_bcount);
263 1.1 ws } while (read == -2);
264 1.4 thorpej
265 1.1 ws if (read < 0) {
266 1.1 ws bp->b_error = EIO;
267 1.1 ws bp->b_flags |= B_ERROR;
268 1.1 ws bp->b_resid = bp->b_bcount;
269 1.1 ws } else
270 1.1 ws bp->b_resid = bp->b_bcount - read;
271 1.1 ws
272 1.1 ws disk_unbusy(&of->sc_dk, bp->b_bcount - bp->b_resid);
273 1.1 ws
274 1.1 ws done:
275 1.1 ws biodone(bp);
276 1.1 ws }
277 1.1 ws
278 1.1 ws static void
279 1.17 matt ofminphys(struct buf *bp)
280 1.1 ws {
281 1.17.2.1 fvdl struct ofdisk_softc *of = vdev_privdata(bp->b_devvp);
282 1.1 ws
283 1.1 ws if (bp->b_bcount > of->max_transfer)
284 1.1 ws bp->b_bcount = of->max_transfer;
285 1.1 ws }
286 1.1 ws
287 1.1 ws int
288 1.17.2.1 fvdl ofdisk_read(struct vnode *devvp, struct uio *uio, int flags)
289 1.1 ws {
290 1.17.2.1 fvdl return physio(ofdisk_strategy, NULL, devvp, B_READ, ofminphys, uio);
291 1.1 ws }
292 1.1 ws
293 1.1 ws int
294 1.17.2.1 fvdl ofdisk_write(struct vnode *devvp, struct uio *uio, int flags)
295 1.1 ws {
296 1.17.2.1 fvdl return physio(ofdisk_strategy, NULL, devvp, B_WRITE, ofminphys, uio);
297 1.1 ws }
298 1.1 ws
299 1.1 ws int
300 1.17.2.1 fvdl ofdisk_ioctl(struct vnode *devvp, u_long cmd, caddr_t data, int flag,
301 1.17.2.1 fvdl struct proc *p)
302 1.1 ws {
303 1.17.2.1 fvdl struct ofdisk_softc *of = vdev_privdata(devvp);
304 1.17.2.1 fvdl dev_t dev = vdev_rdev(devvp);
305 1.1 ws int error;
306 1.14 fvdl #ifdef __HAVE_OLD_DISKLABEL
307 1.14 fvdl struct disklabel newlabel;
308 1.14 fvdl #endif
309 1.1 ws
310 1.1 ws switch (cmd) {
311 1.1 ws case DIOCGDINFO:
312 1.1 ws *(struct disklabel *)data = *of->sc_dk.dk_label;
313 1.1 ws return 0;
314 1.14 fvdl #ifdef __HAVE_OLD_DISKLABEL
315 1.14 fvdl case ODIOCGDINFO:
316 1.14 fvdl newlabel = *of->sc_dk.dk_label;
317 1.14 fvdl if (newlabel.d_npartitions > OLDMAXPARTITIONS)
318 1.15 fvdl return ENOTTY;
319 1.14 fvdl memcpy(data, &newlabel, sizeof (struct olddisklabel));
320 1.14 fvdl return 0;
321 1.14 fvdl #endif
322 1.1 ws
323 1.1 ws case DIOCGPART:
324 1.1 ws ((struct partinfo *)data)->disklab = of->sc_dk.dk_label;
325 1.1 ws ((struct partinfo *)data)->part =
326 1.1 ws &of->sc_dk.dk_label->d_partitions[DISKPART(dev)];
327 1.1 ws return 0;
328 1.1 ws
329 1.1 ws case DIOCWDINFO:
330 1.1 ws case DIOCSDINFO:
331 1.14 fvdl #ifdef __HAVE_OLD_DISKLABEL
332 1.14 fvdl case ODIOCWDINFO:
333 1.14 fvdl case ODIOCSDINFO:
334 1.14 fvdl #endif
335 1.14 fvdl {
336 1.14 fvdl struct disklabel *lp;
337 1.14 fvdl
338 1.14 fvdl #ifdef __HAVE_OLD_DISKLABEL
339 1.14 fvdl if (cmd == ODIOCSDINFO || cmd == ODIOCWDINFO) {
340 1.14 fvdl memset(&newlabel, 0, sizeof newlabel);
341 1.14 fvdl memcpy(&newlabel, data, sizeof (struct olddisklabel));
342 1.14 fvdl lp = &newlabel;
343 1.14 fvdl } else
344 1.14 fvdl #endif
345 1.14 fvdl lp = (struct disklabel *)data;
346 1.14 fvdl
347 1.1 ws if ((flag & FWRITE) == 0)
348 1.1 ws return EBADF;
349 1.1 ws
350 1.1 ws error = setdisklabel(of->sc_dk.dk_label,
351 1.14 fvdl lp, /*of->sc_dk.dk_openmask */0,
352 1.4 thorpej of->sc_dk.dk_cpulabel);
353 1.14 fvdl if (error == 0 && cmd == DIOCWDINFO
354 1.14 fvdl #ifdef __HAVE_OLD_DISKLABEL
355 1.14 fvdl || xfer == ODIOCWDINFO
356 1.14 fvdl #endif
357 1.14 fvdl )
358 1.17.2.1 fvdl error = writedisklabel(devvp, ofdisk_strategy,
359 1.4 thorpej of->sc_dk.dk_label, of->sc_dk.dk_cpulabel);
360 1.1 ws
361 1.1 ws return error;
362 1.14 fvdl }
363 1.7 thorpej
364 1.7 thorpej case DIOCGDEFLABEL:
365 1.10 mycroft ofdisk_getdefaultlabel(of, (struct disklabel *)data);
366 1.7 thorpej return 0;
367 1.14 fvdl #ifdef __HAVE_OLD_DISKLABEL
368 1.14 fvdl case DIOCGDEFLABEL:
369 1.14 fvdl ofdisk_getdefaultlabel(of, &newlabel);
370 1.14 fvdl if (newlabel.d_npartitions > OLDMAXPARTITIONS)
371 1.15 fvdl return ENOTTY;
372 1.14 fvdl memcpy(data, &newlabel, sizeof (struct olddisklabel));
373 1.14 fvdl return 0;
374 1.14 fvdl #endif
375 1.7 thorpej
376 1.1 ws default:
377 1.1 ws return ENOTTY;
378 1.1 ws }
379 1.1 ws }
380 1.1 ws
381 1.1 ws int
382 1.17 matt ofdisk_dump(dev_t dev, daddr_t blkno, caddr_t va, size_t size)
383 1.1 ws {
384 1.1 ws return EINVAL;
385 1.1 ws }
386 1.1 ws
387 1.1 ws int
388 1.17 matt ofdisk_size(dev_t dev)
389 1.1 ws {
390 1.10 mycroft struct ofdisk_softc *of;
391 1.5 thorpej struct disklabel *lp;
392 1.5 thorpej int size, part, omask, unit;
393 1.17.2.1 fvdl struct vnode *devvp;
394 1.5 thorpej
395 1.5 thorpej unit = DISKUNIT(dev);
396 1.5 thorpej if (unit >= ofdisk_cd.cd_ndevs ||
397 1.5 thorpej (of = ofdisk_cd.cd_devs[unit]) == NULL)
398 1.1 ws return -1;
399 1.5 thorpej
400 1.1 ws part = DISKPART(dev);
401 1.5 thorpej omask = of->sc_dk.dk_openmask & (1 << part);
402 1.6 thorpej lp = of->sc_dk.dk_label;
403 1.5 thorpej
404 1.17.2.1 fvdl if (omask == 0) {
405 1.17.2.1 fvdl if (bdevvp(dev, &devvp) != 0)
406 1.17.2.1 fvdl return -1;
407 1.17.2.1 fvdl if (ofdisk_open(devvp, 0, S_IFBLK, curproc) != 0) {
408 1.17.2.1 fvdl vrele(devvp);
409 1.17.2.1 fvdl return -1;
410 1.17.2.1 fvdl }
411 1.17.2.1 fvdl }
412 1.5 thorpej
413 1.5 thorpej if (lp->d_partitions[part].p_fstype != FS_SWAP)
414 1.1 ws size = -1;
415 1.1 ws else
416 1.5 thorpej size = lp->d_partitions[part].p_size *
417 1.5 thorpej (lp->d_secsize / DEV_BSIZE);
418 1.5 thorpej
419 1.17.2.1 fvdl if (omask == 0) {
420 1.17.2.1 fvdl if (ofdisk_close(devvp, 0, S_IFBLK, curproc) != 0)
421 1.17.2.1 fvdl size = -1;
422 1.17.2.1 fvdl vrele(devvp);
423 1.17.2.1 fvdl }
424 1.5 thorpej
425 1.1 ws return size;
426 1.7 thorpej }
427 1.7 thorpej
428 1.7 thorpej void
429 1.17 matt ofdisk_getdefaultlabel(struct ofdisk_softc *of, struct disklabel *lp)
430 1.7 thorpej {
431 1.7 thorpej
432 1.17 matt memset(lp, 0, sizeof *lp);
433 1.7 thorpej
434 1.7 thorpej /*
435 1.7 thorpej * XXX Firmware bug? Asking for block size gives a
436 1.7 thorpej * XXX rediculous number! So we use what the boot program
437 1.7 thorpej * XXX uses.
438 1.7 thorpej */
439 1.7 thorpej lp->d_secsize = DEV_BSIZE;
440 1.7 thorpej
441 1.7 thorpej lp->d_secperunit = OF_call_method_1("#blocks",
442 1.7 thorpej of->sc_ihandle, 0);
443 1.7 thorpej if (lp->d_secperunit == (u_int32_t)-1)
444 1.7 thorpej lp->d_secperunit = 0x7fffffff;
445 1.7 thorpej
446 1.7 thorpej lp->d_secpercyl = 1;
447 1.7 thorpej lp->d_nsectors = 1;
448 1.7 thorpej lp->d_ntracks = 1;
449 1.7 thorpej lp->d_ncylinders = lp->d_secperunit;
450 1.7 thorpej
451 1.7 thorpej lp->d_partitions[RAW_PART].p_offset = 0;
452 1.7 thorpej lp->d_partitions[RAW_PART].p_size = lp->d_secperunit;
453 1.7 thorpej lp->d_npartitions = RAW_PART + 1;
454 1.7 thorpej
455 1.7 thorpej lp->d_magic = DISKMAGIC;
456 1.7 thorpej lp->d_magic2 = DISKMAGIC;
457 1.7 thorpej lp->d_checksum = dkcksum(lp);
458 1.7 thorpej }
459 1.7 thorpej
460 1.7 thorpej void
461 1.17.2.1 fvdl ofdisk_getdisklabel(devvp)
462 1.17.2.1 fvdl struct vnode *devvp;
463 1.7 thorpej {
464 1.17.2.1 fvdl struct ofdisk_softc *of = vdev_privdata(devvp);
465 1.7 thorpej struct disklabel *lp = of->sc_dk.dk_label;
466 1.7 thorpej char *errmes;
467 1.7 thorpej int l;
468 1.7 thorpej
469 1.10 mycroft ofdisk_getdefaultlabel(of, lp);
470 1.7 thorpej
471 1.7 thorpej /*
472 1.7 thorpej * Don't read the disklabel on a floppy; simply
473 1.7 thorpej * assign all partitions the same size/offset as
474 1.7 thorpej * RAW_PART. (This is essentially what the ISA
475 1.7 thorpej * floppy driver does, but we don't deal with
476 1.7 thorpej * density stuff.)
477 1.7 thorpej */
478 1.7 thorpej if (of->sc_flags & OFDF_ISFLOPPY) {
479 1.7 thorpej lp->d_npartitions = MAXPARTITIONS;
480 1.7 thorpej for (l = 0; l < lp->d_npartitions; l++) {
481 1.7 thorpej if (l == RAW_PART)
482 1.7 thorpej continue;
483 1.7 thorpej /* struct copy */
484 1.7 thorpej lp->d_partitions[l] =
485 1.7 thorpej lp->d_partitions[RAW_PART];
486 1.7 thorpej }
487 1.7 thorpej lp->d_checksum = dkcksum(lp);
488 1.7 thorpej } else {
489 1.17.2.1 fvdl errmes = readdisklabel(devvp, ofdisk_strategy, lp,
490 1.7 thorpej of->sc_dk.dk_cpulabel);
491 1.7 thorpej if (errmes != NULL)
492 1.12 cgd printf("%s: %s\n", of->sc_dev.dv_xname, errmes);
493 1.7 thorpej }
494 1.1 ws }
495