diff options
Diffstat (limited to 'sys/i386/isa')
-rw-r--r-- | sys/i386/isa/fd.c | 8 | ||||
-rw-r--r-- | sys/i386/isa/mcd.c | 3 | ||||
-rw-r--r-- | sys/i386/isa/readMBR.c | 232 | ||||
-rw-r--r-- | sys/i386/isa/wd.c | 27 |
4 files changed, 248 insertions, 22 deletions
diff --git a/sys/i386/isa/fd.c b/sys/i386/isa/fd.c index a000acf..e06ac4a 100644 --- a/sys/i386/isa/fd.c +++ b/sys/i386/isa/fd.c @@ -40,7 +40,7 @@ * SUCH DAMAGE. * * from: @(#)fd.c 7.4 (Berkeley) 5/25/91 - * $Id: fd.c,v 1.36 1994/10/21 16:58:50 joerg Exp $ + * $Id: fd.c,v 1.37 1994/10/23 21:27:12 wollman Exp $ * */ @@ -1522,7 +1522,7 @@ fdioctl(dev, cmd, addr, flag, p) dl->d_secpercyl = fdt->size / fdt->tracks; dl->d_type = DTYPE_FLOPPY; - if (readdisklabel(dev, fdstrategy, dl, NULL, 0, 0) == NULL) + if (readdisklabel(dev, fdstrategy, dl, NULL, 0) == NULL) error = 0; else error = EINVAL; @@ -1550,11 +1550,11 @@ fdioctl(dev, cmd, addr, flag, p) dl = (struct disklabel *)addr; if ((error = - setdisklabel ((struct disklabel *)buffer, dl, 0, NULL))) + setdisklabel ((struct disklabel *)buffer, dl, 0))) break; error = writedisklabel(dev, fdstrategy, - (struct disklabel *)buffer, NULL); + (struct disklabel *)buffer); break; case FD_FORM: diff --git a/sys/i386/isa/mcd.c b/sys/i386/isa/mcd.c index e27f600..a6d4bbb 100644 --- a/sys/i386/isa/mcd.c +++ b/sys/i386/isa/mcd.c @@ -39,7 +39,7 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: mcd.c,v 1.25 1994/09/14 20:28:25 ache Exp $ + * $Id: mcd.c,v 1.26 1994/10/23 21:27:29 wollman Exp $ */ static char COPYRIGHT[] = "mcd-driver (C)1993 by H.Veit & B.Moore"; @@ -483,7 +483,6 @@ MCD_TRACE("ioctl called 0x%x\n",cmd,0,0,0); else { return setdisklabel(&cd->dlabel, (struct disklabel *) addr, - 0, 0); } case DIOCWLABEL: diff --git a/sys/i386/isa/readMBR.c b/sys/i386/isa/readMBR.c new file mode 100644 index 0000000..4165d21 --- /dev/null +++ b/sys/i386/isa/readMBR.c @@ -0,0 +1,232 @@ +/* + * + * THIS SOFTWARE IS PROVIDED BY THE WRITERS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE WRITERS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * written by julian elischer (julian@tfs.com) + * + * @(#)readMBR.c 8.5 (tfs) 1/21/94 + * $Id: readMBR.c,v 1.5 1994/10/17 02:31:33 phk Exp $ + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/buf.h> +#include <sys/disklabel.h> + +#define b_cylinder b_resid + +/* + * Attempt to read a machine-type dependent Device partitioning table + * In this case a PC BIOS MBR. + * Destroys the original disklabel if it finds an MBR, so you'd better + * know what you're doing. It assumes that the label you've given it + * Is the one that controls the device, so that it can fiddle with it + * to make sure it's reading absolute sectors. + * On exit: + * Leaves the disklabel set up with the various partitions + * in the last 4 entries, + * the A partition pointing to the BSD part + * the C partition set as the BSD partition, (read the disklabel from there) and + * the D partition set as the whole disk for beating up + * will also give you a copy of the machine dependent table if you ask.. + * returns 0 for success, + * On failure, restores the disklabel and returns a messages pointer. + */ +char * +readMBRtolabel(dev, strat, lp, dp, cyl) + dev_t dev; + void (*strat)(); + register struct disklabel *lp; + struct dos_partition *dp; + int *cyl; +{ + register struct buf *bp; + struct disklabel *dlp; + struct disklabel labelsave; + char *msg = NULL; + int i; + int pseudopart = 4; /* we fill in pseudoparts from e through h*/ + int seenBSD = 0; + + /* + * Save a copy of the disklabel in case we return with an error + */ + bcopy(lp,&labelsave,sizeof(labelsave)); + + /* + * Set the disklabel to some useable partitions in case it's rubbish + */ + if (lp->d_secperunit == 0) + lp->d_secperunit = 0x1fffffff; + lp->d_npartitions = 4; + for (i=0; i<MAXPARTITIONS; i++) { + lp->d_partitions[i].p_offset = 0; + lp->d_partitions[i].p_size = 0; + } + lp->d_partitions[RAWPART].p_size = DOSBBSECTOR + 1; /* start low */ + strcpy(lp->d_packname,"MBR based label"); /* Watch the length ! */ + + /* + * Get a buffer and get ready to read the MBR + */ + bp = geteblk((int)lp->d_secsize); + /* read master boot record */ + bp->b_dev = makedev(major(dev), dkminor(dkunit(dev), RAWPART)); + bp->b_blkno = DOSBBSECTOR; + bp->b_bcount = lp->d_secsize; + bp->b_flags = B_BUSY | B_READ; + bp->b_cylinder = DOSBBSECTOR / lp->d_secpercyl; + (*strat)(bp); + + /* if successful, wander through dos partition table */ + if ( biowait(bp)) { + msg = "dos partition I/O error"; + goto bad; + } else { + /* + * If there seems to be BIOS bootblock and partition table + * in that block, then try interpret it, otherwise + * give up and use whatever we have synthesised so far + */ + if ((*(bp->b_un.b_addr + 510) != (char) 0x55) + ||(*(bp->b_un.b_addr + 511) != (char) 0xaa)) { + msg = "Disk has no Fdisk partitions"; + goto bad; + } + + if(dp) { /* if they asked for a copy, give it to them */ + bcopy(bp->b_un.b_addr + DOSPARTOFF, dp, + NDOSPART * sizeof(*dp)); + } + dp = (struct dos_partition *)(bp->b_un.b_addr + DOSPARTOFF); + /* + * We have a DOS MBR.. + * We set up the last 4 partitions in the + * disklabel to reflect the DOS partitions + * In case we never find a disklabel, in which + * case this information will be all we have + * but it might be all we need to access a DOS + * partition. + */ + for (i = 0; i < NDOSPART; i++, dp++,pseudopart++) { + + if (!dp->dp_size) + continue; + /* + * Set this DOS part into the disklabel + */ + lp->d_partitions[pseudopart].p_size = + dp->dp_size; + lp->d_partitions[pseudopart].p_offset = + dp->dp_start; + + /* + * make sure the D part can hold it all + */ + if((dp->dp_start + dp->dp_size) + > lp->d_partitions[3].p_size) { + lp->d_partitions[3].p_size + = (dp->dp_start + dp->dp_size); + } + + /* + * If we haven't seen a *BSD partition then + * check if this is a valid part.. + * if it is it may be the best we are going to + * to see, so take note of it to deduce a + * geometry in case we never find a disklabel. + */ + switch(dp->dp_typ) { + case DOSPTYP_386BSD: + /* + * at a pinch we could throw + * a FFS on here + */ + lp->d_partitions[pseudopart].p_fstype + = FS_BSDFFS; + /* + * Only get a disklabel from the + * first one we see.. + */ + if (seenBSD == 0) { + /* + * If it IS our part, then we + * need sector address for + * SCSI/IDE, cylinder for + * ESDI/ST506/RLL + */ + seenBSD = 1; + *cyl = DPCYL(dp->dp_scyl, + dp->dp_ssect); + + /* + * Note which part we are in (?) + */ + lp->d_subtype &= ~3; + lp->d_subtype |= i & 3; + lp->d_subtype + |= DSTYPE_INDOSPART; + + /* + * update disklabel with + * details for reading the REAL + * disklabel it it exists + */ + lp->d_partitions[OURPART].p_size = + dp->dp_size; + lp->d_partitions[OURPART].p_offset = + dp->dp_start; + } + break; + case 0xB7: /* BSDI (?)*//* doubtful */ + lp->d_partitions[pseudopart].p_fstype + = FS_BSDFFS; + break; + case 1: + case 4: + case 6: + case 0xF2: + lp->d_partitions[pseudopart].p_fstype + = FS_MSDOS; + break; + } + + /* + * Try deduce the geometry, working + * on the principle that this + * partition PROBABLY ends on a + * cylinder boundary. + * This is really a kludge, but we are + * forced into it by the PC's design. + * If we've seen a 386bsd part, + * believe it and check no further. + */ + if (seenBSD) continue; + lp->d_ntracks = dp->dp_ehd + 1; + lp->d_nsectors = DPSECT(dp->dp_esect); + lp->d_secpercyl = lp->d_ntracks * + lp->d_nsectors; + } + lp->d_npartitions = 8; + } + bp->b_flags = B_INVAL | B_AGE; + brelse(bp); + return 0; +bad: + bcopy(&labelsave,lp,sizeof(labelsave)); + bp->b_flags = B_INVAL | B_AGE; + brelse(bp); + return msg; +} + + diff --git a/sys/i386/isa/wd.c b/sys/i386/isa/wd.c index 8cc7460..30c990d 100644 --- a/sys/i386/isa/wd.c +++ b/sys/i386/isa/wd.c @@ -37,7 +37,7 @@ static int wdtest = 0; * SUCH DAMAGE. * * from: @(#)wd.c 7.2 (Berkeley) 5/9/91 - * $Id: wd.c,v 1.56 1994/10/23 21:27:40 wollman Exp $ + * $Id: wd.c,v 1.57 1994/10/27 05:39:12 phk Exp $ */ /* TODO: @@ -271,8 +271,6 @@ struct isa_driver wdcdriver = { wdprobe, wdattach, "wdc", }; -extern char *readdisklabel(); - /* * Probe for controller. */ @@ -993,14 +991,9 @@ wdopen(dev_t dev, int flags, int fmt, struct proc *p) save_label = du->dk_dd; du->dk_dd.d_partitions[WDRAW].p_offset = 0; du->dk_dd.d_partitions[WDRAW].p_size = 0x7fffffff;/* XXX */ -#define WDSTRATEGY ((int (*)(struct buf *)) wdstrategy) /* XXX */ msg = readdisklabel(makewddev(major(dev), lunit, WDRAW), - WDSTRATEGY, &du->dk_dd, + wdstrategy, &du->dk_dd, du->dk_dospartitions, &du->dk_bad); -/* - msg = readdisklabel(makewddev(major(dev), lunit, WDRAW), - WDSTRATEGY, &du->dk_dd); -*/ du->dk_flags &= ~DKFL_LABELLING; if (msg != NULL) { du->dk_dd = save_label; @@ -1437,8 +1430,7 @@ wdioctl(dev_t dev, int cmd, caddr_t addr, int flag) du->dk_flags & DKFL_BSDLABEL ? du->dk_openpart : #endif - 0, - du->dk_dospartitions); + 0); if (error == 0) { du->dk_flags |= DKFL_BSDLABEL; wdwsetctlr(du); /* XXX - check */ @@ -1463,8 +1455,7 @@ wdioctl(dev_t dev, int cmd, caddr_t addr, int flag) du->dk_flags & DKFL_BSDLABEL ? du->dk_openpart : #endif - 0, - du->dk_dospartitions)) == 0) { + 0)) == 0) { int wlab; du->dk_flags |= DKFL_BSDLABEL; @@ -1474,8 +1465,7 @@ wdioctl(dev_t dev, int cmd, caddr_t addr, int flag) du->dk_openpart |= (1 << 0); /* XXX */ wlab = du->dk_wlabel; du->dk_wlabel = 1; - error = writedisklabel(dev, WDSTRATEGY, - &du->dk_dd, du->dk_dospartitions); + error = writedisklabel(dev, wdstrategy, &du->dk_dd); du->dk_openpart = du->dk_copenpart | du->dk_bopenpart; du->dk_wlabel = wlab; } @@ -1524,7 +1514,12 @@ wdformat(struct buf *bp) { bp->b_flags |= B_FORMAT; - return (wdstrategy(bp)); + wdstrategy(bp); + /* + * phk put this here, better that return(wdstrategy(bp)); + * XXX + */ + return -1; } #endif |