Separate trimming from retry pass fixes #172.

This commit is contained in:
2018-04-10 02:39:41 +01:00
parent 47e78ba0d4
commit 07f0dfe935
14 changed files with 281 additions and 80 deletions

View File

@@ -87,7 +87,7 @@ namespace DiscImageChef.Core.Devices.Dumping
Encoding encoding, string outputPrefix,
string outputPath, Dictionary<string, string> formatOptions,
CICMMetadataType preSidecar, uint skip,
bool nometadata)
bool nometadata, bool notrim)
{
bool sense;
ulong blocks;
@@ -347,6 +347,7 @@ namespace DiscImageChef.Core.Devices.Dumping
throw new InvalidOperationException("Could not process resume file, not continuing...");
if(resume.NextBlock > 0) dumpLog.WriteLine("Resuming from block {0}.", resume.NextBlock);
bool newTrim = false;
for(ulong i = resume.NextBlock; i < blocks; i += blocksToRead)
{
@@ -396,7 +397,8 @@ namespace DiscImageChef.Core.Devices.Dumping
ibgLog.Write(i, 0);
dumpLog.WriteLine("Skipping {0} blocks from errored block {1}.", skip, i);
i += skip - blocksToRead;
i += skip - blocksToRead;
newTrim = true;
}
double newSpeed =
@@ -417,6 +419,39 @@ namespace DiscImageChef.Core.Devices.Dumping
dumpLog.WriteLine("Average write speed {0:F3} KiB/sec.",
(double)blockSize * (double)(blocks + 1) / 1024 / imageWriteDuration);
#region Trimming
if(resume.BadBlocks.Count > 0 && !aborted && !notrim && newTrim)
{
start = DateTime.UtcNow;
dumpLog.WriteLine("Trimming bad sectors");
ulong[] tmpArray = resume.BadBlocks.ToArray();
foreach(ulong badSector in tmpArray)
{
if(aborted)
{
currentTry.Extents = ExtentsConverter.ToMetadata(extents);
dumpLog.WriteLine("Aborted!");
break;
}
DicConsole.Write("\rTrimming sector {0}", badSector);
sense = scsiReader.ReadBlock(out readBuffer, badSector, out double cmdDuration);
if(sense || dev.Error) continue;
resume.BadBlocks.Remove(badSector);
extents.Add(badSector);
outputPlugin.WriteSector(readBuffer, badSector);
}
DicConsole.WriteLine();
end = DateTime.UtcNow;
dumpLog.WriteLine("Trimmming finished in {0} seconds.", (end - start).TotalSeconds);
}
#endregion Trimming
#region Error handling
if(resume.BadBlocks.Count > 0 && !aborted && retryPasses > 0)
{