From 1f8854c702f5c25e5371b8b9eba4a0061483802f Mon Sep 17 00:00:00 2001 From: Neel Natu Date: Tue, 20 Nov 2012 03:57:54 +0000 Subject: [PATCH] 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 --- sys/boot/userboot/userboot/main.c | 35 ++++++------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/sys/boot/userboot/userboot/main.c b/sys/boot/userboot/userboot/main.c index b5e14fd1f83a..a4f1a15cd6bb 100644 --- a/sys/boot/userboot/userboot/main.c +++ b/sys/boot/userboot/userboot/main.c @@ -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;