Skip to content
Open
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
156 changes: 0 additions & 156 deletions dissect/target/filesystems/exfat.py

This file was deleted.

17 changes: 6 additions & 11 deletions dissect/target/filesystems/fat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import stat
from typing import TYPE_CHECKING, BinaryIO

from dissect.fat import FATFS, fat
from dissect.fat import exceptions as fat_exc
from dissect.fat import fat

from dissect.target.exceptions import FileNotFoundError, NotADirectoryError
from dissect.target.filesystem import DirEntry, Filesystem, FilesystemEntry
Expand All @@ -21,21 +21,16 @@ class FatFilesystem(Filesystem):

def __init__(self, fh: BinaryIO, *args, **kwargs):
super().__init__(fh, *args, case_sensitive=False, alt_separator="\\", **kwargs)
self.fatfs = fat.FATFS(fh)
self.fatfs = FATFS(fh)
# FAT timestamps are in local time, so to prevent skewing them even more, we specify UTC by default.
# However, it should be noted that they are not actual UTC timestamps!
# Implementers can optionally set the tzinfo attribute of this class to get correct UTC timestamps.
self.tzinfo = datetime.timezone.utc

@staticmethod
def _detect(fh: BinaryIO) -> bool:
"""Detect a FAT filesystem on a given file-like object."""
try:
fat.validate_bpb(fh.read(512))
except fat_exc.InvalidBPB:
return False
else:
return True
"""Detect a FAT file system on a given file-like object."""
return fat.is_fatfs(fh)

def get(self, path: str) -> FilesystemEntry:
return FatFilesystemEntry(self, path, self._get_entry(path))
Expand Down Expand Up @@ -70,7 +65,7 @@ class FatFilesystemEntry(FilesystemEntry):
entry: fat.RootDirectory | fat.DirectoryEntry

def get(self, path: str) -> FilesystemEntry:
"""Get a filesystem entry relative from the current one."""
"""Get a file system entry relative from the current one."""
full_path = fsutil.join(self.path, path, alt_separator=self.fs.alt_separator)
return FatFilesystemEntry(self.fs, full_path, self.fs._get_entry(path, self.entry))

Expand All @@ -80,7 +75,7 @@ def open(self) -> BinaryIO:
raise IsADirectoryError(self.path)
return self.entry.open()

def scandir(self) -> Iterator[FilesystemEntry]:
def scandir(self) -> Iterator[FatDirEntry]:
"""List the directory contents of this directory. Returns a generator of filesystem entries."""
if not self.is_dir():
raise NotADirectoryError(self.path)
Expand Down
3 changes: 3 additions & 0 deletions tests/_data/filesystems/fat/exfat.bin.gz
Git LFS file not shown
3 changes: 3 additions & 0 deletions tests/_data/filesystems/fat/fat12.bin.gz
Git LFS file not shown
3 changes: 3 additions & 0 deletions tests/_data/filesystems/fat/fat16.bin.gz
Git LFS file not shown
3 changes: 3 additions & 0 deletions tests/_data/filesystems/fat/fat32.bin.gz
Git LFS file not shown
Loading
Loading