biosdisk.c revision 1.29 1 1.29 jmcneill /* $NetBSD: biosdisk.c,v 1.29 2009/09/13 22:45:27 jmcneill Exp $ */
2 1.1 perry
3 1.1 perry /*
4 1.8 drochner * Copyright (c) 1996, 1998
5 1.1 perry * Matthias Drochner. All rights reserved.
6 1.1 perry *
7 1.1 perry * Redistribution and use in source and binary forms, with or without
8 1.1 perry * modification, are permitted provided that the following conditions
9 1.1 perry * are met:
10 1.1 perry * 1. Redistributions of source code must retain the above copyright
11 1.1 perry * notice, this list of conditions and the following disclaimer.
12 1.1 perry * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 perry * notice, this list of conditions and the following disclaimer in the
14 1.1 perry * documentation and/or other materials provided with the distribution.
15 1.1 perry *
16 1.1 perry * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 perry * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 perry * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 perry * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 perry * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.1 perry * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.1 perry * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.1 perry * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.1 perry * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.1 perry * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.1 perry *
27 1.1 perry */
28 1.1 perry
29 1.3 thorpej /*
30 1.4 drochner * raw BIOS disk device for libsa.
31 1.4 drochner * needs lowlevel parts from bios_disk.S and biosdisk_ll.c
32 1.4 drochner * partly from netbsd:sys/arch/i386/boot/disk.c
33 1.4 drochner * no bad144 handling!
34 1.17 dsl *
35 1.17 dsl * A lot of this must match sys/kern/subr_disk_mbr.c
36 1.1 perry */
37 1.1 perry
38 1.1 perry /*
39 1.1 perry * Ported to boot 386BSD by Julian Elischer (julian (at) tfs.com) Sept 1992
40 1.1 perry *
41 1.1 perry * Mach Operating System
42 1.1 perry * Copyright (c) 1992, 1991 Carnegie Mellon University
43 1.1 perry * All Rights Reserved.
44 1.3 thorpej *
45 1.1 perry * Permission to use, copy, modify and distribute this software and its
46 1.1 perry * documentation is hereby granted, provided that both the copyright
47 1.1 perry * notice and this permission notice appear in all copies of the
48 1.1 perry * software, derivative works or modified versions, and any portions
49 1.1 perry * thereof, and that both notices appear in supporting documentation.
50 1.3 thorpej *
51 1.1 perry * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
52 1.1 perry * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
53 1.1 perry * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
54 1.3 thorpej *
55 1.1 perry * Carnegie Mellon requests users of this software to return to
56 1.3 thorpej *
57 1.1 perry * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
58 1.1 perry * School of Computer Science
59 1.1 perry * Carnegie Mellon University
60 1.1 perry * Pittsburgh PA 15213-3890
61 1.3 thorpej *
62 1.1 perry * any improvements or extensions that they make and grant Carnegie Mellon
63 1.1 perry * the rights to redistribute these changes.
64 1.1 perry */
65 1.1 perry
66 1.29 jmcneill #ifndef NO_DISKLABEL
67 1.29 jmcneill #define FSTYPENAMES
68 1.29 jmcneill #endif
69 1.29 jmcneill
70 1.1 perry #include <sys/types.h>
71 1.21 thorpej #include <sys/md5.h>
72 1.24 junyoung #include <sys/param.h>
73 1.29 jmcneill #include <sys/disklabel.h>
74 1.24 junyoung
75 1.24 junyoung #include <fs/cd9660/iso.h>
76 1.1 perry
77 1.1 perry #include <lib/libsa/stand.h>
78 1.1 perry #include <lib/libsa/saerrno.h>
79 1.5 drochner #include <machine/stdarg.h>
80 1.29 jmcneill #include <machine/cpu.h>
81 1.1 perry
82 1.1 perry #include "libi386.h"
83 1.1 perry #include "biosdisk_ll.h"
84 1.5 drochner #include "biosdisk.h"
85 1.9 drochner #ifdef _STANDALONE
86 1.5 drochner #include "bootinfo.h"
87 1.9 drochner #endif
88 1.16 dsl
89 1.24 junyoung #define BUFSIZE 2048 /* must be large enough for a CD sector */
90 1.1 perry
91 1.3 thorpej struct biosdisk {
92 1.3 thorpej struct biosdisk_ll ll;
93 1.3 thorpej int boff;
94 1.3 thorpej char buf[BUFSIZE];
95 1.1 perry };
96 1.1 perry
97 1.9 drochner #ifdef _STANDALONE
98 1.5 drochner static struct btinfo_bootdisk bi_disk;
99 1.21 thorpej static struct btinfo_bootwedge bi_wedge;
100 1.9 drochner #endif
101 1.5 drochner
102 1.13 lukem #define RF_PROTECTED_SECTORS 64 /* XXX refer to <.../rf_optnames.h> */
103 1.13 lukem
104 1.22 junyoung int
105 1.24 junyoung biosdisk_strategy(void *devdata, int flag, daddr_t dblk, size_t size,
106 1.24 junyoung void *buf, size_t *rsize)
107 1.1 perry {
108 1.3 thorpej struct biosdisk *d;
109 1.22 junyoung int blks, frag;
110 1.1 perry
111 1.3 thorpej if (flag != F_READ)
112 1.22 junyoung return EROFS;
113 1.1 perry
114 1.3 thorpej d = (struct biosdisk *) devdata;
115 1.1 perry
116 1.24 junyoung if (d->ll.type == BIOSDISK_TYPE_CD)
117 1.24 junyoung dblk = dblk * DEV_BSIZE / ISO_DEFAULT_BLOCK_SIZE;
118 1.24 junyoung
119 1.3 thorpej dblk += d->boff;
120 1.3 thorpej
121 1.24 junyoung blks = size / d->ll.secsize;
122 1.3 thorpej if (blks && readsects(&d->ll, dblk, blks, buf, 0)) {
123 1.3 thorpej if (rsize)
124 1.3 thorpej *rsize = 0;
125 1.22 junyoung return EIO;
126 1.3 thorpej }
127 1.22 junyoung
128 1.24 junyoung /* needed for CD */
129 1.24 junyoung frag = size % d->ll.secsize;
130 1.3 thorpej if (frag) {
131 1.3 thorpej if (readsects(&d->ll, dblk + blks, 1, d->buf, 0)) {
132 1.3 thorpej if (rsize)
133 1.24 junyoung *rsize = blks * d->ll.secsize;
134 1.22 junyoung return EIO;
135 1.3 thorpej }
136 1.24 junyoung memcpy(buf + blks * d->ll.secsize, d->buf, frag);
137 1.3 thorpej }
138 1.22 junyoung
139 1.3 thorpej if (rsize)
140 1.3 thorpej *rsize = size;
141 1.22 junyoung return 0;
142 1.1 perry }
143 1.1 perry
144 1.16 dsl static struct biosdisk *
145 1.23 junyoung alloc_biosdisk(int biosdev)
146 1.1 perry {
147 1.3 thorpej struct biosdisk *d;
148 1.1 perry
149 1.23 junyoung d = alloc(sizeof(*d));
150 1.22 junyoung if (d == NULL)
151 1.16 dsl return NULL;
152 1.23 junyoung memset(d, 0, sizeof(*d));
153 1.16 dsl
154 1.23 junyoung d->ll.dev = biosdev;
155 1.11 fvdl if (set_geometry(&d->ll, NULL)) {
156 1.1 perry #ifdef DISK_DEBUG
157 1.3 thorpej printf("no geometry information\n");
158 1.1 perry #endif
159 1.26 christos dealloc(d, sizeof(*d));
160 1.16 dsl return NULL;
161 1.3 thorpej }
162 1.16 dsl return d;
163 1.16 dsl }
164 1.16 dsl
165 1.16 dsl #ifndef NO_DISKLABEL
166 1.16 dsl static int
167 1.17 dsl check_label(struct biosdisk *d, int sector)
168 1.17 dsl {
169 1.17 dsl struct disklabel *lp;
170 1.17 dsl
171 1.17 dsl /* find partition in NetBSD disklabel */
172 1.17 dsl if (readsects(&d->ll, sector + LABELSECTOR, 1, d->buf, 0)) {
173 1.17 dsl #ifdef DISK_DEBUG
174 1.17 dsl printf("Error reading disklabel\n");
175 1.17 dsl #endif
176 1.17 dsl return EIO;
177 1.17 dsl }
178 1.17 dsl lp = (struct disklabel *) (d->buf + LABELOFFSET);
179 1.17 dsl if (lp->d_magic != DISKMAGIC || dkcksum(lp)) {
180 1.17 dsl #ifdef DISK_DEBUG
181 1.27 dsl printf("warning: no disklabel in sector %u\n", sector);
182 1.17 dsl #endif
183 1.17 dsl return -1;
184 1.17 dsl }
185 1.17 dsl
186 1.17 dsl d->boff = sector;
187 1.17 dsl return 0;
188 1.17 dsl }
189 1.17 dsl
190 1.17 dsl static int
191 1.16 dsl read_label(struct biosdisk *d)
192 1.16 dsl {
193 1.17 dsl struct disklabel dflt_lbl;
194 1.18 lukem struct mbr_partition mbr[MBR_PART_COUNT];
195 1.17 dsl struct partition *p;
196 1.16 dsl int sector, i;
197 1.17 dsl int error;
198 1.17 dsl int typ;
199 1.17 dsl int ext_base, this_ext, next_ext;
200 1.17 dsl #ifdef COMPAT_386BSD_MBRPART
201 1.17 dsl int sector_386bsd = -1;
202 1.17 dsl #endif
203 1.17 dsl
204 1.23 junyoung memset(&dflt_lbl, 0, sizeof(dflt_lbl));
205 1.17 dsl dflt_lbl.d_npartitions = 8;
206 1.5 drochner
207 1.7 drochner d->boff = 0;
208 1.7 drochner
209 1.24 junyoung if (d->ll.type != BIOSDISK_TYPE_HD)
210 1.24 junyoung /* No label on floppy and CD */
211 1.16 dsl return -1;
212 1.7 drochner
213 1.3 thorpej /*
214 1.7 drochner * find NetBSD Partition in DOS partition table
215 1.7 drochner * XXX check magic???
216 1.3 thorpej */
217 1.17 dsl ext_base = 0;
218 1.17 dsl next_ext = 0;
219 1.17 dsl for (;;) {
220 1.17 dsl this_ext = ext_base + next_ext;
221 1.17 dsl next_ext = 0;
222 1.17 dsl if (readsects(&d->ll, this_ext, 1, d->buf, 0)) {
223 1.1 perry #ifdef DISK_DEBUG
224 1.17 dsl printf("error reading MBR sector %d\n", this_ext);
225 1.17 dsl #endif
226 1.17 dsl return EIO;
227 1.17 dsl }
228 1.23 junyoung memcpy(&mbr, ((struct mbr_sector *)d->buf)->mbr_parts,
229 1.23 junyoung sizeof(mbr));
230 1.17 dsl /* Look for NetBSD partition ID */
231 1.18 lukem for (i = 0; i < MBR_PART_COUNT; i++) {
232 1.18 lukem typ = mbr[i].mbrp_type;
233 1.17 dsl if (typ == 0)
234 1.17 dsl continue;
235 1.17 dsl sector = this_ext + mbr[i].mbrp_start;
236 1.27 dsl #ifdef DISK_DEBUG
237 1.27 dsl printf("ptn type %d in sector %u\n", typ, sector);
238 1.27 dsl #endif
239 1.17 dsl if (typ == MBR_PTYPE_NETBSD) {
240 1.17 dsl error = check_label(d, sector);
241 1.17 dsl if (error >= 0)
242 1.17 dsl return error;
243 1.17 dsl }
244 1.17 dsl if (MBR_IS_EXTENDED(typ)) {
245 1.17 dsl next_ext = mbr[i].mbrp_start;
246 1.17 dsl continue;
247 1.17 dsl }
248 1.17 dsl #ifdef COMPAT_386BSD_MBRPART
249 1.17 dsl if (this_ext == 0 && typ == MBR_PTYPE_386BSD)
250 1.17 dsl sector_386bsd = sector;
251 1.1 perry #endif
252 1.17 dsl if (this_ext != 0) {
253 1.17 dsl if (dflt_lbl.d_npartitions >= MAXPARTITIONS)
254 1.17 dsl continue;
255 1.17 dsl p = &dflt_lbl.d_partitions[dflt_lbl.d_npartitions++];
256 1.17 dsl } else
257 1.17 dsl p = &dflt_lbl.d_partitions[i];
258 1.17 dsl p->p_offset = sector;
259 1.17 dsl p->p_size = mbr[i].mbrp_size;
260 1.17 dsl p->p_fstype = xlat_mbr_fstype(typ);
261 1.17 dsl }
262 1.17 dsl if (next_ext == 0)
263 1.3 thorpej break;
264 1.17 dsl if (ext_base == 0) {
265 1.17 dsl ext_base = next_ext;
266 1.17 dsl next_ext = 0;
267 1.3 thorpej }
268 1.17 dsl }
269 1.17 dsl
270 1.17 dsl sector = 0;
271 1.8 drochner #ifdef COMPAT_386BSD_MBRPART
272 1.17 dsl if (sector_386bsd != -1) {
273 1.17 dsl printf("old BSD partition ID!\n");
274 1.17 dsl sector = sector_386bsd;
275 1.8 drochner }
276 1.8 drochner #endif
277 1.7 drochner
278 1.17 dsl /*
279 1.17 dsl * One of two things:
280 1.17 dsl * 1. no MBR
281 1.17 dsl * 2. no NetBSD partition in MBR
282 1.17 dsl *
283 1.17 dsl * We simply default to "start of disk" in this case and
284 1.17 dsl * press on.
285 1.17 dsl */
286 1.17 dsl error = check_label(d, sector);
287 1.17 dsl if (error >= 0)
288 1.17 dsl return error;
289 1.16 dsl
290 1.17 dsl /*
291 1.17 dsl * Nothing at start of disk, return info from mbr partitions.
292 1.17 dsl */
293 1.17 dsl /* XXX fill it to make checksum match kernel one */
294 1.17 dsl dflt_lbl.d_checksum = dkcksum(&dflt_lbl);
295 1.23 junyoung memcpy(d->buf, &dflt_lbl, sizeof(dflt_lbl));
296 1.27 dsl return 0;
297 1.16 dsl }
298 1.16 dsl #endif /* NO_DISKLABEL */
299 1.16 dsl
300 1.29 jmcneill void
301 1.29 jmcneill biosdisk_probe(void)
302 1.29 jmcneill {
303 1.29 jmcneill #ifndef NO_DISKLABEL
304 1.29 jmcneill struct disklabel *lp;
305 1.29 jmcneill int first, part;
306 1.29 jmcneill #endif
307 1.29 jmcneill struct biosdisk d;
308 1.29 jmcneill struct biosdisk_extinfo ed;
309 1.29 jmcneill uint64_t size;
310 1.29 jmcneill int i;
311 1.29 jmcneill
312 1.29 jmcneill for (i = 0; i < MAX_BIOSDISKS + 2; i++) {
313 1.29 jmcneill first = 1;
314 1.29 jmcneill memset(&d, 0, sizeof(d));
315 1.29 jmcneill memset(&ed, 0, sizeof(ed));
316 1.29 jmcneill if (i >= MAX_BIOSDISKS)
317 1.29 jmcneill d.ll.dev = 0x00 + i - MAX_BIOSDISKS; /* fd */
318 1.29 jmcneill else
319 1.29 jmcneill d.ll.dev = 0x80 + i; /* hd/cd */
320 1.29 jmcneill if (set_geometry(&d.ll, &ed))
321 1.29 jmcneill continue;
322 1.29 jmcneill switch (d.ll.type) {
323 1.29 jmcneill case BIOSDISK_TYPE_CD:
324 1.29 jmcneill printf("disk cd0\n");
325 1.29 jmcneill printf(" cd0a(unknown)\n");
326 1.29 jmcneill break;
327 1.29 jmcneill case BIOSDISK_TYPE_FD:
328 1.29 jmcneill printf("disk fd%d\n", d.ll.dev & 0x7f);
329 1.29 jmcneill printf(" fd%da(unknown)\n", d.ll.dev & 0x7f);
330 1.29 jmcneill break;
331 1.29 jmcneill case BIOSDISK_TYPE_HD:
332 1.29 jmcneill printf("disk hd%d", d.ll.dev & 0x7f);
333 1.29 jmcneill if (d.ll.flags & BIOSDISK_INT13EXT) {
334 1.29 jmcneill printf(" size ");
335 1.29 jmcneill size = ed.totsec * ed.sbytes;
336 1.29 jmcneill if (size >= (10ULL * 1024 * 1024 * 1024))
337 1.29 jmcneill printf("%llu GB",
338 1.29 jmcneill size / (1024 * 1024 * 1024));
339 1.29 jmcneill else
340 1.29 jmcneill printf("%llu MB",
341 1.29 jmcneill size / (1024 * 1024));
342 1.29 jmcneill }
343 1.29 jmcneill printf("\n");
344 1.29 jmcneill break;
345 1.29 jmcneill }
346 1.29 jmcneill #ifndef NO_DISKLABEL
347 1.29 jmcneill if (read_label(&d) == -1)
348 1.29 jmcneill break;
349 1.29 jmcneill lp = (struct disklabel *)(d.buf + LABELOFFSET);
350 1.29 jmcneill for (part = 0; part < lp->d_npartitions; part++) {
351 1.29 jmcneill if (lp->d_partitions[part].p_size == 0)
352 1.29 jmcneill continue;
353 1.29 jmcneill if (lp->d_partitions[part].p_fstype == FS_UNUSED)
354 1.29 jmcneill continue;
355 1.29 jmcneill if (first) {
356 1.29 jmcneill printf(" ");
357 1.29 jmcneill first = 0;
358 1.29 jmcneill }
359 1.29 jmcneill printf(" hd%d%c(", d.ll.dev & 0x7f, part + 'a');
360 1.29 jmcneill if (lp->d_partitions[part].p_fstype < FSMAXTYPES)
361 1.29 jmcneill printf("%s",
362 1.29 jmcneill fstypenames[lp->d_partitions[part].p_fstype]);
363 1.29 jmcneill else
364 1.29 jmcneill printf("%d", lp->d_partitions[part].p_fstype);
365 1.29 jmcneill printf(")");
366 1.29 jmcneill }
367 1.29 jmcneill if (first == 0)
368 1.29 jmcneill printf("\n");
369 1.29 jmcneill #endif
370 1.29 jmcneill }
371 1.29 jmcneill }
372 1.29 jmcneill
373 1.16 dsl /* Determine likely partition for possible sector number of dos
374 1.17 dsl * partition.
375 1.17 dsl */
376 1.16 dsl
377 1.24 junyoung int
378 1.24 junyoung biosdisk_findpartition(int biosdev, u_int sector)
379 1.16 dsl {
380 1.16 dsl #ifdef NO_DISKLABEL
381 1.16 dsl return 0;
382 1.16 dsl #else
383 1.16 dsl struct biosdisk *d;
384 1.24 junyoung int partition = 0;
385 1.16 dsl struct disklabel *lp;
386 1.27 dsl #ifdef DISK_DEBUG
387 1.27 dsl printf("looking for partition device %x, sector %u\n", biosdev, sector);
388 1.27 dsl #endif
389 1.16 dsl
390 1.16 dsl /* Look for netbsd partition that is the dos boot one */
391 1.16 dsl d = alloc_biosdisk(biosdev);
392 1.17 dsl if (d == NULL)
393 1.17 dsl return 0;
394 1.17 dsl
395 1.17 dsl if (read_label(d) == 0) {
396 1.16 dsl lp = (struct disklabel *)(d->buf + LABELOFFSET);
397 1.16 dsl for (partition = lp->d_npartitions; --partition;){
398 1.16 dsl if (lp->d_partitions[partition].p_fstype == FS_UNUSED)
399 1.16 dsl continue;
400 1.16 dsl if (lp->d_partitions[partition].p_offset == sector)
401 1.16 dsl break;
402 1.16 dsl }
403 1.16 dsl }
404 1.16 dsl
405 1.26 christos dealloc(d, sizeof(*d));
406 1.16 dsl return partition;
407 1.22 junyoung #endif /* NO_DISKLABEL */
408 1.16 dsl }
409 1.16 dsl
410 1.22 junyoung int
411 1.24 junyoung biosdisk_open(struct open_file *f, ...)
412 1.23 junyoung /* struct open_file *f, int biosdev, int partition */
413 1.16 dsl {
414 1.16 dsl va_list ap;
415 1.16 dsl struct biosdisk *d;
416 1.23 junyoung int biosdev;
417 1.16 dsl int partition;
418 1.16 dsl #ifndef NO_DISKLABEL
419 1.16 dsl struct disklabel *lp;
420 1.16 dsl #endif
421 1.16 dsl int error = 0;
422 1.16 dsl
423 1.16 dsl va_start(ap, f);
424 1.23 junyoung biosdev = va_arg(ap, int);
425 1.23 junyoung d = alloc_biosdisk(biosdev);
426 1.23 junyoung if (d == NULL) {
427 1.16 dsl error = ENXIO;
428 1.16 dsl goto out;
429 1.16 dsl }
430 1.16 dsl
431 1.16 dsl partition = va_arg(ap, int);
432 1.16 dsl #ifdef _STANDALONE
433 1.16 dsl bi_disk.biosdev = d->ll.dev;
434 1.16 dsl bi_disk.partition = partition;
435 1.16 dsl bi_disk.labelsector = -1;
436 1.21 thorpej
437 1.21 thorpej bi_wedge.biosdev = d->ll.dev;
438 1.21 thorpej bi_wedge.matchblk = -1;
439 1.16 dsl #endif
440 1.16 dsl
441 1.16 dsl #ifndef NO_DISKLABEL
442 1.16 dsl if (partition == RAW_PART)
443 1.16 dsl goto nolabel;
444 1.16 dsl error = read_label(d);
445 1.16 dsl if (error == -1) {
446 1.16 dsl error = 0;
447 1.16 dsl goto nolabel;
448 1.16 dsl }
449 1.16 dsl if (error)
450 1.16 dsl goto out;
451 1.16 dsl
452 1.16 dsl lp = (struct disklabel *) (d->buf + LABELOFFSET);
453 1.16 dsl if (partition >= lp->d_npartitions ||
454 1.23 junyoung lp->d_partitions[partition].p_fstype == FS_UNUSED) {
455 1.1 perry #ifdef DISK_DEBUG
456 1.3 thorpej printf("illegal partition\n");
457 1.1 perry #endif
458 1.3 thorpej error = EPART;
459 1.3 thorpej goto out;
460 1.16 dsl }
461 1.9 drochner #ifdef _STANDALONE
462 1.16 dsl bi_disk.labelsector = d->boff + LABELSECTOR;
463 1.16 dsl bi_disk.label.type = lp->d_type;
464 1.16 dsl memcpy(bi_disk.label.packname, lp->d_packname, 16);
465 1.16 dsl bi_disk.label.checksum = lp->d_checksum;
466 1.21 thorpej
467 1.21 thorpej bi_wedge.startblk = lp->d_partitions[partition].p_offset;
468 1.21 thorpej bi_wedge.nblks = lp->d_partitions[partition].p_size;
469 1.21 thorpej bi_wedge.matchblk = d->boff + LABELSECTOR;
470 1.21 thorpej bi_wedge.matchnblks = 1;
471 1.21 thorpej {
472 1.21 thorpej MD5_CTX ctx;
473 1.21 thorpej
474 1.21 thorpej MD5Init(&ctx);
475 1.21 thorpej MD5Update(&ctx, (void *) d->buf, 512);
476 1.21 thorpej MD5Final(bi_wedge.matchhash, &ctx);
477 1.21 thorpej }
478 1.16 dsl #endif
479 1.16 dsl d->boff = lp->d_partitions[partition].p_offset;
480 1.16 dsl if (lp->d_partitions[partition].p_fstype == FS_RAID)
481 1.16 dsl d->boff += RF_PROTECTED_SECTORS;
482 1.7 drochner nolabel:
483 1.7 drochner #endif /* NO_DISKLABEL */
484 1.1 perry
485 1.1 perry #ifdef DISK_DEBUG
486 1.3 thorpej printf("partition @%d\n", d->boff);
487 1.1 perry #endif
488 1.1 perry
489 1.9 drochner #ifdef _STANDALONE
490 1.5 drochner BI_ADD(&bi_disk, BTINFO_BOOTDISK, sizeof(bi_disk));
491 1.21 thorpej BI_ADD(&bi_wedge, BTINFO_BOOTWEDGE, sizeof(bi_wedge));
492 1.9 drochner #endif
493 1.5 drochner
494 1.3 thorpej f->f_devdata = d;
495 1.1 perry out:
496 1.5 drochner va_end(ap);
497 1.3 thorpej if (error)
498 1.26 christos dealloc(d, sizeof(struct biosdisk));
499 1.22 junyoung return error;
500 1.1 perry }
501 1.1 perry
502 1.12 drochner #ifndef LIBSA_NO_FS_CLOSE
503 1.22 junyoung int
504 1.24 junyoung biosdisk_close(struct open_file *f)
505 1.1 perry {
506 1.3 thorpej struct biosdisk *d = f->f_devdata;
507 1.1 perry
508 1.24 junyoung /* let the floppy drive go off */
509 1.24 junyoung if (d->ll.type == BIOSDISK_TYPE_FD)
510 1.3 thorpej delay(3000000); /* 2s is enough on all PCs I found */
511 1.1 perry
512 1.26 christos dealloc(d, sizeof(struct biosdisk));
513 1.3 thorpej f->f_devdata = NULL;
514 1.22 junyoung return 0;
515 1.1 perry }
516 1.12 drochner #endif
517 1.1 perry
518 1.22 junyoung int
519 1.24 junyoung biosdisk_ioctl(struct open_file *f, u_long cmd, void *arg)
520 1.1 perry {
521 1.3 thorpej return EIO;
522 1.1 perry }
523