Deleted Added
full compact
26c26
< * $Id: biosdisk.c,v 1.7 1998/09/28 20:07:39 peter Exp $
---
> * $Id: biosdisk.c,v 1.8 1998/09/28 20:08:34 peter Exp $
43a44
> #include <sys/reboot.h>
52a54,59
> #define DT_ATAPI 0x10 /* disk type for ATAPI floppies */
> #define WDMAJOR 0 /* major numbers for devices we frontend for */
> #define WFDMAJOR 1
> #define FDMAJOR 2
> #define DAMAJOR 4
>
73c80,83
< u_char od_buf[BUFSIZE]; /* transfer buffer (do we want/need this?) */
---
> struct disklabel od_disklabel;
> struct dos_partition od_parttab;
> #define BD_LABELOK (1<<3)
> #define BD_PARTTABOK (1<<4)
75a86,97
> /*
> * List of BIOS devices, translation from disk unit number to
> * BIOS unit number.
> */
> static struct bdinfo
> {
> int bd_unit; /* BIOS unit number */
> int bd_flags;
> int bd_type; /* BIOS 'drive type' (floppy only) */
> } bdinfo [MAXBDDEV];
> static int nbdinfo = 0;
>
79,81c101
< static int bd_edd3probe(int unit);
< static int bd_edd1probe(int unit);
< static int bd_int13probe(int unit);
---
> static int bd_int13probe(struct bdinfo *bd);
97a118,120
> static int bd_opendisk(struct open_disk **odp, struct i386_devdesc *dev);
> static void bd_closedisk(struct open_disk *od);
>
99,100c122
< * List of BIOS devices, translation from disk unit number to
< * BIOS unit number.
---
> * Translate between BIOS device numbers and our private unit numbers.
102c124,125
< static struct
---
> int
> bd_bios2unit(int biosdev)
104,107c127,133
< int bd_unit; /* BIOS unit number */
< int bd_flags;
< } bdinfo [MAXBDDEV];
< static int nbdinfo = 0;
---
> int i;
>
> for (i = 0; i < nbdinfo; i++)
> if (bdinfo[i].bd_unit == biosdev)
> return(i);
> return(-1);
> }
108a135,142
> int
> bd_unit2bios(int unit)
> {
> if ((unit >= 0) && (unit < nbdinfo))
> return(bdinfo[unit].bd_unit);
> return(-1);
> }
>
123c157
< bdinfo[nbdinfo].bd_unit = -1;
---
> bdinfo[nbdinfo].bd_unit = unit;
125,132c159,161
<
< if (bd_edd3probe(unit)) {
< bdinfo[nbdinfo].bd_flags |= BD_MODEEDD3;
< } else if (bd_edd1probe(unit)) {
< bdinfo[nbdinfo].bd_flags |= BD_MODEEDD1;
< } else if (bd_int13probe(unit)) {
< bdinfo[nbdinfo].bd_flags |= BD_MODEINT13;
< } else {
---
>
> /* XXX add EDD probes */
> if (!bd_int13probe(&bdinfo[nbdinfo]))
134c163
< }
---
>
145,162d173
< /*
< * Try to detect a device supported by an Enhanced Disk Drive 3.0-compliant BIOS
< */
< static int
< bd_edd3probe(int unit)
< {
< return(0); /* XXX not implemented yet */
< }
<
< /*
< * Try to detect a device supported by an Enhanced Disk Drive 1.1-compliant BIOS
< */
< static int
< bd_edd1probe(int unit)
< {
< return(0); /* XXX not implemented yet */
< }
<
168c179
< bd_int13probe(int unit)
---
> bd_int13probe(struct bdinfo *bd)
169a181
>
173c185
< v86.edx = unit;
---
> v86.edx = bd->bd_unit;
176,177c188,191
< if (!(v86.efl & 0x1) && /* carry clear */
< ((v86.edx & 0xff) > (unit & 0x7f))) /* unit # OK */
---
> if (!(v86.efl & 0x1) && /* carry clear */
> ((v86.edx & 0xff) > (bd->bd_unit & 0x7f))) { /* unit # OK */
> bd->bd_flags |= BD_MODEINT13;
> bd->bd_type = v86.ebx & 0xff;
178a193
> }
196d210
< struct dos_partition *dptr;
197a212,228
> int error;
>
> if ((error = bd_opendisk(&od, dev)))
> return(error);
>
> /*
> * Save our context
> */
> ((struct i386_devdesc *)(f->f_devdata))->d_kind.biosdisk.data = od;
> DEBUG("open_disk %p, partition at 0x%x", od, od->od_boff);
> return(0);
> }
>
> static int
> bd_opendisk(struct open_disk **odp, struct i386_devdesc *dev)
> {
> struct dos_partition *dptr;
198a230
> struct open_disk *od;
200a233
> u_char buf[BUFSIZE];
239c272
< if (bd_read(od, 0, 1, od->od_buf)) {
---
> if (bd_read(od, 0, 1, buf)) {
248c281
< if ((od->od_buf[0x1fe] != 0x55) || (od->od_buf[0x1ff] != 0xaa)) {
---
> if ((buf[0x1fe] != 0x55) || (buf[0x1ff] != 0xaa)) {
258c291,293
< dptr = (struct dos_partition *) & od->od_buf[DOSPARTOFF];
---
> bcopy(buf + DOSPARTOFF, &od->od_parttab, sizeof(struct dos_partition));
> dptr = &od->od_parttab;
> od->od_flags |= BD_PARTTABOK;
302c337
< if (bd_read(od, sector + LABELSECTOR, 1, od->od_buf)) {
---
> if (bd_read(od, sector + LABELSECTOR, 1, buf)) {
307c342,345
< lp = (struct disklabel *) (od->od_buf + LABELOFFSET);
---
> DEBUG("copy %d bytes of label from %p to %p", sizeof(struct disklabel), buf + LABELOFFSET, &od->od_disklabel);
> bcopy(buf + LABELOFFSET, &od->od_disklabel, sizeof(struct disklabel));
> lp = &od->od_disklabel;
> od->od_flags |= BD_LABELOK;
329,334c367
< /*
< * Save our context
< */
< ((struct i386_devdesc *)(f->f_devdata))->d_kind.biosdisk.data = od;
< DEBUG("open_disk %p, partition at 0x%x", od, od->od_boff);
<
---
>
336c369
< if (error)
---
> if (error) {
337a371,373
> } else {
> *odp = od; /* return the open disk */
> }
340a377
>
345a383,389
> bd_closedisk(od);
> return(0);
> }
>
> static void
> bd_closedisk(struct open_disk *od)
> {
353d396
< return(0);
523a567,608
>
> /*
> * Return a suitable dev_t value for (dev)
> */
> int
> bd_getdev(struct i386_devdesc *dev)
> {
> struct open_disk *od;
> int biosdev;
> int major;
>
> biosdev = bd_unit2bios(dev->d_kind.biosdisk.unit);
> if (biosdev == -1) /* not a BIOS device */
> return(-1);
> if (bd_opendisk(&od, dev) != 0) /* oops, not a viable device */
> return(-1);
>
> if (biosdev < 0x80) {
> /* floppy (or emulated floppy) or ATAPI device */
> if (bdinfo[dev->d_kind.biosdisk.unit].bd_type == DT_ATAPI) {
> /* is an ATAPI disk */
> major = WFDMAJOR;
> } else {
> /* is a floppy disk */
> major = FDMAJOR;
> }
> } else {
> /* harddisk */
> if ((od->od_flags & BD_LABELOK) && (od->od_disklabel.d_type == DTYPE_SCSI)) {
> /* label OK, disk labelled as SCSI */
> major = DAMAJOR;
> } else {
> /* assume an IDE disk */
> major = WDMAJOR;
> }
> }
> return(MAKEBOOTDEV(major,
> (dev->d_kind.biosdisk.slice + 1) >> 4, /* XXX slices may be wrong here */
> (dev->d_kind.biosdisk.slice + 1) & 0xf,
> biosdev & 0x7f, /* XXX allow/compute shift for da when wd present */
> dev->d_kind.biosdisk.partition));
> }