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

@@ -42,39 +42,39 @@ namespace DiscImageChef.Decoders.MMC
[SuppressMessage("ReSharper", "NotAccessedField.Global")]
public class CSD
{
public byte Structure;
public byte Version;
public byte TAAC;
public byte NSAC;
public byte Speed;
public byte Structure;
public byte Version;
public byte TAAC;
public byte NSAC;
public byte Speed;
public ushort Classes;
public byte ReadBlockLength;
public bool ReadsPartialBlocks;
public bool WriteMisalignment;
public bool ReadMisalignment;
public bool DSRImplemented;
public byte ReadBlockLength;
public bool ReadsPartialBlocks;
public bool WriteMisalignment;
public bool ReadMisalignment;
public bool DSRImplemented;
public ushort Size;
public byte ReadCurrentAtVddMin;
public byte ReadCurrentAtVddMax;
public byte WriteCurrentAtVddMin;
public byte WriteCurrentAtVddMax;
public byte SizeMultiplier;
public byte EraseGroupSize;
public byte EraseGroupSizeMultiplier;
public byte WriteProtectGroupSize;
public bool WriteProtectGroupEnable;
public byte DefaultECC;
public byte WriteSpeedFactor;
public byte WriteBlockLength;
public bool WritesPartialBlocks;
public bool ContentProtection;
public bool FileFormatGroup;
public bool Copy;
public bool PermanentWriteProtect;
public bool TemporaryWriteProtect;
public byte FileFormat;
public byte ECC;
public byte CRC;
public byte ReadCurrentAtVddMin;
public byte ReadCurrentAtVddMax;
public byte WriteCurrentAtVddMin;
public byte WriteCurrentAtVddMax;
public byte SizeMultiplier;
public byte EraseGroupSize;
public byte EraseGroupSizeMultiplier;
public byte WriteProtectGroupSize;
public bool WriteProtectGroupEnable;
public byte DefaultECC;
public byte WriteSpeedFactor;
public byte WriteBlockLength;
public bool WritesPartialBlocks;
public bool ContentProtection;
public bool FileFormatGroup;
public bool Copy;
public bool PermanentWriteProtect;
public bool TemporaryWriteProtect;
public byte FileFormat;
public byte ECC;
public byte CRC;
}
[SuppressMessage("ReSharper", "InconsistentNaming")]
@@ -106,39 +106,40 @@ namespace DiscImageChef.Decoders.MMC
return new CSD
{
Structure = (byte)((response[0] & 0xC0) >> 6),
Version = (byte)((response[0] & 0x3C) >> 2),
TAAC = response[1],
NSAC = response[2],
Speed = response[3],
Classes = (ushort)((response[4] << 4) + ((response[5] & 0xF0) >> 4)),
ReadBlockLength = (byte)(response[5] & 0x0F),
ReadsPartialBlocks = (response[6] & 0x80) == 0x80,
WriteMisalignment = (response[6] & 0x40) == 0x40,
ReadMisalignment = (response[6] & 0x20) == 0x20,
DSRImplemented = (response[6] & 0x10) == 0x10,
Size = (ushort)(((response[6] & 0x03) << 10) + (response[7] << 2) + ((response[8] & 0xC0) >> 6)),
ReadCurrentAtVddMin = (byte)((response[8] & 0x38) >> 3),
ReadCurrentAtVddMax = (byte)(response[8] & 0x07),
WriteCurrentAtVddMin = (byte)((response[9] & 0xE0) >> 5),
WriteCurrentAtVddMax = (byte)((response[9] & 0x1C) >> 2),
SizeMultiplier = (byte)(((response[9] & 0x03) << 1) + ((response[10] & 0x80) >> 7)),
EraseGroupSize = (byte)((response[10] & 0x7C) >> 2),
Structure = (byte)((response[0] & 0xC0) >> 6),
Version = (byte)((response[0] & 0x3C) >> 2),
TAAC = response[1],
NSAC = response[2],
Speed = response[3],
Classes = (ushort)((response[4] << 4) + ((response[5] & 0xF0) >> 4)),
ReadBlockLength = (byte)(response[5] & 0x0F),
ReadsPartialBlocks = (response[6] & 0x80) == 0x80,
WriteMisalignment = (response[6] & 0x40) == 0x40,
ReadMisalignment = (response[6] & 0x20) == 0x20,
DSRImplemented = (response[6] & 0x10) == 0x10,
Size =
(ushort)(((response[6] & 0x03) << 10) + (response[7] << 2) + ((response[8] & 0xC0) >> 6)),
ReadCurrentAtVddMin = (byte)((response[8] & 0x38) >> 3),
ReadCurrentAtVddMax = (byte)(response[8] & 0x07),
WriteCurrentAtVddMin = (byte)((response[9] & 0xE0) >> 5),
WriteCurrentAtVddMax = (byte)((response[9] & 0x1C) >> 2),
SizeMultiplier = (byte)(((response[9] & 0x03) << 1) + ((response[10] & 0x80) >> 7)),
EraseGroupSize = (byte)((response[10] & 0x7C) >> 2),
EraseGroupSizeMultiplier = (byte)(((response[10] & 0x03) << 3) + ((response[11] & 0xE0) >> 5)),
WriteProtectGroupSize = (byte)(response[11] & 0x1F),
WriteProtectGroupEnable = (response[12] & 0x80) == 0x80,
DefaultECC = (byte)((response[12] & 0x60) >> 5),
WriteSpeedFactor = (byte)((response[12] & 0x1C) >> 2),
WriteBlockLength = (byte)(((response[12] & 0x03) << 2) + ((response[13] & 0xC0) >> 6)),
WritesPartialBlocks = (response[13] & 0x20) == 0x20,
ContentProtection = (response[13] & 0x01) == 0x01,
FileFormatGroup = (response[14] & 0x80) == 0x80,
Copy = (response[14] & 0x40) == 0x40,
PermanentWriteProtect = (response[14] & 0x20) == 0x20,
TemporaryWriteProtect = (response[14] & 0x10) == 0x10,
FileFormat = (byte)((response[14] & 0x0C) >> 2),
ECC = (byte)(response[14] & 0x03),
CRC = (byte)((response[15] & 0xFE) >> 1)
WriteProtectGroupSize = (byte)(response[11] & 0x1F),
WriteProtectGroupEnable = (response[12] & 0x80) == 0x80,
DefaultECC = (byte)((response[12] & 0x60) >> 5),
WriteSpeedFactor = (byte)((response[12] & 0x1C) >> 2),
WriteBlockLength = (byte)(((response[12] & 0x03) << 2) + ((response[13] & 0xC0) >> 6)),
WritesPartialBlocks = (response[13] & 0x20) == 0x20,
ContentProtection = (response[13] & 0x01) == 0x01,
FileFormatGroup = (response[14] & 0x80) == 0x80,
Copy = (response[14] & 0x40) == 0x40,
PermanentWriteProtect = (response[14] & 0x20) == 0x20,
TemporaryWriteProtect = (response[14] & 0x10) == 0x10,
FileFormat = (byte)((response[14] & 0x0C) >> 2),
ECC = (byte)(response[14] & 0x03),
CRC = (byte)((response[15] & 0xFE) >> 1)
};
}
@@ -148,7 +149,7 @@ namespace DiscImageChef.Decoders.MMC
double unitFactor = 0;
double multiplier = 0;
string unit = "";
string unit = "";
StringBuilder sb = new StringBuilder();
sb.AppendLine("MultiMediaCard Device Specific Data Register:");
@@ -171,35 +172,35 @@ namespace DiscImageChef.Decoders.MMC
switch(csd.TAAC & 0x07)
{
case 0:
unit = "ns";
unit = "ns";
unitFactor = 1;
break;
case 1:
unit = "ns";
unit = "ns";
unitFactor = 10;
break;
case 2:
unit = "ns";
unit = "ns";
unitFactor = 100;
break;
case 3:
unit = "μs";
unit = "μs";
unitFactor = 1;
break;
case 4:
unit = "μs";
unit = "μs";
unitFactor = 10;
break;
case 5:
unit = "μs";
unit = "μs";
unitFactor = 100;
break;
case 6:
unit = "ms";
unit = "ms";
unitFactor = 1;
break;
case 7:
unit = "ms";
unit = "ms";
unitFactor = 10;
break;
}
@@ -277,7 +278,7 @@ namespace DiscImageChef.Decoders.MMC
unitFactor = 100;
break;
default:
unit = "unknown";
unit = "unknown";
unitFactor = 0;
break;
}
@@ -338,7 +339,9 @@ namespace DiscImageChef.Decoders.MMC
sb.AppendFormat("\tDevice's clock frequency: {0}{1}", result, unit).AppendLine();
unit = "";
for(int cl = 0, mask = 1; cl <= 11; cl++, mask <<= 1) if((csd.Classes & mask) == mask) unit += $" {cl}";
for(int cl = 0, mask = 1; cl <= 11; cl++, mask <<= 1)
if((csd.Classes & mask) == mask)
unit += $" {cl}";
sb.AppendFormat("\tDevice support command classes {0}", unit).AppendLine();
if(csd.ReadBlockLength == 15) sb.AppendLine("\tRead block length size is defined in extended CSD");
@@ -358,7 +361,7 @@ namespace DiscImageChef.Decoders.MMC
sb.AppendFormat("\tDevice has {0} blocks", (int)result).AppendLine();
result = (csd.Size + 1) * Math.Pow(2, csd.SizeMultiplier + 2) * Math.Pow(2, csd.ReadBlockLength);
if(result > 1073741824) sb.AppendFormat("\tDevice has {0} GiB", result / 1073741824.0).AppendLine();
if(result > 1073741824) sb.AppendFormat("\tDevice has {0} GiB", result / 1073741824.0).AppendLine();
else if(result > 1048576) sb.AppendFormat("\tDevice has {0} MiB", result / 1048576.0).AppendLine();
else if(result > 1024) sb.AppendFormat("\tDevice has {0} KiB", result / 1024.0).AppendLine();
else sb.AppendFormat("\tDevice has {0} bytes", result).AppendLine();
@@ -478,7 +481,7 @@ namespace DiscImageChef.Decoders.MMC
// TODO: Check specification
unitFactor = Convert.ToDouble(csd.EraseGroupSize);
multiplier = Convert.ToDouble(csd.EraseGroupSizeMultiplier);
result = (unitFactor + 1) * (multiplier + 1);
result = (unitFactor + 1) * (multiplier + 1);
sb.AppendFormat("\tDevice can erase a minimum of {0} blocks at a time", (int)result).AppendLine();
if(csd.WriteProtectGroupEnable)