svn commit: r243323 - projects/bhyve/sys/boot/userboot/userboot

Neel Natu neel at FreeBSD.org
Tue Nov 20 03:57:55 UTC 2012


Author: neel
Date: Tue Nov 20 03:57:54 2012
New Revision: 243323
URL: http://svnweb.freebsd.org/changeset/base/243323

Log:
  disk_open() is smart enough to detect MBR and GPT partitions. If it is neither
  then fall back to accessing the disk as a raw device.
  
  As an example this is useful when booting the guest from an ISO image file.
  
  Discussed with:	grehan
  Obtained from:	NetApp

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	Tue Nov 20 03:21:26 2012	(r243322)
+++ projects/bhyve/sys/boot/userboot/userboot/main.c	Tue Nov 20 03:57:54 2012	(r243323)
@@ -143,7 +143,6 @@ static void
 extract_currdev(void)
 {
 	struct disk_devdesc dev;
-	int gpt, rc;
 
 	//bzero(&dev, sizeof(dev));
 
@@ -153,37 +152,15 @@ extract_currdev(void)
 		dev.d_unit = 0;
 		dev.d_slice = 0;
 		dev.d_partition = 0;
-
 		/*
-		 * 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.
+		 * Figure out if we are using MBR or GPT.
+		 * If neither, then access the disk as a raw device.
 		 */
-		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;
-			}
+		if ((*dev.d_dev->dv_open)(NULL, &dev)) {
+			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;


More information about the svn-src-projects mailing list