Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/pyreadpartitions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
# http://en.wikipedia.org/wiki/Master_boot_record#Partition_table_entries
MBR_PARTITION_FORMAT = [
(b'B', 'status'), # > 0x80 => active
(b'3p', 'chs_first'), # 8*h + 2*c + 6*s + 8*c
(b'3s', 'chs_first'), # 8*h + 2*c + 6*s + 8*c
(b'B', 'type'),
(b'3p', 'chs_last'), # 8*h + 2*c + 6*s + 8*c
(b'3s', 'chs_last'), # 8*h + 2*c + 6*s + 8*c
(b'L', 'lba'),
(b'L', 'sectors'),
]
Expand Down Expand Up @@ -218,9 +218,9 @@
}


def make_fmt(name, fmt, extras=[]):
def make_fmt(name, fmt, extras=None):
packfmt = b'<' + b''.join(t for t, n in fmt)
tupletype = namedtuple(name, [n for t, n in fmt if n != '_'] + extras)
tupletype = namedtuple(name, [n for t, n in fmt if n != '_'] + (extras or []))
return (packfmt, tupletype)


Expand Down Expand Up @@ -268,6 +268,10 @@ def read_ebr_partition(fp, extended_lba, lba, num):
if ebr.signature != b'\x55\xAA':
raise MBRError('Bad EBR signature')
parts = [read_mbr_partition(ebr.partition, num)]

# LBA of EBRs are relative offsets from to the start of EBR to the partition. Calculate the absolute LBA.
parts[0] = parts[0]._replace(lba=extended_lba + parts[0].lba)

if ebr.next_ebr != 16 * b'\x00':
part_next_ebr = read_mbr_partition(ebr.next_ebr, 0)
next_lba = part_next_ebr.lba
Expand Down Expand Up @@ -465,3 +469,4 @@ def main():

if __name__ == '__main__':
exit(main())