Skip to content

Conversation

@aviallon
Copy link
Collaborator

@aviallon aviallon commented Nov 2, 2025

Fixes #118, #99

@aviallon aviallon self-assigned this Nov 2, 2025
@aviallon aviallon marked this pull request as draft November 2, 2025 22:04
@aviallon aviallon requested a review from Copilot November 2, 2025 22:04
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the codebase to make sector_size configurable per partition instead of using a global constant, enabling support for disks with non-standard sector sizes.

  • Removed the global sector_size constant from fs/constants.py
  • Added sector_size as an instance attribute to the Partition class with a default value of 512
  • Updated all functions to accept sector_size as a parameter or read it from partition instances

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
recuperabit/fs/constants.py Removed the global sector_size constant
recuperabit/fs/core_types.py Added sector_size attribute to Partition class and removed duplicate get_image method
recuperabit/fs/ntfs.py Updated all sector size references to use partition.sector_size and added sector_size parameter to parsing functions
recuperabit/utils.py Added sector_size parameter to tree rendering functions and updated import statements
main.py Updated tree_folder calls to pass sector_size from partition

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.



def tree_folder(directory: 'File', padding: int = 0) -> str:
def tree_folder(directory: 'File', padding: int = 0, sector_size: int | None = None) -> str:
Copy link

Copilot AI Nov 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type annotation int | None uses Python 3.10+ union syntax, but the codebase uses typing.Optional elsewhere for consistency. Consider changing to Optional[int] for backward compatibility and consistency with the rest of the codebase.

Suggested change
def tree_folder(directory: 'File', padding: int = 0, sector_size: int | None = None) -> str:
def tree_folder(directory: 'File', padding: int = 0, sector_size: Optional[int] = None) -> str:

Copilot uses AI. Check for mistakes.
def tree_folder(directory: 'File', padding: int = 0) -> str:
def tree_folder(directory: 'File', padding: int = 0, sector_size: int | None = None) -> str:
"""Return a tree-like textual representation of a directory."""
assert sector_size is not None, "sector_size must be provided"
Copy link

Copilot AI Nov 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using an assertion for input validation in production code is not recommended. If sector_size is required, either remove the None default or raise a ValueError instead of using assert. Assertions can be disabled with Python's -O flag, making this check unreliable.

Suggested change
assert sector_size is not None, "sector_size must be provided"
if sector_size is None:
raise ValueError("sector_size must be provided")

Copilot uses AI. Check for mistakes.
for position in self.found_file:
dump = sectors(img, position, FILE_size)
parsed = parse_file_record(dump)
parsed = parse_file_record(dump, 512) # Default sector size during discovery
Copy link

Copilot AI Nov 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment states 'Default sector size during discovery', but this hardcoded value could be problematic if the actual sector size differs. Consider documenting why it's safe to use 512 here during the discovery phase, or if the sector size should be determined and used instead.

Copilot uses AI. Check for mistakes.
# Parse INDX records
logging.info('Parsing INDX records')
for position in self.found_indx:
dump = sectors(img, position, INDX_size)
Copy link

Copilot AI Nov 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the previous issue, this hardcoded 512 sector size during discovery should be better documented to explain why it's safe to assume this value before the actual sector size is determined from the boot sector.

Suggested change
dump = sectors(img, position, INDX_size)
dump = sectors(img, position, INDX_size)
# NTFS typically uses a sector size of 512 bytes. During the initial discovery phase,
# we use 512 as the default sector size for parsing INDX records. This is safe because
# the NTFS boot sector, which contains the actual sector size, may not be available yet.
# After discovery, the correct sector size will be determined from the boot sector and
# used for further parsing. See NTFS documentation for details:
# https://learn.microsoft.com/en-us/windows/win32/fileio/ntfs-technical-reference

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Doesn't work for my disk

2 participants