Mark newly discovered pregap sectors for retry. Fixes incorrect data on some track type changes.

This commit is contained in:
2022-04-09 20:27:05 +01:00
parent ad4355c2c2
commit f9f97c02c5
10 changed files with 77 additions and 38 deletions

View File

@@ -30,8 +30,6 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
// ReSharper disable JoinDeclarationAndInitializer
// ReSharper disable InlineOutVariableDeclaration
// ReSharper disable TooWideLocalVariableScope
@@ -268,7 +266,8 @@ partial class Dump
bool indexesChanged = Media.CompactDisc.WriteSubchannelToImage(supportedSubchannel,
desiredSubchannel, sub, i + r, 1, subLog, isrcs, 1, ref mcn, tracks,
subchannelExtents, _fixSubchannelPosition, outputOptical, _fixSubchannel,
_fixSubchannelCrc, _dumpLog, UpdateStatus, smallestPregapLbaPerTrack, true);
_fixSubchannelCrc, _dumpLog, UpdateStatus, smallestPregapLbaPerTrack, true,
out List<ulong> newPregapSectors);
// Set tracks and go back
if(indexesChanged)
@@ -350,13 +349,24 @@ partial class Dump
bool indexesChanged = Media.CompactDisc.WriteSubchannelToImage(supportedSubchannel,
desiredSubchannel, sub, i, blocksToRead, subLog, isrcs, 1, ref mcn, tracks,
subchannelExtents, _fixSubchannelPosition, outputOptical, _fixSubchannel,
_fixSubchannelCrc, _dumpLog, UpdateStatus, smallestPregapLbaPerTrack, true);
_fixSubchannelCrc, _dumpLog, UpdateStatus, smallestPregapLbaPerTrack, true,
out List<ulong> newPregapSectors);
// Set tracks and go back
if(indexesChanged)
{
outputOptical.SetTracks(tracks.ToList());
i -= blocksToRead;
foreach(ulong newPregapSector in newPregapSectors)
_resume.BadBlocks.Add(newPregapSector);
if(i >= blocksToRead)
i -= blocksToRead;
else
i = 0;
if(i > 0)
i--;
continue;
}

View File

@@ -50,6 +50,7 @@ using Aaru.Decoders.CD;
using Aaru.Decoders.SCSI;
using Aaru.Devices;
using Schemas;
using TrackType = Aaru.CommonTypes.Enums.TrackType;
partial class Dump
{
@@ -513,13 +514,26 @@ partial class Dump
desiredSubchannel, sub, i + r, 1, subLog, isrcs, (byte)track.Sequence, ref mcn,
tracks, subchannelExtents, _fixSubchannelPosition,
outputFormat as IWritableOpticalImage, _fixSubchannel, _fixSubchannelCrc, _dumpLog,
UpdateStatus, smallestPregapLbaPerTrack, true);
UpdateStatus, smallestPregapLbaPerTrack, true, out List<ulong> newPregapSectors);
// Set tracks and go back
if(indexesChanged)
{
(outputFormat as IWritableOpticalImage).SetTracks(tracks.ToList());
i -= blocksToRead;
foreach(ulong newPregapSector in newPregapSectors)
_resume.BadBlocks.Add(newPregapSector);
if(i >= blocksToRead)
i -= blocksToRead;
else
i = 0;
if(i > 0)
i--;
foreach(Track aTrack in tracks.Where(aTrack => aTrack.Type == TrackType.Audio))
audioExtents.Add(aTrack.StartSector, aTrack.EndSector);
continue;
}
@@ -656,14 +670,27 @@ partial class Dump
bool indexesChanged = Media.CompactDisc.WriteSubchannelToImage(supportedSubchannel,
desiredSubchannel, sub, i, blocksToRead, subLog, isrcs, (byte)track.Sequence, ref mcn,
tracks, subchannelExtents, _fixSubchannelPosition, outputFormat as IWritableOpticalImage,
_fixSubchannel, _fixSubchannelCrc, _dumpLog, UpdateStatus, smallestPregapLbaPerTrack,
true);
_fixSubchannel, _fixSubchannelCrc, _dumpLog, UpdateStatus, smallestPregapLbaPerTrack, true,
out List<ulong> newPregapSectors);
// Set tracks and go back
if(indexesChanged)
{
(outputFormat as IWritableOpticalImage).SetTracks(tracks.ToList());
i -= blocksToRead;
foreach(ulong newPregapSector in newPregapSectors)
_resume.BadBlocks.Add(newPregapSector);
if(i >= blocksToRead)
i -= blocksToRead;
else
i = 0;
if(i > 0)
i--;
foreach(Track aTrack in tracks.Where(aTrack => aTrack.Type == TrackType.Audio))
audioExtents.Add(aTrack.StartSector, aTrack.EndSector);
continue;
}

View File

@@ -30,8 +30,6 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
// ReSharper disable JoinDeclarationAndInitializer
// ReSharper disable InlineOutVariableDeclaration
// ReSharper disable TooWideLocalVariableScope
@@ -367,7 +365,7 @@ partial class Dump
_fixSubchannelPosition, outputOptical,
_fixSubchannel, _fixSubchannelCrc,
_dumpLog, UpdateStatus,
smallestPregapLbaPerTrack, true);
smallestPregapLbaPerTrack, true, out _);
// Set tracks and go back
if(!indexesChanged)
@@ -497,14 +495,14 @@ partial class Dump
bool indexesChanged = Media.CompactDisc.WriteSubchannelToImage(supportedSubchannel,
desiredSubchannel, sub, badSector, 1, subLog, isrcs, (byte)track.Sequence, ref mcn,
tracks, subchannelExtents, _fixSubchannelPosition, outputOptical, _fixSubchannel,
_fixSubchannelCrc, _dumpLog, UpdateStatus, smallestPregapLbaPerTrack, true);
_fixSubchannelCrc, _dumpLog, UpdateStatus, smallestPregapLbaPerTrack, true, out _);
// Set tracks and go back
if(indexesChanged)
{
outputOptical.SetTracks(tracks.ToList());
i--;
}
if(!indexesChanged)
continue;
outputOptical.SetTracks(tracks.ToList());
i--;
}
else
{
@@ -660,7 +658,7 @@ partial class Dump
subLog, isrcs, (byte)track.Sequence, ref mcn, tracks,
subchannelExtents, _fixSubchannelPosition, outputOptical,
_fixSubchannel, _fixSubchannelCrc, _dumpLog, UpdateStatus,
smallestPregapLbaPerTrack, true);
smallestPregapLbaPerTrack, true, out _);
if(subchannelExtents.Contains(bs))
continue;

View File

@@ -30,8 +30,6 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
// ReSharper disable JoinDeclarationAndInitializer
// ReSharper disable InlineOutVariableDeclaration
// ReSharper disable TooWideLocalVariableScope
@@ -165,7 +163,7 @@ partial class Dump
bool indexesChanged = Media.CompactDisc.WriteSubchannelToImage(supportedSubchannel,
desiredSubchannel, sub, i, _maximumReadable, subLog, isrcs, 0xAA, ref mcn, tracks,
subchannelExtents, _fixSubchannelPosition, outputOptical, _fixSubchannel,
_fixSubchannelCrc, _dumpLog, UpdateStatus, smallestPregapLbaPerTrack, true);
_fixSubchannelCrc, _dumpLog, UpdateStatus, smallestPregapLbaPerTrack, true, out _);
// Set tracks and go back
if(indexesChanged)
@@ -333,7 +331,7 @@ partial class Dump
bool indexesChanged = Media.CompactDisc.WriteSubchannelToImage(supportedSubchannel,
desiredSubchannel, sub, i, _maximumReadable, subLog, isrcs, 0xAA, ref mcn, tracks,
subchannelExtents, _fixSubchannelPosition, outputOptical, _fixSubchannel,
_fixSubchannelCrc, _dumpLog, UpdateStatus, smallestPregapLbaPerTrack, true);
_fixSubchannelCrc, _dumpLog, UpdateStatus, smallestPregapLbaPerTrack, true, out _);
// Set tracks and go back
if(indexesChanged)

View File

@@ -30,8 +30,6 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
// ReSharper disable JoinDeclarationAndInitializer
// ReSharper disable InlineOutVariableDeclaration
// ReSharper disable TooWideLocalVariableScope
@@ -271,7 +269,7 @@ partial class Dump
_fixSubchannelPosition, outputOptical,
_fixSubchannel, _fixSubchannelCrc,
_dumpLog, UpdateStatus,
smallestPregapLbaPerTrack, true);
smallestPregapLbaPerTrack, true, out _);
// Set tracks and go back
if(!indexesChanged)

View File

@@ -72,7 +72,7 @@ public static class CompactDisc
bool fixSubchannelPosition, IWritableOpticalImage outputPlugin,
bool fixSubchannel, bool fixSubchannelCrc, DumpLog dumpLog,
UpdateStatusHandler updateStatus,
Dictionary<byte, int> smallestPregapLbaPerTrack, bool dumping)
Dictionary<byte, int> smallestPregapLbaPerTrack, bool dumping, out List<ulong> newPregapSectors)
{
// We need to work in PW raw subchannels
if(supportedSubchannel == MmcSubchannel.Q16)
@@ -88,7 +88,7 @@ public static class CompactDisc
byte[] deSub = Subchannel.Deinterleave(sub);
bool indexesChanged = CheckIndexesFromSubchannel(deSub, isrcs, currentTrack, ref mcn, tracks, dumpLog,
updateStatus, smallestPregapLbaPerTrack, dumping);
updateStatus, smallestPregapLbaPerTrack, dumping, out newPregapSectors);
if(!fixSubchannelPosition ||
desiredSubchannel == MmcSubchannel.None)
@@ -312,9 +312,10 @@ public static class CompactDisc
static bool CheckIndexesFromSubchannel(byte[] deSub, Dictionary<byte, string> isrcs, byte currentTrack,
ref string mcn, Track[] tracks, DumpLog dumpLog,
UpdateStatusHandler updateStatus,
Dictionary<byte, int> smallestPregapLbaPerTrack, bool dumping)
Dictionary<byte, int> smallestPregapLbaPerTrack, bool dumping, out List<ulong> newPregapSectors)
{
var status = false;
newPregapSectors = new List<ulong>();
// Check subchannel
for(var subPos = 0; subPos < deSub.Length; subPos += 96)
@@ -431,6 +432,9 @@ public static class CompactDisc
updateStatus?.Invoke($"Pregap for track {trackNo} set to {tracks[i].Pregap} sectors.");
for(var p = 0; p < dif; p++)
newPregapSectors.Add(tracks[i].StartSector+(ulong)p);
status = true;
}
@@ -450,6 +454,9 @@ public static class CompactDisc
updateStatus?.Invoke($"Pregap for track {trackNo} set to {tracks[i].Pregap} sectors.");
for(var p = 0; p < (int)(tracks[i].Pregap - oldPregap); p++)
newPregapSectors.Add(tracks[i].StartSector +(ulong)p);
status = true;
continue;

View File

@@ -1172,7 +1172,7 @@ public sealed class ImageConvertViewModel : ViewModelBase
MmcSubchannel.Raw, sector, doneSectors, 1, null, isrcs, (byte)track.Sequence,
ref mcn, tracks.ToArray(), subchannelExtents, false,
outputFormat as IWritableOpticalImage, false, false, null, null,
smallestPregapLbaPerTrack, false);
smallestPregapLbaPerTrack, false, out _);
if(indexesChanged)
outputOptical.SetTracks(tracks.ToList());
@@ -1224,7 +1224,7 @@ public sealed class ImageConvertViewModel : ViewModelBase
MmcSubchannel.Raw, sector, doneSectors, sectorsToDo, null, isrcs,
(byte)track.Sequence, ref mcn, tracks.ToArray(), subchannelExtents, false,
outputFormat as IWritableOpticalImage, false, false, null, null,
smallestPregapLbaPerTrack, false);
smallestPregapLbaPerTrack, false, out _);
if(indexesChanged)
outputOptical.SetTracks(tracks.ToList());

View File

@@ -298,7 +298,7 @@ public abstract class OpticalImageConvertIssueTest
bool indexesChanged = CompactDisc.WriteSubchannelToImage(MmcSubchannel.Raw,
MmcSubchannel.Raw, sector, doneSectors + track.StartSector, 1, null, isrcs,
(byte)track.Sequence, ref mcn, tracks, subchannelExtents, true, outputOptical,
true, true, null, null, smallestPregapLbaPerTrack, false);
true, true, null, null, smallestPregapLbaPerTrack, false, out _);
if(indexesChanged)
outputOptical.SetTracks(tracks.ToList());
@@ -320,7 +320,7 @@ public abstract class OpticalImageConvertIssueTest
bool indexesChanged = CompactDisc.WriteSubchannelToImage(MmcSubchannel.Raw,
MmcSubchannel.Raw, sector, doneSectors + track.StartSector, sectorsToDo, null,
isrcs, (byte)track.Sequence, ref mcn, tracks, subchannelExtents, true,
outputOptical, true, true, null, null, smallestPregapLbaPerTrack, false);
outputOptical, true, true, null, null, smallestPregapLbaPerTrack, false, out _);
if(indexesChanged)
outputOptical.SetTracks(tracks.ToList());

View File

@@ -365,7 +365,8 @@ public abstract class WritableOpticalMediaImageTest : BaseWritableMediaImageTest
bool indexesChanged = CompactDisc.WriteSubchannelToImage(MmcSubchannel.Raw,
MmcSubchannel.Raw, sector, doneSectors + track.StartSector, 1, null, isrcs,
(byte)track.Sequence, ref mcn, tracks, subchannelExtents, true,
outputFormat, true, true, null, null, smallestPregapLbaPerTrack, false);
outputFormat, true, true, null, null, smallestPregapLbaPerTrack, false,
out _);
if(indexesChanged)
outputFormat.SetTracks(tracks.ToList());
@@ -389,7 +390,7 @@ public abstract class WritableOpticalMediaImageTest : BaseWritableMediaImageTest
MmcSubchannel.Raw, sector, doneSectors + track.StartSector, sectorsToDo,
null, isrcs, (byte)track.Sequence, ref mcn, tracks, subchannelExtents,
true, outputFormat, true, true, null, null, smallestPregapLbaPerTrack,
false);
false, out _);
if(indexesChanged)
outputFormat.SetTracks(tracks.ToList());

View File

@@ -1136,7 +1136,7 @@ sealed class ConvertImageCommand : Command
(byte)track.Sequence, ref mcn, tracks,
subchannelExtents, fixSubchannelPosition,
outputOptical, fixSubchannel, fixSubchannelCrc, null,
null, smallestPregapLbaPerTrack, false);
null, smallestPregapLbaPerTrack, false, out _);
if(indexesChanged)
outputOptical.SetTracks(tracks.ToList());
@@ -1182,7 +1182,7 @@ sealed class ConvertImageCommand : Command
isrcs, (byte)track.Sequence, ref mcn, tracks,
subchannelExtents, fixSubchannelPosition,
outputOptical, fixSubchannel, fixSubchannelCrc, null,
null, smallestPregapLbaPerTrack, false);
null, smallestPregapLbaPerTrack, false, out _);
if(indexesChanged)
outputOptical.SetTracks(tracks.ToList());