Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take disklabel table offset into account #21

Merged
merged 3 commits into from
Aug 18, 2023
Merged
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
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