WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [PATCH v2] Add HybridISO support for PyGrub2

To: Ian Campbell <Ian.Campbell@xxxxxxxxxx>
Subject: Re: [Xen-devel] [PATCH v2] Add HybridISO support for PyGrub2
From: Philipp Hahn <hahn@xxxxxxxxxxxxx>
Date: Fri, 28 Oct 2011 09:46:46 +0200
Cc: "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Delivery-date: Fri, 28 Oct 2011 00:47:51 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <1319710865.9436.106.camel@xxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Organization: Univention.de
References: <201110251057.06774.hahn@xxxxxxxxxxxxx> <201110251233.45315.hahn@xxxxxxxxxxxxx> <1319710865.9436.106.camel@xxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: KMail/1.9.10 (enterprise35 20100903.1171286)
Hello Ian,

On Thursday 27 October 2011 12:21:05 Ian Campbell wrote:
> On Tue, 2011-10-25 at 11:33 +0100, Philipp Hahn wrote:
> [...snip explanations...]
>
> Thanks Philipp, that all seems to make sense.
>
> Tim had some suggestions on how/where this functionality could be better
> implemented though.

v2: For HybrisISOs use offset 0 in addition instead of replacement.

Signed-off-by: Philipp Hahn <hahn@xxxxxxxxxxxxx>
---
grub-mkrescue internally uses xorriso, which generates a so-called "Hybrid 
ISO": The ISO images also contains a DOS partition table, which allows the 
identical ISO file to be stored on an USB stick for booting from it. This 
breaks PyGrub, since it (wrongly) detects only the DOS partition table and 
uses the first partition instead of the complete ISO file.

Add a check to detect HybridISO files and use offset 0 in addition to 
partition table parsing.
--- a/tools/pygrub/src/pygrub
+++ b/tools/pygrub/src/pygrub
@@ -40,15 +40,20 @@ def enable_cursor(ison):
     except _curses.error:
         pass
 
-def is_disk_image(file):
+DISK_TYPE_RAW, DISK_TYPE_HYBRIDISO, DISK_TYPE_DOS = range(3)
+def identify_disk_image(file):
+    """Detect DOS partition table or HybridISO format."""
     fd = os.open(file, os.O_RDONLY)
-    buf = os.read(fd, 512)
+    buf = os.read(fd, 0x8006)
     os.close(fd)
 
     if len(buf) >= 512 and \
            struct.unpack("H", buf[0x1fe: 0x200]) == (0xaa55,):
-        return True
-    return False
+        # HybridISO contains a DOS partition table for booting from USB 
devices, but really is an ISO image
+        if len(buf) >= 0x8006 and buf[0x8001:0x8006] == 'CD001':
+            return DISK_TYPE_HYBRIDISO
+        return DISK_TYPE_DOS
+    return DISK_TYPE_RAW
 
 SECTOR_SIZE=512
 DK_LABEL_LOC=1
@@ -87,12 +92,19 @@ FDISK_PART_SOLARIS_OLD=0x82
 FDISK_PART_GPT=0xee
 
 def get_partition_offsets(file):
-    if not is_disk_image(file):
+    image_type = identify_disk_image(file)
+    if image_type == DISK_TYPE_RAW:
         # No MBR: assume whole disk filesystem, which is like a 
         # single partition starting at 0
         return [0]
-
-    part_offs = []
+    elif image_type == DISK_TYPE_HYBRIDISO:
+        # A HybridISO contains an ISO filesystem at 0 in addition
+        # to the DOS partition table
+        part_offs = [0]
+    elif image_type == DISK_TYPE_DOS:
+        part_offs = []
+    else:
+        raise ValueError('Unhandled image type returnd by 
identify_disk_image(): %d' % (image_type,))
 
     fd = os.open(file, os.O_RDONLY)
     buf = os.read(fd, 512)

Sincerely
Philipp
-- 
Philipp Hahn           Open Source Software Engineer      hahn@xxxxxxxxxxxxx
Univention GmbH        Linux for Your Business        fon: +49 421 22 232- 0
Mary-Somerville-Str.1  D-28359 Bremen                 fax: +49 421 22 232-99
                                                   http://www.univention.de/

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel