General refactor and cleanup.

This commit is contained in:
2024-05-01 04:05:22 +01:00
parent 185a8c3fd5
commit e46d21bde6
922 changed files with 36437 additions and 29485 deletions

View File

@@ -60,7 +60,11 @@ public partial class Device
/// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param>
public bool GetConfiguration(out byte[] buffer, out byte[] senseBuffer, ushort startingFeatureNumber, uint timeout,
out double duration) =>
GetConfiguration(out buffer, out senseBuffer, startingFeatureNumber, MmcGetConfigurationRt.All, timeout,
GetConfiguration(out buffer,
out senseBuffer,
startingFeatureNumber,
MmcGetConfigurationRt.All,
timeout,
out duration);
/// <summary>Sends the MMC GET CONFIGURATION command</summary>
@@ -86,13 +90,17 @@ public partial class Device
cdb[8] = (byte)(buffer.Length & 0xFF);
cdb[9] = 0;
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
LastError = SendScsiCommand(cdb,
ref buffer,
out senseBuffer,
timeout,
ScsiDirection.In,
out duration,
out bool sense);
Error = LastError != 0;
if(sense)
return true;
if(sense) return true;
var confLength = (ushort)((buffer[2] << 8) + buffer[3] + 4);
buffer = new byte[confLength];
@@ -100,15 +108,24 @@ public partial class Device
cdb[8] = (byte)(buffer.Length & 0xFF);
senseBuffer = new byte[64];
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
LastError = SendScsiCommand(cdb,
ref buffer,
out senseBuffer,
timeout,
ScsiDirection.In,
out duration,
out sense);
Error = LastError != 0;
AaruConsole.DebugWriteLine(SCSI_MODULE_NAME,
Localization.
GET_CONFIGURATION_Starting_Feature_Number_1_Return_Type_2_Sense_3_Last_Error_4_took_0_ms,
duration, startingFeatureNumber, rt, sense, LastError);
Localization
.GET_CONFIGURATION_Starting_Feature_Number_1_Return_Type_2_Sense_3_Last_Error_4_took_0_ms,
duration,
startingFeatureNumber,
rt,
sense,
LastError);
return sense;
}
@@ -144,13 +161,17 @@ public partial class Device
cdb[9] = (byte)(buffer.Length & 0xFF);
cdb[10] = (byte)((agid & 0x03) << 6);
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
LastError = SendScsiCommand(cdb,
ref buffer,
out senseBuffer,
timeout,
ScsiDirection.In,
out duration,
out bool sense);
Error = LastError != 0;
if(sense)
return true;
if(sense) return true;
var strctLength = (ushort)((buffer[0] << 8) + buffer[1] + 2);
@@ -174,15 +195,27 @@ public partial class Device
cdb[9] = (byte)(buffer.Length & 0xFF);
senseBuffer = new byte[64];
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
LastError = SendScsiCommand(cdb,
ref buffer,
out senseBuffer,
timeout,
ScsiDirection.In,
out duration,
out sense);
Error = LastError != 0;
AaruConsole.DebugWriteLine(SCSI_MODULE_NAME,
Localization.
READ_DISC_STRUCTURE_Media_Type_1_Address_2_Layer_Number_3_Format_4_AGID_5_Sense_6_Last_Error_7_took_0_ms,
duration, mediaType, address, layerNumber, format, agid, sense, LastError);
Localization
.READ_DISC_STRUCTURE_Media_Type_1_Address_2_Layer_Number_3_Format_4_AGID_5_Sense_6_Last_Error_7_took_0_ms,
duration,
mediaType,
address,
layerNumber,
format,
agid,
sense,
LastError);
return sense;
}
@@ -286,15 +319,19 @@ public partial class Device
cdb[0] = (byte)ScsiCommands.ReadTocPmaAtip;
if(msf)
cdb[1] = 0x02;
if(msf) cdb[1] = 0x02;
cdb[2] = (byte)(format & 0x0F);
cdb[6] = trackSessionNumber;
cdb[7] = (byte)((tmpBuffer.Length & 0xFF00) >> 8);
cdb[8] = (byte)(tmpBuffer.Length & 0xFF);
LastError = SendScsiCommand(cdb, ref tmpBuffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
LastError = SendScsiCommand(cdb,
ref tmpBuffer,
out senseBuffer,
timeout,
ScsiDirection.In,
out duration,
out bool sense);
Error = LastError != 0;
@@ -307,16 +344,26 @@ public partial class Device
Array.Copy(tmpBuffer, 0, buffer, 0, buffer.Length);
AaruConsole.DebugWriteLine(SCSI_MODULE_NAME,
Localization.
READ_TOC_PMA_ATIP_took_MSF_1_Format_2_Track_Session_Number_3_Sense_4_LastError_5_0_ms,
duration, msf, format, trackSessionNumber, sense, LastError);
Localization
.READ_TOC_PMA_ATIP_took_MSF_1_Format_2_Track_Session_Number_3_Sense_4_LastError_5_0_ms,
duration,
msf,
format,
trackSessionNumber,
sense,
LastError);
return sense;
}
double tmpDuration = duration;
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
LastError = SendScsiCommand(cdb,
ref buffer,
out senseBuffer,
timeout,
ScsiDirection.In,
out duration,
out sense);
Error = LastError != 0;
@@ -324,9 +371,14 @@ public partial class Device
duration += tmpDuration;
AaruConsole.DebugWriteLine(SCSI_MODULE_NAME,
Localization.
READ_TOC_PMA_ATIP_took_MSF_1_Format_2_Track_Session_Number_3_Sense_4_LastError_5_0_ms,
duration, msf, format, trackSessionNumber, sense, LastError);
Localization
.READ_TOC_PMA_ATIP_took_MSF_1_Format_2_Track_Session_Number_3_Sense_4_LastError_5_0_ms,
duration,
msf,
format,
trackSessionNumber,
sense,
LastError);
return sense;
}
@@ -338,7 +390,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>
public bool ReadDiscInformation(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration) =>
ReadDiscInformation(out buffer, out senseBuffer, MmcDiscInformationDataTypes.DiscInformation, timeout,
ReadDiscInformation(out buffer,
out senseBuffer,
MmcDiscInformationDataTypes.DiscInformation,
timeout,
out duration);
/// <summary>Sends the MMC READ DISC INFORMATION command</summary>
@@ -360,22 +415,29 @@ public partial class Device
cdb[7] = (byte)((tmpBuffer.Length & 0xFF00) >> 8);
cdb[8] = (byte)(tmpBuffer.Length & 0xFF);
LastError = SendScsiCommand(cdb, ref tmpBuffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
LastError = SendScsiCommand(cdb,
ref tmpBuffer,
out senseBuffer,
timeout,
ScsiDirection.In,
out duration,
out bool sense);
Error = LastError != 0;
var strctLength = (uint)((tmpBuffer[0] << 8) + tmpBuffer[1] + 2);
if(strctLength > tmpBuffer.Length)
strctLength = (uint)tmpBuffer.Length;
if(strctLength > tmpBuffer.Length) strctLength = (uint)tmpBuffer.Length;
buffer = new byte[strctLength];
Array.Copy(tmpBuffer, 0, buffer, 0, buffer.Length);
AaruConsole.DebugWriteLine(SCSI_MODULE_NAME,
Localization.READ_DISC_INFORMATION_Data_Type_1_Sense_2_Last_Error_3_took_0_ms,
duration, dataType, sense, LastError);
duration,
dataType,
sense,
LastError);
return sense;
}
@@ -409,11 +471,9 @@ public partial class Device
cdb[0] = (byte)ScsiCommands.ReadCd;
cdb[1] = (byte)((byte)expectedSectorType << 2);
if(dap)
cdb[1] += 0x02;
if(dap) cdb[1] += 0x02;
if(relAddr)
cdb[1] += 0x01;
if(relAddr) cdb[1] += 0x01;
cdb[2] = (byte)((lba & 0xFF000000) >> 24);
cdb[3] = (byte)((lba & 0xFF0000) >> 16);
@@ -425,29 +485,44 @@ public partial class Device
cdb[9] = (byte)((byte)c2Error << 1);
cdb[9] += (byte)((byte)headerCodes << 5);
if(sync)
cdb[9] += 0x80;
if(sync) cdb[9] += 0x80;
if(userData)
cdb[9] += 0x10;
if(userData) cdb[9] += 0x10;
if(edcEcc)
cdb[9] += 0x08;
if(edcEcc) cdb[9] += 0x08;
cdb[10] = (byte)subchannel;
buffer = new byte[blockSize * transferLength];
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
LastError = SendScsiCommand(cdb,
ref buffer,
out senseBuffer,
timeout,
ScsiDirection.In,
out duration,
out bool sense);
Error = LastError != 0;
AaruConsole.DebugWriteLine(SCSI_MODULE_NAME,
Localization.
READ_CD_LBA_1_Block_Size_2_Transfer_Length_3_Expected_Sector_Type_4_DAP_5_Relative_Address_6_Sync_7_Headers_8_User_Data_9_ECC_EDC_10_C2_11_Subchannel_12_Sense_13_Last_Error_14_took_0_ms,
duration, lba, blockSize, transferLength, expectedSectorType, dap, relAddr, sync,
headerCodes, userData, edcEcc, c2Error, subchannel, sense, LastError);
Localization
.READ_CD_LBA_1_Block_Size_2_Transfer_Length_3_Expected_Sector_Type_4_DAP_5_Relative_Address_6_Sync_7_Headers_8_User_Data_9_ECC_EDC_10_C2_11_Subchannel_12_Sense_13_Last_Error_14_took_0_ms,
duration,
lba,
blockSize,
transferLength,
expectedSectorType,
dap,
relAddr,
sync,
headerCodes,
userData,
edcEcc,
c2Error,
subchannel,
sense,
LastError);
return sense;
}
@@ -480,8 +555,7 @@ public partial class Device
cdb[0] = (byte)ScsiCommands.ReadCdMsf;
cdb[1] = (byte)((byte)expectedSectorType << 2);
if(dap)
cdb[1] += 0x02;
if(dap) cdb[1] += 0x02;
cdb[3] = (byte)((startMsf & 0xFF0000) >> 16);
cdb[4] = (byte)((startMsf & 0xFF00) >> 8);
@@ -492,14 +566,11 @@ public partial class Device
cdb[9] = (byte)((byte)c2Error << 1);
cdb[9] += (byte)((byte)headerCodes << 5);
if(sync)
cdb[9] += 0x80;
if(sync) cdb[9] += 0x80;
if(userData)
cdb[9] += 0x10;
if(userData) cdb[9] += 0x10;
if(edcEcc)
cdb[9] += 0x08;
if(edcEcc) cdb[9] += 0x08;
cdb[10] = (byte)subchannel;
@@ -507,16 +578,33 @@ public partial class Device
buffer = new byte[blockSize * transferLength];
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
LastError = SendScsiCommand(cdb,
ref buffer,
out senseBuffer,
timeout,
ScsiDirection.In,
out duration,
out bool sense);
Error = LastError != 0;
AaruConsole.DebugWriteLine(SCSI_MODULE_NAME,
Localization.
READ_CD_MSF_Start_MSF_1_End_MSF_2_Block_Size_3_Expected_Sector_Type_4_DAP_5_Sync_6_Headers_7_User_Data_8_ECC_EDC_9_C2_10_Subchannel_11_Sense_12_LastError_13_took_0_ms,
duration, startMsf, endMsf, blockSize, expectedSectorType, dap, sync, headerCodes,
userData, edcEcc, c2Error, subchannel, sense, LastError);
Localization
.READ_CD_MSF_Start_MSF_1_End_MSF_2_Block_Size_3_Expected_Sector_Type_4_DAP_5_Sync_6_Headers_7_User_Data_8_ECC_EDC_9_C2_10_Subchannel_11_Sense_12_LastError_13_took_0_ms,
duration,
startMsf,
endMsf,
blockSize,
expectedSectorType,
dap,
sync,
headerCodes,
userData,
edcEcc,
c2Error,
subchannel,
sense,
LastError);
return sense;
}
@@ -553,21 +641,28 @@ public partial class Device
cdb[0] = (byte)ScsiCommands.PreventAllowMediumRemoval;
if(prevent)
cdb[4] += 0x01;
if(prevent) cdb[4] += 0x01;
if(persistent)
cdb[4] += 0x02;
if(persistent) cdb[4] += 0x02;
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
LastError = SendScsiCommand(cdb,
ref buffer,
out senseBuffer,
timeout,
ScsiDirection.None,
out duration,
out bool sense);
Error = LastError != 0;
AaruConsole.DebugWriteLine(SCSI_MODULE_NAME,
Localization.
PREVENT_ALLOW_MEDIUM_REMOVAL_Persistent_1_Prevent_2_Sense_3_LastError_4_took_0_ms,
duration, persistent, prevent, sense, LastError);
Localization
.PREVENT_ALLOW_MEDIUM_REMOVAL_Persistent_1_Prevent_2_Sense_3_LastError_4_took_0_ms,
duration,
persistent,
prevent,
sense,
LastError);
return sense;
}
@@ -624,8 +719,7 @@ public partial class Device
cdb[0] = (byte)ScsiCommands.StartStopUnit;
if(immediate)
cdb[1] += 0x01;
if(immediate) cdb[1] += 0x01;
if(changeFormatLayer)
{
@@ -634,25 +728,35 @@ public partial class Device
}
else
{
if(loadEject)
cdb[4] += 0x02;
if(loadEject) cdb[4] += 0x02;
if(start)
cdb[4] += 0x01;
if(start) cdb[4] += 0x01;
}
cdb[4] += (byte)((powerConditions & 0x0F) << 4);
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
LastError = SendScsiCommand(cdb,
ref buffer,
out senseBuffer,
timeout,
ScsiDirection.None,
out duration,
out bool sense);
Error = LastError != 0;
AaruConsole.DebugWriteLine(SCSI_MODULE_NAME,
Localization.
START_STOP_UNIT_Immediate_1_FormatLayer_2_Power_Conditions_3_Change_Format_Layer_4_Load_Eject_5_Start_6_Sense_7_Last_Error_8_took_0_ms,
duration, immediate, formatLayer, powerConditions, changeFormatLayer, loadEject,
start, sense, LastError);
Localization
.START_STOP_UNIT_Immediate_1_FormatLayer_2_Power_Conditions_3_Change_Format_Layer_4_Load_Eject_5_Start_6_Sense_7_Last_Error_8_took_0_ms,
duration,
immediate,
formatLayer,
powerConditions,
changeFormatLayer,
loadEject,
start,
sense,
LastError);
return sense;
}
@@ -680,17 +784,23 @@ public partial class Device
buffer = new byte[23];
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
LastError = SendScsiCommand(cdb,
ref buffer,
out senseBuffer,
timeout,
ScsiDirection.In,
out duration,
out bool sense);
Error = LastError != 0;
AaruConsole.DebugWriteLine(SCSI_MODULE_NAME,
Localization.READ_READ_SUB_CHANNEL_MCN_Sense_1_Last_Error_2_took_0_ms, duration,
sense, LastError);
Localization.READ_READ_SUB_CHANNEL_MCN_Sense_1_Last_Error_2_took_0_ms,
duration,
sense,
LastError);
if(!sense && (buffer[8] & 0x80) == 0x80)
mcn = Encoding.ASCII.GetString(buffer, 9, 13);
if(!sense && (buffer[8] & 0x80) == 0x80) mcn = Encoding.ASCII.GetString(buffer, 9, 13);
return sense;
}
@@ -721,18 +831,25 @@ public partial class Device
buffer = new byte[23];
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
LastError = SendScsiCommand(cdb,
ref buffer,
out senseBuffer,
timeout,
ScsiDirection.In,
out duration,
out bool sense);
Error = LastError != 0;
AaruConsole.DebugWriteLine(SCSI_MODULE_NAME,
Localization.
READ_READ_SUB_CHANNEL_ISRC_Track_Number_1_Sense_2_Last_Error_3_took_0_ms,
duration, trackNumber, sense, LastError);
Localization
.READ_READ_SUB_CHANNEL_ISRC_Track_Number_1_Sense_2_Last_Error_3_took_0_ms,
duration,
trackNumber,
sense,
LastError);
if(!sense && (buffer[8] & 0x80) == 0x80)
isrc = Encoding.ASCII.GetString(buffer, 9, 12);
if(!sense && (buffer[8] & 0x80) == 0x80) isrc = Encoding.ASCII.GetString(buffer, 9, 12);
return sense;
}
@@ -759,15 +876,25 @@ public partial class Device
cdb[4] = (byte)((writeSpeed & 0xFF00) >> 8);
cdb[5] = (byte)(writeSpeed & 0xFF);
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.None, out duration,
LastError = SendScsiCommand(cdb,
ref buffer,
out senseBuffer,
timeout,
ScsiDirection.None,
out duration,
out bool sense);
Error = LastError != 0;
AaruConsole.DebugWriteLine(SCSI_MODULE_NAME,
Localization.
SET_CD_SPEED_Rotational_Control_1_Read_Speed_2_Write_Speed_3_Sense_4_Last_Error_5_took_0_ms,
duration, rotationalControl, readSpeed, writeSpeed, sense, LastError);
Localization
.SET_CD_SPEED_Rotational_Control_1_Read_Speed_2_Write_Speed_3_Sense_4_Last_Error_5_took_0_ms,
duration,
rotationalControl,
readSpeed,
writeSpeed,
sense,
LastError);
return sense;
}
@@ -797,17 +924,24 @@ public partial class Device
cdb[7] = (byte)((buffer.Length & 0xFF00) >> 8);
cdb[8] = (byte)(buffer.Length & 0xFF);
if(open)
cdb[1] += 4;
if(open) cdb[1] += 4;
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
LastError = SendScsiCommand(cdb,
ref buffer,
out senseBuffer,
timeout,
ScsiDirection.In,
out duration,
out bool sense);
Error = LastError != 0;
AaruConsole.DebugWriteLine(SCSI_MODULE_NAME,
Localization.READ_TRACK_INFORMATION_Data_Type_1_Sense_2_Last_Error_3_took_0_ms,
duration, type, sense, LastError);
duration,
type,
sense,
LastError);
return sense;
}