Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 Oct 2012 03:00:38 +0000 (UTC)
From:      Peter Grehan <grehan@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r241151 - projects/bhyve/sys/boot/userboot/userboot
Message-ID:  <201210030300.q9330cAx048022@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: grehan
Date: Wed Oct  3 03:00:37 2012
New Revision: 241151
URL: http://svn.freebsd.org/changeset/base/241151

Log:
  Rework the GPT/MBR/raw policy so that it actually works, and navigates
  around disk_open's current handling of falling back from GPT to MBR.
  
  As in the previous commit, this should all be fixed in CURRENT.

Modified:
  projects/bhyve/sys/boot/userboot/userboot/main.c

Modified: projects/bhyve/sys/boot/userboot/userboot/main.c
==============================================================================
--- projects/bhyve/sys/boot/userboot/userboot/main.c	Wed Oct  3 02:58:55 2012	(r241150)
+++ projects/bhyve/sys/boot/userboot/userboot/main.c	Wed Oct  3 03:00:37 2012	(r241151)
@@ -129,6 +129,7 @@ static void
 extract_currdev(void)
 {
 	struct disk_devdesc dev;
+	int gpt, rc;
 
 	//bzero(&dev, sizeof(dev));
 
@@ -138,12 +139,37 @@ extract_currdev(void)
 		dev.d_unit = 0;
 		dev.d_slice = 0;
 		dev.d_partition = 0;
+
 		/*
-		 * Figure out if we are using MBR or GPT - for GPT we
-		 * set the partition to 0 since everything is a GPT slice.
+		 * The priority is GPT, MBR and raw disk. Unfortunately,
+		 * disk_open() doesn't really get this right so first
+		 * probe for MBR, and then GPT. If GPT fails, re-probe
+		 * MBR if it succeeded, else assume raw.
 		 */
-		if (dev.d_dev->dv_open(NULL, &dev))
-			dev.d_partition = 255;
+		rc = (*dev.d_dev->dv_open)(NULL, &dev);
+
+		dev.d_unit = 0;
+		dev.d_slice = 0;
+		dev.d_partition = 255;
+		gpt = (*dev.d_dev->dv_open)(NULL, &dev);
+
+		if (gpt) {
+			dev.d_unit = 0;
+			dev.d_slice = 0;
+			dev.d_partition = 0;
+			
+			if (!rc) {
+				(void) (*dev.d_dev->dv_open)(NULL, &dev);
+			} else {
+				/*
+				 * Force raw disk access
+				 */
+				dev.d_slice = -1;
+				dev.d_partition = -1;
+				dev.d_offset = 0;
+			}
+		}
+
 	} else {
 		dev.d_dev = &host_dev;
 		dev.d_type = dev.d_dev->dv_type;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201210030300.q9330cAx048022>