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

@@ -41,13 +41,13 @@ namespace DiscImageChef.Decoders.SecureDigital
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public class CID
{
public byte Manufacturer;
public byte Manufacturer;
public string ApplicationID;
public string ProductName;
public byte ProductRevision;
public uint ProductSerialNumber;
public byte ProductRevision;
public uint ProductSerialNumber;
public ushort ManufacturingDate;
public byte CRC;
public byte CRC;
}
[SuppressMessage("ReSharper", "InconsistentNaming")]
@@ -79,16 +79,16 @@ namespace DiscImageChef.Decoders.SecureDigital
CID cid = new CID
{
Manufacturer = response[0],
ProductRevision = response[8],
Manufacturer = response[0],
ProductRevision = response[8],
ProductSerialNumber = BitConverter.ToUInt32(response, 9),
ManufacturingDate = (ushort)(((response[13] & 0x0F) << 4) + response[14]),
CRC = (byte)((response[15] & 0xFE) >> 1)
ManufacturingDate = (ushort)(((response[13] & 0x0F) << 4) + response[14]),
CRC = (byte)((response[15] & 0xFE) >> 1)
};
byte[] tmp = new byte[2];
Array.Copy(response, 1, tmp, 0, 2);
cid.ApplicationID = StringHandlers.CToString(tmp);
tmp = new byte[5];
tmp = new byte[5];
Array.Copy(response, 3, tmp, 0, 5);
cid.ProductName = StringHandlers.CToString(tmp);
@@ -109,7 +109,8 @@ namespace DiscImageChef.Decoders.SecureDigital
cid.ProductRevision & 0x0F).AppendLine();
sb.AppendFormat("\tProduct serial number: {0}", cid.ProductSerialNumber).AppendLine();
sb.AppendFormat("\tDevice manufactured month {0} of {1}", (cid.ManufacturingDate & 0xF00) >> 8,
(cid.ManufacturingDate & 0xFF) + 2000).AppendLine();
(cid.ManufacturingDate & 0xFF) + 2000)
.AppendLine();
sb.AppendFormat("\tCID CRC: 0x{0:X2}", cid.CRC).AppendLine();
return sb.ToString();

View File

@@ -41,35 +41,35 @@ namespace DiscImageChef.Decoders.SecureDigital
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public class CSD
{
public byte Structure;
public byte TAAC;
public byte NSAC;
public byte Speed;
public byte Structure;
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 uint Size;
public byte ReadCurrentAtVddMin;
public byte ReadCurrentAtVddMax;
public byte WriteCurrentAtVddMin;
public byte WriteCurrentAtVddMax;
public byte SizeMultiplier;
public bool EraseBlockEnable;
public byte EraseSectorSize;
public byte WriteProtectGroupSize;
public bool WriteProtectGroupEnable;
public byte WriteSpeedFactor;
public byte WriteBlockLength;
public bool WritesPartialBlocks;
public bool FileFormatGroup;
public bool Copy;
public bool PermanentWriteProtect;
public bool TemporaryWriteProtect;
public byte FileFormat;
public byte CRC;
public byte ReadBlockLength;
public bool ReadsPartialBlocks;
public bool WriteMisalignment;
public bool ReadMisalignment;
public bool DSRImplemented;
public uint Size;
public byte ReadCurrentAtVddMin;
public byte ReadCurrentAtVddMax;
public byte WriteCurrentAtVddMin;
public byte WriteCurrentAtVddMax;
public byte SizeMultiplier;
public bool EraseBlockEnable;
public byte EraseSectorSize;
public byte WriteProtectGroupSize;
public bool WriteProtectGroupEnable;
public byte WriteSpeedFactor;
public byte WriteBlockLength;
public bool WritesPartialBlocks;
public bool FileFormatGroup;
public bool Copy;
public bool PermanentWriteProtect;
public bool TemporaryWriteProtect;
public byte FileFormat;
public byte CRC;
}
[SuppressMessage("ReSharper", "InconsistentNaming")]
@@ -100,39 +100,40 @@ namespace DiscImageChef.Decoders.SecureDigital
CSD csd = new CSD
{
Structure = (byte)((response[0] & 0xC0) >> 6),
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,
EraseBlockEnable = (response[10] & 0x40) == 0x40,
EraseSectorSize = (byte)(((response[10] & 0x3F) << 1) + ((response[11] & 0x80) >> 7)),
WriteProtectGroupSize = (byte)(response[11] & 0x7F),
WriteProtectGroupEnable = (response[12] & 0x80) == 0x80,
WriteSpeedFactor = (byte)((response[12] & 0x1C) >> 2),
WriteBlockLength = (byte)(((response[12] & 0x03) << 2) + ((response[13] & 0xC0) >> 6)),
WritesPartialBlocks = (response[13] & 0x20) == 0x20,
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),
CRC = (byte)((response[15] & 0xFE) >> 1)
Structure = (byte)((response[0] & 0xC0) >> 6),
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,
EraseBlockEnable = (response[10] & 0x40) == 0x40,
EraseSectorSize = (byte)(((response[10] & 0x3F) << 1) + ((response[11] & 0x80) >> 7)),
WriteProtectGroupSize = (byte)(response[11] & 0x7F),
WriteProtectGroupEnable = (response[12] & 0x80) == 0x80,
WriteSpeedFactor = (byte)((response[12] & 0x1C) >> 2),
WriteBlockLength = (byte)(((response[12] & 0x03) << 2) + ((response[13] & 0xC0) >> 6)),
WritesPartialBlocks = (response[13] & 0x20) == 0x20,
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),
CRC = (byte)((response[15] & 0xFE) >> 1)
};
if(csd.Structure == 0)
{
csd.Size = (ushort)(((response[6] & 0x03) << 10) + (response[7] << 2) + ((response[8] & 0xC0) >> 6));
csd.ReadCurrentAtVddMin = (byte)((response[8] & 0x38) >> 3);
csd.ReadCurrentAtVddMax = (byte)(response[8] & 0x07);
csd.Size =
(ushort)(((response[6] & 0x03) << 10) + (response[7] << 2) + ((response[8] & 0xC0) >> 6));
csd.ReadCurrentAtVddMin = (byte)((response[8] & 0x38) >> 3);
csd.ReadCurrentAtVddMax = (byte)(response[8] & 0x07);
csd.WriteCurrentAtVddMin = (byte)((response[9] & 0xE0) >> 5);
csd.WriteCurrentAtVddMax = (byte)((response[9] & 0x1C) >> 2);
csd.SizeMultiplier = (byte)(((response[9] & 0x03) << 1) + ((response[10] & 0x80) >> 7));
csd.SizeMultiplier = (byte)(((response[9] & 0x03) << 1) + ((response[10] & 0x80) >> 7));
}
else csd.Size = (uint)(((response[7] & 0x3F) << 16) + (response[8] << 8) + response[9]);
@@ -145,7 +146,7 @@ namespace DiscImageChef.Decoders.SecureDigital
double unitFactor = 0;
double multiplier = 0;
string unit = "";
string unit = "";
StringBuilder sb = new StringBuilder();
sb.AppendLine("SecureDigital Device Specific Data Register:");
@@ -162,35 +163,35 @@ namespace DiscImageChef.Decoders.SecureDigital
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;
}
@@ -268,7 +269,7 @@ namespace DiscImageChef.Decoders.SecureDigital
unitFactor = 100;
break;
default:
unit = "unknown";
unit = "unknown";
unitFactor = 0;
break;
}
@@ -329,7 +330,9 @@ namespace DiscImageChef.Decoders.SecureDigital
sb.AppendFormat("\tDevice's transfer speed: {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();
sb.AppendFormat("\tRead block length is {0} bytes", Math.Pow(2, csd.ReadBlockLength)).AppendLine();
@@ -347,7 +350,8 @@ namespace DiscImageChef.Decoders.SecureDigital
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();

View File

@@ -67,20 +67,20 @@ namespace DiscImageChef.Decoders.SecureDigital
{
return new OCR
{
PowerUp = (response & 0x80000000) == 0x80000000,
CCS = (response & 0x40000000) == 0x40000000,
UHS = (response & 0x20000000) == 0x20000000,
OneEight = (response & 0x01000000) == 0x01000000,
ThreeFive = (response & 0x00800000) == 0x00800000,
ThreeFour = (response & 0x00400000) == 0x00400000,
PowerUp = (response & 0x80000000) == 0x80000000,
CCS = (response & 0x40000000) == 0x40000000,
UHS = (response & 0x20000000) == 0x20000000,
OneEight = (response & 0x01000000) == 0x01000000,
ThreeFive = (response & 0x00800000) == 0x00800000,
ThreeFour = (response & 0x00400000) == 0x00400000,
ThreeThree = (response & 0x00200000) == 0x00200000,
ThreeTwo = (response & 0x00100000) == 0x00100000,
ThreeOne = (response & 0x00080000) == 0x00080000,
ThreeZero = (response & 0x00040000) == 0x00040000,
TwoNine = (response & 0x00020000) == 0x00020000,
TwoEight = (response & 0x00010000) == 0x00010000,
TwoSeven = (response & 0x00008000) == 0x00008000,
LowPower = (response & 0x00000080) == 0x00000080
ThreeTwo = (response & 0x00100000) == 0x00100000,
ThreeOne = (response & 0x00080000) == 0x00080000,
ThreeZero = (response & 0x00040000) == 0x00040000,
TwoNine = (response & 0x00020000) == 0x00020000,
TwoEight = (response & 0x00010000) == 0x00010000,
TwoSeven = (response & 0x00008000) == 0x00008000,
LowPower = (response & 0x00000080) == 0x00000080
};
}

View File

@@ -42,16 +42,16 @@ namespace DiscImageChef.Decoders.SecureDigital
[SuppressMessage("ReSharper", "NotAccessedField.Global")]
public class SCR
{
public byte Structure;
public byte Spec;
public bool DataStatusAfterErase;
public byte Security;
public byte BusWidth;
public bool Spec3;
public byte ExtendedSecurity;
public bool Spec4;
public byte SpecX;
public byte CommandSupport;
public byte Structure;
public byte Spec;
public bool DataStatusAfterErase;
public byte Security;
public byte BusWidth;
public bool Spec3;
public byte ExtendedSecurity;
public bool Spec4;
public byte SpecX;
public byte CommandSupport;
public byte[] ManufacturerReserved;
}
@@ -79,16 +79,16 @@ namespace DiscImageChef.Decoders.SecureDigital
SCR scr = new SCR
{
Structure = (byte)((response[0] & 0xF0) >> 4),
Spec = (byte)(response[0] & 0x0F),
DataStatusAfterErase = (response[1] & 0x80) == 0x80,
Security = (byte)((response[1] & 0x70) >> 4),
BusWidth = (byte)(response[1] & 0x0F),
Spec3 = (response[2] & 0x80) == 0x80,
ExtendedSecurity = (byte)((response[2] & 0x78) >> 3),
Spec4 = (response[2] & 0x04) == 0x04,
SpecX = (byte)(((response[2] & 0x03) << 2) + ((response[3] & 0xC0) >> 6)),
CommandSupport = (byte)(response[3] & 0x0F),
Structure = (byte)((response[0] & 0xF0) >> 4),
Spec = (byte)(response[0] & 0x0F),
DataStatusAfterErase = (response[1] & 0x80) == 0x80,
Security = (byte)((response[1] & 0x70) >> 4),
BusWidth = (byte)(response[1] & 0x0F),
Spec3 = (response[2] & 0x80) == 0x80,
ExtendedSecurity = (byte)((response[2] & 0x78) >> 3),
Spec4 = (response[2] & 0x04) == 0x04,
SpecX = (byte)(((response[2] & 0x03) << 2) + ((response[3] & 0xC0) >> 6)),
CommandSupport = (byte)(response[3] & 0x0F),
ManufacturerReserved = new byte[4]
};
Array.Copy(response, 4, scr.ManufacturerReserved, 0, 4);
@@ -119,8 +119,8 @@ namespace DiscImageChef.Decoders.SecureDigital
sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 5.xx");
else
sb
.AppendFormat("\tDevice follows SecureDigital Physical Layer Specification with unknown version {0}.{1}.{2}.{3}",
scr.Spec, scr.Spec3, scr.Spec4, scr.SpecX).AppendLine();
.AppendFormat("\tDevice follows SecureDigital Physical Layer Specification with unknown version {0}.{1}.{2}.{3}",
scr.Spec, scr.Spec3, scr.Spec4, scr.SpecX).AppendLine();
switch(scr.Security)
{
case 0:

View File

@@ -39,7 +39,7 @@ namespace DiscImageChef.Decoders.SecureDigital
switch(sdVendorId)
{
case 0xAA: return "QEMU";
default: return $"Unknown manufacturer ID 0x{sdVendorId:X2}";
default: return $"Unknown manufacturer ID 0x{sdVendorId:X2}";
}
}
}