Revision 9666a511 image_creator/gpt.py
b/image_creator/gpt.py | ||
---|---|---|
255 | 255 |
"""Returns the payload size of GPT partitioned device.""" |
256 | 256 |
return (self.primary.backup_lba + 1) * BLOCKSIZE |
257 | 257 |
|
258 |
def shrink(self, size): |
|
258 |
def shrink(self, size, old_size):
|
|
259 | 259 |
"""Move the secondary GPT Header entries to the address specified by |
260 | 260 |
size parameter. |
261 | 261 |
""" |
262 |
if size == self.size(): |
|
263 |
return size |
|
264 | 262 |
|
265 |
assert size < self.size() |
|
263 |
# Most partition manipulation programs leave 2048 sector after the last |
|
264 |
# partition |
|
265 |
aligned = size + 2048 * BLOCKSIZE |
|
266 |
|
|
267 |
# new_size is at least: size + Partition Entries + Secondary GPT Header |
|
268 |
new_size = aligned if aligned <= old_size else \ |
|
269 |
size + len(self.part_entries) + BLOCKSIZE |
|
270 |
|
|
271 |
assert new_size <= old_size, "The secodary GPT fits in the device" |
|
272 |
|
|
273 |
if new_size == self.size(): |
|
274 |
return new_size |
|
266 | 275 |
|
267 |
# new_size = size + Partition Entries + Secondary GPT Header |
|
268 |
new_size = size + len(self.part_entries) + BLOCKSIZE |
|
269 |
new_size = ((new_size + 4095) // 4096) * 4096 # align to 4K |
|
270 | 276 |
lba_count = new_size // BLOCKSIZE |
271 | 277 |
|
272 | 278 |
# Correct MBR |
Also available in: Unified diff