svn commit: r348748 - head/stand/common

Toomas Soome tsoome at FreeBSD.org
Thu Jun 6 16:27:07 UTC 2019


Author: tsoome
Date: Thu Jun  6 16:27:05 2019
New Revision: 348748
URL: https://svnweb.freebsd.org/changeset/base/348748

Log:
  loader: disk_open() should honor D_PARTNONE
  
  The D_PARTNONE is documented to make it possible to open raw MBR
  partition, but the current disk_open() does not really implement this
  statement.
  
  The current code is checking partition against -1 (D_PARTNONE) but does
  attempt to open partition table in case we do have FreeBSD MBR partition type.
  Instead, we should check -2 (D_PARTWILD).
  
  In case we do have MBR + BSD label, this code is only working because
  by default, the first BSD partiton is created starting with relative sector
  0, and we can still access the BSD table from that MBR slice.
  
  Reviewed by:	imp
  MFC after:	2 weeks
  Differential Revision:	https://reviews.freebsd.org/D20501

Modified:
  head/stand/common/disk.c

Modified: head/stand/common/disk.c
==============================================================================
--- head/stand/common/disk.c	Thu Jun  6 16:26:58 2019	(r348747)
+++ head/stand/common/disk.c	Thu Jun  6 16:27:05 2019	(r348748)
@@ -263,8 +263,8 @@ disk_open(struct disk_devdesc *dev, uint64_t mediasize
 	slice = dev->d_slice;
 	partition = dev->d_partition;
 
-	DPRINTF("%s unit %d, slice %d, partition %d => %p",
-	    disk_fmtdev(dev), dev->dd.d_unit, dev->d_slice, dev->d_partition, od);
+	DPRINTF("%s unit %d, slice %d, partition %d => %p", disk_fmtdev(dev),
+	    dev->dd.d_unit, dev->d_slice, dev->d_partition, od);
 
 	/* Determine disk layout. */
 	od->table = ptable_open(&partdev, mediasize / sectorsize, sectorsize,
@@ -309,17 +309,25 @@ disk_open(struct disk_devdesc *dev, uint64_t mediasize
 		} else if (partition == D_PARTISGPT) {
 			/*
 			 * When we try to open GPT partition, but partition
-			 * table isn't GPT, reset d_partition value to -1
-			 * and try to autodetect appropriate value.
+			 * table isn't GPT, reset partition value to
+			 * D_PARTWILD and try to autodetect appropriate value.
 			 */
-			partition = -1;
+			partition = D_PARTWILD;
 		}
+
 		/*
-		 * If d_partition < 0 and we are looking at a BSD slice,
+		 * If partition is D_PARTNONE, then disk_open() was called
+		 * to open raw MBR slice.
+		 */
+		if (partition == D_PARTNONE)
+			goto out;
+
+		/*
+		 * If partition is D_PARTWILD and we are looking at a BSD slice,
 		 * then try to read BSD label, otherwise return the
 		 * whole MBR slice.
 		 */
-		if (partition == -1 &&
+		if (partition == D_PARTWILD &&
 		    part.type != PART_FREEBSD)
 			goto out;
 		/* Try to read BSD label */
@@ -331,7 +339,7 @@ disk_open(struct disk_devdesc *dev, uint64_t mediasize
 			goto out;
 		}
 		/*
-		 * If slice contains BSD label and d_partition < 0, then
+		 * If slice contains BSD label and partition < 0, then
 		 * assume the 'a' partition. Otherwise just return the
 		 * whole MBR slice, because it can contain ZFS.
 		 */


More information about the svn-src-head mailing list