diff mbox

[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
State Accepted
Headers show

Commit Message

Loïc Minier Feb. 10, 2011, 7:10 p.m. UTC
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 <lool@dooz.org>
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
diff mbox

Patch

=== 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],