mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Device type, manufacturer, model, revision and serial number
are now obtained in device constructor.
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
2015-10-19 Natalia Portillo <claunia@claunia.com>
|
||||||
|
|
||||||
|
* Device/Constructor.cs:
|
||||||
|
* DiscImageChef.Devices.csproj:
|
||||||
|
Device type, manufacturer, model, revision and serial number
|
||||||
|
are now obtained in device constructor.
|
||||||
|
|
||||||
2015-10-19 Natalia Portillo <claunia@claunia.com>
|
2015-10-19 Natalia Portillo <claunia@claunia.com>
|
||||||
|
|
||||||
* DiscImageChef.Devices.csproj:
|
* DiscImageChef.Devices.csproj:
|
||||||
|
|||||||
@@ -90,6 +90,79 @@ namespace DiscImageChef.Devices
|
|||||||
}
|
}
|
||||||
|
|
||||||
type = DeviceType.Unknown;
|
type = DeviceType.Unknown;
|
||||||
|
|
||||||
|
AtaErrorRegistersCHS errorRegisters;
|
||||||
|
|
||||||
|
byte[] ataBuf;
|
||||||
|
bool sense = AtaIdentify(out ataBuf, out errorRegisters);
|
||||||
|
|
||||||
|
if (!sense)
|
||||||
|
{
|
||||||
|
type = DeviceType.ATA;
|
||||||
|
Decoders.ATA.Identify.IdentifyDevice? ATAID = Decoders.ATA.Identify.Decode(ataBuf);
|
||||||
|
|
||||||
|
if (ATAID.HasValue)
|
||||||
|
{
|
||||||
|
string[] separated = ATAID.Value.Model.Split(' ');
|
||||||
|
|
||||||
|
if (separated.Length == 1)
|
||||||
|
model = separated[0];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
manufacturer = separated[0];
|
||||||
|
model = separated[separated.Length - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
revision = ATAID.Value.FirmwareRevision;
|
||||||
|
serial = ATAID.Value.SerialNumber;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sense = AtapiIdentify(out ataBuf, out errorRegisters);
|
||||||
|
|
||||||
|
if (!sense)
|
||||||
|
{
|
||||||
|
type = DeviceType.ATAPI;
|
||||||
|
Decoders.ATA.Identify.IdentifyDevice? ATAID = Decoders.ATA.Identify.Decode(ataBuf);
|
||||||
|
|
||||||
|
if (ATAID.HasValue)
|
||||||
|
serial = ATAID.Value.SerialNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] senseBuf;
|
||||||
|
byte[] inqBuf;
|
||||||
|
|
||||||
|
sense = ScsiInquiry(out inqBuf, out senseBuf);
|
||||||
|
|
||||||
|
if (!sense)
|
||||||
|
{
|
||||||
|
Decoders.SCSI.Inquiry.SCSIInquiry? Inquiry = Decoders.SCSI.Inquiry.Decode(inqBuf);
|
||||||
|
|
||||||
|
if (type != DeviceType.ATAPI)
|
||||||
|
{
|
||||||
|
type = DeviceType.SCSI;
|
||||||
|
sense = ScsiInquiry(out inqBuf, out senseBuf, 0x80);
|
||||||
|
if (!sense)
|
||||||
|
serial = Decoders.SCSI.EVPD.DecodePage80(inqBuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Inquiry.HasValue)
|
||||||
|
{
|
||||||
|
revision = StringHandlers.SpacePaddedToString(Inquiry.Value.ProductRevisionLevel);
|
||||||
|
model = StringHandlers.SpacePaddedToString(Inquiry.Value.ProductIdentification);
|
||||||
|
manufacturer = StringHandlers.SpacePaddedToString(Inquiry.Value.VendorIdentification);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == DeviceType.Unknown)
|
||||||
|
{
|
||||||
|
manufacturer = null;
|
||||||
|
model = null;
|
||||||
|
revision = null;
|
||||||
|
serial = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,5 +77,13 @@
|
|||||||
<Project>{CCAA7AFE-C094-4D82-A66D-630DE8A3F545}</Project>
|
<Project>{CCAA7AFE-C094-4D82-A66D-630DE8A3F545}</Project>
|
||||||
<Name>DiscImageChef.Console</Name>
|
<Name>DiscImageChef.Console</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\DiscImageChef.Decoders\DiscImageChef.Decoders.csproj">
|
||||||
|
<Project>{0BEB3088-B634-4289-AE17-CDF2D25D00D5}</Project>
|
||||||
|
<Name>DiscImageChef.Decoders</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\DiscImageChef.Helpers\DiscImageChef.Helpers.csproj">
|
||||||
|
<Project>{F8BDF57B-1571-4CD0-84B3-B422088D359A}</Project>
|
||||||
|
<Name>DiscImageChef.Helpers</Name>
|
||||||
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
|
2015-10-19 Natalia Portillo <claunia@claunia.com>
|
||||||
|
|
||||||
|
* Commands/DeviceInfo.cs:
|
||||||
|
Device type, manufacturer, model, revision and serial number
|
||||||
|
are now obtained in device constructor.
|
||||||
|
|
||||||
2015-10-19 Natalia Portillo <claunia@claunia.com>
|
2015-10-19 Natalia Portillo <claunia@claunia.com>
|
||||||
|
|
||||||
* Commands/DeviceInfo.cs:
|
* Commands/DeviceInfo.cs:
|
||||||
|
|||||||
@@ -65,158 +65,136 @@ namespace DiscImageChef.Commands
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ata = false;
|
switch (dev.Type)
|
||||||
bool atapi = false;
|
|
||||||
bool scsi = false;
|
|
||||||
bool scsi83 = false;
|
|
||||||
|
|
||||||
string decodedAta = null;
|
|
||||||
string decodedAtapi = null;
|
|
||||||
string decodedScsi = null;
|
|
||||||
string scsiSerial = null;
|
|
||||||
|
|
||||||
StringBuilder sb = null;
|
|
||||||
|
|
||||||
AtaErrorRegistersCHS errorRegisters;
|
|
||||||
|
|
||||||
byte[] ataBuf;
|
|
||||||
bool sense = dev.AtaIdentify(out ataBuf, out errorRegisters);
|
|
||||||
|
|
||||||
if (sense)
|
|
||||||
{
|
{
|
||||||
|
case DeviceType.ATA:
|
||||||
if ((errorRegisters.status & 0x01) == 0x01
|
|
||||||
&& (errorRegisters.error & 0x04) == 0x04
|
|
||||||
&& errorRegisters.cylinderHigh == 0xEB
|
|
||||||
&& errorRegisters.cylinderLow == 0x14)
|
|
||||||
{
|
|
||||||
sense = dev.AtapiIdentify(out ataBuf, out errorRegisters);
|
|
||||||
|
|
||||||
if (sense)
|
|
||||||
{
|
{
|
||||||
DicConsole.DebugWriteLine("Device-Info command", "STATUS = 0x{0:X2}", errorRegisters.status);
|
AtaErrorRegistersCHS errorRegisters;
|
||||||
DicConsole.DebugWriteLine("Device-Info command", "ERROR = 0x{0:X2}", errorRegisters.error);
|
|
||||||
DicConsole.DebugWriteLine("Device-Info command", "NSECTOR = 0x{0:X2}", errorRegisters.sectorCount);
|
|
||||||
DicConsole.DebugWriteLine("Device-Info command", "SECTOR = 0x{0:X2}", errorRegisters.sector);
|
|
||||||
DicConsole.DebugWriteLine("Device-Info command", "CYLHIGH = 0x{0:X2}", errorRegisters.cylinderHigh);
|
|
||||||
DicConsole.DebugWriteLine("Device-Info command", "CYLLOW = 0x{0:X2}", errorRegisters.cylinderLow);
|
|
||||||
DicConsole.DebugWriteLine("Device-Info command", "DEVICE = 0x{0:X2}", errorRegisters.deviceHead);
|
|
||||||
DicConsole.DebugWriteLine("Device-Info command", "COMMAND = 0x{0:X2}", errorRegisters.command);
|
|
||||||
DicConsole.DebugWriteLine("Device-Info command", "Error code = {0}", dev.LastError);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
atapi = true;
|
|
||||||
decodedAtapi = Decoders.ATA.Identify.Prettify(ataBuf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DicConsole.DebugWriteLine("Device-Info command", "STATUS = 0x{0:X2}", errorRegisters.status);
|
|
||||||
DicConsole.DebugWriteLine("Device-Info command", "ERROR = 0x{0:X2}", errorRegisters.error);
|
|
||||||
DicConsole.DebugWriteLine("Device-Info command", "NSECTOR = 0x{0:X2}", errorRegisters.sectorCount);
|
|
||||||
DicConsole.DebugWriteLine("Device-Info command", "SECTOR = 0x{0:X2}", errorRegisters.sector);
|
|
||||||
DicConsole.DebugWriteLine("Device-Info command", "CYLHIGH = 0x{0:X2}", errorRegisters.cylinderHigh);
|
|
||||||
DicConsole.DebugWriteLine("Device-Info command", "CYLLOW = 0x{0:X2}", errorRegisters.cylinderLow);
|
|
||||||
DicConsole.DebugWriteLine("Device-Info command", "DEVICE = 0x{0:X2}", errorRegisters.deviceHead);
|
|
||||||
DicConsole.DebugWriteLine("Device-Info command", "COMMAND = 0x{0:X2}", errorRegisters.command);
|
|
||||||
DicConsole.DebugWriteLine("Device-Info command", "Error code = {0}", dev.LastError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ata = true;
|
|
||||||
decodedAta = Decoders.ATA.Identify.Prettify(ataBuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ata)
|
byte[] ataBuf;
|
||||||
{
|
bool sense = dev.AtaIdentify(out ataBuf, out errorRegisters);
|
||||||
byte[] senseBuf;
|
|
||||||
byte[] inqBuf;
|
|
||||||
|
|
||||||
sense = dev.ScsiInquiry(out inqBuf, out senseBuf);
|
if (sense)
|
||||||
|
|
||||||
if (sense)
|
|
||||||
{
|
|
||||||
DicConsole.ErrorWriteLine("SCSI error. Sense decoding not yet implemented.");
|
|
||||||
|
|
||||||
#if DEBUG
|
|
||||||
FileStream senseFs = File.Open("sense.bin", FileMode.OpenOrCreate);
|
|
||||||
senseFs.Write(senseBuf, 0, senseBuf.Length);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
scsi = true;
|
|
||||||
decodedScsi = Decoders.SCSI.Inquiry.Prettify(inqBuf);
|
|
||||||
|
|
||||||
sense = dev.ScsiInquiry(out inqBuf, out senseBuf, 0x00);
|
|
||||||
|
|
||||||
if (!sense)
|
|
||||||
{
|
|
||||||
byte[] pages = Decoders.SCSI.EVPD.DecodePage00(inqBuf);
|
|
||||||
|
|
||||||
foreach (byte page in pages)
|
|
||||||
{
|
{
|
||||||
if (page >= 0x01 && page <= 0x7F)
|
DicConsole.DebugWriteLine("Device-Info command", "STATUS = 0x{0:X2}", errorRegisters.status);
|
||||||
|
DicConsole.DebugWriteLine("Device-Info command", "ERROR = 0x{0:X2}", errorRegisters.error);
|
||||||
|
DicConsole.DebugWriteLine("Device-Info command", "NSECTOR = 0x{0:X2}", errorRegisters.sectorCount);
|
||||||
|
DicConsole.DebugWriteLine("Device-Info command", "SECTOR = 0x{0:X2}", errorRegisters.sector);
|
||||||
|
DicConsole.DebugWriteLine("Device-Info command", "CYLHIGH = 0x{0:X2}", errorRegisters.cylinderHigh);
|
||||||
|
DicConsole.DebugWriteLine("Device-Info command", "CYLLOW = 0x{0:X2}", errorRegisters.cylinderLow);
|
||||||
|
DicConsole.DebugWriteLine("Device-Info command", "DEVICE = 0x{0:X2}", errorRegisters.deviceHead);
|
||||||
|
DicConsole.DebugWriteLine("Device-Info command", "COMMAND = 0x{0:X2}", errorRegisters.command);
|
||||||
|
DicConsole.DebugWriteLine("Device-Info command", "Error code = {0}", dev.LastError);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
DicConsole.WriteLine(Decoders.ATA.Identify.Prettify(ataBuf));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DeviceType.ATAPI:
|
||||||
|
{
|
||||||
|
AtaErrorRegistersCHS errorRegisters;
|
||||||
|
|
||||||
|
byte[] ataBuf;
|
||||||
|
bool sense = dev.AtapiIdentify(out ataBuf, out errorRegisters);
|
||||||
|
|
||||||
|
if (sense)
|
||||||
|
{
|
||||||
|
DicConsole.DebugWriteLine("Device-Info command", "STATUS = 0x{0:X2}", errorRegisters.status);
|
||||||
|
DicConsole.DebugWriteLine("Device-Info command", "ERROR = 0x{0:X2}", errorRegisters.error);
|
||||||
|
DicConsole.DebugWriteLine("Device-Info command", "NSECTOR = 0x{0:X2}", errorRegisters.sectorCount);
|
||||||
|
DicConsole.DebugWriteLine("Device-Info command", "SECTOR = 0x{0:X2}", errorRegisters.sector);
|
||||||
|
DicConsole.DebugWriteLine("Device-Info command", "CYLHIGH = 0x{0:X2}", errorRegisters.cylinderHigh);
|
||||||
|
DicConsole.DebugWriteLine("Device-Info command", "CYLLOW = 0x{0:X2}", errorRegisters.cylinderLow);
|
||||||
|
DicConsole.DebugWriteLine("Device-Info command", "DEVICE = 0x{0:X2}", errorRegisters.deviceHead);
|
||||||
|
DicConsole.DebugWriteLine("Device-Info command", "COMMAND = 0x{0:X2}", errorRegisters.command);
|
||||||
|
DicConsole.DebugWriteLine("Device-Info command", "Error code = {0}", dev.LastError);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
DicConsole.WriteLine(Decoders.ATA.Identify.Prettify(ataBuf));
|
||||||
|
|
||||||
|
// ATAPI devices are also SCSI devices
|
||||||
|
goto case DeviceType.SCSI;
|
||||||
|
}
|
||||||
|
case DeviceType.SCSI:
|
||||||
|
{
|
||||||
|
byte[] senseBuf;
|
||||||
|
byte[] inqBuf;
|
||||||
|
|
||||||
|
bool sense = dev.ScsiInquiry(out inqBuf, out senseBuf);
|
||||||
|
|
||||||
|
if (sense)
|
||||||
|
{
|
||||||
|
DicConsole.ErrorWriteLine("SCSI error. Sense decoding not yet implemented.");
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
FileStream senseFs = File.Open("sense.bin", FileMode.OpenOrCreate);
|
||||||
|
senseFs.Write(senseBuf, 0, senseBuf.Length);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dev.Type != DeviceType.ATAPI)
|
||||||
|
DicConsole.WriteLine("SCSI device");
|
||||||
|
|
||||||
|
DicConsole.WriteLine(Decoders.SCSI.Inquiry.Prettify(inqBuf));
|
||||||
|
|
||||||
|
bool scsi83 = false;
|
||||||
|
string scsiSerial = null;
|
||||||
|
StringBuilder sb = null;
|
||||||
|
|
||||||
|
sense = dev.ScsiInquiry(out inqBuf, out senseBuf, 0x00);
|
||||||
|
|
||||||
|
if (!sense)
|
||||||
|
{
|
||||||
|
byte[] pages = Decoders.SCSI.EVPD.DecodePage00(inqBuf);
|
||||||
|
|
||||||
|
foreach (byte page in pages)
|
||||||
{
|
{
|
||||||
sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page);
|
if (page >= 0x01 && page <= 0x7F)
|
||||||
if (!sense)
|
|
||||||
{
|
{
|
||||||
if(sb == null)
|
sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page);
|
||||||
sb = new StringBuilder();
|
if (!sense)
|
||||||
sb.AppendFormat("Page 0x{0:X2}: ", Decoders.SCSI.EVPD.DecodeASCIIPage(inqBuf)).AppendLine();
|
{
|
||||||
|
if (sb == null)
|
||||||
|
sb = new StringBuilder();
|
||||||
|
sb.AppendFormat("Page 0x{0:X2}: ", Decoders.SCSI.EVPD.DecodeASCIIPage(inqBuf)).AppendLine();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else if (page == 0x80)
|
||||||
else if (page == 0x80)
|
|
||||||
{
|
|
||||||
sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page);
|
|
||||||
if (!sense)
|
|
||||||
{
|
{
|
||||||
scsi83 = true;
|
sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page);
|
||||||
scsiSerial = Decoders.SCSI.EVPD.DecodePage80(inqBuf);
|
if (!sense)
|
||||||
|
{
|
||||||
|
scsi83 = true;
|
||||||
|
scsiSerial = Decoders.SCSI.EVPD.DecodePage80(inqBuf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (page != 0x00)
|
||||||
|
DicConsole.DebugWriteLine("Device-Info command", "Found undecoded SCSI VPD page 0x{0:X2}", page);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(page != 0x00)
|
|
||||||
DicConsole.DebugWriteLine("Device-Info command", "Found undecoded SCSI VPD page 0x{0:X2}", page);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (scsi83)
|
||||||
|
DicConsole.WriteLine("Unit Serial Number: {0}", scsiSerial);
|
||||||
|
|
||||||
|
if (sb != null)
|
||||||
|
{
|
||||||
|
DicConsole.WriteLine("ASCII VPDs:");
|
||||||
|
DicConsole.WriteLine(sb.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
default:
|
||||||
|
DicConsole.ErrorWriteLine("Unknown device type {0}, cannot get information.", dev.Type);
|
||||||
if (atapi)
|
break;
|
||||||
{
|
|
||||||
DicConsole.WriteLine(decodedAtapi);
|
|
||||||
}
|
|
||||||
else if (scsi)
|
|
||||||
{
|
|
||||||
DicConsole.WriteLine("SCSI device");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(scsi)
|
|
||||||
{
|
|
||||||
DicConsole.WriteLine(decodedScsi);
|
|
||||||
|
|
||||||
if(scsi83)
|
|
||||||
DicConsole.WriteLine("Unit Serial Number: {0}", scsiSerial);
|
|
||||||
|
|
||||||
if(sb != null)
|
|
||||||
{
|
|
||||||
DicConsole.WriteLine("ASCII VPDs:");
|
|
||||||
DicConsole.WriteLine(sb.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
DicConsole.WriteLine("ATA device");
|
|
||||||
DicConsole.WriteLine(decodedAta);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!ata && !atapi && !scsi)
|
|
||||||
DicConsole.ErrorWriteLine("Unknown device type, cannot get information.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user