Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/sandpoint/stand/altboot Refactor disklabel decode l...



details:   https://anonhg.NetBSD.org/src/rev/22a3d2f11bd9
branches:  trunk
changeset: 778706:22a3d2f11bd9
user:      nisimura <nisimura%NetBSD.org@localhost>
date:      Mon Apr 09 12:40:55 2012 +0000

description:
Refactor disklabel decode logic.  RAIDFRAME case needs more attention
as it's not certain whether a general solution.

diffstat:

 sys/arch/sandpoint/stand/altboot/dsk.c |  62 ++++++++++++++++++---------------
 1 files changed, 34 insertions(+), 28 deletions(-)

diffs (104 lines):

diff -r b9651beb296a -r 22a3d2f11bd9 sys/arch/sandpoint/stand/altboot/dsk.c
--- a/sys/arch/sandpoint/stand/altboot/dsk.c    Mon Apr 09 11:10:06 2012 +0000
+++ b/sys/arch/sandpoint/stand/altboot/dsk.c    Mon Apr 09 12:40:55 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dsk.c,v 1.14 2012/01/22 13:16:54 phx Exp $ */
+/* $NetBSD: dsk.c,v 1.15 2012/04/09 12:40:55 nisimura Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -77,6 +77,7 @@
 static char *mkident(char *, int);
 static void set_xfermode(struct dkdev_ata *, int);
 static void decode_dlabel(struct disk *, char *);
+static struct disklabel *search_dmagic(char *);
 static int lba_read(struct disk *, int64_t, int, void *);
 static void issue48(struct dvata_chan *, int64_t, int);
 static void issue28(struct dvata_chan *, int64_t, int);
@@ -306,7 +307,6 @@
         struct mbr_partition *mp, *bsdp;
        struct disklabel *dlp;
        struct partition *pp;
-       char *dp;
        int i, first, rf_offset;
 
        bsdp = NULL;
@@ -324,39 +324,26 @@
        rf_offset = 0;
        first = (bsdp) ? bswap32(bsdp->mbrp_start) : 0;
        (*d->lba_read)(d, first + LABELSECTOR, 1, iobuf);
-       dp = iobuf /* + LABELOFFSET */;
-       for (i = 0; i < 512 - sizeof(struct disklabel); i++, dp += 4) {
-               dlp = (struct disklabel *)dp;
-               if (dlp->d_magic == DISKMAGIC && dlp->d_magic2 == DISKMAGIC) {
-                       if (dlp->d_partitions[0].p_fstype == FS_RAID) {
-                               printf("%s%c: raid\n", d->xname, i + 'a');
-                               snprintf(d->xname, sizeof(d->xname), "raid.");
-                               rf_offset = dlp->d_partitions[0].p_offset +
-                                   RF_PROTECTED_SECTORS;
-                               (*d->lba_read)(d, rf_offset + LABELSECTOR, 1,
-                                   iobuf);
-                               dp = iobuf /* + LABELOFFSET */;
-                               for (i = 0; i < 512 - sizeof(struct disklabel); i++, dp += 4) {
-                                       dlp = (struct disklabel *)dp;
-                                       if (dlp->d_magic == DISKMAGIC &&
-                                           dlp->d_magic2 == DISKMAGIC)
-                                               goto found;
-                               }
-                       } else  /* Not RAID */
-                               goto found;
-               }
+       dlp = search_dmagic(iobuf);
+       if (dlp == NULL)
+               goto notfound;
+       if (dlp->d_partitions[0].p_fstype == FS_RAID) {
+               printf("%s%c: raid\n", d->xname, 0 + 'a');
+               snprintf(d->xname, sizeof(d->xname), "raid.");
+               rf_offset
+                   = dlp->d_partitions[0].p_offset + RF_PROTECTED_SECTORS;
+               (*d->lba_read)(d, rf_offset + LABELSECTOR, 1, iobuf);
+               dlp = search_dmagic(iobuf);
+               if (dlp == NULL)
+                       goto notfound;
        }
-       d->dlabel = NULL;
-       printf("%s: no disklabel\n", d->xname);
-       return;
-  found:
        for (i = 0; i < dlp->d_npartitions; i += 1) {
                const char *type;
                pp = &dlp->d_partitions[i];
                pp->p_offset += rf_offset;
                type = NULL;
                switch (pp->p_fstype) {
-               case FS_SWAP: /* swap */
+               case FS_SWAP:
                        type = "swap";
                        break;
                case FS_BSDFFS:
@@ -372,6 +359,25 @@
        }
        d->dlabel = allocaligned(sizeof(struct disklabel), 4);
        memcpy(d->dlabel, dlp, sizeof(struct disklabel));
+       return;
+  notfound:
+       d->dlabel = NULL;
+       printf("%s: no disklabel\n", d->xname);
+       return;
+}
+
+struct disklabel *
+search_dmagic(char *dp)
+{
+       int i;
+       struct disklabel *dlp;
+
+       for (i = 0; i < 512 - sizeof(struct disklabel); i += 4, dp += 4) {
+               dlp = (struct disklabel *)dp;
+               if (dlp->d_magic == DISKMAGIC && dlp->d_magic2 == DISKMAGIC)
+                       return dlp;
+       }
+       return NULL;
 }
 
 static void



Home | Main Index | Thread Index | Old Index