Allocate SENSE buffer only once.

This commit is contained in:
2025-08-22 19:57:09 +01:00
parent 8e2fdd91a6
commit e4f55d3b3c
73 changed files with 1892 additions and 2565 deletions

View File

@@ -148,15 +148,15 @@ partial class Dump
bool cdiReadyReadAsAudio, int offsetBytes, int sectorsForOffset,
Dictionary<byte, int> smallestPregapLbaPerTrack)
{
ulong sectorSpeedStart = 0; // Used to calculate correct speed
bool sense; // Sense indicator
byte[] cmdBuf; // Data buffer
byte[] senseBuf; // Sense buffer
double cmdDuration; // Command execution time
const uint sectorSize = 2352; // Full sector size
Track firstTrack = tracks.FirstOrDefault();
uint blocksToRead; // How many sectors to read at once
var outputOptical = _outputPlugin as IWritableOpticalImage;
ulong sectorSpeedStart = 0; // Used to calculate correct speed
bool sense; // Sense indicator
byte[] cmdBuf; // Data buffer
ReadOnlySpan<byte> senseBuf; // Sense buffer
double cmdDuration; // Command execution time
const uint sectorSize = 2352; // Full sector size
Track firstTrack = tracks.FirstOrDefault();
uint blocksToRead; // How many sectors to read at once
var outputOptical = _outputPlugin as IWritableOpticalImage;
if(firstTrack is null) return;
@@ -337,7 +337,7 @@ partial class Dump
}
else
{
_errorLog?.WriteLine(i + r, _dev.Error, _dev.LastError, senseBuf);
_errorLog?.WriteLine(i + r, _dev.Error, _dev.LastError, senseBuf.ToArray());
leadOutExtents.Add(i + r, firstTrack.EndSector);
@@ -469,7 +469,7 @@ partial class Dump
}
else
{
_errorLog?.WriteLine(i, _dev.Error, _dev.LastError, senseBuf);
_errorLog?.WriteLine(i, _dev.Error, _dev.LastError, senseBuf.ToArray());
_resume.NextBlock = firstTrack.EndSector + 1;

View File

@@ -101,13 +101,13 @@ partial class Dump
Dictionary<byte, string> isrcs, ref string mcn, HashSet<int> subchannelExtents,
Dictionary<byte, int> smallestPregapLbaPerTrack)
{
ulong sectorSpeedStart = 0; // Used to calculate correct speed
uint blocksToRead; // How many sectors to read at once
bool sense = true; // Sense indicator
byte[] cmdBuf = null; // Data buffer
byte[] senseBuf = null; // Sense buffer
double cmdDuration = 0; // Command execution time
const uint sectorSize = 2352; // Full sector size
ulong sectorSpeedStart = 0; // Used to calculate correct speed
uint blocksToRead; // How many sectors to read at once
bool sense = true; // Sense indicator
byte[] cmdBuf = null; // Data buffer
ReadOnlySpan<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;
@@ -859,7 +859,7 @@ partial class Dump
}
else
{
_errorLog?.WriteLine(i + r, _dev.Error, _dev.LastError, senseBuf);
_errorLog?.WriteLine(i + r, _dev.Error, _dev.LastError, senseBuf.ToArray());
// Write empty data
_writeStopwatch.Restart();
@@ -1054,7 +1054,7 @@ partial class Dump
continue;
}
_errorLog?.WriteLine(firstSectorToRead, _dev.Error, _dev.LastError, senseBuf);
_errorLog?.WriteLine(firstSectorToRead, _dev.Error, _dev.LastError, senseBuf.ToArray());
// TODO: Reset device after X errors
if(_stopOnError) return; // TODO: Return more cleanly

View File

@@ -80,13 +80,13 @@ partial class Dump
ref string mcn, HashSet<int> subchannelExtents,
Dictionary<byte, int> smallestPregapLbaPerTrack, bool supportsLongSectors)
{
bool sense = true; // Sense indicator
byte[] cmdBuf = null; // Data buffer
double cmdDuration; // Command execution time
const uint sectorSize = 2352; // Full sector size
byte[] senseBuf = null; // Sense buffer
PlextorSubchannel supportedPlextorSubchannel;
var outputOptical = _outputPlugin as IWritableOpticalImage;
bool sense = true; // Sense indicator
byte[] cmdBuf = null; // Data buffer
double cmdDuration; // Command execution time
const uint sectorSize = 2352; // Full sector size
ReadOnlySpan<byte> senseBuf = null; // Sense buffer
PlextorSubchannel supportedPlextorSubchannel;
var outputOptical = _outputPlugin as IWritableOpticalImage;
supportedPlextorSubchannel = supportedSubchannel switch
{
@@ -457,7 +457,7 @@ partial class Dump
if(sense || _dev.Error)
{
_errorLog?.WriteLine(badSector, _dev.Error, _dev.LastError, senseBuf);
_errorLog?.WriteLine(badSector, _dev.Error, _dev.LastError, senseBuf.ToArray());
if(!runningPersistent) continue;
@@ -465,9 +465,8 @@ partial class Dump
// MEDIUM ERROR, retry with ignore error below
if(decSense is { ASC: 0x11 })
{
if(!sectorsNotEvenPartial.Contains(badSector)) sectorsNotEvenPartial.Add(badSector);
}
if(!sectorsNotEvenPartial.Contains(badSector))
sectorsNotEvenPartial.Add(badSector);
}
// Because one block has been partially used to fix the offset
@@ -499,7 +498,7 @@ partial class Dump
sectorsNotEvenPartial.Remove(badSector);
}
else
_errorLog?.WriteLine(badSector, _dev.Error, _dev.LastError, senseBuf);
_errorLog?.WriteLine(badSector, _dev.Error, _dev.LastError, senseBuf.ToArray());
if(supportedSubchannel != MmcSubchannel.None)
{
@@ -647,7 +646,7 @@ partial class Dump
if(sense || _dev.Error)
{
_errorLog?.WriteLine(badSector, _dev.Error, _dev.LastError, senseBuf);
_errorLog?.WriteLine(badSector, _dev.Error, _dev.LastError, senseBuf.ToArray());
continue;
}
@@ -742,12 +741,12 @@ partial class Dump
Dictionary<byte, string> isrcs, ref string mcn, HashSet<int> subchannelExtents,
Dictionary<byte, int> smallestPregapLbaPerTrack)
{
bool sense = true; // Sense indicator
byte[] cmdBuf = null; // Data buffer
double cmdDuration; // Command execution time
byte[] senseBuf = null; // Sense buffer
PlextorSubchannel supportedPlextorSubchannel;
var outputOptical = _outputPlugin as IWritableOpticalImage;
bool sense = true; // Sense indicator
byte[] cmdBuf = null; // Data buffer
double cmdDuration; // Command execution time
ReadOnlySpan<byte> senseBuf = null; // Sense buffer
PlextorSubchannel supportedPlextorSubchannel;
var outputOptical = _outputPlugin as IWritableOpticalImage;
if(supportedSubchannel == MmcSubchannel.None || desiredSubchannel == MmcSubchannel.None) return;
@@ -836,7 +835,7 @@ partial class Dump
if(sense || _dev.Error)
{
_errorLog?.WriteLine(badSector, _dev.Error, _dev.LastError, senseBuf);
_errorLog?.WriteLine(badSector, _dev.Error, _dev.LastError, senseBuf.ToArray());
continue;
}

View File

@@ -90,11 +90,11 @@ partial class Dump
ref string mcn, Track[] tracks, HashSet<int> subchannelExtents,
Dictionary<byte, int> smallestPregapLbaPerTrack)
{
byte[] cmdBuf = null; // Data buffer
const uint sectorSize = 2352; // Full sector size
bool sense = true; // Sense indicator
byte[] senseBuf = null;
var outputOptical = _outputPlugin as IWritableOpticalImage;
byte[] cmdBuf = null; // Data buffer
const uint sectorSize = 2352; // Full sector size
bool sense = true; // Sense indicator
ReadOnlySpan<byte> senseBuf = null;
var outputOptical = _outputPlugin as IWritableOpticalImage;
UpdateStatus?.Invoke(Localization.Core.Reading_lead_outs);
@@ -253,7 +253,7 @@ partial class Dump
}
else
{
_errorLog?.WriteLine(i, _dev.Error, _dev.LastError, senseBuf);
_errorLog?.WriteLine(i, _dev.Error, _dev.LastError, senseBuf.ToArray());
// TODO: Reset device after X errors
if(_stopOnError) return; // TODO: Return more cleanly
@@ -329,11 +329,11 @@ partial class Dump
ref string mcn, Track[] tracks, HashSet<int> subchannelExtents,
Dictionary<byte, int> smallestPregapLbaPerTrack)
{
byte[] cmdBuf = null; // Data buffer
const uint sectorSize = 2352; // Full sector size
bool sense = true; // Sense indicator
byte[] senseBuf = null;
var outputOptical = _outputPlugin as IWritableOpticalImage;
byte[] cmdBuf = null; // Data buffer
const uint sectorSize = 2352; // Full sector size
bool sense = true; // Sense indicator
ReadOnlySpan<byte> senseBuf = null;
var outputOptical = _outputPlugin as IWritableOpticalImage;
AaruLogging.WriteLine("Retrying lead-outs");
@@ -492,7 +492,7 @@ partial class Dump
}
else
{
_errorLog?.WriteLine(i, _dev.Error, _dev.LastError, senseBuf);
_errorLog?.WriteLine(i, _dev.Error, _dev.LastError, senseBuf.ToArray());
// TODO: Reset device after X errors
if(_stopOnError) return; // TODO: Return more cleanly

View File

@@ -46,8 +46,8 @@ partial class Dump
/// <param name="supportedPlextorSubchannel">Supported subchannel type</param>
/// <param name="cmdDuration">Time spent sending commands to the drive</param>
/// <returns><c>true</c> if an error occured, <c>false</c> otherwise</returns>
bool ReadPlextorWithSubchannel(out byte[] cmdBuf, out byte[] senseBuf, uint firstSectorToRead, uint blockSize,
uint blocksToRead, PlextorSubchannel supportedPlextorSubchannel,
bool ReadPlextorWithSubchannel(out byte[] cmdBuf, out ReadOnlySpan<byte> senseBuf, uint firstSectorToRead,
uint blockSize, uint blocksToRead, PlextorSubchannel supportedPlextorSubchannel,
out double cmdDuration)
{
bool sense;
@@ -140,7 +140,7 @@ partial class Dump
cmdBuf = new byte[2352 * blocksToRead + subSize * blocksToRead];
for(var b = 0; b < blocksToRead; b++)
for(int b = 0; b < blocksToRead; b++)
{
Array.Copy(dataBuf, 2352 * b, cmdBuf, (2352 + subSize) * b, 2352);
Array.Copy(subBuf, subSize * b, cmdBuf, (2352 + subSize) * b + 2352, subSize);

View File

@@ -84,13 +84,13 @@ partial class Dump
Dictionary<byte, string> isrcs, ref string mcn, HashSet<int> subchannelExtents,
Dictionary<byte, int> smallestPregapLbaPerTrack)
{
bool sense = true; // Sense indicator
byte[] cmdBuf = null; // Data buffer
double cmdDuration = 0; // Command execution time
const uint sectorSize = 2352; // Full sector size
PlextorSubchannel supportedPlextorSubchannel;
byte[] senseBuf = null;
var outputOptical = _outputPlugin as IWritableOpticalImage;
bool sense = true; // Sense indicator
byte[] cmdBuf = null; // Data buffer
double cmdDuration = 0; // Command execution time
const uint sectorSize = 2352; // Full sector size
PlextorSubchannel supportedPlextorSubchannel;
ReadOnlySpan<byte> senseBuf = null;
var outputOptical = _outputPlugin as IWritableOpticalImage;
supportedPlextorSubchannel = supportedSubchannel switch
{
@@ -387,7 +387,7 @@ partial class Dump
if(sense || _dev.Error)
{
_errorLog?.WriteLine(badSectorToRead, _dev.Error, _dev.LastError, senseBuf);
_errorLog?.WriteLine(badSectorToRead, _dev.Error, _dev.LastError, senseBuf.ToArray());
continue;
}