From patchwork Thu Feb 10 19:10:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Lo=C3=AFc_Minier?= X-Patchwork-Id: 119 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:40:08 -0000 Delivered-To: patches@linaro.org Received: by 10.147.124.5 with SMTP id b5cs193567yan; Thu, 10 Feb 2011 11:11:01 -0800 (PST) Received: by 10.103.214.9 with SMTP id r9mr9998067muq.135.1297365060598; Thu, 10 Feb 2011 11:11:00 -0800 (PST) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id b40si723357wek.49.2011.02.10.11.11.00; Thu, 10 Feb 2011 11:11:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) client-ip=91.189.90.139; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) smtp.mail=bounces@canonical.com Received: from loganberry.canonical.com ([91.189.90.37]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1Pnbut-0004jl-Kz for ; Thu, 10 Feb 2011 19:10:59 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 9B3DB2E80CD for ; Thu, 10 Feb 2011 19:10:59 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: linaro-image-tools X-Launchpad-Branch: ~linaro-maintainers/linaro-image-tools/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 287 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-maintainers/linaro-image-tools/trunk] Rev 287: Merge lp:~lool/linaro-image-tools/part-size-rework; fixes various issues with Message-Id: <20110210191059.16084.18361.launchpad@loganberry.canonical.com> Date: Thu, 10 Feb 2011 19:10:59 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="12335"; Instance="initZopeless config overlay" X-Launchpad-Hash: 94b7c2b5af624b82df8283e34195b13d96a07832 Merge authors: Loïc Minier (lool) Related merge proposals: https://code.launchpad.net/~lool/linaro-image-tools/part-size-rework/+merge/49161 proposed by: Loïc Minier (lool) review: Approve - Guilherme Salgado (salgado) ------------------------------------------------------------ revno: 287 [merge] committer: Loïc Minier branch nick: linaro-image-tools timestamp: Thu 2011-02-10 20:08:06 +0100 message: Merge lp:~lool/linaro-image-tools/part-size-rework; fixes various issues with the partition-handling code; prepares the ground for aligned partitions. modified: linaro_media_create/partitions.py linaro_media_create/tests/test_media_create.py --- lp:linaro-image-tools https://code.launchpad.net/~linaro-maintainers/linaro-image-tools/trunk You are subscribed to branch lp:linaro-image-tools. To unsubscribe from this branch go to https://code.launchpad.net/~linaro-maintainers/linaro-image-tools/trunk/+edit-subscription === modified file 'linaro_media_create/partitions.py' --- linaro_media_create/partitions.py 2011-01-28 19:50:48 +0000 +++ linaro_media_create/partitions.py 2011-02-10 17:16:48 +0000 @@ -27,6 +27,7 @@ from parted import ( Device, Disk, + PARTITION_NORMAL, ) from linaro_media_create import cmd_runner @@ -60,9 +61,9 @@ if not media.is_block_device: image_size_in_bytes = convert_size_to_bytes(image_size) cylinders = image_size_in_bytes / CYLINDER_SIZE - image_size_in_bytes = cylinders * CYLINDER_SIZE proc = cmd_runner.run( - ['qemu-img', 'create', '-f', 'raw', media.path, image_size], + ['qemu-img', 'create', '-f', 'raw', media.path, + str(image_size_in_bytes)], stdout=open('/dev/null', 'w')) proc.wait() @@ -173,19 +174,32 @@ # block device we'd need root rights. disk = Disk(Device(image_file)) vfat_partition = None + linux_partition = None for partition in disk.partitions: + assert partition.type == PARTITION_NORMAL, ( + "Parted should only return normal partitions but got type %i" % + partition.type) if 'boot' in partition.getFlagsAsString(): geometry = partition.geometry vfat_offset = geometry.start * 512 vfat_size = geometry.length * 512 vfat_partition = partition + elif vfat_partition is not None: + # next partition after boot partition is the root partition + # NB: don't use vfat_partition.nextPartition() as that might return + # a partition of type PARTITION_FREESPACE; it's much easier to + # iterate disk.partitions which only returns + # parted.PARTITION_NORMAL partitions + geometry = partition.geometry + linux_offset = geometry.start * 512 + linux_size = geometry.length * 512 + linux_partition = partition + break assert vfat_partition is not None, ( "Couldn't find boot partition on %s" % image_file) - linux_partition = vfat_partition.nextPartition() - geometry = linux_partition.geometry - linux_offset = geometry.start * 512 - linux_size = geometry.length * 512 + assert linux_partition is not None, ( + "Couldn't find root partition on %s" % image_file) return vfat_size, vfat_offset, linux_size, linux_offset === modified file 'linaro_media_create/tests/test_media_create.py' --- linaro_media_create/tests/test_media_create.py 2011-02-10 16:58:11 +0000 +++ linaro_media_create/tests/test_media_create.py 2011-02-10 19:08:06 +0000 @@ -722,6 +722,16 @@ [129024L, 32256L, 10321920L, 161280L], [vfat_size, vfat_offset, linux_size, linux_offset]) + def test_partition_numbering(self): + # another Linux partition after the boot/root parts + tempfile = self._create_qemu_img_with_partitions( + ',1,0x0C,*\n,1,,-\n,,,-') + vfat_size, vfat_offset, linux_size, linux_offset = ( + calculate_partition_size_and_offset(tempfile)) + # check that the linux partition offset starts on second cylinder so + # that it's the partition immediately following the vfat one + self.assertEqual(linux_offset, 5 * 63 * 512) + def test_get_boot_and_root_partitions_for_media_beagle(self): self.useFixture(MockSomethingFixture( partitions, '_get_device_file_for_partition_number', @@ -829,7 +839,7 @@ 'root', 'ext3', True, True, True) self.assertEqual( # This is the call that would create the image file. - [['qemu-img', 'create', '-f', 'raw', tempfile, '2G'], + [['qemu-img', 'create', '-f', 'raw', tempfile, '2147483648'], # This call would partition the image file. ['sudo', 'sfdisk', '-D', '-H', '255', '-S', '63', '-C', '261', tempfile],