Skip to content

Commit

Permalink
Take disklabel table offset into account (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Schamper authored Aug 18, 2023
1 parent 46e0f27 commit 8157662
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions dissect/volume/disk/schemes/bsd.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Reference:
# - https://github.com/freebsd/freebsd-src/blob/main/sys/geom/part/g_part_bsd.c

import io
from typing import BinaryIO, Iterator
from uuid import UUID
Expand Down Expand Up @@ -319,19 +322,36 @@ def __init__(self, fh: BinaryIO, sector_size: int = 512):
self.partitions = list(self._partitions())

def _partitions(self) -> Iterator[Partition]:
table_offset = 0
if self.type == 32:
# Get the table offset first
self.fh.seek(self._partitions_offset + (c_bsd.BSD_PART_RAW * len(c_bsd.partition)))
table_offset = c_bsd.partition(self.fh).p_offset

self.fh.seek(self._partitions_offset)
for i in range(self.disklabel.d_npartitions):
if self.type == 32:
partition = c_bsd.partition(self.fh)
if partition.p_fstype == 0:
if i == c_bsd.BSD_PART_RAW:
# Skip internal partition
continue

if partition.p_size == 0 or partition.p_fstype == 0:
continue

offset = partition.p_offset * self.sector_size
if partition.p_offset < table_offset:
continue

offset = (partition.p_offset - table_offset) * self.sector_size
size = partition.p_size * self.sector_size
guid = None
elif self.type == 64:
partition = c_bsd.partition64(self.fh)
if (partition.p_boffset == 0 and partition.p_bsize) or partition.p_fstype == 0:
if i == c_bsd.BSD_PART_RAW:
# Skip internal partition
continue

if (partition.p_boffset == 0 and partition.p_bsize == 0) or partition.p_fstype == 0:
continue

offset = partition.p_boffset
Expand Down

0 comments on commit 8157662

Please sign in to comment.