2020-01-01 18:31:14 +00:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2020-01-01 18:31:14 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
2020-03-11 21:56:55 +00:00
|
|
|
// Filename : Data.cs
|
2020-01-01 18:31:14 +00:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
2020-03-11 21:56:55 +00:00
|
|
|
// Component : CompactDisc dumping.
|
2020-01-01 18:31:14 +00:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2020-03-11 21:56:55 +00:00
|
|
|
// Dumps user data part.
|
2020-01-01 18:31:14 +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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-02-18 10:02:53 +00:00
|
|
|
// Copyright © 2011-2022 Natalia Portillo
|
2020-01-01 18:31:14 +00:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
// ReSharper disable JoinDeclarationAndInitializer
|
|
|
|
|
// ReSharper disable InlineOutVariableDeclaration
|
|
|
|
|
// ReSharper disable TooWideLocalVariableScope
|
|
|
|
|
|
|
|
|
|
namespace Aaru.Core.Devices.Dumping;
|
|
|
|
|
|
2020-01-01 18:31:14 +00:00
|
|
|
using System;
|
2020-05-05 20:26:18 +01:00
|
|
|
using System.Collections.Generic;
|
2020-10-23 04:01:55 +01:00
|
|
|
using System.IO;
|
2020-01-01 23:05:52 +00:00
|
|
|
using System.Linq;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.CommonTypes.Enums;
|
|
|
|
|
using Aaru.CommonTypes.Extents;
|
2020-05-05 23:25:15 +01:00
|
|
|
using Aaru.CommonTypes.Interfaces;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.CommonTypes.Structs;
|
|
|
|
|
using Aaru.Console;
|
2020-02-29 18:03:35 +00:00
|
|
|
using Aaru.Core.Logging;
|
2020-03-05 03:41:02 +00:00
|
|
|
using Aaru.Decoders.CD;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.Decoders.SCSI;
|
|
|
|
|
using Aaru.Devices;
|
2020-01-01 18:31:14 +00:00
|
|
|
using Schemas;
|
2022-04-09 20:27:05 +01:00
|
|
|
using TrackType = Aaru.CommonTypes.Enums.TrackType;
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
partial class Dump
|
2020-01-01 18:31:14 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
/// <summary>Reads all CD user data</summary>
|
|
|
|
|
/// <param name="audioExtents">Extents with audio sectors</param>
|
|
|
|
|
/// <param name="blocks">Total number of positive sectors</param>
|
|
|
|
|
/// <param name="blockSize">Size of the read sector in bytes</param>
|
|
|
|
|
/// <param name="currentSpeed">Current read speed</param>
|
|
|
|
|
/// <param name="currentTry">Current dump hardware try</param>
|
|
|
|
|
/// <param name="extents">Extents</param>
|
|
|
|
|
/// <param name="ibgLog">IMGBurn log</param>
|
|
|
|
|
/// <param name="imageWriteDuration">Duration of image write</param>
|
|
|
|
|
/// <param name="lastSector">Last sector number</param>
|
|
|
|
|
/// <param name="leadOutExtents">Lead-out extents</param>
|
|
|
|
|
/// <param name="maxSpeed">Maximum speed</param>
|
|
|
|
|
/// <param name="mhddLog">MHDD log</param>
|
|
|
|
|
/// <param name="minSpeed">Minimum speed</param>
|
|
|
|
|
/// <param name="newTrim">Is trim a new one?</param>
|
|
|
|
|
/// <param name="nextData">Next cluster of sectors is all data</param>
|
|
|
|
|
/// <param name="offsetBytes">Read offset</param>
|
|
|
|
|
/// <param name="read6">Device supports READ(6)</param>
|
|
|
|
|
/// <param name="read10">Device supports READ(10)</param>
|
|
|
|
|
/// <param name="read12">Device supports READ(12)</param>
|
|
|
|
|
/// <param name="read16">Device supports READ(16)</param>
|
|
|
|
|
/// <param name="readcd">Device supports READ CD</param>
|
|
|
|
|
/// <param name="sectorsForOffset">Sectors needed to fix offset</param>
|
|
|
|
|
/// <param name="subSize">Subchannel size in bytes</param>
|
|
|
|
|
/// <param name="supportedSubchannel">Drive's maximum supported subchannel</param>
|
|
|
|
|
/// <param name="supportsLongSectors">Supports reading EDC and ECC</param>
|
|
|
|
|
/// <param name="totalDuration">Total commands duration</param>
|
|
|
|
|
/// <param name="tracks">Disc tracks</param>
|
|
|
|
|
/// <param name="subLog">Subchannel log</param>
|
|
|
|
|
/// <param name="desiredSubchannel">Subchannel desired to save</param>
|
|
|
|
|
/// <param name="isrcs">List of disc ISRCs</param>
|
|
|
|
|
/// <param name="mcn">Disc media catalogue number</param>
|
|
|
|
|
/// <param name="subchannelExtents">List of subchannels not yet dumped correctly</param>
|
|
|
|
|
/// <param name="smallestPregapLbaPerTrack">List of smallest pregap relative address per track</param>
|
|
|
|
|
void ReadCdData(ExtentsULong audioExtents, ulong blocks, uint blockSize, ref double currentSpeed,
|
|
|
|
|
DumpHardwareType currentTry, ExtentsULong extents, IbgLog ibgLog, ref double imageWriteDuration,
|
|
|
|
|
long lastSector, ExtentsULong leadOutExtents, ref double maxSpeed, MhddLog mhddLog,
|
|
|
|
|
ref double minSpeed, out bool newTrim, bool nextData, int offsetBytes, bool read6, bool read10,
|
|
|
|
|
bool read12, bool read16, bool readcd, int sectorsForOffset, uint subSize,
|
|
|
|
|
MmcSubchannel supportedSubchannel, bool supportsLongSectors, ref double totalDuration,
|
|
|
|
|
Track[] tracks, SubchannelLog subLog, MmcSubchannel desiredSubchannel,
|
|
|
|
|
Dictionary<byte, string> isrcs, ref string mcn, HashSet<int> subchannelExtents,
|
|
|
|
|
Dictionary<byte, int> smallestPregapLbaPerTrack)
|
2020-01-01 18:31:14 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
ulong sectorSpeedStart = 0; // Used to calculate correct speed
|
|
|
|
|
DateTime timeSpeedStart = DateTime.UtcNow; // Time of start for speed calculation
|
|
|
|
|
uint blocksToRead; // How many sectors to read at once
|
2022-03-07 07:36:44 +00:00
|
|
|
var sense = true; // Sense indicator
|
2022-03-06 13:29:38 +00:00
|
|
|
byte[] cmdBuf = null; // Data buffer
|
|
|
|
|
byte[] senseBuf = null; // Sense buffer
|
|
|
|
|
double cmdDuration = 0; // Command execution time
|
|
|
|
|
const uint sectorSize = 2352; // Full sector size
|
|
|
|
|
newTrim = false;
|
|
|
|
|
PlextorSubchannel supportedPlextorSubchannel;
|
|
|
|
|
var outputFormat = _outputPlugin as IWritableImage;
|
|
|
|
|
|
|
|
|
|
switch(supportedSubchannel)
|
2020-01-01 18:31:14 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
case MmcSubchannel.None:
|
|
|
|
|
supportedPlextorSubchannel = PlextorSubchannel.None;
|
2020-03-02 23:58:20 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
case MmcSubchannel.Raw:
|
|
|
|
|
supportedPlextorSubchannel = PlextorSubchannel.Pack;
|
2020-03-02 23:58:20 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
case MmcSubchannel.Q16:
|
|
|
|
|
supportedPlextorSubchannel = PlextorSubchannel.Q16;
|
2020-03-02 23:58:20 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
supportedPlextorSubchannel = PlextorSubchannel.None;
|
2020-03-02 23:58:20 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
InitProgress?.Invoke();
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
int currentReadSpeed = _speed;
|
|
|
|
|
var crossingLeadOut = false;
|
|
|
|
|
var failedCrossingLeadOut = false;
|
|
|
|
|
var skippingLead = false;
|
2020-01-02 23:15:58 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
for(ulong i = _resume.NextBlock; (long)i <= lastSector; i += blocksToRead)
|
|
|
|
|
{
|
|
|
|
|
if(_aborted)
|
2020-01-01 18:31:14 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
currentTry.Extents = ExtentsConverter.ToMetadata(extents);
|
|
|
|
|
UpdateStatus?.Invoke("Aborted!");
|
|
|
|
|
_dumpLog.WriteLine("Aborted!");
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
while(leadOutExtents.Contains(i))
|
|
|
|
|
{
|
|
|
|
|
skippingLead = true;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if((long)i > lastSector)
|
|
|
|
|
break;
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
var firstSectorToRead = (uint)i;
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Track track = tracks.OrderBy(t => t.StartSector).LastOrDefault(t => i >= t.StartSector);
|
2020-01-01 23:05:52 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
blocksToRead = 0;
|
|
|
|
|
bool inData = nextData;
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
for(ulong j = i; j < i + _maximumReadable; j++)
|
|
|
|
|
{
|
|
|
|
|
if(j > (ulong)lastSector)
|
2020-01-01 18:31:14 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
if(!failedCrossingLeadOut &&
|
|
|
|
|
!inData)
|
|
|
|
|
blocksToRead += (uint)sectorsForOffset;
|
2020-01-02 23:15:58 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(sectorsForOffset > 0 &&
|
|
|
|
|
!inData)
|
|
|
|
|
crossingLeadOut = true;
|
2020-01-02 23:15:58 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2020-01-01 23:36:18 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(nextData)
|
|
|
|
|
{
|
|
|
|
|
if(audioExtents.Contains(j))
|
2020-01-01 18:31:14 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
nextData = false;
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
2020-01-01 18:31:14 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
blocksToRead++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(!audioExtents.Contains(j))
|
|
|
|
|
{
|
|
|
|
|
nextData = true;
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
break;
|
2020-01-01 18:31:14 +00:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
blocksToRead++;
|
2020-01-01 18:31:14 +00:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(track.Sequence != 0 &&
|
|
|
|
|
i + blocksToRead - (ulong)sectorsForOffset > track.EndSector + 1)
|
|
|
|
|
blocksToRead = (uint)(track.EndSector + 1 - i + (ulong)sectorsForOffset);
|
2020-01-01 23:05:52 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(blocksToRead == 1 &&
|
|
|
|
|
!inData)
|
|
|
|
|
blocksToRead += (uint)sectorsForOffset;
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(blocksToRead == 0)
|
|
|
|
|
{
|
|
|
|
|
if(!skippingLead)
|
|
|
|
|
i += (ulong)sectorsForOffset;
|
2021-09-05 05:36:05 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
skippingLead = false;
|
2021-09-05 05:36:05 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2021-09-05 05:36:05 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(_fixOffset && !inData)
|
|
|
|
|
if(offsetBytes < 0)
|
2020-01-01 18:31:14 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
if(i == 0)
|
|
|
|
|
firstSectorToRead = uint.MaxValue - (uint)(sectorsForOffset - 1); // -1
|
|
|
|
|
else
|
|
|
|
|
firstSectorToRead -= (uint)sectorsForOffset;
|
2020-07-18 13:59:22 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(blocksToRead <= sectorsForOffset)
|
|
|
|
|
blocksToRead += (uint)sectorsForOffset;
|
2020-01-01 18:31:14 +00:00
|
|
|
}
|
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
switch(inData)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
2022-11-13 19:38:03 +00:00
|
|
|
case false when currentReadSpeed == 0xFFFF:
|
|
|
|
|
_dumpLog.WriteLine("Setting speed to 8x for audio reading.");
|
|
|
|
|
UpdateStatus?.Invoke("Setting speed to 8x for audio reading.");
|
2020-03-03 03:04:01 +00:00
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
_dev.SetCdSpeed(out _, RotationalControl.ClvAndImpureCav, 1416, 0, _dev.Timeout, out _);
|
2020-03-03 03:04:01 +00:00
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
currentReadSpeed = 1200;
|
2020-03-03 03:04:01 +00:00
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
break;
|
|
|
|
|
case true when currentReadSpeed != _speed:
|
|
|
|
|
{
|
|
|
|
|
_dumpLog.WriteLine($"Setting speed to {(_speed == 0xFFFF ? "MAX for data reading" : $"{_speed}x")
|
|
|
|
|
}.");
|
2020-03-04 22:58:34 +00:00
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
UpdateStatus?.Invoke($"Setting speed to {(_speed == 0xFFFF ? "MAX for data reading" : $"{_speed}x")
|
|
|
|
|
}.");
|
2020-03-03 03:04:01 +00:00
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
_speed *= _speedMultiplier;
|
2020-03-03 03:04:01 +00:00
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
if(_speed is 0 or > 0xFFFF)
|
|
|
|
|
_speed = 0xFFFF;
|
2020-03-03 03:04:01 +00:00
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
currentReadSpeed = _speed;
|
2020-04-03 02:45:15 +01:00
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
_dev.SetCdSpeed(out _, RotationalControl.ClvAndImpureCav, (ushort)_speed, 0, _dev.Timeout, out _);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
2020-03-03 03:04:01 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(inData && crossingLeadOut)
|
|
|
|
|
{
|
|
|
|
|
firstSectorToRead = (uint)i;
|
|
|
|
|
blocksToRead = (uint)(lastSector - firstSectorToRead) + 1;
|
|
|
|
|
crossingLeadOut = false;
|
|
|
|
|
}
|
2020-04-24 13:29:50 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(currentSpeed > maxSpeed &&
|
|
|
|
|
currentSpeed > 0)
|
|
|
|
|
maxSpeed = currentSpeed;
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(currentSpeed < minSpeed &&
|
|
|
|
|
currentSpeed > 0)
|
|
|
|
|
minSpeed = currentSpeed;
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
UpdateProgress?.Invoke($"Reading sector {i} of {blocks} ({currentSpeed:F3} MiB/sec.)", (long)i,
|
|
|
|
|
(long)blocks);
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(crossingLeadOut &&
|
|
|
|
|
failedCrossingLeadOut &&
|
|
|
|
|
blocksToRead > 1)
|
|
|
|
|
blocksToRead--;
|
2020-06-14 15:13:50 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(_supportsPlextorD8 && !inData)
|
|
|
|
|
{
|
2022-03-07 07:36:44 +00:00
|
|
|
sense = ReadPlextorWithSubchannel(out cmdBuf, out senseBuf, firstSectorToRead, blockSize, blocksToRead,
|
|
|
|
|
supportedPlextorSubchannel, out cmdDuration);
|
2020-03-02 23:58:20 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
totalDuration += cmdDuration;
|
|
|
|
|
}
|
|
|
|
|
else if(readcd)
|
|
|
|
|
{
|
|
|
|
|
if(inData)
|
2020-01-01 18:31:14 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
sense = _dev.ReadCd(out cmdBuf, out senseBuf, firstSectorToRead, blockSize, blocksToRead,
|
2022-03-07 07:36:44 +00:00
|
|
|
MmcSectorTypes.AllTypes, false, false, true, MmcHeaderCodes.AllHeaders, true,
|
|
|
|
|
true, MmcErrorField.None, supportedSubchannel, _dev.Timeout, out cmdDuration);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
if(sense)
|
2021-08-03 21:14:59 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
DecodedSense? decSense = Sense.Decode(senseBuf);
|
2021-08-03 21:14:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// Try to workaround firmware
|
|
|
|
|
if(decSense?.ASC == 0x64)
|
2021-08-03 21:14:59 +01:00
|
|
|
{
|
2022-03-07 07:36:44 +00:00
|
|
|
var goBackTrackTypeChange = false;
|
2021-08-03 21:14:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// Go one for one as the drive does not tell us which one failed
|
2022-03-07 07:36:44 +00:00
|
|
|
for(var bi = 0; bi < blocksToRead; bi++)
|
2021-08-03 21:14:59 +01:00
|
|
|
{
|
2022-03-07 07:36:44 +00:00
|
|
|
sense = _dev.ReadCd(out cmdBuf, out senseBuf, (uint)(firstSectorToRead + bi), blockSize,
|
|
|
|
|
1, MmcSectorTypes.AllTypes, false, false, true,
|
2022-03-06 13:29:38 +00:00
|
|
|
MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None,
|
|
|
|
|
supportedSubchannel, _dev.Timeout, out double cmdDuration2);
|
2021-09-05 19:09:22 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
cmdDuration += cmdDuration2;
|
2021-09-05 19:09:22 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(!sense &&
|
|
|
|
|
cmdBuf[0] == 0x00 &&
|
|
|
|
|
cmdBuf[1] == 0xFF &&
|
|
|
|
|
cmdBuf[2] == 0xFF &&
|
|
|
|
|
cmdBuf[3] == 0xFF &&
|
|
|
|
|
cmdBuf[4] == 0xFF &&
|
|
|
|
|
cmdBuf[5] == 0xFF &&
|
|
|
|
|
cmdBuf[6] == 0xFF &&
|
|
|
|
|
cmdBuf[7] == 0xFF &&
|
|
|
|
|
cmdBuf[8] == 0xFF &&
|
|
|
|
|
cmdBuf[9] == 0xFF &&
|
|
|
|
|
cmdBuf[10] == 0xFF &&
|
|
|
|
|
cmdBuf[11] == 0x00)
|
2021-09-05 19:09:22 +01:00
|
|
|
continue;
|
2021-08-03 21:14:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// Set those sectors as audio
|
|
|
|
|
for(int bip = bi; bip < blocksToRead; bip++)
|
|
|
|
|
audioExtents.Add((ulong)(firstSectorToRead + bip));
|
2021-08-03 21:14:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
goBackTrackTypeChange = true;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Go back to read again
|
|
|
|
|
if(goBackTrackTypeChange)
|
2021-08-03 21:14:59 +01:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
blocksToRead = 0;
|
|
|
|
|
nextData = true;
|
2021-08-03 21:14:59 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
continue;
|
2021-08-03 21:14:59 +01:00
|
|
|
}
|
2022-04-09 16:46:57 +01:00
|
|
|
|
|
|
|
|
// Drive definitively didn't like to read everything so just do something clever...
|
|
|
|
|
|
|
|
|
|
// Try again
|
|
|
|
|
sense = _dev.ReadCd(out cmdBuf, out senseBuf, firstSectorToRead, blockSize, blocksToRead,
|
|
|
|
|
MmcSectorTypes.AllTypes, false, false, true, MmcHeaderCodes.AllHeaders,
|
|
|
|
|
true, true, MmcErrorField.None, supportedSubchannel, _dev.Timeout,
|
|
|
|
|
out cmdDuration);
|
|
|
|
|
|
|
|
|
|
if(sense)
|
|
|
|
|
|
|
|
|
|
// Try reading one less every time
|
|
|
|
|
for(uint bi = blocksToRead; bi > 0; bi--)
|
|
|
|
|
{
|
|
|
|
|
sense = _dev.ReadCd(out cmdBuf, out senseBuf, firstSectorToRead, blockSize, bi,
|
|
|
|
|
MmcSectorTypes.AllTypes, false, false, true,
|
|
|
|
|
MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None,
|
|
|
|
|
supportedSubchannel, _dev.Timeout, out cmdDuration);
|
|
|
|
|
|
|
|
|
|
if(sense)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
blocksToRead = bi;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-08-03 21:14:59 +01:00
|
|
|
}
|
|
|
|
|
}
|
2020-01-01 18:31:14 +00:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
else
|
2020-01-01 18:31:14 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
sense = _dev.ReadCd(out cmdBuf, out senseBuf, firstSectorToRead, blockSize, blocksToRead,
|
|
|
|
|
MmcSectorTypes.Cdda, false, false, false, MmcHeaderCodes.None, true, false,
|
|
|
|
|
MmcErrorField.None, supportedSubchannel, _dev.Timeout, out cmdDuration);
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(sense)
|
2020-03-05 03:41:02 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
DecodedSense? decSense = Sense.Decode(senseBuf);
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// Try to workaround firmware
|
2022-03-07 07:36:44 +00:00
|
|
|
if(decSense?.ASC == 0x11 && decSense?.ASCQ == 0x05 ||
|
2022-03-06 13:29:38 +00:00
|
|
|
decSense?.ASC == 0x64)
|
2020-03-05 03:41:02 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
sense = _dev.ReadCd(out cmdBuf, out _, firstSectorToRead, blockSize, blocksToRead,
|
2022-03-07 07:36:44 +00:00
|
|
|
MmcSectorTypes.AllTypes, false, false, true, MmcHeaderCodes.AllHeaders,
|
|
|
|
|
true, true, MmcErrorField.None, supportedSubchannel, _dev.Timeout,
|
|
|
|
|
out double cmdDuration2);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
cmdDuration += cmdDuration2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-07 20:05:17 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
totalDuration += cmdDuration;
|
|
|
|
|
}
|
|
|
|
|
else if(read16)
|
2022-03-07 07:36:44 +00:00
|
|
|
sense = _dev.Read16(out cmdBuf, out senseBuf, 0, false, false, false, firstSectorToRead, blockSize, 0,
|
|
|
|
|
blocksToRead, false, _dev.Timeout, out cmdDuration);
|
2022-03-06 13:29:38 +00:00
|
|
|
else if(read12)
|
|
|
|
|
sense = _dev.Read12(out cmdBuf, out senseBuf, 0, false, false, false, false, firstSectorToRead,
|
|
|
|
|
blockSize, 0, blocksToRead, false, _dev.Timeout, out cmdDuration);
|
|
|
|
|
else if(read10)
|
|
|
|
|
sense = _dev.Read10(out cmdBuf, out senseBuf, 0, false, false, false, false, firstSectorToRead,
|
|
|
|
|
blockSize, 0, (ushort)blocksToRead, _dev.Timeout, out cmdDuration);
|
|
|
|
|
else if(read6)
|
|
|
|
|
sense = _dev.Read6(out cmdBuf, out senseBuf, firstSectorToRead, blockSize, (byte)blocksToRead,
|
|
|
|
|
_dev.Timeout, out cmdDuration);
|
2020-03-07 20:05:17 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
double elapsed;
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// Overcome the track mode change drive error
|
|
|
|
|
if(inData &&
|
|
|
|
|
!nextData &&
|
|
|
|
|
sense)
|
|
|
|
|
{
|
|
|
|
|
for(uint r = 0; r < blocksToRead; r++)
|
|
|
|
|
{
|
|
|
|
|
UpdateProgress?.Invoke($"Reading sector {i + r} of {blocks} ({currentSpeed:F3} MiB/sec.)",
|
|
|
|
|
(long)i + r, (long)blocks);
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(_supportsPlextorD8)
|
|
|
|
|
{
|
2022-03-07 07:36:44 +00:00
|
|
|
var adjustment = 0;
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(offsetBytes < 0)
|
|
|
|
|
adjustment = -sectorsForOffset;
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
sense = ReadPlextorWithSubchannel(out cmdBuf, out senseBuf,
|
|
|
|
|
(uint)(firstSectorToRead + r + adjustment), blockSize,
|
|
|
|
|
(uint)sectorsForOffset + 1, supportedPlextorSubchannel,
|
|
|
|
|
out cmdDuration);
|
2020-03-07 20:05:17 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
totalDuration += cmdDuration;
|
|
|
|
|
|
|
|
|
|
if(!sense)
|
2020-03-05 03:41:02 +00:00
|
|
|
{
|
2022-03-07 07:36:44 +00:00
|
|
|
var sectorsForFix = (uint)(1 + sectorsForOffset);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
FixOffsetData(offsetBytes, sectorSize, sectorsForOffset, supportedSubchannel,
|
|
|
|
|
ref sectorsForFix, subSize, ref cmdBuf, blockSize, false);
|
|
|
|
|
|
|
|
|
|
// TODO: Implement sector validity
|
|
|
|
|
cmdBuf = Sector.Scramble(cmdBuf);
|
2020-03-05 03:41:02 +00:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
|
|
|
|
else if(readcd)
|
|
|
|
|
{
|
|
|
|
|
sense = _dev.ReadCd(out cmdBuf, out senseBuf, (uint)(i + r), blockSize, 1,
|
|
|
|
|
MmcSectorTypes.AllTypes, false, false, true, MmcHeaderCodes.AllHeaders,
|
|
|
|
|
true, true, MmcErrorField.None, supportedSubchannel, _dev.Timeout,
|
|
|
|
|
out cmdDuration);
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
totalDuration += cmdDuration;
|
|
|
|
|
}
|
|
|
|
|
else if(read16)
|
|
|
|
|
sense = _dev.Read16(out cmdBuf, out senseBuf, 0, false, true, false, i + r, blockSize, 0, 1,
|
|
|
|
|
false, _dev.Timeout, out cmdDuration);
|
|
|
|
|
else if(read12)
|
|
|
|
|
sense = _dev.Read12(out cmdBuf, out senseBuf, 0, false, true, false, false, (uint)(i + r),
|
|
|
|
|
blockSize, 0, 1, false, _dev.Timeout, out cmdDuration);
|
|
|
|
|
else if(read10)
|
|
|
|
|
sense = _dev.Read10(out cmdBuf, out senseBuf, 0, false, true, false, false, (uint)(i + r),
|
|
|
|
|
blockSize, 0, 1, _dev.Timeout, out cmdDuration);
|
|
|
|
|
else if(read6)
|
|
|
|
|
sense = _dev.Read6(out cmdBuf, out senseBuf, (uint)(i + r), blockSize, 1, _dev.Timeout,
|
|
|
|
|
out cmdDuration);
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(!sense &&
|
|
|
|
|
!_dev.Error)
|
|
|
|
|
{
|
|
|
|
|
mhddLog.Write(i + r, cmdDuration);
|
|
|
|
|
ibgLog.Write(i + r, currentSpeed * 1024);
|
|
|
|
|
extents.Add(i + r, 1, true);
|
|
|
|
|
DateTime writeStart = DateTime.Now;
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(supportedSubchannel != MmcSubchannel.None)
|
|
|
|
|
{
|
2022-03-07 07:36:44 +00:00
|
|
|
var data = new byte[sectorSize];
|
|
|
|
|
var sub = new byte[subSize];
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Array.Copy(cmdBuf, 0, data, 0, sectorSize);
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
Array.Copy(cmdBuf, sectorSize, sub, 0, subSize);
|
2020-10-23 04:01:55 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(supportsLongSectors)
|
|
|
|
|
outputFormat.WriteSectorsLong(data, i + r, 1);
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-03-07 07:36:44 +00:00
|
|
|
var cooked = new MemoryStream();
|
|
|
|
|
var sector = new byte[sectorSize];
|
2020-10-23 04:01:55 +01:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
for(var b = 0; b < blocksToRead; b++)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
2022-03-07 07:36:44 +00:00
|
|
|
Array.Copy(cmdBuf, (int)(0 + b * blockSize), sector, 0, sectorSize);
|
2022-03-06 13:29:38 +00:00
|
|
|
byte[] cookedSector = Sector.GetUserData(sector);
|
|
|
|
|
cooked.Write(cookedSector, 0, cookedSector.Length);
|
2020-10-23 04:01:55 +01:00
|
|
|
}
|
2020-05-05 13:28:34 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
outputFormat.WriteSectors(cooked.ToArray(), i, blocksToRead);
|
|
|
|
|
}
|
2020-05-05 23:25:15 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
bool indexesChanged = Media.CompactDisc.WriteSubchannelToImage(supportedSubchannel,
|
2022-03-07 07:36:44 +00:00
|
|
|
desiredSubchannel, sub, i + r, 1, subLog, isrcs, (byte)track.Sequence, ref mcn,
|
|
|
|
|
tracks, subchannelExtents, _fixSubchannelPosition,
|
|
|
|
|
outputFormat as IWritableOpticalImage, _fixSubchannel, _fixSubchannelCrc, _dumpLog,
|
2022-04-09 20:27:05 +01:00
|
|
|
UpdateStatus, smallestPregapLbaPerTrack, true, out List<ulong> newPregapSectors);
|
2020-05-05 23:25:15 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// Set tracks and go back
|
|
|
|
|
if(indexesChanged)
|
|
|
|
|
{
|
|
|
|
|
(outputFormat as IWritableOpticalImage).SetTracks(tracks.ToList());
|
2022-04-09 20:27:05 +01:00
|
|
|
|
|
|
|
|
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);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
continue;
|
2020-03-05 03:41:02 +00:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(supportsLongSectors)
|
|
|
|
|
outputFormat.WriteSectorsLong(cmdBuf, i + r, 1);
|
2020-03-05 03:41:02 +00:00
|
|
|
else
|
|
|
|
|
{
|
2022-03-07 07:36:44 +00:00
|
|
|
var cooked = new MemoryStream();
|
|
|
|
|
var sector = new byte[sectorSize];
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
for(var b = 0; b < blocksToRead; b++)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
Array.Copy(cmdBuf, (int)(b * sectorSize), sector, 0, sectorSize);
|
|
|
|
|
byte[] cookedSector = Sector.GetUserData(sector);
|
|
|
|
|
cooked.Write(cookedSector, 0, cookedSector.Length);
|
2020-03-05 03:41:02 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
outputFormat.WriteSectors(cooked.ToArray(), i, blocksToRead);
|
|
|
|
|
}
|
2020-03-05 03:41:02 +00:00
|
|
|
}
|
2020-07-13 18:54:41 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
imageWriteDuration += (DateTime.Now - writeStart).TotalSeconds;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_errorLog?.WriteLine(i + r, _dev.Error, _dev.LastError, senseBuf);
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// Write empty data
|
|
|
|
|
DateTime writeStart = DateTime.Now;
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(supportedSubchannel != MmcSubchannel.None)
|
|
|
|
|
{
|
|
|
|
|
outputFormat.WriteSectorsLong(new byte[sectorSize], i + r, 1);
|
|
|
|
|
|
|
|
|
|
if(desiredSubchannel != MmcSubchannel.None)
|
|
|
|
|
outputFormat.WriteSectorsTag(new byte[subSize], i + r, 1,
|
|
|
|
|
SectorTagType.CdSectorSubchannel);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(supportsLongSectors)
|
|
|
|
|
outputFormat.WriteSectorsLong(new byte[blockSize], i + r, 1);
|
2020-03-05 03:41:02 +00:00
|
|
|
else
|
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
if(cmdBuf.Length % sectorSize == 0)
|
|
|
|
|
outputFormat.WriteSectors(new byte[2048], i + r, 1);
|
2020-03-05 03:41:02 +00:00
|
|
|
else
|
2022-03-06 13:29:38 +00:00
|
|
|
outputFormat.WriteSectorsLong(new byte[blockSize], i + r, 1);
|
2020-03-05 03:41:02 +00:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
imageWriteDuration += (DateTime.Now - writeStart).TotalSeconds;
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
_resume.BadBlocks.Add(i + r);
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
AaruConsole.DebugWriteLine("Dump-Media", "READ error:\n{0}", Sense.PrettifySense(senseBuf));
|
|
|
|
|
mhddLog.Write(i + r, cmdDuration < 500 ? 65535 : cmdDuration);
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ibgLog.Write(i + r, 0);
|
|
|
|
|
_dumpLog.WriteLine("Skipping {0} blocks from errored block {1}.", 1, i + r);
|
|
|
|
|
newTrim = true;
|
|
|
|
|
}
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
sectorSpeedStart += r;
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
_resume.NextBlock = i + r;
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
elapsed = (DateTime.UtcNow - timeSpeedStart).TotalSeconds;
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(elapsed <= 0)
|
|
|
|
|
continue;
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
currentSpeed = sectorSpeedStart * blockSize / (1048576 * elapsed);
|
|
|
|
|
sectorSpeedStart = 0;
|
|
|
|
|
timeSpeedStart = DateTime.UtcNow;
|
|
|
|
|
}
|
2020-03-05 03:41:02 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!sense &&
|
|
|
|
|
!_dev.Error)
|
|
|
|
|
{
|
|
|
|
|
if(crossingLeadOut && failedCrossingLeadOut)
|
|
|
|
|
{
|
2022-03-07 07:36:44 +00:00
|
|
|
var tmp = new byte[cmdBuf.Length + blockSize];
|
2022-03-06 13:29:38 +00:00
|
|
|
Array.Copy(cmdBuf, 0, tmp, 0, cmdBuf.Length);
|
2020-03-05 03:41:02 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// Because one block has been partially used to fix the offset
|
|
|
|
|
if(_fixOffset &&
|
|
|
|
|
!inData &&
|
|
|
|
|
offsetBytes != 0)
|
|
|
|
|
FixOffsetData(offsetBytes, sectorSize, sectorsForOffset, supportedSubchannel, ref blocksToRead,
|
|
|
|
|
subSize, ref cmdBuf, blockSize, failedCrossingLeadOut);
|
|
|
|
|
|
|
|
|
|
mhddLog.Write(i, cmdDuration);
|
|
|
|
|
ibgLog.Write(i, currentSpeed * 1024);
|
|
|
|
|
extents.Add(i, blocksToRead, true);
|
|
|
|
|
DateTime writeStart = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
if(supportedSubchannel != MmcSubchannel.None)
|
2020-01-01 18:31:14 +00:00
|
|
|
{
|
2022-03-07 07:36:44 +00:00
|
|
|
var data = new byte[sectorSize * blocksToRead];
|
|
|
|
|
var sub = new byte[subSize * blocksToRead];
|
2020-06-14 15:13:50 +01:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
for(var b = 0; b < blocksToRead; b++)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
2022-03-07 07:36:44 +00:00
|
|
|
Array.Copy(cmdBuf, (int)(0 + b * blockSize), data, sectorSize * b, sectorSize);
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
Array.Copy(cmdBuf, (int)(sectorSize + b * blockSize), sub, subSize * b, subSize);
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(supportsLongSectors)
|
|
|
|
|
outputFormat.WriteSectorsLong(data, i, blocksToRead);
|
|
|
|
|
else
|
2020-01-01 18:31:14 +00:00
|
|
|
{
|
2022-03-07 07:36:44 +00:00
|
|
|
var cooked = new MemoryStream();
|
|
|
|
|
var sector = new byte[sectorSize];
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
for(var b = 0; b < blocksToRead; b++)
|
2020-01-01 18:31:14 +00:00
|
|
|
{
|
2022-03-07 07:36:44 +00:00
|
|
|
Array.Copy(cmdBuf, (int)(0 + b * blockSize), sector, 0, sectorSize);
|
2022-03-06 13:29:38 +00:00
|
|
|
byte[] cookedSector = Sector.GetUserData(sector);
|
|
|
|
|
cooked.Write(cookedSector, 0, cookedSector.Length);
|
2020-01-01 18:31:14 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
outputFormat.WriteSectors(cooked.ToArray(), i, blocksToRead);
|
|
|
|
|
}
|
2020-05-05 13:28:34 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
bool indexesChanged = Media.CompactDisc.WriteSubchannelToImage(supportedSubchannel,
|
2022-03-07 07:36:44 +00:00
|
|
|
desiredSubchannel, sub, i, blocksToRead, subLog, isrcs, (byte)track.Sequence, ref mcn,
|
|
|
|
|
tracks, subchannelExtents, _fixSubchannelPosition, outputFormat as IWritableOpticalImage,
|
2022-04-09 20:27:05 +01:00
|
|
|
_fixSubchannel, _fixSubchannelCrc, _dumpLog, UpdateStatus, smallestPregapLbaPerTrack, true,
|
|
|
|
|
out List<ulong> newPregapSectors);
|
2020-05-05 23:25:15 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// Set tracks and go back
|
|
|
|
|
if(indexesChanged)
|
|
|
|
|
{
|
|
|
|
|
(outputFormat as IWritableOpticalImage).SetTracks(tracks.ToList());
|
2022-04-09 20:27:05 +01:00
|
|
|
|
|
|
|
|
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);
|
2020-05-05 23:25:15 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
continue;
|
2020-01-01 18:31:14 +00:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(supportsLongSectors)
|
|
|
|
|
outputFormat.WriteSectorsLong(cmdBuf, i, blocksToRead);
|
2020-01-01 18:31:14 +00:00
|
|
|
else
|
|
|
|
|
{
|
2022-03-07 07:36:44 +00:00
|
|
|
var cooked = new MemoryStream();
|
|
|
|
|
var sector = new byte[sectorSize];
|
2020-10-23 04:01:55 +01:00
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
for(var b = 0; b < blocksToRead; b++)
|
2022-03-06 13:29:38 +00:00
|
|
|
{
|
|
|
|
|
Array.Copy(cmdBuf, (int)(b * sectorSize), sector, 0, sectorSize);
|
|
|
|
|
byte[] cookedSector = Sector.GetUserData(sector);
|
|
|
|
|
cooked.Write(cookedSector, 0, cookedSector.Length);
|
2020-01-01 18:31:14 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
outputFormat.WriteSectors(cooked.ToArray(), i, blocksToRead);
|
|
|
|
|
}
|
2020-01-01 18:31:14 +00:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
imageWriteDuration += (DateTime.Now - writeStart).TotalSeconds;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(crossingLeadOut && Sense.Decode(senseBuf)?.ASC == 0x21)
|
2020-01-01 18:31:14 +00:00
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
if(failedCrossingLeadOut)
|
|
|
|
|
break;
|
2020-07-14 14:24:44 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
failedCrossingLeadOut = true;
|
|
|
|
|
blocksToRead = 0;
|
2020-01-02 23:15:58 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2020-01-02 23:15:58 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
_errorLog?.WriteLine(firstSectorToRead, _dev.Error, _dev.LastError, senseBuf);
|
2020-07-13 18:54:41 +01:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// TODO: Reset device after X errors
|
|
|
|
|
if(_stopOnError)
|
|
|
|
|
return; // TODO: Return more cleanly
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(i + _skip > blocks)
|
|
|
|
|
_skip = (uint)(blocks - i);
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
// Write empty data
|
|
|
|
|
DateTime writeStart = DateTime.Now;
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(supportedSubchannel != MmcSubchannel.None)
|
|
|
|
|
{
|
|
|
|
|
outputFormat.WriteSectorsLong(new byte[sectorSize * _skip], i, _skip);
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(desiredSubchannel != MmcSubchannel.None)
|
|
|
|
|
outputFormat.WriteSectorsTag(new byte[subSize * _skip], i, _skip,
|
|
|
|
|
SectorTagType.CdSectorSubchannel);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(supportsLongSectors)
|
|
|
|
|
outputFormat.WriteSectorsLong(new byte[blockSize * _skip], i, _skip);
|
2020-01-01 18:31:14 +00:00
|
|
|
else
|
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
if(cmdBuf.Length % sectorSize == 0)
|
|
|
|
|
outputFormat.WriteSectors(new byte[2048 * _skip], i, _skip);
|
2020-01-01 18:31:14 +00:00
|
|
|
else
|
2022-03-06 13:29:38 +00:00
|
|
|
outputFormat.WriteSectorsLong(new byte[blockSize * _skip], i, _skip);
|
2020-01-01 18:31:14 +00:00
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
}
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
imageWriteDuration += (DateTime.Now - writeStart).TotalSeconds;
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
for(ulong b = i; b < i + _skip; b++)
|
|
|
|
|
_resume.BadBlocks.Add(b);
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
AaruConsole.DebugWriteLine("Dump-Media", "READ error:\n{0}", Sense.PrettifySense(senseBuf));
|
|
|
|
|
mhddLog.Write(i, cmdDuration < 500 ? 65535 : cmdDuration);
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
ibgLog.Write(i, 0);
|
|
|
|
|
_dumpLog.WriteLine("Skipping {0} blocks from errored block {1}.", _skip, i);
|
|
|
|
|
i += _skip - blocksToRead;
|
|
|
|
|
newTrim = true;
|
|
|
|
|
}
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
sectorSpeedStart += blocksToRead;
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
_resume.NextBlock = i + blocksToRead;
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
elapsed = (DateTime.UtcNow - timeSpeedStart).TotalSeconds;
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(elapsed <= 0)
|
|
|
|
|
continue;
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
currentSpeed = sectorSpeedStart * blockSize / (1048576 * elapsed);
|
|
|
|
|
sectorSpeedStart = 0;
|
|
|
|
|
timeSpeedStart = DateTime.UtcNow;
|
|
|
|
|
}
|
2020-01-01 18:31:14 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
EndProgress?.Invoke();
|
2020-01-02 23:15:58 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
_resume.BadBlocks = _resume.BadBlocks.Distinct().ToList();
|
2020-11-03 01:40:10 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
if(!failedCrossingLeadOut)
|
|
|
|
|
return;
|
2020-01-02 23:15:58 +00:00
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
_dumpLog.WriteLine("Failed crossing into Lead-Out, dump may not be correct.");
|
|
|
|
|
UpdateStatus?.Invoke("Failed crossing into Lead-Out, dump may not be correct.");
|
2020-01-01 18:31:14 +00:00
|
|
|
}
|
|
|
|
|
}
|