Skip to content

Commit

Permalink
rouge: workaround changes in gpt-image
Browse files Browse the repository at this point in the history
gpt-image is package for working with GPTs. We use it to create
partition layout in rouge. To properly write sub-images into final
image, we need to know offset for every partition. To do this, we
read "first_lba" field in Partition object. Problem is that in
gpt-image 0.9.0 this property contains zero and we need to read
"first_lba_staged" property instead.

Also, we need to support old installation, so we just can't replace
"first_lba" with "first_lba_staged" in the code. Instead we should try
the new field first and then fall back to the old one.

Tested with both gpt-image 0.9.0 and gpt-image 0.8.1

Signed-off-by: Volodymyr Babchuk <[email protected]>
Reviewed-by: Ruslan Shymkevych <[email protected]>
Tested-by: Mykhailo Androsiuk <[email protected]>
  • Loading branch information
lorc committed Aug 5, 2024
1 parent 8374c87 commit 940485b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion moulin/rouge/gpti.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,19 @@ def fixup_partition_table(partitions: List[Any], sector_size=512) -> Tuple[List[
part.gpt_guid, DEFAULT_ALIGNMENT // sector_size)
)
pe = table.partitions.entries[-1]
start = pe.first_lba * sector_size

# Workaround for gpt-image: in release 0.9.0 they changed how first LBA
# is stored. Now we need to read `first_lba_staged` property. Problem
# is that we don't know which version is installed on the user's
# machine. So, first we try to read `first_lba_staged` and if it fails
# - old `first_lba` property.
first_lba = 0
try:
first_lba = pe.first_lba_staged
except AttributeError:
first_lba = pe.first_lba

start = first_lba * sector_size
ret.append(part._replace(start=start, size=size))
end = start + size

Expand Down

0 comments on commit 940485b

Please sign in to comment.