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

@@ -47,10 +47,11 @@ public partial class Device
/// <param name="timeout">Timeout in seconds.</param>
/// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
/// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns>
public bool MiniDiscReadDataTOC(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
public bool MiniDiscReadDataTOC(out byte[] buffer, out ReadOnlySpan<byte> senseBuffer, uint timeout,
out double duration)
{
const ushort transferLength = 2336;
senseBuffer = new byte[64];
senseBuffer = SenseBuffer;
Span<byte> cdb = CdbBuffer[..10];
cdb.Clear();
@@ -61,13 +62,7 @@ public partial class Device
buffer = new byte[transferLength];
LastError = SendScsiCommand(cdb,
ref buffer,
out senseBuffer,
timeout,
ScsiDirection.In,
out duration,
out bool sense);
LastError = SendScsiCommand(cdb, ref buffer, timeout, ScsiDirection.In, out duration, out bool sense);
Error = LastError != 0;
@@ -83,11 +78,11 @@ public partial class Device
/// <param name="timeout">Timeout in seconds.</param>
/// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
/// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns>
public bool MiniDiscReadUserTOC(out byte[] buffer, out byte[] senseBuffer, uint sector, uint timeout,
public bool MiniDiscReadUserTOC(out byte[] buffer, out ReadOnlySpan<byte> senseBuffer, uint sector, uint timeout,
out double duration)
{
const ushort transferLength = 2336;
senseBuffer = new byte[64];
senseBuffer = SenseBuffer;
Span<byte> cdb = CdbBuffer[..10];
cdb.Clear();
@@ -102,13 +97,7 @@ public partial class Device
buffer = new byte[transferLength];
LastError = SendScsiCommand(cdb,
ref buffer,
out senseBuffer,
timeout,
ScsiDirection.In,
out duration,
out bool sense);
LastError = SendScsiCommand(cdb, ref buffer, timeout, ScsiDirection.In, out duration, out bool sense);
Error = LastError != 0;
@@ -123,10 +112,10 @@ public partial class Device
/// <param name="timeout">Timeout in seconds.</param>
/// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
/// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns>
public bool MiniDiscD5(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
public bool MiniDiscD5(out byte[] buffer, out ReadOnlySpan<byte> senseBuffer, uint timeout, out double duration)
{
const ushort transferLength = 4;
senseBuffer = new byte[64];
senseBuffer = SenseBuffer;
Span<byte> cdb = CdbBuffer[..10];
cdb.Clear();
@@ -137,13 +126,7 @@ public partial class Device
buffer = new byte[transferLength];
LastError = SendScsiCommand(cdb,
ref buffer,
out senseBuffer,
timeout,
ScsiDirection.In,
out duration,
out bool sense);
LastError = SendScsiCommand(cdb, ref buffer, timeout, ScsiDirection.In, out duration, out bool sense);
Error = LastError != 0;
@@ -158,9 +141,10 @@ public partial class Device
/// <param name="timeout">Timeout in seconds.</param>
/// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
/// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns>
public bool MiniDiscStopPlaying(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
public bool MiniDiscStopPlaying(out byte[] buffer, out ReadOnlySpan<byte> senseBuffer, uint timeout,
out double duration)
{
senseBuffer = new byte[64];
senseBuffer = SenseBuffer;
Span<byte> cdb = CdbBuffer[..10];
cdb.Clear();
@@ -168,13 +152,7 @@ public partial class Device
buffer = [];
LastError = SendScsiCommand(cdb,
ref buffer,
out senseBuffer,
timeout,
ScsiDirection.None,
out duration,
out bool sense);
LastError = SendScsiCommand(cdb, ref buffer, timeout, ScsiDirection.None, out duration, out bool sense);
Error = LastError != 0;
@@ -189,10 +167,11 @@ public partial class Device
/// <param name="timeout">Timeout in seconds.</param>
/// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
/// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns>
public bool MiniDiscReadPosition(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
public bool MiniDiscReadPosition(out byte[] buffer, out ReadOnlySpan<byte> senseBuffer, uint timeout,
out double duration)
{
const ushort transferLength = 4;
senseBuffer = new byte[64];
senseBuffer = SenseBuffer;
Span<byte> cdb = CdbBuffer[..10];
cdb.Clear();
@@ -203,13 +182,7 @@ public partial class Device
buffer = new byte[transferLength];
LastError = SendScsiCommand(cdb,
ref buffer,
out senseBuffer,
timeout,
ScsiDirection.In,
out duration,
out bool sense);
LastError = SendScsiCommand(cdb, ref buffer, timeout, ScsiDirection.In, out duration, out bool sense);
Error = LastError != 0;
@@ -224,10 +197,11 @@ public partial class Device
/// <param name="timeout">Timeout in seconds.</param>
/// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
/// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns>
public bool MiniDiscGetType(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
public bool MiniDiscGetType(out byte[] buffer, out ReadOnlySpan<byte> senseBuffer, uint timeout,
out double duration)
{
const ushort transferLength = 8;
senseBuffer = new byte[64];
senseBuffer = SenseBuffer;
Span<byte> cdb = CdbBuffer[..10];
cdb.Clear();
@@ -238,13 +212,7 @@ public partial class Device
buffer = new byte[transferLength];
LastError = SendScsiCommand(cdb,
ref buffer,
out senseBuffer,
timeout,
ScsiDirection.In,
out duration,
out bool sense);
LastError = SendScsiCommand(cdb, ref buffer, timeout, ScsiDirection.In, out duration, out bool sense);
Error = LastError != 0;