Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/ofppc/stand/ofwboot Finding the disklabel on MBR pa...



details:   https://anonhg.NetBSD.org/src/rev/2f02b4e7defe
branches:  trunk
changeset: 768524:2f02b4e7defe
user:      phx <phx%NetBSD.org@localhost>
date:      Thu Aug 18 09:03:28 2011 +0000

description:
Finding the disklabel on MBR partitioned disks did no longer work since RDB
support was added. Fixed that and bumped the version to 1.12.

diffstat:

 sys/arch/ofppc/stand/ofwboot/mbr.c   |   7 +-
 sys/arch/ofppc/stand/ofwboot/ofdev.c |  77 +++++++++++++++++++----------------
 sys/arch/ofppc/stand/ofwboot/version |   3 +-
 3 files changed, 46 insertions(+), 41 deletions(-)

diffs (236 lines):

diff -r 83701e0ada1a -r 2f02b4e7defe sys/arch/ofppc/stand/ofwboot/mbr.c
--- a/sys/arch/ofppc/stand/ofwboot/mbr.c        Thu Aug 18 08:55:43 2011 +0000
+++ b/sys/arch/ofppc/stand/ofwboot/mbr.c        Thu Aug 18 09:03:28 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mbr.c,v 1.1 2009/09/11 12:00:12 phx Exp $      */
+/*     $NetBSD: mbr.c,v 1.2 2011/08/18 09:03:28 phx Exp $      */
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -48,7 +48,6 @@
        return cp[0] | (cp[1] << 8) | (cp[2] << 16) | (cp[3] << 24);
 }
 
-
 /*
  * Find a valid MBR disklabel.
  */
@@ -81,10 +80,10 @@
 #endif
                    ) {
                        poff = get_long(&p->mbrp_start) + off0;
-                       if (strategy(devp, F_READ, poff + LABELSECTOR,
+                       if (strategy(devp, F_READ, poff + MBR_LABELSECTOR,
                                     DEV_BSIZE, buf, &read) == 0
                            && read == DEV_BSIZE) {
-                               if (!getdisklabel(buf, lp)) {
+                               if (getdisklabel(buf, lp) == NULL) {
                                        recursion--;
                                        return 0;
                                }
diff -r 83701e0ada1a -r 2f02b4e7defe sys/arch/ofppc/stand/ofwboot/ofdev.c
--- a/sys/arch/ofppc/stand/ofwboot/ofdev.c      Thu Aug 18 08:55:43 2011 +0000
+++ b/sys/arch/ofppc/stand/ofwboot/ofdev.c      Thu Aug 18 09:03:28 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ofdev.c,v 1.17 2009/09/11 12:00:12 phx Exp $   */
+/*     $NetBSD: ofdev.c,v 1.18 2011/08/18 09:03:28 phx Exp $   */
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -96,13 +96,12 @@
                                for (cp = lp;
                                     --cp >= str && *cp != '/' && *cp != ':';)
                                        ;
+
                                if (cp >= str && *cp == ':') {
-
                                        /*
                                         * found some arguments,
                                         * make OFW ignore them.
                                         */
-
                                        *cp = 0;
                                        for (cp = lp; *--cp && *cp != ',';)
                                                ;
@@ -122,7 +121,7 @@
 
 int
 strategy(void *devdata, int rw, daddr_t blk, size_t size, void *buf,
-        size_t *rsize)
+    size_t *rsize)
 {
        struct of_dev *dev = devdata;
        u_quad_t pos;
@@ -150,7 +149,9 @@
 }
 
 static int
-devopen_dummy(struct open_file *of, ...) {
+devopen_dummy(struct open_file *of, ...)
+{
+
        return -1;
 }
 
@@ -186,7 +187,6 @@
 char opened_name[256];
 int floppyboot;
 
-
 int
 devopen(struct open_file *of, const char *name, char **file)
 {
@@ -204,6 +204,7 @@
                panic("devopen");
        if (of->f_flags != F_READ)
                return EPERM;
+
        strcpy(fname, name);
        cp = filename(fname, &partition);
        if (cp) {
@@ -213,6 +214,7 @@
        }
        if (!cp || !*buf)
                strcpy(buf, DEFAULT_KERNEL);
+
        if (!*fname)
                strcpy(fname, bootdev);
        DPRINTF("fname=%s\n", fname);
@@ -230,74 +232,75 @@
        if (partition) {
                *file += 2;
        }
+
        if ((handle = OF_finddevice(fname)) == -1) {
                DPRINTF("OF_finddevice(\"%s\") failed\n", fname);
                return ENOENT;
        }
+
        if (OF_getprop(handle, "name", buf, sizeof buf) < 0)
                return ENXIO;
        floppyboot = !strcmp(buf, "floppy");
        if (OF_getprop(handle, "device_type", buf, sizeof buf) < 0)
                return ENXIO;
        if (!strcmp(buf, "block")) {
-
                /*
                 * For block devices, indicate raw partition
                 * (:0 in OpenFirmware)
                 */
-
                strcat(fname, ":0");
        }
+
        DPRINTF("calling OF_open(fname=%s)\n", fname);
        if ((handle = OF_open(fname)) == -1)
                return ENXIO;
        memset(&ofdev, 0, sizeof ofdev);
        ofdev.handle = handle;
+
        if (!strcmp(buf, "block")) {
                ofdev.type = OFDEV_DISK;
                ofdev.bsize = DEV_BSIZE;
 
-               /* First try to find a disklabel without MBR/RDB partitions */
-               if (strategy(&ofdev, F_READ,
-                            LABELSECTOR, DEV_BSIZE, buf, &read) != 0
-                   || read != DEV_BSIZE
-                   || getdisklabel(buf, &label)) {
+               /* First try to read a disklabel from a NetBSD MBR partition */
+               error = search_mbr_label(&ofdev, 0, buf, &label, 0);
+
+               if (error == ERDLAB) {
+                       /* Try to construct a disklabel from RDB partitions */
+                       error = search_rdb_label(&ofdev, buf, &label);
 
-                       /* Else try MBR partitions */
-                       error = search_mbr_label(&ofdev, 0, buf, &label, 0);
-                       if (error && error != ERDLAB)
-                               goto bad;
-
-                       /* and finally try RDB partitions */
-                       error = search_rdb_label(&ofdev, buf, &label);
-                       if (error && error != ERDLAB)
-                               goto bad;
+                       if (error == ERDLAB) {
+                               /* At last read a raw NetBSD disklabel */
+                               error = strategy(&ofdev, F_READ, LABELSECTOR,
+                                   DEV_BSIZE, buf, &read);
+                               if (error == 0 && read != DEV_BSIZE)
+                                       error = EIO;
+                               if (error == 0)
+                                       if (getdisklabel(buf, &label) != NULL)
+                                               error = ERDLAB;
+                       }
                }
 
                if (error == ERDLAB) {
                        if (partition) {
-
                                /*
-                                * User specified a parititon,
+                                * User specified a partition,
                                 * but there is none.
                                 */
-
                                goto bad;
                        }
-
                        /* No label, just use complete disk */
                        ofdev.partoff = 0;
-               } else {
-                       part = partition ? partition - 'a' : 0;
-                       ofdev.partoff = label.d_partitions[part].p_offset;
-                       if (label.d_partitions[part].p_fstype == FS_RAID) {
+               } else if (error != 0)
+                       goto bad;
+
+               part = partition ? partition - 'a' : 0;
+               ofdev.partoff = label.d_partitions[part].p_offset;
+               if (label.d_partitions[part].p_fstype == FS_RAID) {
 #define RF_PROTECTED_SECTORS 64
-                               ofdev.partoff += RF_PROTECTED_SECTORS;
-                               DPRINTF("devopen: found RAID partition, "
-                                   "adjusting offset to %lx\n", ofdev.partoff);
-                       }
+                       ofdev.partoff += RF_PROTECTED_SECTORS;
+                       DPRINTF("devopen: found RAID partition, "
+                           "adjusting offset to %lx\n", ofdev.partoff);
                }
-
                of->f_dev = devsw;
                of->f_devdata = &ofdev;
                file_system[0] = file_system_ufs;
@@ -306,6 +309,7 @@
                nfsys = 3;
                return 0;
        }
+
        if (!strcmp(buf, "network")) {
                ofdev.type = OFDEV_NET;
                of->f_dev = devsw;
@@ -316,8 +320,9 @@
                        goto bad;
                return 0;
        }
+
        error = EFTYPE;
-bad:
+    bad:
        OF_close(handle);
        ofdev.handle = -1;
        return error;
diff -r 83701e0ada1a -r 2f02b4e7defe sys/arch/ofppc/stand/ofwboot/version
--- a/sys/arch/ofppc/stand/ofwboot/version      Thu Aug 18 08:55:43 2011 +0000
+++ b/sys/arch/ofppc/stand/ofwboot/version      Thu Aug 18 09:03:28 2011 +0000
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.11 2009/09/11 12:00:12 phx Exp $
+$NetBSD: version,v 1.12 2011/08/18 09:03:28 phx Exp $
 
 1.1:           Boot program for OpenFirmware; initial revision
 1.2:           Boot program rearrangement
@@ -11,3 +11,4 @@
 1.9:           Add support for auto-detection of 64bit CPUs
 1.10:          Change note to indicate real mode, add ldscript to support 7046
 1.11:          Support for RDB partitions.
+1.12:          Fixed MBR support, which had been broken in 1.11.



Home | Main Index | Thread Index | Old Index