Module Name:    src
Committed By:   phx
Date:           Thu Feb  2 21:54:34 UTC 2012

Modified Files:
        src/sys/arch/ofppc/include: disklabel.h
        src/sys/arch/ofppc/ofppc: disksubr.c
        src/sys/arch/ofppc/stand/ofwboot: mbr.c

Log Message:
Fixed writing of MBR disklabel. It was written by disklabel(8) -r directly
into sector 0, corrupting the MBR. Moved to sector 1.
Removed MBR_LABELSECTOR, which is no longer needed.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/ofppc/include/disklabel.h
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/ofppc/ofppc/disksubr.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/ofppc/stand/ofwboot/mbr.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/ofppc/include/disklabel.h
diff -u src/sys/arch/ofppc/include/disklabel.h:1.10 src/sys/arch/ofppc/include/disklabel.h:1.11
--- src/sys/arch/ofppc/include/disklabel.h:1.10	Tue Aug 30 12:39:57 2011
+++ src/sys/arch/ofppc/include/disklabel.h	Thu Feb  2 21:54:34 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: disklabel.h,v 1.10 2011/08/30 12:39:57 bouyer Exp $	*/
+/*	$NetBSD: disklabel.h,v 1.11 2012/02/02 21:54:34 phx Exp $	*/
 
 /*-
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -34,10 +34,8 @@
 #define _MACHINE_DISKLABEL_H_
 
 #define LABELUSESMBR	0			/* no MBR partitionning */
-#define	LABELSECTOR	0			/* sector containing label */
-#define	LABELOFFSET	64			/* offset of label in sector */
-#define MBR_LABELSECTOR 1			/* label sector in MBR */
-#define MBR_LABELOFFSET 0			/* label offset in MBR */
+#define	LABELSECTOR	1			/* sector containing label */
+#define	LABELOFFSET	0			/* offset of label in sector */
 #define	MAXPARTITIONS	16			/* number of partitions */
 #define	RAW_PART	2			/* raw partition: xx?c */
 

Index: src/sys/arch/ofppc/ofppc/disksubr.c
diff -u src/sys/arch/ofppc/ofppc/disksubr.c:1.24 src/sys/arch/ofppc/ofppc/disksubr.c:1.25
--- src/sys/arch/ofppc/ofppc/disksubr.c:1.24	Sat Oct  8 06:55:19 2011
+++ src/sys/arch/ofppc/ofppc/disksubr.c	Thu Feb  2 21:54:34 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: disksubr.c,v 1.24 2011/10/08 06:55:19 kiyohara Exp $	*/
+/*	$NetBSD: disksubr.c,v 1.25 2012/02/02 21:54:34 phx Exp $	*/
 
 /*-
  * Copyright (c) 2010 Frank Wille.
@@ -63,7 +63,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: disksubr.c,v 1.24 2011/10/08 06:55:19 kiyohara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: disksubr.c,v 1.25 2012/02/02 21:54:34 phx Exp $");
 
 #include "opt_disksubr.h"
 
@@ -190,8 +190,8 @@ read_dos_label(dev_t dev, void (*strat)(
 		if (2 > maxslot)
 			maxslot = 2;
 		/* read in disklabel, blkno + 1 for DOS disklabel offset */
-		osdep->cd_labelsector = bsdpartoff + MBR_LABELSECTOR;
-		osdep->cd_labeloffset = MBR_LABELOFFSET;
+		osdep->cd_labelsector = bsdpartoff + LABELSECTOR;
+		osdep->cd_labeloffset = LABELOFFSET;
 		if (read_netbsd_label(dev, strat, lp, osdep))
 			goto done;
 		msg = "no NetBSD disk label";
@@ -430,7 +430,9 @@ read_rdb_label(dev_t dev, void (*strat)(
 		case ADT_NETBSDROOT:
 			pp = &lp->d_partitions[0];
 			if (pp->p_size) {
+#ifdef DIAGNOSTIC
 				printf("more than one root, ignoring\n");
+#endif
 				osdep->rdblock = RDBNULL; /* invalidate cpulab */
 				continue;
 			}
@@ -438,7 +440,9 @@ read_rdb_label(dev_t dev, void (*strat)(
 		case ADT_NETBSDSWAP:
 			pp = &lp->d_partitions[1];
 			if (pp->p_size) {
+#ifdef DIAGNOSTIC
 				printf("more than one swap, ignoring\n");
+#endif
 				osdep->rdblock = RDBNULL; /* invalidate cpulab */
 				continue;
 			}
@@ -730,14 +734,24 @@ readdisklabel(dev_t dev, void (*strat)(s
 	if (lp->d_secpercyl == 0) {
 		return msg = "Zero secpercyl";
 	}
+
+	/* no valid RDB found */
+	osdep->rdblock = RDBNULL;
+
+	/* XXX cd_start is abused as a flag for fictitious disklabel */
+	osdep->cd_start = -1;
+
+	osdep->cd_labelsector = LABELSECTOR;
+	osdep->cd_labeloffset = LABELOFFSET;
+
 	bp = geteblk((int)lp->d_secsize);
 
 	bp->b_dev = dev;
-	bp->b_blkno = 0;
+	bp->b_blkno = MBR_BBSECTOR;
 	bp->b_resid = 0;
 	bp->b_bcount = lp->d_secsize;
 	bp->b_flags |= B_READ;
-	bp->b_cylinder = 1 / lp->d_secpercyl;
+	bp->b_cylinder = MBR_BBSECTOR / lp->d_secpercyl;
 	(*strat)(bp);
 
 	if (biowait(bp)) {
@@ -745,15 +759,6 @@ readdisklabel(dev_t dev, void (*strat)(s
 		goto done;
 	}
 
-	/* no valid RDB found */
-	osdep->rdblock = RDBNULL;
-
-	/* XXX cd_start is abused as a flag for fictitious disklabel */
-	osdep->cd_start = -1;
-
-	osdep->cd_labelsector = LABELSECTOR;
-	osdep->cd_labeloffset = LABELOFFSET;
-
 	if (bswap16(*(u_int16_t *)((char *)bp->b_data + MBR_MAGIC_OFFSET))
 	    == MBR_MAGIC) {
 		/*
@@ -851,7 +856,7 @@ writedisklabel(dev_t dev, void (*strat)(
 	label = *lp;
 	readdisklabel(dev, strat, &label, osdep);
 
-	/* If RDB was present, we don't support writing them yet. */
+	/* If an RDB was present, we don't support writing it yet. */
 	if (osdep->rdblock != RDBNULL)
 		return EINVAL;
 
@@ -859,7 +864,7 @@ writedisklabel(dev_t dev, void (*strat)(
 	bp = geteblk(lp->d_secsize);
 	bp->b_dev = dev;
 
-	bp->b_blkno = osdep->cd_start + osdep->cd_labelsector;
+	bp->b_blkno = osdep->cd_labelsector;
 	bp->b_cylinder = bp->b_blkno / (lp->d_secsize / DEV_BSIZE) /
 	    lp->d_secpercyl;
 	bp->b_bcount = lp->d_secsize;

Index: src/sys/arch/ofppc/stand/ofwboot/mbr.c
diff -u src/sys/arch/ofppc/stand/ofwboot/mbr.c:1.3 src/sys/arch/ofppc/stand/ofwboot/mbr.c:1.4
--- src/sys/arch/ofppc/stand/ofwboot/mbr.c:1.3	Sun Aug 21 13:08:57 2011
+++ src/sys/arch/ofppc/stand/ofwboot/mbr.c	Thu Feb  2 21:54:34 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: mbr.c,v 1.3 2011/08/21 13:08:57 phx Exp $	*/
+/*	$NetBSD: mbr.c,v 1.4 2012/02/02 21:54:34 phx Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -69,7 +69,7 @@ search_mbr_label(struct of_dev *devp, u_
 	}
 #endif
 	if (poff != 0) {
-		if (strategy(devp, F_READ, poff + MBR_LABELSECTOR, DEV_BSIZE,
+		if (strategy(devp, F_READ, poff + LABELSECTOR, DEV_BSIZE,
 		    buf, &read) == 0 && read == DEV_BSIZE)
 			if (getdisklabel(buf, lp) == NULL)
 				return 0;

Reply via email to