diff --git a/src/drive_handle.py b/src/drive_handle.py index 518a6c24e85f2a1609a66bf44c13cd86c77cb485..f4d27748502d2a017c87749f86d32a8b61b1d25b 100644 --- a/src/drive_handle.py +++ b/src/drive_handle.py @@ -1,4 +1,5 @@ import ctypes +import errno import os import shutil import subprocess @@ -151,12 +152,26 @@ class DriveHandle: path (str): The path to the pattern file """ 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(): - file_descriptor.write(symbol.encode() * cluster_size) - progressbar.next() + + write_string = str(symbol)*1024*1024*5 # 5 MiB + with open(path, "w") as file_descriptor: + while True: + try: + file_descriptor.write(write_string) + file_descriptor.flush() + progressbar.next() + except OSError as error: + if error.errno == errno.ENOSPC: + if len(write_string) > 1: + write_string = write_string[:(len(write_string)//2)] + if (self.get_free_drive_space() == 0): + break + else: + break + else: + raise + progressbar.finish() print(colored("[DriveHandle] Completed writing the pattern file.", "light_grey"))