From e42ecd80da0f3778ebb9c4e389affc9796672128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lesimple?= Date: Fri, 2 Aug 2024 23:49:31 +0200 Subject: [PATCH] enh: speedup RS03 repair (fixes #100) --- src/rs03-fix.c | 57 +++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/src/rs03-fix.c b/src/rs03-fix.c index 33c26c6..a0af984 100644 --- a/src/rs03-fix.c +++ b/src/rs03-fix.c @@ -734,33 +734,42 @@ void RS03Fix(Image *image) if(num1 != 0) { int location = loc[j]; - if(erasure_map[location] != 1) /* erasure came from CRC error */ - { int old = fc->imgBlock[location][offset]; - int new = old ^ gf_alpha_to[mod_fieldmax(gf_index_of[num1] + gf_index_of[num2] + GF_FIELDMAX - gf_index_of[den])]; - char *msg, *type; - gint64 sector; - - if(erasure_map[location] == 3) /* erasure came from CRC error */ - { msg = _("-> CRC-predicted error in sector %lld%s at byte %4d (value %02x '%c', expected %02x '%c')\n"); - } - else - { msg = _("-> Non-predicted error in sector %lld%s at byte %4d (value %02x '%c', expected %02x '%c')\n"); - if(erasure_map[location] == 0) /* remember error location */ - { erasure_map[location] = 7; - error_count++; + if((Closure->debugMode && Closure->verbose) || Closure->regtestMode) + { if (erasure_map[location] != 1) /* erasure came from CRC error */ + { int old = fc->imgBlock[location][offset]; + int new = old ^ gf_alpha_to[mod_fieldmax(gf_index_of[num1] + gf_index_of[num2] + GF_FIELDMAX - gf_index_of[den])]; + char *msg, *type; + gint64 sector; + + if(erasure_map[location] == 3) /* erasure came from CRC error */ + { msg = _("-> CRC-predicted error in sector %lld%s at byte %4d (value %02x '%c', expected %02x '%c')\n"); + } + else + { msg = _("-> Non-predicted error in sector %lld%s at byte %4d (value %02x '%c', expected %02x '%c')\n"); + if(erasure_map[location] == 0) /* remember error location */ + { erasure_map[location] = 7; + error_count++; + } } - } - sector = RS03SectorIndex(lay, location, s); - if(eh->methodFlags[0] & MFLAG_ECC_FILE && location >= ndata-1) - type="(ecc)"; - else - type=""; + sector = RS03SectorIndex(lay, location, s); + if(eh->methodFlags[0] & MFLAG_ECC_FILE && location >= ndata-1) + type="(ecc)"; + else + type=""; - PrintCLI(msg, - sector, type, bi, - old, canprint(old) ? old : '.', - new, canprint(new) ? new : '.'); + PrintCLI(msg, + sector, type, bi, + old, canprint(old) ? old : '.', + new, canprint(new) ? new : '.'); + } + } + else /* in non-debug mode, apply the only non-printf-preparing code of the above block */ + { + if (erasure_map[location] == 0) + { erasure_map[location] = 7; + error_count++; + } } fc->imgBlock[location][offset] ^= gf_alpha_to[mod_fieldmax(gf_index_of[num1] + gf_index_of[num2] + GF_FIELDMAX - gf_index_of[den])];