Skip to content

Commit

Permalink
Compatibility with cstruct v4
Browse files Browse the repository at this point in the history
  • Loading branch information
Schamper committed May 24, 2024
1 parent 7266125 commit 7313894
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
5 changes: 2 additions & 3 deletions dissect/extfs/c_ext.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import stat

from dissect import cstruct
from dissect.cstruct import cstruct

ext_def = """
#define EXT2_SBOFF 1024 // offset to superblock
Expand Down Expand Up @@ -397,8 +397,7 @@
};
"""

c_ext = cstruct.cstruct()
c_ext.load(ext_def)
c_ext = cstruct().load(ext_def)

EXT2 = 2
EXT3 = 3
Expand Down
5 changes: 2 additions & 3 deletions dissect/extfs/c_jdb2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dissect import cstruct
from dissect.cstruct import cstruct

jdb2_def = """
#define JBD2_MAGIC_NUMBER 0xC03B3998
Expand Down Expand Up @@ -87,5 +87,4 @@
};
"""

c_jdb2 = cstruct.cstruct(endian=">")
c_jdb2.load(jdb2_def)
c_jdb2 = cstruct(endian=">").load(jdb2_def)
13 changes: 9 additions & 4 deletions dissect/extfs/journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import io
from typing import BinaryIO, Iterator, Optional

from dissect.cstruct import Instance
from dissect.util.stream import RangeStream

from dissect.extfs.c_jdb2 import c_jdb2
Expand Down Expand Up @@ -83,7 +82,7 @@ def walk(self) -> Iterator[CommitBlock]:


class DescriptorBlock:
def __init__(self, jdb2: JDB2, header: Instance, block: int):
def __init__(self, jdb2: JDB2, header: c_jdb2.journal_header, block: int):
self.jdb2 = jdb2
self.header = header
self.journal_block = block
Expand All @@ -110,7 +109,9 @@ def tags(self) -> Iterator[DescriptorBlockTag]:


class DescriptorBlockTag:
def __init__(self, descriptor: DescriptorBlock, tag: Instance, journal_block: int):
def __init__(
self, descriptor: DescriptorBlock, tag: c_jdb2.journal_block_tag | c_jdb2.journal_block_tag3, journal_block: int
):
self.descriptor = descriptor
self.tag = tag
self.journal_block = journal_block
Expand All @@ -127,7 +128,11 @@ def open(self) -> BinaryIO:

class CommitBlock:
def __init__(
self, jdb2: JDB2, header: Instance, journal_block: int, descriptors: Optional[list[DescriptorBlock]] = None
self,
jdb2: JDB2,
header: c_jdb2.commit_header,
journal_block: int,
descriptors: Optional[list[DescriptorBlock]] = None,
):
self.jdb2 = jdb2
self.header = header
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ classifiers = [
"Topic :: Utilities",
]
dependencies = [
"dissect.cstruct>=3.0.dev,<4.0.dev",
"dissect.util>=3.0.dev,<4.0.dev",
"dissect.cstruct>3,<5",
"dissect.util>2,<4",
]
dynamic = ["version"]

Expand Down
7 changes: 7 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ deps =
pytest
pytest-cov
coverage
# Unfortunately, tox does not allow separate installation flags for the project
# dependencies and the test dependencies. When running tox, we want to install the
# project dependencies with the --pre flag, so that we get the latest version of all
# dependencies. We do the installation step ourselves for this reason.
skip_install = true
commands_pre =
pip install --pre -e .
commands =
pytest --basetemp="{envtmpdir}" {posargs:--color=yes --cov=dissect --cov-report=term-missing -v tests}
coverage report
Expand Down

0 comments on commit 7313894

Please sign in to comment.