From 8b75c34a82dd74beee96cdbc51388cd4289ad712 Mon Sep 17 00:00:00 2001 From: Justus Mueller <justus.mueller@fau.de> Date: Mon, 3 Jun 2024 20:22:49 +0200 Subject: [PATCH] feat: Make the pattern file non rolling --- hash_longterm.py | 2 +- src/drive_handle.py | 10 +++------- src/tests/slack_test.py | 10 ++++++++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/hash_longterm.py b/hash_longterm.py index 7ec760d..49a2a20 100644 --- a/hash_longterm.py +++ b/hash_longterm.py @@ -57,8 +57,8 @@ if __name__ == "__main__": # write random data to the disk print(colored("[Hash-Longtermstudy] Starting the hash run!", "light_blue")) drive_handle.copy_demo_files() - print(colored("[Hash-Longtermstudy] Waiting 120s for the OS to flush the write buffer.", "cyan")) drive_handle.flush_cache() + print(colored("[Hash-Longtermstudy] Waiting 120s for the OS to flush the write buffer.", "cyan")) time.sleep(120) # create hash print(colored(f"[Hash-Longtermstudy] The hash prior to the deletion is {drive_handle.generate_hash()}", "light_blue")) diff --git a/src/drive_handle.py b/src/drive_handle.py index ed93e65..251019c 100644 --- a/src/drive_handle.py +++ b/src/drive_handle.py @@ -142,23 +142,19 @@ class DriveHandle: return True return False - def write_pattern(self, path: str) -> None: + def write_pattern(self, symbol: chr, path: str) -> None: """ Writes the pattern file to the disk Parameters: path (str): The path to the pattern file """ - print(colored(f"[DriveHandle] Writing a file ({path}) with a rolling pattern to fill the disk.", "light_grey")) - pattern_start_symbol: chr = 'A' - iteration: int = 0 + print(colored(f"[DriveHandle] Writing a file ({path}) with 0x{symbol.encode().hex()} pattern to fill the disk.", "light_grey")) (_, _, cluster_size) = self.get_allocation_unit_sizes() progressbar = Spinner('[DriveHandle] Writing the pattern file') with open(path, "wb") as file_descriptor: while os.path.getsize(path) + cluster_size < self.get_free_drive_space(): - current_pattern_symbol: chr = chr(ord(pattern_start_symbol) + iteration) - file_descriptor.write(current_pattern_symbol.encode() * cluster_size) - iteration = (iteration + 1) % 26 + file_descriptor.write(symbol.encode() * cluster_size) progressbar.next() progressbar.finish() print(colored("[DriveHandle] Completed writing the pattern file.", "light_grey")) diff --git a/src/tests/slack_test.py b/src/tests/slack_test.py index b3b1dcb..efe65e3 100644 --- a/src/tests/slack_test.py +++ b/src/tests/slack_test.py @@ -31,8 +31,10 @@ class SlackTest(DecisionTest): # create rolling pattern pattern_file_path: str = f'{self.drive_handle.get_path()}transsd-slacktest-pattern' - self.drive_handle.write_pattern(pattern_file_path) + self.drive_handle.write_pattern('A', pattern_file_path) self.drive_handle.flush_cache() + print(colored("[SlackTest] Waiting 120s for the OS to flush the write cache.", "light_grey")) + time.sleep(120) pattern_file_clusters: list = [] if self._check_cluster_overlap: pattern_file_clusters = self.drive_handle.get_clusters_for_file(pattern_file_path) @@ -41,8 +43,8 @@ class SlackTest(DecisionTest): # delete file self.drive_handle.delete_file(pattern_file_path) - print("[SlackTest] Waiting 120s for OS to clean up the disk...") self.drive_handle.flush_cache() + print("[SlackTest] Waiting 120s for OS to clean up the disk...") time.sleep(120) print(colored("[SlackTest] File should be removed from disk without remainder.", "light_grey")) @@ -82,6 +84,10 @@ class SlackTest(DecisionTest): else: print(colored("[SlackTest] All bytes are zero!", "red")) + print(colored("[SlackTest] Cleaning up files.", "light_grey")) + self.drive_handle.delete_file(f'{self.drive_handle.get_path()}transsd-slacktest-overwrite') + self.drive_handle.flush_cache() + print(colored("[SlackTest] Slack test completed.", "light_blue")) return not found_non_zero_byte -- GitLab