Module Name: src
Committed By: nisimura
Date: Mon Apr 9 12:40:56 UTC 2012
Modified Files:
src/sys/arch/sandpoint/stand/altboot: dsk.c
Log Message:
Refactor disklabel decode logic. RAIDFRAME case needs more attention
as it's not certain whether a general solution.
To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/sandpoint/stand/altboot/dsk.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/sandpoint/stand/altboot/dsk.c
diff -u src/sys/arch/sandpoint/stand/altboot/dsk.c:1.14 src/sys/arch/sandpoint/stand/altboot/dsk.c:1.15
--- src/sys/arch/sandpoint/stand/altboot/dsk.c:1.14 Sun Jan 22 13:16:54 2012
+++ src/sys/arch/sandpoint/stand/altboot/dsk.c Mon Apr 9 12:40:55 2012
@@ -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 void drive_ident(struct disk *, c
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 @@ decode_dlabel(struct disk *d, char *iobu
struct mbr_partition *mp, *bsdp;
struct disklabel *dlp;
struct partition *pp;
- char *dp;
int i, first, rf_offset;
bsdp = NULL;
@@ -324,39 +324,26 @@ decode_dlabel(struct disk *d, char *iobu
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 @@ decode_dlabel(struct disk *d, char *iobu
}
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