Skip to content

Commit 76dfe96

Browse files
authored
Add birthtime_ns to ExtFilesystemEntry.lstat (#876)
1 parent 7e856fd commit 76dfe96

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

dissect/target/filesystems/extfs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def lstat(self) -> fsutil.stat_result:
128128
# Set birthtime if available
129129
if self.entry.crtime:
130130
st_info.st_birthtime = self.entry.crtime.timestamp()
131+
st_info.st_birthtime_ns = self.entry.crtime_ns
131132

132133
# Set the nanosecond resolution separately
133134
st_info.st_atime_ns = self.entry.atime_ns

tests/filesystems/test_extfs.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from io import BytesIO
2+
from unittest.mock import Mock
3+
4+
from dissect.extfs.c_ext import c_ext
5+
from dissect.extfs.extfs import INode
6+
7+
from dissect.target.filesystems.extfs import ExtFilesystemEntry
8+
9+
10+
def test_stat_information() -> None:
11+
extfs = Mock(block_size=0x1000)
12+
extfs.sb.s_inode_size = 129
13+
14+
entry = INode(extfs, 42)
15+
16+
inode_bytes = (
17+
b"\xa4\x81\xe8\x03\xbb\x0e\x00\x00\x9f!\tf\xb8\x17\xe8f\x9f!\tf\x00\x00\x00\x00\xe8\x03\x01\x00\x08\x00"
18+
b"\x00\x00\x00\x00\x08\x00\x04\x00\x00\x00\n\xf3\x01\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
19+
b"\x01\x00\x00\x00\xa1\x8b\xa8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
20+
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00t\xab\x19\x19\x00\x00\x00\x00\x00"
21+
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x90p\x00\x00 \x00\xe44\xe0\xe8Ho\x00\x00\x00"
22+
b"\x00\x00\x00\x00\x00\xb8\x17\xe8f\xe0\xe8Ho\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
23+
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
24+
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
25+
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
26+
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
27+
)
28+
29+
inode = c_ext.ext4_inode(BytesIO(inode_bytes))
30+
31+
entry._inode = inode
32+
33+
fs_entry = ExtFilesystemEntry(Mock(), "some/path", entry)
34+
35+
stat_info = fs_entry.lstat()
36+
37+
assert stat_info.st_ino == 42
38+
assert stat_info.st_nlink == 1
39+
assert stat_info.st_uid == 1000
40+
assert stat_info.st_gid == 1000
41+
assert stat_info.st_size == 3771
42+
43+
assert stat_info.st_atime == 1711874463.0
44+
assert stat_info.st_atime_ns == 1711874463000000000
45+
assert stat_info.st_mtime == 1711874463.0
46+
assert stat_info.st_mtime_ns == 1711874463000000000
47+
assert stat_info.st_ctime == 1726486456.466762
48+
assert stat_info.st_ctime_ns == 1726486456466762296
49+
assert stat_info.st_birthtime == 1726486456.466762
50+
assert stat_info.st_birthtime_ns == 1726486456466762296
51+
52+
assert stat_info.st_blksize == 0x1000
53+
assert stat_info.st_blocks == 8

0 commit comments

Comments
 (0)