def __init__(self, name, size, start=None, ptype=None, fstype="raw", bootable=False, **kwargs):
self.name = name
self.size = size
+ self.size_sectors = kwargs.get("size_sectors", None)
self.start = start
+ self.start_sector = kwargs.get("start_sector", None)
self.ptype = ptype
self.bootable = bootable
+ if type(self.size_sectors) == int and self.size_sectors >= 0:
+ if type(self.size) == int and self.size >= 0:
+ logging.warning(f"partition:{name} overriding size to the value obtained from size_sectors")
+ # size is used to calculate free space, so adjust it here
+ self.size = (self.size_sectors * 512 - 1) / (1024*1024) + 1
+ if type(self.start_sector) == int and self.start_sector >= 0:
+ if type(self.start) == int and self.start >= 0:
+ logging.warning(f"partition:{name} overriding start to the value obtained from start_sector")
+ self.size = None
+
def __str__(self):
output = []
- if self.start:
+ if self.start_sector:
+ output.append(f"start={self.start_sector}")
+ elif self.start:
output.append(f"start={self.start}MiB")
- if type(self.size) == int and self.size >= 0:
+ if type(self.size_sectors) == int and self.size_sectors >= 0:
+ output.append(f"size={self.size_sectors}")
+ elif type(self.size) == int and self.size >= 0:
output.append(f"size={self.size}MiB")
if self.name:
output.append(f"name={self.name}")
self.part_table.append(Partition(**part))
def __str__(self):
output = f"label: {self.ltype}\n"
+ if self.ltype == 'gpt':
+ output += f"first-lba: 34\n"
for part in self.part_table:
output += str(part)
return output