Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion ext4/extent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from ctypes import c_uint16
from ctypes import sizeof

from .struct import Ext4Struct
from .struct import crc32c
from .struct import Ext4Struct


class ExtentBlocks(object):
Expand Down
19 changes: 17 additions & 2 deletions ext4/inode.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

from ._compat import override

from .struct import Ext4Struct
from .struct import crc32c
from .struct import Ext4Struct
from .struct import MagicError

from .enum import EXT4_OS
Expand Down Expand Up @@ -189,6 +189,16 @@ def __init__(self, volume, offset, i_no):
super().__init__(volume, offset)
self.tree = ExtentTree(self)

@property
def extra_inode_data(self) -> bytes:
if not self.has_hi:
return b""

size = sizeof(self)
assert size == self.EXT2_GOOD_OLD_INODE_SIZE + self.i_extra_isize
_ = self.volume.seek(self.offset + size)
return self.volume.read(self.superblock.s_inode_size - size)

@property
def superblock(self):
return self.volume.superblock
Expand Down Expand Up @@ -248,7 +258,12 @@ def checksum(self):
csum = crc32c(b"\0" * Inode.i_checksum_hi.size, csum)
offset += Inode.i_checksum_hi.size

csum = crc32c(data[offset:], csum)
csum = crc32c(
data[offset:],
csum,
)
if self.superblock.s_inode_size - len(data) > 0:
csum = crc32c(self.extra_inode_data, csum)

if not self.has_hi:
csum &= 0xFFFF
Expand Down
10 changes: 6 additions & 4 deletions ext4/xattr.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from ctypes import c_uint8
from ctypes import sizeof

from .struct import Ext4Struct
from .struct import crc32c
from .enum import EXT4_FL
from .enum import EXT4_FEATURE_INCOMPAT
from ._compat import override

from .enum import EXT4_FEATURE_INCOMPAT
from .enum import EXT4_FL

from .struct import crc32c
from .struct import Ext4Struct


class ExtendedAttributeError(Exception):
pass
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "ext4"
version = "1.2.1"
version = "1.2.2"
authors = [
{ name="Eeems", email="eeems@eeems.email" },
]
Expand Down
12 changes: 12 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ def _assert(source: str):

# Extract specific file
volume = ext4.Volume(f, offset=offset)

try:
print("Validate root inode: ", end="")
volume.root.validate()
print("pass")

except ext4.struct.ChecksumError as e:
FAILED = True
print("fail")
print(" ", end="")
print(e)

inode = cast(ext4.File, volume.inode_at("/test.txt"))
_assert("isinstance(inode, ext4.File)")
b = inode.open()
Expand Down
Loading