Do not fix offset in CD dumping if sector has not been read correctly.

This commit is contained in:
2020-01-12 21:13:51 +00:00
parent 2486f2e679
commit c5cdb5da80

View File

@@ -229,73 +229,77 @@ namespace DiscImageChef.Core.Devices.Dumping
_dev.Timeout, out cmdDuration);
}
// Because one block has been partially used to fix the offset
if(_fixOffset &&
!inData &&
offsetBytes != 0)
{
int offsetFix = offsetBytes < 0 ? (int)(sectorSize - (offsetBytes * -1)) : offsetBytes;
if(supportedSubchannel != MmcSubchannel.None)
{
// De-interleave subchannel
byte[] data = new byte[sectorSize * blocksToRead];
byte[] sub = new byte[subSize * blocksToRead];
for(int b = 0; b < blocksToRead; b++)
{
Array.Copy(cmdBuf, (int)(0 + (b * blockSize)), data, sectorSize * b, sectorSize);
Array.Copy(cmdBuf, (int)(sectorSize + (b * blockSize)), sub, subSize * b, subSize);
}
if(failedCrossingLeadOut)
{
blocksToRead += (uint)sectorsForOffset;
tmpBuf = new byte[sectorSize * blocksToRead];
Array.Copy(data, 0, tmpBuf, 0, data.Length);
data = tmpBuf;
tmpBuf = new byte[subSize * blocksToRead];
Array.Copy(sub, 0, tmpBuf, 0, sub.Length);
sub = tmpBuf;
}
tmpBuf = new byte[sectorSize * (blocksToRead - sectorsForOffset)];
Array.Copy(data, offsetFix, tmpBuf, 0, tmpBuf.Length);
data = tmpBuf;
blocksToRead -= (uint)sectorsForOffset;
// Re-interleave subchannel
cmdBuf = new byte[blockSize * blocksToRead];
for(int b = 0; b < blocksToRead; b++)
{
Array.Copy(data, sectorSize * b, cmdBuf, (int)(0 + (b * blockSize)), sectorSize);
Array.Copy(sub, subSize * b, cmdBuf, (int)(sectorSize + (b * blockSize)), subSize);
}
}
else
{
if(failedCrossingLeadOut)
{
blocksToRead += (uint)sectorsForOffset;
tmpBuf = new byte[blockSize * blocksToRead];
Array.Copy(cmdBuf, 0, tmpBuf, 0, cmdBuf.Length);
cmdBuf = tmpBuf;
}
tmpBuf = new byte[blockSize * (blocksToRead - sectorsForOffset)];
Array.Copy(cmdBuf, offsetFix, tmpBuf, 0, tmpBuf.Length);
cmdBuf = tmpBuf;
blocksToRead -= (uint)sectorsForOffset;
}
}
if(!sense &&
!_dev.Error)
{
// Because one block has been partially used to fix the offset
if(_fixOffset &&
!inData &&
offsetBytes != 0)
{
int offsetFix = offsetBytes < 0 ? (int)(sectorSize - (offsetBytes * -1)) : offsetBytes;
if(supportedSubchannel != MmcSubchannel.None)
{
// De-interleave subchannel
byte[] data = new byte[sectorSize * blocksToRead];
byte[] sub = new byte[subSize * blocksToRead];
for(int b = 0; b < blocksToRead; b++)
{
Array.Copy(cmdBuf, (int)(0 + (b * blockSize)), data, sectorSize * b,
sectorSize);
Array.Copy(cmdBuf, (int)(sectorSize + (b * blockSize)), sub, subSize * b, subSize);
}
if(failedCrossingLeadOut)
{
blocksToRead += (uint)sectorsForOffset;
tmpBuf = new byte[sectorSize * blocksToRead];
Array.Copy(data, 0, tmpBuf, 0, data.Length);
data = tmpBuf;
tmpBuf = new byte[subSize * blocksToRead];
Array.Copy(sub, 0, tmpBuf, 0, sub.Length);
sub = tmpBuf;
}
tmpBuf = new byte[sectorSize * (blocksToRead - sectorsForOffset)];
Array.Copy(data, offsetFix, tmpBuf, 0, tmpBuf.Length);
data = tmpBuf;
blocksToRead -= (uint)sectorsForOffset;
// Re-interleave subchannel
cmdBuf = new byte[blockSize * blocksToRead];
for(int b = 0; b < blocksToRead; b++)
{
Array.Copy(data, sectorSize * b, cmdBuf, (int)(0 + (b * blockSize)),
sectorSize);
Array.Copy(sub, subSize * b, cmdBuf, (int)(sectorSize + (b * blockSize)), subSize);
}
}
else
{
if(failedCrossingLeadOut)
{
blocksToRead += (uint)sectorsForOffset;
tmpBuf = new byte[blockSize * blocksToRead];
Array.Copy(cmdBuf, 0, tmpBuf, 0, cmdBuf.Length);
cmdBuf = tmpBuf;
}
tmpBuf = new byte[blockSize * (blocksToRead - sectorsForOffset)];
Array.Copy(cmdBuf, offsetFix, tmpBuf, 0, tmpBuf.Length);
cmdBuf = tmpBuf;
blocksToRead -= (uint)sectorsForOffset;
}
}
mhddLog.Write(i, cmdDuration);
ibgLog.Write(i, currentSpeed * 1024);
extents.Add(i, blocksToRead, true);