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

Add XFS metadata: blocks per file and block size #33

Merged
merged 4 commits into from
Oct 7, 2024
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
4 changes: 4 additions & 0 deletions dissect/xfs/xfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ def _has_large_extent_counts(self) -> bool:
def size(self) -> int:
return self.inode.di_size

@property
def nblocks(self) -> int:
return self.inode.di_nblocks

@property
def data_extents(self) -> int:
if self._has_large_extent_counts():
Expand Down
7 changes: 7 additions & 0 deletions tests/test_xfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def test_xfs(xfs_bin):
xfs = XFS(xfs_bin)

assert xfs.version == 5
assert xfs.block_size == 4096
assert str(xfs.uuid) == "3fb8342e-e144-4f0c-8bd7-725e78966200"
assert str(xfs.meta_uuid) == "00000000-0000-0000-0000-000000000000"

Expand All @@ -22,9 +23,11 @@ def test_xfs(xfs_bin):
assert list(root.listdir().keys()) == [".", "..", "test_file", "test_dir", "test_link"]

test_file = xfs.get("test_file")
assert test_file.nblocks == 1
assert test_file.open().read() == b"test content\n"

test_link = xfs.get("test_link")
assert test_link.nblocks == 0
assert test_link.filetype == stat.S_IFLNK
assert test_link.link == "test_dir/test_file"

Expand All @@ -34,18 +37,22 @@ def test_xfs_sparse(xfs_sparse_bin):

sparse_start = xfs.get("sparse_start")
assert sparse_start.size == 0x258000
assert sparse_start.nblocks == 200
assert sparse_start.dataruns() == [(None, 400), (1392, 200)]

sparse_hole = xfs.get("sparse_hole")
assert sparse_hole.size == 0x258000
assert sparse_hole.nblocks == 400
assert sparse_hole.dataruns() == [(1792, 200), (None, 200), (2192, 200)]

sparse_end = xfs.get("sparse_end")
assert sparse_end.size == 0x190000
assert sparse_end.nblocks == 200
assert sparse_end.dataruns() == [(2392, 200), (None, 200)]

sparse_all = xfs.get("sparse_all")
assert sparse_all.size == 0x500000
assert sparse_all.nblocks == 0
assert sparse_all.dataruns() == [(None, 1280)]


Expand Down