2020-01-01 19:07:52 +00:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2020-01-01 19:07:52 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
2020-03-11 21:56:55 +00:00
|
|
|
// Filename : Error.cs
|
2020-01-01 19:07:52 +00:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
2020-03-11 21:56:55 +00:00
|
|
|
// Component : CompactDisc dumping.
|
2020-01-01 19:07:52 +00:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2020-03-11 21:56:55 +00:00
|
|
|
// Manages error recovering when dumping CompactDisc.
|
2020-01-01 19:07:52 +00:00
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as
|
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-01-03 17:51:30 +00:00
|
|
|
// Copyright © 2011-2020 Natalia Portillo
|
2020-01-01 19:07:52 +00:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-05-05 20:26:18 +01:00
|
|
|
using System.Linq;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.CommonTypes.Extents;
|
2020-05-05 23:25:15 +01:00
|
|
|
using Aaru.CommonTypes.Interfaces;
|
2020-05-05 20:26:18 +01:00
|
|
|
using Aaru.CommonTypes.Structs;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.CommonTypes.Structs.Devices.SCSI;
|
|
|
|
|
using Aaru.Console;
|
2020-04-27 02:29:49 +01:00
|
|
|
using Aaru.Core.Logging;
|
2020-10-23 04:01:55 +01:00
|
|
|
using Aaru.Decoders.CD;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.Decoders.SCSI;
|
|
|
|
|
using Aaru.Devices;
|
2020-01-01 19:07:52 +00:00
|
|
|
using Schemas;
|
|
|
|
|
|
|
|
|
|
// ReSharper disable JoinDeclarationAndInitializer
|
|
|
|
|
// ReSharper disable InlineOutVariableDeclaration
|
|
|
|
|
// ReSharper disable TooWideLocalVariableScope
|
|
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
namespace Aaru.Core.Devices.Dumping
|
2020-01-01 19:07:52 +00:00
|
|
|
{
|
|
|
|
|
partial class Dump
|
|
|
|
|
{
|
|
|
|
|
void RetryCdUserData(ExtentsULong audioExtents, uint blockSize, DumpHardwareType currentTry,
|
|
|
|
|
ExtentsULong extents, int offsetBytes, bool readcd, int sectorsForOffset, uint subSize,
|
2020-05-05 13:28:34 +01:00
|
|
|
MmcSubchannel supportedSubchannel, ref double totalDuration, SubchannelLog subLog,
|
2020-05-05 21:08:41 +01:00
|
|
|
MmcSubchannel desiredSubchannel, Track[] tracks, Dictionary<byte, string> isrcs,
|
2020-07-18 20:43:37 +01:00
|
|
|
ref string mcn, HashSet<int> subchannelExtents,
|
2020-10-23 04:01:55 +01:00
|
|
|
Dictionary<byte, int> smallestPregapLbaPerTrack, bool supportsLongSectors)
|
2020-01-01 19:07:52 +00:00
|
|
|
{
|
2020-03-02 23:58:20 +00:00
|
|
|
bool sense = true; // Sense indicator
|
|
|
|
|
byte[] cmdBuf = null; // Data buffer
|
|
|
|
|
double cmdDuration; // Command execution time
|
|
|
|
|
const uint sectorSize = 2352; // Full sector size
|
2020-03-12 00:29:39 +00:00
|
|
|
byte[] senseBuf = null; // Sense buffer
|
2020-03-02 23:58:20 +00:00
|
|
|
PlextorSubchannel supportedPlextorSubchannel;
|
|
|
|
|
|
|
|
|
|
switch(supportedSubchannel)
|
|
|
|
|
{
|
|
|
|
|
case MmcSubchannel.None:
|
|
|
|
|
supportedPlextorSubchannel = PlextorSubchannel.None;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case MmcSubchannel.Raw:
|
2020-11-06 00:26:23 +00:00
|
|
|
supportedPlextorSubchannel = PlextorSubchannel.Pack;
|
2020-03-02 23:58:20 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case MmcSubchannel.Q16:
|
|
|
|
|
supportedPlextorSubchannel = PlextorSubchannel.Q16;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
supportedPlextorSubchannel = PlextorSubchannel.None;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-01-01 19:07:52 +00:00
|
|
|
|
|
|
|
|
if(_resume.BadBlocks.Count <= 0 ||
|
|
|
|
|
_aborted ||
|
|
|
|
|
_retryPasses <= 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int pass = 1;
|
|
|
|
|
bool forward = true;
|
|
|
|
|
bool runningPersistent = false;
|
|
|
|
|
|
|
|
|
|
Modes.ModePage? currentModePage = null;
|
|
|
|
|
byte[] md6;
|
|
|
|
|
byte[] md10;
|
|
|
|
|
|
|
|
|
|
if(_persistent)
|
|
|
|
|
{
|
|
|
|
|
Modes.ModePage_01_MMC pgMmc;
|
|
|
|
|
|
|
|
|
|
sense = _dev.ModeSense6(out cmdBuf, out _, false, ScsiModeSensePageControl.Current, 0x01, _dev.Timeout,
|
|
|
|
|
out _);
|
|
|
|
|
|
|
|
|
|
if(sense)
|
|
|
|
|
{
|
|
|
|
|
sense = _dev.ModeSense10(out cmdBuf, out _, false, ScsiModeSensePageControl.Current, 0x01,
|
|
|
|
|
_dev.Timeout, out _);
|
|
|
|
|
|
|
|
|
|
if(!sense)
|
|
|
|
|
{
|
|
|
|
|
Modes.DecodedMode? dcMode10 =
|
|
|
|
|
Modes.DecodeMode10(cmdBuf, PeripheralDeviceTypes.MultiMediaDevice);
|
|
|
|
|
|
|
|
|
|
if(dcMode10?.Pages != null)
|
2020-07-22 13:20:25 +01:00
|
|
|
foreach(Modes.ModePage modePage in dcMode10.Value.Pages.Where(modePage =>
|
2020-10-23 04:01:55 +01:00
|
|
|
modePage.Page == 0x01 && modePage.Subpage == 0x00))
|
2020-07-22 13:20:25 +01:00
|
|
|
currentModePage = modePage;
|
2020-01-01 19:07:52 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Modes.DecodedMode? dcMode6 = Modes.DecodeMode6(cmdBuf, PeripheralDeviceTypes.MultiMediaDevice);
|
|
|
|
|
|
|
|
|
|
if(dcMode6?.Pages != null)
|
2020-07-22 13:20:25 +01:00
|
|
|
foreach(Modes.ModePage modePage in dcMode6.Value.Pages.Where(modePage =>
|
2020-10-23 04:01:55 +01:00
|
|
|
modePage.Page == 0x01 && modePage.Subpage == 0x00))
|
2020-07-22 13:20:25 +01:00
|
|
|
currentModePage = modePage;
|
2020-01-01 19:07:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(currentModePage == null)
|
|
|
|
|
{
|
|
|
|
|
pgMmc = new Modes.ModePage_01_MMC
|
|
|
|
|
{
|
2020-07-20 04:34:16 +01:00
|
|
|
PS = false,
|
|
|
|
|
ReadRetryCount = 32,
|
|
|
|
|
Parameter = 0x00
|
2020-01-01 19:07:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
currentModePage = new Modes.ModePage
|
|
|
|
|
{
|
2020-07-20 04:34:16 +01:00
|
|
|
Page = 0x01,
|
|
|
|
|
Subpage = 0x00,
|
|
|
|
|
PageResponse = Modes.EncodeModePage_01_MMC(pgMmc)
|
2020-01-01 19:07:52 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pgMmc = new Modes.ModePage_01_MMC
|
|
|
|
|
{
|
2020-07-20 04:34:16 +01:00
|
|
|
PS = false,
|
|
|
|
|
ReadRetryCount = 255,
|
|
|
|
|
Parameter = 0x20
|
2020-01-01 19:07:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var md = new Modes.DecodedMode
|
|
|
|
|
{
|
2020-07-20 04:34:16 +01:00
|
|
|
Header = new Modes.ModeHeader(),
|
|
|
|
|
Pages = new[]
|
2020-01-01 19:07:52 +00:00
|
|
|
{
|
|
|
|
|
new Modes.ModePage
|
|
|
|
|
{
|
2020-07-20 04:34:16 +01:00
|
|
|
Page = 0x01,
|
|
|
|
|
Subpage = 0x00,
|
|
|
|
|
PageResponse = Modes.EncodeModePage_01_MMC(pgMmc)
|
2020-01-01 19:07:52 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
md6 = Modes.EncodeMode6(md, _dev.ScsiType);
|
|
|
|
|
md10 = Modes.EncodeMode10(md, _dev.ScsiType);
|
|
|
|
|
|
|
|
|
|
UpdateStatus?.Invoke("Sending MODE SELECT to drive (return damaged blocks).");
|
|
|
|
|
_dumpLog.WriteLine("Sending MODE SELECT to drive (return damaged blocks).");
|
|
|
|
|
sense = _dev.ModeSelect(md6, out senseBuf, true, false, _dev.Timeout, out _);
|
|
|
|
|
|
|
|
|
|
if(sense)
|
|
|
|
|
sense = _dev.ModeSelect10(md10, out senseBuf, true, false, _dev.Timeout, out _);
|
|
|
|
|
|
|
|
|
|
if(sense)
|
|
|
|
|
{
|
|
|
|
|
UpdateStatus?.
|
|
|
|
|
Invoke("Drive did not accept MODE SELECT command for persistent error reading, try another drive.");
|
|
|
|
|
|
2020-02-27 23:48:41 +00:00
|
|
|
AaruConsole.DebugWriteLine("Error: {0}", Sense.PrettifySense(senseBuf));
|
2020-01-01 19:07:52 +00:00
|
|
|
|
|
|
|
|
_dumpLog.WriteLine("Drive did not accept MODE SELECT command for persistent error reading, try another drive.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
runningPersistent = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InitProgress?.Invoke();
|
|
|
|
|
cdRepeatRetry:
|
|
|
|
|
ulong[] tmpArray = _resume.BadBlocks.ToArray();
|
|
|
|
|
List<ulong> sectorsNotEvenPartial = new List<ulong>();
|
|
|
|
|
|
2020-05-05 23:25:15 +01:00
|
|
|
for(int i = 0; i < tmpArray.Length; i++)
|
2020-01-01 19:07:52 +00:00
|
|
|
{
|
2020-05-05 23:25:15 +01:00
|
|
|
ulong badSector = tmpArray[i];
|
|
|
|
|
|
2020-01-01 19:07:52 +00:00
|
|
|
if(_aborted)
|
|
|
|
|
{
|
|
|
|
|
currentTry.Extents = ExtentsConverter.ToMetadata(extents);
|
|
|
|
|
_dumpLog.WriteLine("Aborted!");
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PulseProgress?.Invoke(string.Format("Retrying sector {0}, pass {1}, {3}{2}", badSector, pass,
|
|
|
|
|
forward ? "forward" : "reverse",
|
|
|
|
|
runningPersistent ? "recovering partial data, " : ""));
|
|
|
|
|
|
2020-05-05 20:26:18 +01:00
|
|
|
Track track = tracks.OrderBy(t => t.TrackStartSector).
|
|
|
|
|
LastOrDefault(t => badSector >= t.TrackStartSector);
|
|
|
|
|
|
2020-01-01 19:07:52 +00:00
|
|
|
byte sectorsToReRead = 1;
|
|
|
|
|
uint badSectorToReRead = (uint)badSector;
|
|
|
|
|
|
|
|
|
|
if(_fixOffset &&
|
|
|
|
|
audioExtents.Contains(badSector) &&
|
|
|
|
|
offsetBytes != 0)
|
|
|
|
|
{
|
|
|
|
|
if(offsetBytes > 0)
|
|
|
|
|
{
|
|
|
|
|
badSectorToReRead -= (uint)sectorsForOffset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sectorsToReRead = (byte)(sectorsForOffset + 1);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-02 23:58:20 +00:00
|
|
|
if(_supportsPlextorD8 && audioExtents.Contains(badSector))
|
|
|
|
|
{
|
2020-03-07 19:38:41 +00:00
|
|
|
sense = ReadPlextorWithSubchannel(out cmdBuf, out senseBuf, badSectorToReRead, blockSize,
|
|
|
|
|
sectorsToReRead, supportedPlextorSubchannel, out cmdDuration);
|
2020-03-02 23:58:20 +00:00
|
|
|
|
|
|
|
|
totalDuration += cmdDuration;
|
|
|
|
|
}
|
|
|
|
|
else if(readcd)
|
2020-01-01 19:07:52 +00:00
|
|
|
{
|
|
|
|
|
sense = _dev.ReadCd(out cmdBuf, out senseBuf, badSectorToReRead, blockSize, sectorsToReRead,
|
|
|
|
|
MmcSectorTypes.AllTypes, false, false, true, MmcHeaderCodes.AllHeaders, true,
|
|
|
|
|
true, MmcErrorField.None, supportedSubchannel, _dev.Timeout, out cmdDuration);
|
|
|
|
|
|
|
|
|
|
totalDuration += cmdDuration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(sense || _dev.Error)
|
|
|
|
|
{
|
2020-07-13 18:54:41 +01:00
|
|
|
_errorLog?.WriteLine(badSector, _dev.Error, _dev.LastError, senseBuf);
|
|
|
|
|
|
2020-01-01 19:07:52 +00:00
|
|
|
if(!runningPersistent)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
FixedSense? decSense = Sense.DecodeFixed(senseBuf);
|
|
|
|
|
|
|
|
|
|
// MEDIUM ERROR, retry with ignore error below
|
|
|
|
|
if(decSense.HasValue &&
|
|
|
|
|
decSense.Value.ASC == 0x11)
|
|
|
|
|
if(!sectorsNotEvenPartial.Contains(badSector))
|
|
|
|
|
sectorsNotEvenPartial.Add(badSector);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Because one block has been partially used to fix the offset
|
|
|
|
|
if(_fixOffset &&
|
|
|
|
|
audioExtents.Contains(badSector) &&
|
|
|
|
|
offsetBytes != 0)
|
|
|
|
|
{
|
2020-03-06 18:49:45 +00:00
|
|
|
uint blocksToRead = sectorsToReRead;
|
2020-01-01 19:07:52 +00:00
|
|
|
|
2020-03-06 18:49:45 +00:00
|
|
|
FixOffsetData(offsetBytes, sectorSize, sectorsForOffset, supportedSubchannel, ref blocksToRead,
|
|
|
|
|
subSize, ref cmdBuf, blockSize, false);
|
2020-01-01 19:07:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!sense &&
|
|
|
|
|
!_dev.Error)
|
|
|
|
|
{
|
|
|
|
|
_resume.BadBlocks.Remove(badSector);
|
|
|
|
|
extents.Add(badSector);
|
|
|
|
|
UpdateStatus?.Invoke($"Correctly retried sector {badSector} in pass {pass}.");
|
|
|
|
|
_dumpLog.WriteLine("Correctly retried sector {0} in pass {1}.", badSector, pass);
|
|
|
|
|
sectorsNotEvenPartial.Remove(badSector);
|
|
|
|
|
}
|
2020-07-13 18:54:41 +01:00
|
|
|
else
|
|
|
|
|
_errorLog?.WriteLine(badSector, _dev.Error, _dev.LastError, senseBuf);
|
2020-01-01 19:07:52 +00:00
|
|
|
|
|
|
|
|
if(supportedSubchannel != MmcSubchannel.None)
|
|
|
|
|
{
|
|
|
|
|
byte[] data = new byte[sectorSize];
|
|
|
|
|
byte[] sub = new byte[subSize];
|
|
|
|
|
Array.Copy(cmdBuf, 0, data, 0, sectorSize);
|
|
|
|
|
Array.Copy(cmdBuf, sectorSize, sub, 0, subSize);
|
2020-10-23 04:01:55 +01:00
|
|
|
|
|
|
|
|
if(supportsLongSectors)
|
|
|
|
|
_outputPlugin.WriteSectorLong(data, badSector);
|
|
|
|
|
else
|
|
|
|
|
_outputPlugin.WriteSector(Sector.GetUserData(data), badSector);
|
2020-05-05 13:28:34 +01:00
|
|
|
|
2020-07-14 01:06:23 +01:00
|
|
|
bool indexesChanged = Media.CompactDisc.WriteSubchannelToImage(supportedSubchannel,
|
2020-10-23 04:01:55 +01:00
|
|
|
desiredSubchannel, sub, badSector, 1, subLog, isrcs, (byte)track.TrackSequence, ref mcn,
|
|
|
|
|
tracks, subchannelExtents, _fixSubchannelPosition, _outputPlugin, _fixSubchannel,
|
2020-11-04 23:55:24 +00:00
|
|
|
_fixSubchannelCrc, _dumpLog, UpdateStatus, smallestPregapLbaPerTrack, true);
|
2020-05-05 23:25:15 +01:00
|
|
|
|
|
|
|
|
// Set tracks and go back
|
|
|
|
|
if(indexesChanged)
|
|
|
|
|
{
|
|
|
|
|
(_outputPlugin as IWritableOpticalImage).SetTracks(tracks.ToList());
|
|
|
|
|
i--;
|
|
|
|
|
}
|
2020-01-01 19:07:52 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-10-23 04:01:55 +01:00
|
|
|
if(supportsLongSectors)
|
|
|
|
|
_outputPlugin.WriteSectorLong(cmdBuf, badSector);
|
|
|
|
|
else
|
|
|
|
|
_outputPlugin.WriteSector(Sector.GetUserData(cmdBuf), badSector);
|
2020-01-01 19:07:52 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(pass < _retryPasses &&
|
|
|
|
|
!_aborted &&
|
|
|
|
|
_resume.BadBlocks.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
pass++;
|
|
|
|
|
forward = !forward;
|
|
|
|
|
_resume.BadBlocks.Sort();
|
2020-06-14 19:08:12 +01:00
|
|
|
|
|
|
|
|
if(!forward)
|
|
|
|
|
_resume.BadBlocks.Reverse();
|
2020-01-01 19:07:52 +00:00
|
|
|
|
|
|
|
|
goto cdRepeatRetry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EndProgress?.Invoke();
|
|
|
|
|
|
|
|
|
|
// TODO: Enable when underlying images support lead-outs
|
|
|
|
|
/*
|
|
|
|
|
RetryCdLeadOuts(blocks, blockSize, ref currentSpeed, currentTry, extents, ibgLog, ref imageWriteDuration,
|
|
|
|
|
leadOutExtents, ref maxSpeed, mhddLog, ref minSpeed, read6, read10, read12, read16, readcd,
|
|
|
|
|
supportedSubchannel, subSize, ref totalDuration);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Try to ignore read errors, on some drives this allows to recover partial even if damaged data
|
|
|
|
|
if(_persistent && sectorsNotEvenPartial.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var pgMmc = new Modes.ModePage_01_MMC
|
|
|
|
|
{
|
2020-07-20 04:34:16 +01:00
|
|
|
PS = false,
|
|
|
|
|
ReadRetryCount = 255,
|
|
|
|
|
Parameter = 0x01
|
2020-01-01 19:07:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var md = new Modes.DecodedMode
|
|
|
|
|
{
|
2020-07-20 04:34:16 +01:00
|
|
|
Header = new Modes.ModeHeader(),
|
|
|
|
|
Pages = new[]
|
2020-01-01 19:07:52 +00:00
|
|
|
{
|
|
|
|
|
new Modes.ModePage
|
|
|
|
|
{
|
2020-07-20 04:34:16 +01:00
|
|
|
Page = 0x01,
|
|
|
|
|
Subpage = 0x00,
|
|
|
|
|
PageResponse = Modes.EncodeModePage_01_MMC(pgMmc)
|
2020-01-01 19:07:52 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
md6 = Modes.EncodeMode6(md, _dev.ScsiType);
|
|
|
|
|
md10 = Modes.EncodeMode10(md, _dev.ScsiType);
|
|
|
|
|
|
|
|
|
|
_dumpLog.WriteLine("Sending MODE SELECT to drive (ignore error correction).");
|
|
|
|
|
sense = _dev.ModeSelect(md6, out senseBuf, true, false, _dev.Timeout, out _);
|
|
|
|
|
|
|
|
|
|
if(sense)
|
|
|
|
|
sense = _dev.ModeSelect10(md10, out senseBuf, true, false, _dev.Timeout, out _);
|
|
|
|
|
|
|
|
|
|
if(!sense)
|
|
|
|
|
{
|
|
|
|
|
runningPersistent = true;
|
|
|
|
|
|
|
|
|
|
InitProgress?.Invoke();
|
|
|
|
|
|
2020-05-05 23:25:15 +01:00
|
|
|
for(int i = 0; i < sectorsNotEvenPartial.Count; i++)
|
2020-01-01 19:07:52 +00:00
|
|
|
{
|
2020-05-05 23:25:15 +01:00
|
|
|
ulong badSector = sectorsNotEvenPartial[i];
|
|
|
|
|
|
2020-01-01 19:07:52 +00:00
|
|
|
if(_aborted)
|
|
|
|
|
{
|
|
|
|
|
currentTry.Extents = ExtentsConverter.ToMetadata(extents);
|
|
|
|
|
_dumpLog.WriteLine("Aborted!");
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PulseProgress?.Invoke($"Trying to get partial data for sector {badSector}");
|
|
|
|
|
|
2020-05-05 20:26:18 +01:00
|
|
|
Track track = tracks.OrderBy(t => t.TrackStartSector).
|
|
|
|
|
LastOrDefault(t => badSector >= t.TrackStartSector);
|
|
|
|
|
|
2020-01-01 19:07:52 +00:00
|
|
|
if(readcd)
|
|
|
|
|
{
|
|
|
|
|
sense = _dev.ReadCd(out cmdBuf, out senseBuf, (uint)badSector, blockSize, 1,
|
|
|
|
|
MmcSectorTypes.AllTypes, false, false, true, MmcHeaderCodes.AllHeaders,
|
|
|
|
|
true, true, MmcErrorField.None, supportedSubchannel, _dev.Timeout,
|
|
|
|
|
out cmdDuration);
|
|
|
|
|
|
|
|
|
|
totalDuration += cmdDuration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(sense || _dev.Error)
|
2020-07-13 18:54:41 +01:00
|
|
|
{
|
|
|
|
|
_errorLog?.WriteLine(badSector, _dev.Error, _dev.LastError, senseBuf);
|
|
|
|
|
|
2020-01-01 19:07:52 +00:00
|
|
|
continue;
|
2020-07-13 18:54:41 +01:00
|
|
|
}
|
2020-01-01 19:07:52 +00:00
|
|
|
|
|
|
|
|
_dumpLog.WriteLine("Got partial data for sector {0} in pass {1}.", badSector, pass);
|
|
|
|
|
|
|
|
|
|
if(supportedSubchannel != MmcSubchannel.None)
|
|
|
|
|
{
|
|
|
|
|
byte[] data = new byte[sectorSize];
|
|
|
|
|
byte[] sub = new byte[subSize];
|
|
|
|
|
Array.Copy(cmdBuf, 0, data, 0, sectorSize);
|
|
|
|
|
Array.Copy(cmdBuf, sectorSize, sub, 0, subSize);
|
2020-10-23 04:01:55 +01:00
|
|
|
|
|
|
|
|
if(supportsLongSectors)
|
|
|
|
|
_outputPlugin.WriteSectorLong(data, badSector);
|
|
|
|
|
else
|
|
|
|
|
_outputPlugin.WriteSector(Sector.GetUserData(data), badSector);
|
2020-05-05 13:28:34 +01:00
|
|
|
|
2020-07-14 01:06:23 +01:00
|
|
|
bool indexesChanged = Media.CompactDisc.WriteSubchannelToImage(supportedSubchannel,
|
2020-10-23 04:01:55 +01:00
|
|
|
desiredSubchannel, sub, badSector, 1, subLog, isrcs, (byte)track.TrackSequence,
|
|
|
|
|
ref mcn, tracks, subchannelExtents, _fixSubchannelPosition, _outputPlugin,
|
|
|
|
|
_fixSubchannel, _fixSubchannelCrc, _dumpLog, UpdateStatus,
|
2020-11-04 23:55:24 +00:00
|
|
|
smallestPregapLbaPerTrack, true);
|
2020-05-05 23:25:15 +01:00
|
|
|
|
|
|
|
|
// Set tracks and go back
|
|
|
|
|
if(indexesChanged)
|
|
|
|
|
{
|
|
|
|
|
(_outputPlugin as IWritableOpticalImage).SetTracks(tracks.ToList());
|
|
|
|
|
i--;
|
|
|
|
|
}
|
2020-01-01 19:07:52 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-10-23 04:01:55 +01:00
|
|
|
if(supportsLongSectors)
|
|
|
|
|
_outputPlugin.WriteSectorLong(cmdBuf, badSector);
|
|
|
|
|
else
|
|
|
|
|
_outputPlugin.WriteSector(Sector.GetUserData(cmdBuf), badSector);
|
2020-01-01 19:07:52 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EndProgress?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(runningPersistent && currentModePage.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var md = new Modes.DecodedMode
|
|
|
|
|
{
|
2020-07-20 04:34:16 +01:00
|
|
|
Header = new Modes.ModeHeader(),
|
|
|
|
|
Pages = new[]
|
2020-01-01 19:07:52 +00:00
|
|
|
{
|
|
|
|
|
currentModePage.Value
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
md6 = Modes.EncodeMode6(md, _dev.ScsiType);
|
|
|
|
|
md10 = Modes.EncodeMode10(md, _dev.ScsiType);
|
|
|
|
|
|
|
|
|
|
_dumpLog.WriteLine("Sending MODE SELECT to drive (return device to previous status).");
|
|
|
|
|
sense = _dev.ModeSelect(md6, out senseBuf, true, false, _dev.Timeout, out _);
|
|
|
|
|
|
|
|
|
|
if(sense)
|
|
|
|
|
_dev.ModeSelect10(md10, out senseBuf, true, false, _dev.Timeout, out _);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EndProgress?.Invoke();
|
|
|
|
|
}
|
2020-06-13 19:15:27 +01:00
|
|
|
|
|
|
|
|
void RetrySubchannel(bool readcd, uint subSize, MmcSubchannel supportedSubchannel, ref double totalDuration,
|
|
|
|
|
SubchannelLog subLog, MmcSubchannel desiredSubchannel, Track[] tracks,
|
2020-07-18 20:43:37 +01:00
|
|
|
Dictionary<byte, string> isrcs, ref string mcn, HashSet<int> subchannelExtents,
|
|
|
|
|
Dictionary<byte, int> smallestPregapLbaPerTrack)
|
2020-06-13 19:15:27 +01:00
|
|
|
{
|
2020-07-20 07:47:12 +01:00
|
|
|
bool sense = true; // Sense indicator
|
|
|
|
|
byte[] cmdBuf = null; // Data buffer
|
|
|
|
|
double cmdDuration; // Command execution time
|
|
|
|
|
byte[] senseBuf = null; // Sense buffer
|
2020-06-13 19:15:27 +01:00
|
|
|
PlextorSubchannel supportedPlextorSubchannel;
|
|
|
|
|
|
|
|
|
|
if(supportedSubchannel == MmcSubchannel.None ||
|
|
|
|
|
desiredSubchannel == MmcSubchannel.None)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
switch(supportedSubchannel)
|
|
|
|
|
{
|
|
|
|
|
case MmcSubchannel.None:
|
|
|
|
|
supportedPlextorSubchannel = PlextorSubchannel.None;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case MmcSubchannel.Raw:
|
|
|
|
|
supportedPlextorSubchannel = PlextorSubchannel.All;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case MmcSubchannel.Q16:
|
|
|
|
|
supportedPlextorSubchannel = PlextorSubchannel.Q16;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case MmcSubchannel.Rw:
|
|
|
|
|
supportedPlextorSubchannel = PlextorSubchannel.Pack;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
supportedPlextorSubchannel = PlextorSubchannel.None;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(_aborted)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int pass = 1;
|
|
|
|
|
bool forward = true;
|
|
|
|
|
|
|
|
|
|
InitProgress?.Invoke();
|
|
|
|
|
|
|
|
|
|
cdRepeatRetry:
|
|
|
|
|
|
|
|
|
|
_resume.BadSubchannels = new List<int>();
|
2020-06-14 18:42:33 +01:00
|
|
|
_resume.BadSubchannels.AddRange(subchannelExtents);
|
2020-06-13 19:15:27 +01:00
|
|
|
_resume.BadSubchannels.Sort();
|
|
|
|
|
|
|
|
|
|
if(!forward)
|
|
|
|
|
_resume.BadSubchannels.Reverse();
|
|
|
|
|
|
|
|
|
|
int[] tmpArray = _resume.BadSubchannels.ToArray();
|
|
|
|
|
|
2020-07-22 13:20:25 +01:00
|
|
|
foreach(int bs in tmpArray)
|
2020-06-13 19:15:27 +01:00
|
|
|
{
|
2020-07-22 13:20:25 +01:00
|
|
|
uint badSector = (uint)bs;
|
2020-06-13 19:15:27 +01:00
|
|
|
|
|
|
|
|
Track track = tracks.OrderBy(t => t.TrackStartSector).
|
|
|
|
|
LastOrDefault(t => badSector >= t.TrackStartSector);
|
|
|
|
|
|
|
|
|
|
if(_aborted)
|
|
|
|
|
{
|
|
|
|
|
_dumpLog.WriteLine("Aborted!");
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PulseProgress?.
|
|
|
|
|
Invoke($"Retrying sector {badSector} subchannel, pass {pass}, {(forward ? "forward" : "reverse")}");
|
|
|
|
|
|
|
|
|
|
uint startSector = badSector - 2;
|
|
|
|
|
|
|
|
|
|
if(_supportsPlextorD8)
|
|
|
|
|
{
|
|
|
|
|
sense = _dev.PlextorReadCdDa(out cmdBuf, out senseBuf, startSector, subSize, 5,
|
|
|
|
|
supportedPlextorSubchannel, 0, out cmdDuration);
|
|
|
|
|
|
|
|
|
|
totalDuration += cmdDuration;
|
|
|
|
|
}
|
|
|
|
|
else if(readcd)
|
|
|
|
|
{
|
|
|
|
|
sense = _dev.ReadCd(out cmdBuf, out senseBuf, startSector, subSize, 5, MmcSectorTypes.AllTypes,
|
|
|
|
|
false, false, false, MmcHeaderCodes.None, false, false, MmcErrorField.None,
|
|
|
|
|
supportedSubchannel, _dev.Timeout, out cmdDuration);
|
|
|
|
|
|
|
|
|
|
totalDuration += cmdDuration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(sense || _dev.Error)
|
2020-07-13 18:54:41 +01:00
|
|
|
{
|
|
|
|
|
_errorLog?.WriteLine(badSector, _dev.Error, _dev.LastError, senseBuf);
|
|
|
|
|
|
2020-06-13 19:15:27 +01:00
|
|
|
continue;
|
2020-07-13 18:54:41 +01:00
|
|
|
}
|
2020-06-13 19:15:27 +01:00
|
|
|
|
2020-07-14 01:06:23 +01:00
|
|
|
Media.CompactDisc.WriteSubchannelToImage(supportedSubchannel, desiredSubchannel, cmdBuf, badSector, 5,
|
|
|
|
|
subLog, isrcs, (byte)track.TrackSequence, ref mcn, tracks,
|
|
|
|
|
subchannelExtents, _fixSubchannelPosition, _outputPlugin,
|
2020-07-18 20:43:37 +01:00
|
|
|
_fixSubchannel, _fixSubchannelCrc, _dumpLog, UpdateStatus,
|
2020-11-04 23:55:24 +00:00
|
|
|
smallestPregapLbaPerTrack, true);
|
2020-06-13 19:15:27 +01:00
|
|
|
|
2020-07-22 13:20:25 +01:00
|
|
|
if(subchannelExtents.Contains(bs))
|
2020-06-13 19:15:27 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
UpdateStatus?.Invoke($"Correctly retried sector {badSector} subchannel in pass {pass}.");
|
|
|
|
|
_dumpLog.WriteLine("Correctly retried sector {0} subchannel in pass {1}.", badSector, pass);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(pass < _retryPasses &&
|
|
|
|
|
!_aborted &&
|
|
|
|
|
subchannelExtents.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
pass++;
|
|
|
|
|
forward = !forward;
|
|
|
|
|
|
|
|
|
|
goto cdRepeatRetry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EndProgress?.Invoke();
|
|
|
|
|
}
|
2020-01-01 19:07:52 +00:00
|
|
|
}
|
|
|
|
|
}
|