Skip to content

Commit badd7a8

Browse files
authored
Fix DirectoryEntry type parsing (#4)
1 parent 0a1a529 commit badd7a8

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

dissect/apfs/objects/fs.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -792,43 +792,43 @@ def dt(self) -> c_apfs.DT:
792792
@cached_property
793793
def type(self) -> int:
794794
"""The file type of this directory entry."""
795-
return self.value.flags & c_apfs.DREC_TYPE_MASK << 12
795+
return (self.value.flags & c_apfs.DREC_TYPE_MASK) << 12
796796

797797
def is_dir(self) -> bool:
798798
"""Return whether this directory entry is a directory."""
799-
return stat.S_ISDIR(self.type << 12)
799+
return stat.S_ISDIR(self.type)
800800

801801
def is_file(self) -> bool:
802802
"""Return whether this directory entry is a regular file."""
803-
return stat.S_ISREG(self.type << 12)
803+
return stat.S_ISREG(self.type)
804804

805805
def is_symlink(self) -> bool:
806806
"""Return whether this directory entry is a symbolic link."""
807-
return stat.S_ISLNK(self.type << 12)
807+
return stat.S_ISLNK(self.type)
808808

809809
def is_block_device(self) -> bool:
810810
"""Return whether this directory entry is a block device."""
811-
return stat.S_ISBLK(self.type << 12)
811+
return stat.S_ISBLK(self.type)
812812

813813
def is_character_device(self) -> bool:
814814
"""Return whether this directory entry is a character device."""
815-
return stat.S_ISCHR(self.type << 12)
815+
return stat.S_ISCHR(self.type)
816816

817817
def is_device(self) -> bool:
818818
"""Return whether this directory entry is a device (block or character)."""
819819
return self.is_block_device() or self.is_character_device()
820820

821821
def is_fifo(self) -> bool:
822822
"""Return whether this directory entry is a FIFO."""
823-
return stat.S_ISFIFO(self.type << 12)
823+
return stat.S_ISFIFO(self.type)
824824

825825
def is_socket(self) -> bool:
826826
"""Return whether this directory entry is a socket."""
827-
return stat.S_ISSOCK(self.type << 12)
827+
return stat.S_ISSOCK(self.type)
828828

829829
def is_whiteout(self) -> bool:
830830
"""Return whether this directory entry is a whiteout."""
831-
return stat.S_ISWHT(self.type << 12)
831+
return stat.S_ISWHT(self.type)
832832

833833

834834
class XAttr:

tests/test_apfs.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ def _assert_apfs_content(volume: FS, beta: bool) -> None:
3636
]
3737
)
3838

39+
# Test direntry parsing
40+
assert node.listdir()["dir"].is_dir()
41+
assert node.listdir()["hardlink"].is_file()
42+
assert node.listdir()["symlink-dir"].is_symlink()
43+
3944
# Empty file
4045
node = volume.get("empty")
4146
assert node.name == "empty"
@@ -240,6 +245,9 @@ def _assert_apfs_content(volume: FS, beta: bool) -> None:
240245

241246
if ".HFS+ Private Directory Data\r" not in volume.get("/").listdir() and not beta:
242247
# Special files
248+
dirents = volume.get("dir").listdir()
249+
assert dirents["blockdev"].is_block_device()
250+
243251
node = volume.get("dir/blockdev")
244252
assert node.name == "blockdev"
245253
assert node.is_block_device()
@@ -263,6 +271,8 @@ def _assert_apfs_content(volume: FS, beta: bool) -> None:
263271
"chardev-svr4",
264272
"chardev-ultrix",
265273
]:
274+
assert dirents[name].is_character_device()
275+
266276
node = volume.get(f"dir/{name}")
267277
assert node.name == name
268278
assert node.is_character_device()

0 commit comments

Comments
 (0)