Module Name:    src
Committed By:   riz
Date:           Sun Feb 10 20:17:23 UTC 2013

Modified Files:
        src/sys/arch/arm/arm [netbsd-6]: disksubr_mbr.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #804):
        sys/arch/arm/arm/disksubr_mbr.c: revision 1.15
Change for non MBR disk (PR#47463):
  - Check each mbrp_type field in fdisk partition table in MBR to know whether
    a sector is really MBR or not. Same as MI subr_disk_mbr.c
  - Check whether each number in a partition table is out of bound or not.
    Same as MI subr_disk_mbr.c
  - Update d_packname and d_npartitions if we found any partitions.
  - Currently, the exended partitions is not supported...


To generate a diff of this commit:
cvs rdiff -u -r1.13.4.1 -r1.13.4.2 src/sys/arch/arm/arm/disksubr_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/arm/arm/disksubr_mbr.c
diff -u src/sys/arch/arm/arm/disksubr_mbr.c:1.13.4.1 src/sys/arch/arm/arm/disksubr_mbr.c:1.13.4.2
--- src/sys/arch/arm/arm/disksubr_mbr.c:1.13.4.1	Tue Oct 23 16:21:32 2012
+++ src/sys/arch/arm/arm/disksubr_mbr.c	Sun Feb 10 20:17:23 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: disksubr_mbr.c,v 1.13.4.1 2012/10/23 16:21:32 riz Exp $	*/
+/*	$NetBSD: disksubr_mbr.c,v 1.13.4.2 2013/02/10 20:17:23 riz Exp $	*/
 
 /*
  * Copyright (c) 1998 Christopher G. Demetriou.  All rights reserved.
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: disksubr_mbr.c,v 1.13.4.1 2012/10/23 16:21:32 riz Exp $");
+__KERNEL_RCSID(0, "$NetBSD: disksubr_mbr.c,v 1.13.4.2 2013/02/10 20:17:23 riz Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -117,6 +117,7 @@ mbr_label_read(dev_t dev,
 		goto out;
 	} else {
 		struct mbr_partition *ourmbrp = NULL;
+		int nfound = 0;
 
 		/* XXX "there has to be a better check than this." */
 		if (memcmp((char *)bp->b_data + MBRSIGOFS, mbrsig, sizeof(mbrsig))) {
@@ -145,9 +146,14 @@ mbr_label_read(dev_t dev,
 		}
 #endif
 		for (i = 0; i < MBR_PART_COUNT; i++, mbrp++) {
-
-			strncpy(lp->d_packname, "fictitious-MBR",
-			    sizeof lp->d_packname);
+			if (mbrp->mbrp_type == MBR_PTYPE_UNUSED)
+				continue;
+			if (le32toh(mbrp->mbrp_start) +
+			    le32toh(mbrp->mbrp_size) > lp->d_secperunit) {
+				/* This mbr doesn't look good.... */
+				continue;
+			}
+			nfound++;
 
 			/* Install in partition e, f, g, or h. */
 			pp = &lp->d_partitions['e' - 'a' + i];
@@ -175,7 +181,11 @@ mbr_label_read(dev_t dev,
 #endif
 			}
 		}
-		lp->d_npartitions = 'e' - 'a' + i;
+		if (nfound > 0) {
+			lp->d_npartitions = 'e' - 'a' + i;
+			strncpy(lp->d_packname, "fictitious-MBR",
+			    sizeof lp->d_packname);
+		}
 	}
 
 	*cylp = cyl;

Reply via email to