Wrong partition size is displayed for HDD disk

This commit removes the hardcoded 512B sector size in the space 
calculation and replaces that with the reported sector size as 
reported by blockdev.

Change-Id: I10d6157d57b30914c0204bc5ddd3d00abc8fe4b0
Signed-off-by: Wei Zhou <wei.zhou@windriver.com>
Closes-Bug: 1802388
This commit is contained in:
Wei Zhou 2018-11-13 16:45:34 -05:00
parent b934bb23d3
commit 349da34431
1 changed files with 7 additions and 3 deletions

View File

@ -228,7 +228,8 @@ def _get_free_space(device_node):
return free_spaces
def _get_partition_start_end_size(disk_device_path, part_number):
def _get_partition_start_end_size(disk_device_path, part_number,
sector_size_bytes):
"""Return the start, end and size of a partitions.
:param disk_device_path: disk's device path
:param part_number: partition's number
@ -248,7 +249,8 @@ def _get_partition_start_end_size(disk_device_path, part_number):
row = next((row for row in rows if value in row), None)
if row:
part_attr = re.findall('\d+', row)[0].rstrip()
partition[key] = math.ceil(float(part_attr) * 512 / (1024 ** 2))
partition[key] = math.ceil(
float(part_attr) * sector_size_bytes / (1024 ** 2))
return partition
@ -330,7 +332,9 @@ def _create_partition(disk_device_path, part_number, start_mib, size_mib,
_wait_for_partition(part_device_path,
loop_wait_time=PARTITION_LOOP_WAIT_TIME)
partition = _get_partition_start_end_size(disk_device_path, part_number)
partition = _get_partition_start_end_size(disk_device_path,
part_number,
sector_size_bytes)
return partition