2017-05-27 20:02:57 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2017-05-27 20:02:57 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : SCSI.cs
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2017-05-27 20:02:57 +01:00
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Core algorithms.
|
2017-05-27 20:02:57 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Dumps media from SCSI devices.
|
2017-05-27 20:02:57 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
|
// it under the terms of the GNU General Public License as
|
|
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
//
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-02-18 10:02:53 +00:00
|
|
|
|
// Copyright © 2011-2022 Natalia Portillo
|
2017-05-27 20:02:57 +01:00
|
|
|
|
// ****************************************************************************/
|
2017-12-19 03:50:57 +00:00
|
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
|
namespace Aaru.Core.Devices.Dumping;
|
|
|
|
|
|
|
2020-07-22 13:20:25 +01:00
|
|
|
|
using System;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using System.Threading;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
|
using Aaru.CommonTypes.Structs.Devices.SCSI;
|
|
|
|
|
|
using Aaru.Decoders.SCSI;
|
2017-05-27 20:02:57 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <summary>Implements dumping SCSI and ATAPI devices</summary>
|
|
|
|
|
|
public partial class Dump
|
2017-05-27 20:02:57 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
// TODO: Get cartridge serial number from Certance vendor EVPD
|
|
|
|
|
|
/// <summary>Dumps a SCSI Block Commands device or a Reduced Block Commands devices</summary>
|
|
|
|
|
|
void Scsi()
|
2017-05-27 20:02:57 +01:00
|
|
|
|
{
|
2022-03-07 07:36:44 +00:00
|
|
|
|
var resets = 0;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
if(_dev.IsRemovable)
|
2017-05-27 20:02:57 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
InitProgress?.Invoke();
|
2022-03-07 07:36:44 +00:00
|
|
|
|
deviceGotReset:
|
2022-03-06 13:29:38 +00:00
|
|
|
|
bool sense = _dev.ScsiTestUnitReady(out byte[] senseBuf, _dev.Timeout, out _);
|
2017-05-27 20:02:57 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(sense)
|
2017-05-27 20:02:57 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
DecodedSense? decSense = Sense.Decode(senseBuf);
|
2019-12-25 18:07:05 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(decSense.HasValue)
|
2017-05-27 20:02:57 +01:00
|
|
|
|
{
|
2022-11-13 19:38:03 +00:00
|
|
|
|
ErrorMessage?.Invoke($"Device not ready. Sense {decSense.Value.SenseKey} ASC {decSense.Value.ASC
|
|
|
|
|
|
:X2}h ASCQ {decSense.Value.ASCQ:X2}h");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
|
_dumpLog.WriteLine("Device not ready. Sense {0} ASC {1:X2}h ASCQ {2:X2}h", decSense.Value.SenseKey,
|
|
|
|
|
|
decSense.Value.ASC, decSense.Value.ASCQ);
|
2019-12-25 18:07:05 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
// Just retry, for 5 times
|
|
|
|
|
|
if(decSense.Value.ASC == 0x29)
|
|
|
|
|
|
{
|
|
|
|
|
|
resets++;
|
2017-11-26 22:20:31 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(resets < 5)
|
|
|
|
|
|
goto deviceGotReset;
|
|
|
|
|
|
}
|
2019-12-25 18:07:05 +00:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
switch(decSense.Value.ASC)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
2022-11-13 19:38:03 +00:00
|
|
|
|
case 0x3A:
|
2017-05-27 20:02:57 +01:00
|
|
|
|
{
|
2022-11-13 19:38:03 +00:00
|
|
|
|
var leftRetries = 5;
|
|
|
|
|
|
|
|
|
|
|
|
while(leftRetries > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
PulseProgress?.Invoke("Waiting for drive to become ready");
|
|
|
|
|
|
Thread.Sleep(2000);
|
|
|
|
|
|
sense = _dev.ScsiTestUnitReady(out senseBuf, _dev.Timeout, out _);
|
|
|
|
|
|
|
|
|
|
|
|
if(!sense)
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
decSense = Sense.Decode(senseBuf);
|
2019-12-25 18:07:05 +00:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
if(decSense.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage?.Invoke($"Device not ready. Sense {decSense.Value.SenseKey} ASC {
|
|
|
|
|
|
decSense.Value.ASC:X2}h ASCQ {decSense.Value.ASCQ:X2}h");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
_dumpLog.WriteLine("Device not ready. Sense {0} ASC {1:X2}h ASCQ {2:X2}h",
|
|
|
|
|
|
decSense.Value.SenseKey, decSense.Value.ASC,
|
|
|
|
|
|
decSense.Value.ASCQ);
|
|
|
|
|
|
}
|
2017-05-27 20:02:57 +01:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
leftRetries--;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(sense)
|
2017-05-27 20:02:57 +01:00
|
|
|
|
{
|
2022-11-13 19:38:03 +00:00
|
|
|
|
StoppingErrorMessage?.Invoke("Please insert media in drive");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
return;
|
2017-05-27 20:02:57 +01:00
|
|
|
|
}
|
2019-12-25 18:07:05 +00:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
break;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
2022-11-13 19:38:03 +00:00
|
|
|
|
case 0x04 when decSense.Value.ASCQ == 0x01:
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
2022-11-13 19:38:03 +00:00
|
|
|
|
var leftRetries = 50;
|
2017-05-27 20:02:57 +01:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
while(leftRetries > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
PulseProgress?.Invoke("Waiting for drive to become ready");
|
|
|
|
|
|
Thread.Sleep(2000);
|
|
|
|
|
|
sense = _dev.ScsiTestUnitReady(out senseBuf, _dev.Timeout, out _);
|
2019-12-25 18:07:05 +00:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
if(!sense)
|
|
|
|
|
|
break;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
decSense = Sense.Decode(senseBuf);
|
2019-04-20 02:11:18 +01:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
if(decSense.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage?.Invoke($"Device not ready. Sense {decSense.Value.SenseKey} ASC {
|
|
|
|
|
|
decSense.Value.ASC:X2}h ASCQ {decSense.Value.ASCQ:X2}h");
|
2017-05-27 20:02:57 +01:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
_dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h",
|
|
|
|
|
|
decSense.Value.SenseKey, decSense.Value.ASC,
|
|
|
|
|
|
decSense.Value.ASCQ);
|
|
|
|
|
|
}
|
2019-12-25 18:07:05 +00:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
leftRetries--;
|
2017-05-27 20:02:57 +01:00
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
|
|
|
|
|
StoppingErrorMessage?.Invoke($"Error testing unit was ready:\n{
|
|
|
|
|
|
Sense.PrettifySense(senseBuf)}");
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2017-05-27 20:02:57 +01:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
break;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
2022-11-13 19:38:03 +00:00
|
|
|
|
/*else if (decSense.Value.ASC == 0x29 && decSense.Value.ASCQ == 0x00)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (!deviceReset)
|
2017-09-11 18:34:01 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
deviceReset = true;
|
|
|
|
|
|
ErrorMessage?.Invoke("Device did reset, retrying...");
|
|
|
|
|
|
goto retryTestReady;
|
|
|
|
|
|
}
|
2017-09-11 18:34:01 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
StoppingErrorMessage?.Invoke(string.Format("Error testing unit was ready:\n{0}",
|
|
|
|
|
|
Decoders.SCSI.Sense.PrettifySense(senseBuf)));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}*/
|
2022-11-13 19:38:03 +00:00
|
|
|
|
// These should be trapped by the OS but seems in some cases they're not
|
|
|
|
|
|
case 0x28:
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
2022-11-13 19:38:03 +00:00
|
|
|
|
var leftRetries = 10;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
while(leftRetries > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
PulseProgress?.Invoke("Waiting for drive to become ready");
|
|
|
|
|
|
Thread.Sleep(2000);
|
|
|
|
|
|
sense = _dev.ScsiTestUnitReady(out senseBuf, _dev.Timeout, out _);
|
2019-04-20 02:11:18 +01:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
if(!sense)
|
|
|
|
|
|
break;
|
2017-09-11 18:34:01 +01:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
decSense = Sense.Decode(senseBuf);
|
|
|
|
|
|
|
|
|
|
|
|
if(decSense.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage?.Invoke($"Device not ready. Sense {decSense.Value.SenseKey} ASC {
|
|
|
|
|
|
decSense.Value.ASC:X2}h ASCQ {decSense.Value.ASCQ:X2}h");
|
|
|
|
|
|
|
|
|
|
|
|
_dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h",
|
|
|
|
|
|
decSense.Value.SenseKey, decSense.Value.ASC,
|
|
|
|
|
|
decSense.Value.ASCQ);
|
|
|
|
|
|
}
|
2019-12-25 18:07:05 +00:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
leftRetries--;
|
2017-09-11 18:34:01 +01:00
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
|
|
|
|
|
StoppingErrorMessage?.Invoke($"Error testing unit was ready:\n{
|
|
|
|
|
|
Sense.PrettifySense(senseBuf)}");
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2019-12-25 18:07:05 +00:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
break;
|
2017-05-27 20:02:57 +01:00
|
|
|
|
}
|
2022-11-13 19:38:03 +00:00
|
|
|
|
default:
|
|
|
|
|
|
StoppingErrorMessage?.Invoke($"Error testing unit was ready:\n{Sense.PrettifySense(senseBuf)
|
|
|
|
|
|
}");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
|
2022-11-13 19:38:03 +00:00
|
|
|
|
return;
|
2017-05-27 20:02:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
StoppingErrorMessage?.Invoke("Unknown testing unit was ready.");
|
2019-04-20 02:11:18 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2017-05-27 20:02:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
EndProgress?.Invoke();
|
|
|
|
|
|
}
|
2019-12-25 18:07:05 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
switch(_dev.ScsiType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case PeripheralDeviceTypes.SequentialAccess:
|
|
|
|
|
|
if(_dumpRaw)
|
|
|
|
|
|
{
|
|
|
|
|
|
StoppingErrorMessage?.Invoke("Tapes cannot be dumped raw.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
|
2017-12-21 04:43:29 +00:00
|
|
|
|
return;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
2019-12-25 18:07:05 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(_outputPlugin is IWritableTapeImage)
|
|
|
|
|
|
Ssc();
|
|
|
|
|
|
else
|
|
|
|
|
|
StoppingErrorMessage?.
|
|
|
|
|
|
Invoke("The specified plugin does not support storing streaming tape images.");
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
case PeripheralDeviceTypes.MultiMediaDevice:
|
|
|
|
|
|
if(_outputPlugin is IWritableOpticalImage)
|
|
|
|
|
|
Mmc();
|
|
|
|
|
|
else
|
2022-03-07 07:36:44 +00:00
|
|
|
|
StoppingErrorMessage?.Invoke("The specified plugin does not support storing optical disc images.");
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
case PeripheralDeviceTypes.BridgingExpander
|
|
|
|
|
|
when _dev.Model.StartsWith("MDM", StringComparison.InvariantCulture) ||
|
|
|
|
|
|
_dev.Model.StartsWith("MDH", StringComparison.InvariantCulture):
|
|
|
|
|
|
MiniDisc();
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
Sbc(null, MediaType.Unknown, false);
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
2017-05-27 20:02:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|