Code cleanup.

This commit is contained in:
2018-06-22 08:08:38 +01:00
parent 82f474c7e3
commit 88da8fc019
581 changed files with 22423 additions and 20839 deletions

View File

@@ -85,7 +85,7 @@ namespace DiscImageChef.Devices
/// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
public bool ScsiInquiry(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
{
buffer = new byte[36];
buffer = new byte[36];
senseBuffer = new byte[32];
byte[] cdb = {(byte)ScsiCommands.Inquiry, 0, 0, 0, 36, 0};
@@ -97,8 +97,8 @@ namespace DiscImageChef.Devices
byte pagesLength = (byte)(buffer[4] + 5);
cdb = new byte[] {(byte)ScsiCommands.Inquiry, 0, 0, 0, pagesLength, 0};
buffer = new byte[pagesLength];
cdb = new byte[] {(byte)ScsiCommands.Inquiry, 0, 0, 0, pagesLength, 0};
buffer = new byte[pagesLength];
senseBuffer = new byte[32];
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
@@ -159,7 +159,7 @@ namespace DiscImageChef.Devices
/// <param name="page">The Extended Vital Product Data</param>
public bool ScsiInquiry(out byte[] buffer, out byte[] senseBuffer, byte page, uint timeout, out double duration)
{
buffer = new byte[36];
buffer = new byte[36];
senseBuffer = new byte[32];
byte[] cdb = {(byte)ScsiCommands.Inquiry, 1, page, 0, 36, 0};
@@ -174,8 +174,8 @@ namespace DiscImageChef.Devices
byte pagesLength = (byte)(buffer[3] + 4);
cdb = new byte[] {(byte)ScsiCommands.Inquiry, 1, page, 0, pagesLength, 0};
buffer = new byte[pagesLength];
cdb = new byte[] {(byte)ScsiCommands.Inquiry, 1, page, 0, pagesLength, 0};
buffer = new byte[pagesLength];
senseBuffer = new byte[32];
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
@@ -197,7 +197,7 @@ namespace DiscImageChef.Devices
public bool ScsiTestUnitReady(out byte[] senseBuffer, uint timeout, out double duration)
{
senseBuffer = new byte[32];
byte[] cdb = {(byte)ScsiCommands.TestUnitReady, 0, 0, 0, 0, 0};
byte[] cdb = {(byte)ScsiCommands.TestUnitReady, 0, 0, 0, 0, 0};
byte[] buffer = new byte[0];
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
@@ -234,8 +234,9 @@ namespace DiscImageChef.Devices
/// <param name="dbd">If set to <c>true</c> device MUST not return any block descriptor.</param>
/// <param name="pageControl">Page control.</param>
/// <param name="pageCode">Page code.</param>
public bool ModeSense6(out byte[] buffer, out byte[] senseBuffer, bool dbd,
ScsiModeSensePageControl pageControl, byte pageCode, uint timeout, out double duration)
public bool ModeSense6(out byte[] buffer, out byte[] senseBuffer, bool dbd,
ScsiModeSensePageControl pageControl, byte pageCode, uint timeout,
out double duration)
{
return ModeSense6(out buffer, out senseBuffer, dbd, pageControl, pageCode, 0, timeout, out duration);
}
@@ -252,9 +253,10 @@ namespace DiscImageChef.Devices
/// <param name="pageControl">Page control.</param>
/// <param name="pageCode">Page code.</param>
/// <param name="subPageCode">Sub-page code.</param>
public bool ModeSense6(out byte[] buffer, out byte[] senseBuffer, bool dbd,
ScsiModeSensePageControl pageControl, byte pageCode, byte subPageCode, uint timeout,
out double duration)
public bool ModeSense6(out byte[] buffer, out byte[] senseBuffer, bool dbd,
ScsiModeSensePageControl pageControl, byte pageCode, byte subPageCode,
uint timeout,
out double duration)
{
senseBuffer = new byte[32];
byte[] cdb = new byte[6];
@@ -264,9 +266,9 @@ namespace DiscImageChef.Devices
if(dbd) cdb[1] = 0x08;
cdb[2] |= (byte)pageControl;
cdb[2] |= (byte)(pageCode & 0x3F);
cdb[3] = subPageCode;
cdb[4] = (byte)buffer.Length;
cdb[5] = 0;
cdb[3] = subPageCode;
cdb[4] = (byte)buffer.Length;
cdb[5] = 0;
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
out bool sense);
@@ -275,8 +277,8 @@ namespace DiscImageChef.Devices
if(sense) return true;
byte modeLength = (byte)(buffer[0] + 1);
buffer = new byte[modeLength];
cdb[4] = (byte)buffer.Length;
buffer = new byte[modeLength];
cdb[4] = (byte)buffer.Length;
senseBuffer = new byte[32];
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
@@ -299,8 +301,9 @@ namespace DiscImageChef.Devices
/// <param name="dbd">If set to <c>true</c> device MUST not return any block descriptor.</param>
/// <param name="pageControl">Page control.</param>
/// <param name="pageCode">Page code.</param>
public bool ModeSense10(out byte[] buffer, out byte[] senseBuffer, bool dbd,
ScsiModeSensePageControl pageControl, byte pageCode, uint timeout, out double duration)
public bool ModeSense10(out byte[] buffer, out byte[] senseBuffer, bool dbd,
ScsiModeSensePageControl pageControl, byte pageCode, uint timeout,
out double duration)
{
return ModeSense10(out buffer, out senseBuffer, false, dbd, pageControl, pageCode, 0, timeout,
out duration);
@@ -318,8 +321,10 @@ namespace DiscImageChef.Devices
/// <param name="pageControl">Page control.</param>
/// <param name="pageCode">Page code.</param>
/// <param name="llbaa">If set means 64-bit LBAs are accepted by the caller.</param>
public bool ModeSense10(out byte[] buffer, out byte[] senseBuffer, bool llbaa, bool dbd,
ScsiModeSensePageControl pageControl, byte pageCode, uint timeout, out double duration)
public bool ModeSense10(out byte[] buffer, out byte[] senseBuffer, bool llbaa,
bool dbd,
ScsiModeSensePageControl pageControl, byte pageCode, uint timeout,
out double duration)
{
return ModeSense10(out buffer, out senseBuffer, llbaa, dbd, pageControl, pageCode, 0, timeout,
out duration);
@@ -338,9 +343,11 @@ namespace DiscImageChef.Devices
/// <param name="pageCode">Page code.</param>
/// <param name="subPageCode">Sub-page code.</param>
/// <param name="llbaa">If set means 64-bit LBAs are accepted by the caller.</param>
public bool ModeSense10(out byte[] buffer, out byte[] senseBuffer, bool llbaa, bool dbd,
ScsiModeSensePageControl pageControl, byte pageCode, byte subPageCode, uint timeout,
out double duration)
public bool ModeSense10(out byte[] buffer, out byte[] senseBuffer, bool llbaa,
bool dbd,
ScsiModeSensePageControl pageControl, byte pageCode, byte subPageCode,
uint timeout,
out double duration)
{
senseBuffer = new byte[32];
byte[] cdb = new byte[10];
@@ -348,13 +355,13 @@ namespace DiscImageChef.Devices
cdb[0] = (byte)ScsiCommands.ModeSense10;
if(llbaa) cdb[1] |= 0x10;
if(dbd) cdb[1] |= 0x08;
if(dbd) cdb[1] |= 0x08;
cdb[2] |= (byte)pageControl;
cdb[2] |= (byte)(pageCode & 0x3F);
cdb[3] = subPageCode;
cdb[7] = (byte)((buffer.Length & 0xFF00) >> 8);
cdb[8] = (byte)(buffer.Length & 0xFF);
cdb[9] = 0;
cdb[3] = subPageCode;
cdb[7] = (byte)((buffer.Length & 0xFF00) >> 8);
cdb[8] = (byte)(buffer.Length & 0xFF);
cdb[9] = 0;
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
out bool sense);
@@ -363,9 +370,9 @@ namespace DiscImageChef.Devices
if(sense) return true;
ushort modeLength = (ushort)((buffer[0] << 8) + buffer[1] + 2);
buffer = new byte[modeLength];
cdb[7] = (byte)((buffer.Length & 0xFF00) >> 8);
cdb[8] = (byte)(buffer.Length & 0xFF);
buffer = new byte[modeLength];
cdb[7] = (byte)((buffer.Length & 0xFF00) >> 8);
cdb[8] = (byte)(buffer.Length & 0xFF);
senseBuffer = new byte[32];
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
@@ -431,7 +438,7 @@ namespace DiscImageChef.Devices
out double duration)
{
senseBuffer = new byte[32];
byte[] cdb = new byte[6];
byte[] cdb = new byte[6];
byte[] buffer = new byte[0];
cdb[0] = (byte)ScsiCommands.PreventAllowMediumRemoval;
@@ -470,8 +477,8 @@ namespace DiscImageChef.Devices
/// <param name="pmi">If set, it is requesting partial media capacity</param>
/// <param name="timeout">Timeout in seconds.</param>
/// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
public bool ReadCapacity(out byte[] buffer, out byte[] senseBuffer, bool relAddr, uint address, bool pmi,
uint timeout, out double duration)
public bool ReadCapacity(out byte[] buffer, out byte[] senseBuffer, bool relAddr, uint address, bool pmi,
uint timeout, out double duration)
{
senseBuffer = new byte[32];
byte[] cdb = new byte[10];
@@ -485,8 +492,8 @@ namespace DiscImageChef.Devices
if(relAddr) cdb[1] = 0x01;
cdb[2] = (byte)((address & 0xFF000000) >> 24);
cdb[3] = (byte)((address & 0xFF0000) >> 16);
cdb[4] = (byte)((address & 0xFF00) >> 8);
cdb[3] = (byte)((address & 0xFF0000) >> 16);
cdb[4] = (byte)((address & 0xFF00) >> 8);
cdb[5] = (byte)(address & 0xFF);
}
@@ -547,8 +554,8 @@ namespace DiscImageChef.Devices
}
cdb[10] = (byte)((buffer.Length & 0xFF000000) >> 24);
cdb[11] = (byte)((buffer.Length & 0xFF0000) >> 16);
cdb[12] = (byte)((buffer.Length & 0xFF00) >> 8);
cdb[11] = (byte)((buffer.Length & 0xFF0000) >> 16);
cdb[12] = (byte)((buffer.Length & 0xFF00) >> 8);
cdb[13] = (byte)(buffer.Length & 0xFF);
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
@@ -577,8 +584,8 @@ namespace DiscImageChef.Devices
cdb[0] = (byte)ScsiCommands.ReadSerialNumber;
cdb[1] = 0x01;
cdb[6] = (byte)((buffer.Length & 0xFF000000) >> 24);
cdb[7] = (byte)((buffer.Length & 0xFF0000) >> 16);
cdb[8] = (byte)((buffer.Length & 0xFF00) >> 8);
cdb[7] = (byte)((buffer.Length & 0xFF0000) >> 16);
cdb[8] = (byte)((buffer.Length & 0xFF00) >> 8);
cdb[9] = (byte)(buffer.Length & 0xFF);
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
@@ -588,11 +595,11 @@ namespace DiscImageChef.Devices
if(sense) return true;
uint strctLength = (uint)((buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3] + 4);
buffer = new byte[strctLength];
cdb[6] = (byte)((buffer.Length & 0xFF000000) >> 24);
cdb[7] = (byte)((buffer.Length & 0xFF0000) >> 16);
cdb[8] = (byte)((buffer.Length & 0xFF00) >> 8);
cdb[9] = (byte)(buffer.Length & 0xFF);
buffer = new byte[strctLength];
cdb[6] = (byte)((buffer.Length & 0xFF000000) >> 24);
cdb[7] = (byte)((buffer.Length & 0xFF0000) >> 16);
cdb[8] = (byte)((buffer.Length & 0xFF00) >> 8);
cdb[9] = (byte)(buffer.Length & 0xFF);
senseBuffer = new byte[32];
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
@@ -615,11 +622,13 @@ namespace DiscImageChef.Devices
/// <param name="cache">If set to <c>true</c> device can return cached data.</param>
/// <param name="timeout">Timeout.</param>
/// <param name="duration">Duration.</param>
public bool ReadAttribute(out byte[] buffer, out byte[] senseBuffer, ScsiAttributeAction action, byte partition,
ushort firstAttribute, bool cache, uint timeout, out double duration)
public bool ReadAttribute(out byte[] buffer, out byte[] senseBuffer, ScsiAttributeAction action,
byte partition,
ushort firstAttribute, bool cache, uint timeout,
out double duration)
{
return ReadAttribute(out buffer, out senseBuffer, action, 0, 0, 0, partition, firstAttribute, cache,
timeout, out duration);
timeout, out duration);
}
/// <summary>
@@ -632,8 +641,9 @@ namespace DiscImageChef.Devices
/// <param name="cache">If set to <c>true</c> device can return cached data.</param>
/// <param name="timeout">Timeout.</param>
/// <param name="duration">Duration.</param>
public bool ReadAttribute(out byte[] buffer, out byte[] senseBuffer, ScsiAttributeAction action,
ushort firstAttribute, bool cache, uint timeout, out double duration)
public bool ReadAttribute(out byte[] buffer, out byte[] senseBuffer, ScsiAttributeAction action,
ushort firstAttribute, bool cache, uint timeout,
out double duration)
{
return ReadAttribute(out buffer, out senseBuffer, action, 0, 0, 0, 0, firstAttribute, cache, timeout,
out duration);
@@ -649,11 +659,12 @@ namespace DiscImageChef.Devices
/// <param name="firstAttribute">First attribute identifier.</param>
/// <param name="timeout">Timeout.</param>
/// <param name="duration">Duration.</param>
public bool ReadAttribute(out byte[] buffer, out byte[] senseBuffer, ScsiAttributeAction action, byte partition,
ushort firstAttribute, uint timeout, out double duration)
public bool ReadAttribute(out byte[] buffer, out byte[] senseBuffer, ScsiAttributeAction action,
byte partition,
ushort firstAttribute, uint timeout, out double duration)
{
return ReadAttribute(out buffer, out senseBuffer, action, 0, 0, 0, partition, firstAttribute, false,
timeout, out duration);
timeout, out duration);
}
/// <summary>
@@ -665,8 +676,8 @@ namespace DiscImageChef.Devices
/// <param name="firstAttribute">First attribute identifier.</param>
/// <param name="timeout">Timeout.</param>
/// <param name="duration">Duration.</param>
public bool ReadAttribute(out byte[] buffer, out byte[] senseBuffer, ScsiAttributeAction action,
ushort firstAttribute, uint timeout, out double duration)
public bool ReadAttribute(out byte[] buffer, out byte[] senseBuffer, ScsiAttributeAction action,
ushort firstAttribute, uint timeout, out double duration)
{
return ReadAttribute(out buffer, out senseBuffer, action, 0, 0, 0, 0, firstAttribute, false, timeout,
out duration);
@@ -683,11 +694,13 @@ namespace DiscImageChef.Devices
/// <param name="firstAttribute">First attribute identifier.</param>
/// <param name="timeout">Timeout.</param>
/// <param name="duration">Duration.</param>
public bool ReadAttribute(out byte[] buffer, out byte[] senseBuffer, ScsiAttributeAction action, byte volume,
byte partition, ushort firstAttribute, uint timeout, out double duration)
public bool ReadAttribute(out byte[] buffer, out byte[] senseBuffer, ScsiAttributeAction action,
byte volume,
byte partition, ushort firstAttribute, uint timeout,
out double duration)
{
return ReadAttribute(out buffer, out senseBuffer, action, 0, 0, volume, partition, firstAttribute, false,
timeout, out duration);
timeout, out duration);
}
/// <summary>
@@ -702,11 +715,13 @@ namespace DiscImageChef.Devices
/// <param name="cache">If set to <c>true</c> device can return cached data.</param>
/// <param name="timeout">Timeout.</param>
/// <param name="duration">Duration.</param>
public bool ReadAttribute(out byte[] buffer, out byte[] senseBuffer, ScsiAttributeAction action, byte volume,
byte partition, ushort firstAttribute, bool cache, uint timeout, out double duration)
public bool ReadAttribute(out byte[] buffer, out byte[] senseBuffer, ScsiAttributeAction action,
byte volume,
byte partition, ushort firstAttribute, bool cache,
uint timeout, out double duration)
{
return ReadAttribute(out buffer, out senseBuffer, action, 0, 0, volume, partition, firstAttribute, cache,
timeout, out duration);
timeout, out duration);
}
/// <summary>
@@ -719,7 +734,7 @@ namespace DiscImageChef.Devices
/// <param name="timeout">Timeout in seconds.</param>
/// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
/// <param name="pageFormat">Set if page is formatted.</param>
public bool ModeSelect(byte[] buffer, out byte[] senseBuffer, bool pageFormat, bool savePages, uint timeout,
public bool ModeSelect(byte[] buffer, out byte[] senseBuffer, bool pageFormat, bool savePages, uint timeout,
out double duration)
{
senseBuffer = new byte[32];
@@ -727,11 +742,11 @@ namespace DiscImageChef.Devices
// Prevent overflows
if(buffer.Length > 255)
{
if(PlatformId != PlatformID.Win32NT && PlatformId != PlatformID.Win32S &&
PlatformId != PlatformID.Win32Windows && PlatformId != PlatformID.WinCE &&
if(PlatformId != PlatformID.Win32NT && PlatformId != PlatformID.Win32S &&
PlatformId != PlatformID.Win32Windows && PlatformId != PlatformID.WinCE &&
PlatformId != PlatformID.WindowsPhone && PlatformId != PlatformID.Xbox) LastError = 75;
else LastError = 111;
Error = true;
else LastError = 111;
Error = true;
duration = 0;
return true;
}
@@ -740,7 +755,7 @@ namespace DiscImageChef.Devices
cdb[0] = (byte)ScsiCommands.ModeSelect;
if(pageFormat) cdb[1] += 0x10;
if(savePages) cdb[1] += 0x01;
if(savePages) cdb[1] += 0x01;
cdb[4] = (byte)buffer.Length;
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.Out, out duration,
@@ -762,7 +777,8 @@ namespace DiscImageChef.Devices
/// <param name="timeout">Timeout in seconds.</param>
/// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
/// <param name="pageFormat">Set if page is formatted.</param>
public bool ModeSelect10(byte[] buffer, out byte[] senseBuffer, bool pageFormat, bool savePages, uint timeout,
public bool ModeSelect10(byte[] buffer, out byte[] senseBuffer, bool pageFormat, bool savePages,
uint timeout,
out double duration)
{
senseBuffer = new byte[32];
@@ -770,11 +786,11 @@ namespace DiscImageChef.Devices
// Prevent overflows
if(buffer.Length > 65535)
{
if(PlatformId != PlatformID.Win32NT && PlatformId != PlatformID.Win32S &&
PlatformId != PlatformID.Win32Windows && PlatformId != PlatformID.WinCE &&
if(PlatformId != PlatformID.Win32NT && PlatformId != PlatformID.Win32S &&
PlatformId != PlatformID.Win32Windows && PlatformId != PlatformID.WinCE &&
PlatformId != PlatformID.WindowsPhone && PlatformId != PlatformID.Xbox) LastError = 75;
else LastError = 111;
Error = true;
else LastError = 111;
Error = true;
duration = 0;
return true;
}
@@ -783,7 +799,7 @@ namespace DiscImageChef.Devices
cdb[0] = (byte)ScsiCommands.ModeSelect10;
if(pageFormat) cdb[1] += 0x10;
if(savePages) cdb[1] += 0x01;
if(savePages) cdb[1] += 0x01;
cdb[7] = (byte)((buffer.Length & 0xFF00) << 8);
cdb[8] = (byte)(buffer.Length & 0xFF);