From mboxrd@z Thu Jan 1 00:00:00 1970 From: Philipp Hahn Subject: Re: [PATCH v2] Add HybridISO support for PyGrub2 Date: Fri, 28 Oct 2011 09:46:46 +0200 Message-ID: <201110280946.51201.hahn@univention.de> References: <201110251057.06774.hahn@univention.de> <201110251233.45315.hahn@univention.de> <1319710865.9436.106.camel@zakaz.uk.xensource.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1026875165==" Return-path: In-Reply-To: <1319710865.9436.106.camel@zakaz.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Ian Campbell Cc: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org --===============1026875165== Content-Type: multipart/signed; boundary="nextPart3003844.VCLHnCeY7C"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit --nextPart3003844.VCLHnCeY7C Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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 =2D-- grub-mkrescue internally uses xorriso, which generates a so-called "Hybrid= =20 ISO": The ISO images also contains a DOS partition table, which allows the= =20 identical ISO file to be stored on an USB stick for booting from it. This=20 breaks PyGrub, since it (wrongly) detects only the DOS partition table and= =20 uses the first partition instead of the complete ISO file. Add a check to detect HybridISO files and use offset 0 in addition to=20 partition table parsing. =2D-- a/tools/pygrub/src/pygrub +++ b/tools/pygrub/src/pygrub @@ -40,15 +40,20 @@ def enable_cursor(ison): except _curses.error: pass =20 =2Ddef is_disk_image(file): +DISK_TYPE_RAW, DISK_TYPE_HYBRIDISO, DISK_TYPE_DOS =3D range(3) +def identify_disk_image(file): + """Detect DOS partition table or HybridISO format.""" fd =3D os.open(file, os.O_RDONLY) =2D buf =3D os.read(fd, 512) + buf =3D os.read(fd, 0x8006) os.close(fd) =20 if len(buf) >=3D 512 and \ struct.unpack("H", buf[0x1fe: 0x200]) =3D=3D (0xaa55,): =2D return True =2D return False + # HybridISO contains a DOS partition table for booting from USB=20 devices, but really is an ISO image + if len(buf) >=3D 0x8006 and buf[0x8001:0x8006] =3D=3D 'CD001': + return DISK_TYPE_HYBRIDISO + return DISK_TYPE_DOS + return DISK_TYPE_RAW =20 SECTOR_SIZE=3D512 DK_LABEL_LOC=3D1 @@ -87,12 +92,19 @@ FDISK_PART_SOLARIS_OLD=3D0x82 FDISK_PART_GPT=3D0xee =20 def get_partition_offsets(file): =2D if not is_disk_image(file): + image_type =3D identify_disk_image(file) + if image_type =3D=3D DISK_TYPE_RAW: # No MBR: assume whole disk filesystem, which is like a=20 # single partition starting at 0 return [0] =2D =2D part_offs =3D [] + elif image_type =3D=3D DISK_TYPE_HYBRIDISO: + # A HybridISO contains an ISO filesystem at 0 in addition + # to the DOS partition table + part_offs =3D [0] + elif image_type =3D=3D DISK_TYPE_DOS: + part_offs =3D [] + else: + raise ValueError('Unhandled image type returnd by=20 identify_disk_image(): %d' % (image_type,)) =20 fd =3D os.open(file, os.O_RDONLY) buf =3D os.read(fd, 512) Sincerely Philipp =2D-=20 Philipp Hahn Open Source Software Engineer hahn@univention.de 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/ --nextPart3003844.VCLHnCeY7C Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEABECAAYFAk6qXecACgkQYPlgoZpUDjmhswCgmiKYnpVAFpR0AJ+NBON/yxTd G3cAoJUcrLVAEc6wcPRAM0G8+Ty1LkUx =wPnJ -----END PGP SIGNATURE----- --nextPart3003844.VCLHnCeY7C-- --===============1026875165== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============1026875165==--