From c5cdb5da80e6f7247421203f2be431970d3e6f45 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 12 Jan 2020 21:13:51 +0000 Subject: [PATCH] Do not fix offset in CD dumping if sector has not been read correctly. --- .../Devices/Dumping/CompactDisc/Data.cs | 132 +++++++++--------- 1 file changed, 68 insertions(+), 64 deletions(-) diff --git a/DiscImageChef.Core/Devices/Dumping/CompactDisc/Data.cs b/DiscImageChef.Core/Devices/Dumping/CompactDisc/Data.cs index 35fd1749e..cdddc7dbd 100644 --- a/DiscImageChef.Core/Devices/Dumping/CompactDisc/Data.cs +++ b/DiscImageChef.Core/Devices/Dumping/CompactDisc/Data.cs @@ -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);