[Dumping] Add option to fix sectors that didn't pass integrity checks.

This commit is contained in:
2025-11-23 13:44:59 +00:00
parent 70f005f61f
commit b8d55ff741
7 changed files with 67 additions and 11 deletions

View File

@@ -254,7 +254,7 @@ partial class Dump
pass));
}
Track track = tracks.OrderBy(t => t.StartSector).LastOrDefault(t => badSector >= t.StartSector);
Track track = tracks.OrderBy(static t => t.StartSector).LastOrDefault(t => badSector >= t.StartSector);
byte sectorsToReRead = 1;
var badSectorToReRead = (uint)badSector;
@@ -506,17 +506,38 @@ partial class Dump
if(correctEdc != true || correctEccP != true || correctEccQ != true)
{
sectorStatus = SectorStatus.Errored;
_mediaGraph?.PaintSectorBad(badSector);
if(_cureParanoia && correctEdc == true && correctEccP == true)
{
Track trk = tracks.FirstOrDefault(t => t.StartSector <= badSector &&
t.EndSector >= badSector);
if(correctEdc != true)
UpdateStatus?.Invoke(string.Format(UI.Incorrect_EDC_in_sector_0, badSector));
SectorBuilder sb = new();
sb.ReconstructEcc(ref sector, track.Type);
Array.Copy(sector, 0, cmdBuf, 0, sectorSize);
if(correctEccP != true)
UpdateStatus?.Invoke(string.Format(UI.Incorrect_ECC_P_in_sector_0, badSector));
_resume.BadBlocks.Remove(badSector);
extents.Add(badSector);
_mediaGraph?.PaintSectorGood(badSector);
if(correctEccQ != true)
UpdateStatus?.Invoke(string.Format(UI.Incorrect_ECC_Q_in_sector_0, badSector));
UpdateStatus?.Invoke(string.Format(UI.Fixed_ECC_Q_for_sector_0,
badSector));
sectorsNotEvenPartial.Remove(badSector);
}
else
{
sectorStatus = SectorStatus.Errored;
_mediaGraph?.PaintSectorBad(badSector);
if(correctEdc != true)
UpdateStatus?.Invoke(string.Format(UI.Incorrect_EDC_in_sector_0, badSector));
if(correctEccP != true)
UpdateStatus?.Invoke(string.Format(UI.Incorrect_ECC_P_in_sector_0, badSector));
if(correctEccQ != true)
UpdateStatus?.Invoke(string.Format(UI.Incorrect_ECC_Q_in_sector_0, badSector));
}
}
else
{

View File

@@ -72,6 +72,7 @@ public partial class Dump
const string MODULE_NAME = "Media dumping";
static readonly TimeSpan _oneSecond = 1.Seconds();
readonly bool _createGraph;
readonly bool _cureParanoia;
readonly bool _debug;
readonly Device _dev;
readonly string _devicePath;
@@ -167,6 +168,7 @@ public partial class Dump
/// <param name="createGraph">If set to <c>true</c> creates a graph of the dump.</param>
/// <param name="dimensions">Dimensions of graph in pixels for a square</param>
/// <param name="paranoia">Check sectors integrity before writing to image</param>
/// <param name="cureParanoia">Try to fix sectors integrity</param>
public Dump(bool doResume, Device dev, string devicePath, IBaseWritableImage outputPlugin, ushort retryPasses,
bool force, bool dumpRaw, bool persistent, bool stopOnError, Resume resume, Encoding encoding,
string outputPrefix, string outputPath, Dictionary<string, string> formatOptions, Metadata preSidecar,
@@ -174,7 +176,8 @@ public partial class Dump
DumpSubchannel subchannel, int speed, bool @private, bool fixSubchannelPosition, bool retrySubchannel,
bool fixSubchannel, bool fixSubchannelCrc, bool skipCdireadyHole, ErrorLog errorLog,
bool generateSubchannels, uint maximumReadable, bool useBufferedReads, bool storeEncrypted,
bool titleKeys, uint ignoreCdrRunOuts, bool createGraph, uint dimensions, bool paranoia)
bool titleKeys, uint ignoreCdrRunOuts, bool createGraph, uint dimensions, bool paranoia,
bool cureParanoia)
{
_doResume = doResume;
_dev = dev;
@@ -217,6 +220,7 @@ public partial class Dump
_createGraph = createGraph;
_dimensions = dimensions;
_paranoia = paranoia;
_cureParanoia = cureParanoia;
_dumpStopwatch = new Stopwatch();
_sidecarStopwatch = new Stopwatch();
_speedStopwatch = new Stopwatch();