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
10 changes: 7 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ jobs:
for i in {1..100};do
echo "hello world" >> test/test.txt
done
dd if=/dev/zero of=test.ext4 count=1024 bs=1024
mkfs.ext4 test.ext4 -d test
dd if=/dev/zero of=test.ext4.tmp count=1024 bs=1024
mkfs.ext4 test.ext4.tmp -d test
echo -n F > test.ext4
cat test.ext4.tmp >> test.ext4
- uses: actions/upload-artifact@v4
with:
name: test.ext4
path: test.ext4
path: |
test.ext4
test.ext4.tmp
if-no-files-found: error
test:
name: Test on ${{ matrix.os }} python ${{ matrix.python }}
Expand Down
4 changes: 2 additions & 2 deletions ext4/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def field_type(cls, name):
return None

def read_from_volume(self):
self.volume.stream.seek(self.offset)
data = self.volume.stream.read(sizeof(self))
self.volume.seek(self.offset)
data = self.volume.read(sizeof(self))
memmove(addressof(self), data, sizeof(self))

@property
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.1.0"
version = "1.1.1"
authors = [
{ name="Eeems", email="eeems@eeems.email" },
]
Expand Down
20 changes: 19 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import os
import sys
import ext4

Expand Down Expand Up @@ -43,9 +44,26 @@ def _assert(source: str):
test_path_tuple("/test/test", (b"test", b"test"))
test_path_tuple(b"/test/test", (b"test", b"test"))

offset = os.path.getsize("test.ext4") - os.path.getsize("test.ext4.tmp")
_assert("offset > 0")
with open("test.ext4", "rb") as f:
try:
print("check MagicError: ", end="")
_ = ext4.Volume(f, offset=0)
FAILED = True
print("fail")
print(" MagicError not raised")
except ext4.struct.MagicError:
print("pass")

except Exception as e:
FAILED = True
print("fail")
print(" ", end="")
print(e)

# Extract specific file
volume = ext4.Volume(f, offset=0)
volume = ext4.Volume(f, offset=offset)
inode = cast(ext4.File, volume.inode_at("/test.txt"))
_assert("isinstance(inode, ext4.File)")
b = inode.open()
Expand Down
8 changes: 5 additions & 3 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ if ! [ -f test.ext4 ];then
for i in {1..100};do
echo "hello world" >> "$tmp_dir"/test.txt
done
dd if=/dev/zero of=test.ext4 count=1024 bs=1024
trap "rm test.ext4" EXIT
mkfs.ext4 test.ext4 -d "$tmp_dir"
trap "rm -f test.ext4{,.tmp}" EXIT
dd if=/dev/zero of=test.ext4.tmp count=1024 bs=1024
mkfs.ext4 test.ext4.tmp -d "$tmp_dir"
echo -n F > test.ext4
cat test.ext4.tmp >> test.ext4
fi
python test.py
Loading