Move SCSI device reporting to non-static class and its UI to CLI.

This commit is contained in:
2018-11-25 20:08:28 +00:00
parent 624c88ae61
commit 745e408233
4 changed files with 653 additions and 681 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -46,7 +46,7 @@ namespace DiscImageChef.Core.Devices.Report.SCSI
/// <summary>
/// Implements creating a report for a SCSI MultiMedia device
/// </summary>
static class Mmc
public static class Mmc
{
/// <summary>
/// Fills a SCSI device report with parameters and media tests specific to a MultiMedia device
@@ -55,8 +55,8 @@ namespace DiscImageChef.Core.Devices.Report.SCSI
/// <param name="report">Device report</param>
/// <param name="debug">If debug is enabled</param>
/// <param name="cdromMode">Decoded MODE PAGE 2Ah</param>
internal static void Report(Device dev, ref DeviceReportV2 report, bool debug, ref Modes.ModePage_2A? cdromMode,
string productIdentification)
public static void Report(Device dev, ref DeviceReportV2 report, bool debug, Modes.ModePage_2A? cdromMode,
string productIdentification)
{
if(report == null) return;

View File

@@ -44,7 +44,7 @@ namespace DiscImageChef.Core.Devices.Report.SCSI
/// <summary>
/// Implements creating a report for a SCSI Streaming device
/// </summary>
static class Ssc
public static class Ssc
{
/// <summary>
/// Fills a SCSI device report with parameters and media tests specific to a Streaming device
@@ -52,7 +52,7 @@ namespace DiscImageChef.Core.Devices.Report.SCSI
/// <param name="dev">Device</param>
/// <param name="report">Device report</param>
/// <param name="debug">If debug is enabled</param>
internal static void Report(Device dev, ref DeviceReportV2 report, bool debug)
public static void Report(Device dev, ref DeviceReportV2 report, bool debug)
{
if(report == null) return;

View File

@@ -33,12 +33,16 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using DiscImageChef.CommonTypes.Metadata;
using DiscImageChef.Console;
using DiscImageChef.Core.Devices.Report.SCSI;
using DiscImageChef.Core;
using DiscImageChef.Decoders.ATA;
using DiscImageChef.Decoders.SCSI;
using DiscImageChef.Devices;
using Newtonsoft.Json;
using Mmc = DiscImageChef.Core.Devices.Report.SCSI.Mmc;
using Ssc = DiscImageChef.Core.Devices.Report.SCSI.Ssc;
namespace DiscImageChef.Commands
{
@@ -224,8 +228,7 @@ namespace DiscImageChef.Commands
case DeviceType.SecureDigital:
report.SecureDigital = reporter.MmcSdReport();
break;
case DeviceType.NVMe:
throw new NotImplementedException("NVMe devices not yet supported.");
case DeviceType.NVMe: throw new NotImplementedException("NVMe devices not yet supported.");
case DeviceType.ATAPI:
DicConsole.WriteLine("Querying ATAPI IDENTIFY...");
@@ -234,13 +237,261 @@ namespace DiscImageChef.Commands
if(!Identify.Decode(buffer).HasValue) return;
Identify.IdentifyDevice? atapiIdNullable = Identify.Decode(buffer);
if(atapiIdNullable != null) report.ATAPI = new CommonTypes.Metadata.Ata {IdentifyDevice = atapiIdNullable};
if(atapiIdNullable != null) report.ATAPI = new Ata {IdentifyDevice = atapiIdNullable};
if(options.Debug) report.ATAPI.Identify = buffer;
goto case DeviceType.SCSI;
case DeviceType.SCSI:
General.Report(dev, ref report, options.Debug, ref removable);
if(!dev.IsUsb && !dev.IsFireWire && dev.IsRemovable)
{
pressedKey = new ConsoleKeyInfo();
while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N)
{
DicConsole
.Write("Is the media removable from the reading/writing elements (flash memories ARE NOT removable)? (Y/N): ");
pressedKey = System.Console.ReadKey();
DicConsole.WriteLine();
}
removable = pressedKey.Key == ConsoleKey.Y;
}
if(removable)
{
switch(dev.ScsiType)
{
case PeripheralDeviceTypes.MultiMediaDevice:
dev.AllowMediumRemoval(out buffer, dev.Timeout, out _);
dev.EjectTray(out buffer, dev.Timeout, out _);
break;
case PeripheralDeviceTypes.SequentialAccess:
dev.SpcAllowMediumRemoval(out buffer, dev.Timeout, out _);
DicConsole.WriteLine("Asking drive to unload tape (can take a few minutes)...");
dev.Unload(out buffer, dev.Timeout, out _);
break;
}
DicConsole
.WriteLine("Please remove any media from the device and press any key when it is out.");
System.Console.ReadKey(true);
}
report.SCSI = reporter.ReportScsiInquiry();
if(report.SCSI == null) break;
report.SCSI.EVPDPages = reporter.ReportEvpdPages();
Modes.ModePage_2A? cdromMode = null;
reporter.ReportScsiModes(ref report, ref cdromMode);
string productIdentification = null;
if(!string.IsNullOrWhiteSpace(StringHandlers.CToString(report.SCSI.Inquiry?.ProductIdentification)))
productIdentification =
StringHandlers.CToString(report.SCSI.Inquiry?.ProductIdentification).Trim();
switch(dev.ScsiType)
{
case PeripheralDeviceTypes.MultiMediaDevice:
Mmc.Report(dev, ref report, options.Debug, cdromMode, productIdentification);
break;
case PeripheralDeviceTypes.SequentialAccess:
Ssc.Report(dev, ref report, options.Debug);
break;
default:
{
if(removable)
{
List<TestedMedia> mediaTests = new List<TestedMedia>();
pressedKey = new ConsoleKeyInfo();
while(pressedKey.Key != ConsoleKey.N)
{
pressedKey = new ConsoleKeyInfo();
while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N)
{
DicConsole.Write("Do you have media that you can insert in the drive? (Y/N): ");
pressedKey = System.Console.ReadKey();
DicConsole.WriteLine();
}
if(pressedKey.Key != ConsoleKey.Y) continue;
DicConsole
.WriteLine("Please insert it in the drive and press any key when it is ready.");
System.Console.ReadKey(true);
DicConsole.Write("Please write a description of the media type and press enter: ");
string mediumTypeName = System.Console.ReadLine();
DicConsole.Write("Please write the media manufacturer and press enter: ");
string manufacturer = System.Console.ReadLine();
DicConsole.Write("Please write the media model and press enter: ");
string model = System.Console.ReadLine();
bool mediaIsRecognized = true;
bool sense = dev.ScsiTestUnitReady(out byte[] senseBuffer, dev.Timeout, out _);
if(sense)
{
FixedSense? decSense = Sense.DecodeFixed(senseBuffer);
if(decSense.HasValue)
if(decSense.Value.ASC == 0x3A)
{
int leftRetries = 20;
while(leftRetries > 0)
{
DicConsole.Write("\rWaiting for drive to become ready");
Thread.Sleep(2000);
sense = dev.ScsiTestUnitReady(out senseBuffer, dev.Timeout, out _);
if(!sense) break;
leftRetries--;
}
mediaIsRecognized &= !sense;
}
else if(decSense.Value.ASC == 0x04 && decSense.Value.ASCQ == 0x01)
{
int leftRetries = 20;
while(leftRetries > 0)
{
DicConsole.Write("\rWaiting for drive to become ready");
Thread.Sleep(2000);
sense = dev.ScsiTestUnitReady(out senseBuffer, dev.Timeout, out _);
if(!sense) break;
leftRetries--;
}
mediaIsRecognized &= !sense;
}
else mediaIsRecognized = false;
else mediaIsRecognized = false;
}
TestedMedia mediaTest = new TestedMedia();
if(mediaIsRecognized)
{
mediaTest = reporter.ReportScsiMedia();
if(mediaTest.SupportsReadLong == true &&
mediaTest.LongBlockSize == mediaTest.BlockSize)
{
pressedKey = new ConsoleKeyInfo();
while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N)
{
DicConsole
.Write("Drive supports SCSI READ LONG but I cannot find the correct size. Do you want me to try? (This can take hours) (Y/N): ");
pressedKey = System.Console.ReadKey();
DicConsole.WriteLine();
}
if(pressedKey.Key == ConsoleKey.Y)
{
for(ushort i = (ushort)mediaTest.BlockSize;; i++)
{
DicConsole
.Write("\rTrying to READ LONG with a size of {0} bytes...", i);
sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0,
i, dev.Timeout, out _);
if(!sense)
{
mediaTest.LongBlockSize = i;
break;
}
if(i == ushort.MaxValue) break;
}
DicConsole.WriteLine();
}
}
if(options.Debug && mediaTest.SupportsReadLong == true &&
mediaTest.LongBlockSize != mediaTest.BlockSize)
{
sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0,
(ushort)mediaTest.LongBlockSize, dev.Timeout, out _);
if(!sense)
DataFile.WriteTo("SCSI Report", "readlong10",
"_debug_" + mediaTest.MediumTypeName + ".bin",
"read results", buffer);
}
}
mediaTest.MediumTypeName = mediumTypeName;
mediaTest.Manufacturer = manufacturer;
mediaTest.Model = model;
mediaTests.Add(mediaTest);
}
report.SCSI.RemovableMedias = mediaTests.ToArray();
}
else
{
report.SCSI.ReadCapabilities = reporter.ReportScsi();
if(report.SCSI.ReadCapabilities.SupportsReadLong == true &&
report.SCSI.ReadCapabilities.LongBlockSize ==
report.SCSI.ReadCapabilities.BlockSize)
{
pressedKey = new ConsoleKeyInfo();
while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N)
{
DicConsole
.Write("Drive supports SCSI READ LONG but I cannot find the correct size. Do you want me to try? (This can take hours) (Y/N): ");
pressedKey = System.Console.ReadKey();
DicConsole.WriteLine();
}
if(pressedKey.Key == ConsoleKey.Y)
{
for(ushort i = (ushort)report.SCSI.ReadCapabilities.BlockSize;; i++)
{
DicConsole.Write("\rTrying to READ LONG with a size of {0} bytes...", i);
bool sense = dev.ReadLong10(out buffer, out byte[] senseBuffer, false,
false, 0, i, dev.Timeout, out _);
if(!sense)
{
if(options.Debug)
{
FileStream bingo =
new FileStream($"{dev.Model}_readlong.bin", FileMode.Create);
bingo.Write(buffer, 0, buffer.Length);
bingo.Close();
}
report.SCSI.ReadCapabilities.LongBlockSize = i;
break;
}
if(i == ushort.MaxValue) break;
}
DicConsole.WriteLine();
}
}
if(options.Debug && report.SCSI.ReadCapabilities.SupportsReadLong == true &&
report.SCSI.ReadCapabilities.LongBlockSize !=
report.SCSI.ReadCapabilities.BlockSize)
{
bool sense = dev.ReadLong10(out buffer, out byte[] senseBuffer, false, false, 0,
(ushort)report.SCSI.ReadCapabilities.LongBlockSize,
dev.Timeout, out _);
if(!sense)
DataFile.WriteTo("SCSI Report", "readlong10", "_debug_" + dev.Model + ".bin",
"read results", buffer);
}
}
break;
}
}
break;
default: throw new NotSupportedException("Unknown device type.");
}