From b82493b12b3a6d88c8b0ce56bff55832915ff84a Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 8 Mar 2022 11:55:23 -0700 Subject: [PATCH] Generate new map files when starting a recovery This is done to define the domain size and let us use --complete-only. This also enables us to open ddrescueview immediately since that tool requires a valid map file from the start. If you open an empty map file ddrescueview doesn't auto-reload the file correctly. Addresses #184 --- scripts/wk/cfg/ddrescue.py | 4 ++++ scripts/wk/hw/ddrescue.py | 33 +++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/scripts/wk/cfg/ddrescue.py b/scripts/wk/cfg/ddrescue.py index 6e3459b8..f40cf70c 100644 --- a/scripts/wk/cfg/ddrescue.py +++ b/scripts/wk/cfg/ddrescue.py @@ -20,6 +20,10 @@ AUTO_PASS_THRESHOLDS = { 'trim': 98, 'scrape': float('inf'), } +DDRESCUE_MAP_TEMPLATE = '''# Mapfile. Created by {name} +0x0 ? 1 +0x0 {size:#x} ? +''' DDRESCUE_SETTINGS = { 'Default': { '--binary-prefixes': {'Selected': True, 'Hidden': True, }, diff --git a/scripts/wk/hw/ddrescue.py b/scripts/wk/hw/ddrescue.py index 2b7d5c4c..b907c871 100644 --- a/scripts/wk/hw/ddrescue.py +++ b/scripts/wk/hw/ddrescue.py @@ -22,7 +22,7 @@ import psutil import pytz from wk import cfg, debug, exe, io, log, net, std, tmux -from wk.cfg.ddrescue import DDRESCUE_SETTINGS +from wk.cfg.ddrescue import DDRESCUE_MAP_TEMPLATE, DDRESCUE_SETTINGS from wk.hw import obj as hw_obj @@ -139,7 +139,7 @@ class BlockPair(): self.view_proc = None - # Set map file + # Set map path # e.g. '(Clone|Image)_Model[_p#]_Size[_Label].map' map_name = model if model else 'None' if source.details['bus'] == 'Image': @@ -148,7 +148,7 @@ class BlockPair(): part_num = re.sub(r"^.*?(\d+)$", r"\1", source.path.name) map_name += f'_p{part_num}' size_str = std.bytes_to_string( - size=source.details["size"], + size=self.size, use_binary=False, ) map_name += f'_{size_str.replace(" ", "")}' @@ -164,7 +164,17 @@ class BlockPair(): else: # Cloning self.map_path = pathlib.Path(f'{working_dir}/Clone_{map_name}.map') - self.map_path.touch() + + # Create map file if needed + # NOTE: We need to set the domain size for --complete-only to work + if not self.map_path.exists(): + self.map_path.write_text( + data=DDRESCUE_MAP_TEMPLATE.format( + name=cfg.main.KIT_NAME_FULL, + size=self.size, + ), + encoding='utf-8', + ) # Set initial status self.set_initial_status() @@ -2044,8 +2054,12 @@ def run_ddrescue(state, block_pair, pass_name, settings, dry_run=True): LOG.info('ddrescue cmd: %s', cmd) return - # Start ddrescue + # Start ddrescue and ddrescueview proc = exe.popen_program(cmd) + exe.popen_program( + ['ddrescueview', '-r', '5s', block_pair.map_path], + pipe=True, + ) # ddrescue loop _i = 0 @@ -2062,15 +2076,6 @@ def run_ddrescue(state, block_pair, pass_name, settings, dry_run=True): std.print_error(warning_message) break - # Open ddrescueview - ## NOTE: This needs to be started a bit into the recovery since it needs - ## a non-zero map file to read - if not block_pair.view_proc and _i > 1: - block_pair.view_proc = exe.popen_program( - ['ddrescueview', '-r', '5s', block_pair.map_path], - pipe=True, - ) - if _i % 60 == 0: # Clear ddrescue pane tmux.clear_pane()