partitionedfs: simplify the code a tiny bit
authorArtem Bityutskiy <artem.bityutskiy@intel.com>
Fri, 15 Feb 2013 09:09:31 +0000 (11:09 +0200)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Mon, 18 Feb 2013 15:57:00 +0000 (17:57 +0200)
When we calculate the minimum disk size, we do not have to search for the last
parition, because we have d['offset'] which points to the first available
sector.

Change-Id: Ida5f92ec11939caa76ad1bf90aee137a2e918d2d
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
mic/utils/partitionedfs.py

index 60ae93c..6b5a65d 100644 (file)
@@ -233,15 +233,13 @@ class PartitionedMount(Mount):
 
         # Once all the partitions have been layed out, we can calculate the
         # minumim disk sizes.
-        for disk_name, disk in self.disks.items():
-            last_partition = self.partitions[disk['partitions'][-1]]
-            disk['min_size'] = last_partition['start'] + last_partition['size']
-
-            if disk['ptable_format'] == 'gpt':
+        for disk_name, d in self.disks.items():
+            d['min_size'] = d['offset']
+            if d['ptable_format'] == 'gpt':
                 # Account for the backup partition table at the end of the disk
-                disk['min_size'] += GPT_OVERHEAD
+                d['min_size'] += GPT_OVERHEAD
 
-            disk['min_size'] *= self.sector_size
+            d['min_size'] *= self.sector_size
 
     def __run_parted(self, args):
         """ Run parted with arguments specified in the 'args' list. """