2017-05-31 01:00:58 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : SSC.cs
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2017-05-31 01:00:58 +01:00
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Core algorithms.
|
2017-05-31 01:00:58 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Dumps media from SCSI Streaming devices.
|
2017-05-31 01:00:58 +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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-01-03 17:51:30 +00:00
|
|
|
|
// Copyright © 2011-2020 Natalia Portillo
|
2017-05-31 01:00:58 +01:00
|
|
|
|
// ****************************************************************************/
|
2017-12-19 03:50:57 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
using System;
|
2019-05-03 00:24:30 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
2019-05-02 00:24:56 +01:00
|
|
|
|
using System.Linq;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using System.Threading;
|
2019-05-03 00:24:30 +01:00
|
|
|
|
using System.Xml.Serialization;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
using DiscImageChef.CommonTypes;
|
2019-05-02 00:48:03 +01:00
|
|
|
|
using DiscImageChef.CommonTypes.Enums;
|
2019-05-01 01:19:37 +01:00
|
|
|
|
using DiscImageChef.CommonTypes.Extents;
|
2019-04-30 23:45:13 +01:00
|
|
|
|
using DiscImageChef.CommonTypes.Interfaces;
|
2019-05-03 00:24:30 +01:00
|
|
|
|
using DiscImageChef.CommonTypes.Metadata;
|
2019-04-30 23:45:13 +01:00
|
|
|
|
using DiscImageChef.CommonTypes.Structs;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
using DiscImageChef.Core.Logging;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using DiscImageChef.Decoders.SCSI;
|
2019-11-10 00:48:32 +00:00
|
|
|
|
using DiscImageChef.Decoders.SCSI.SSC;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
using DiscImageChef.Devices;
|
|
|
|
|
|
using Schemas;
|
2019-05-03 00:24:30 +01:00
|
|
|
|
using MediaType = DiscImageChef.CommonTypes.MediaType;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Core.Devices.Dumping
|
|
|
|
|
|
{
|
2019-04-19 18:54:25 +01:00
|
|
|
|
partial class Dump
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
2019-11-10 00:48:32 +00:00
|
|
|
|
/// <summary>Dumps the tape from a SCSI Streaming device</summary>
|
2019-04-20 13:23:58 +01:00
|
|
|
|
internal void Ssc()
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
2019-05-03 00:24:30 +01:00
|
|
|
|
FixedSense? fxSense;
|
|
|
|
|
|
bool sense;
|
|
|
|
|
|
uint blockSize;
|
|
|
|
|
|
ulong blocks = 0;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
MediaType dskType = MediaType.Unknown;
|
2019-05-03 00:24:30 +01:00
|
|
|
|
DateTime start;
|
|
|
|
|
|
DateTime end;
|
|
|
|
|
|
double totalDuration = 0;
|
|
|
|
|
|
double currentSpeed = 0;
|
|
|
|
|
|
double maxSpeed = double.MinValue;
|
|
|
|
|
|
double minSpeed = double.MaxValue;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dev.RequestSense(out byte[] senseBuf, _dev.Timeout, out double duration);
|
2017-12-21 14:30:38 +00:00
|
|
|
|
fxSense = Sense.DecodeFixed(senseBuf, out string strSense);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-04-20 02:43:53 +01:00
|
|
|
|
InitProgress?.Invoke();
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
|
|
|
|
|
if(fxSense.HasValue &&
|
|
|
|
|
|
fxSense?.SenseKey != SenseKeys.NoSense)
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h", fxSense?.SenseKey,
|
|
|
|
|
|
fxSense?.ASC, fxSense?.ASCQ);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-04-20 02:43:53 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Drive has status error, please correct. Sense follows..." +
|
|
|
|
|
|
Environment.NewLine + strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Not in BOM/P
|
2019-11-10 00:48:32 +00:00
|
|
|
|
if(fxSense.HasValue &&
|
|
|
|
|
|
fxSense?.ASC == 0x00 &&
|
|
|
|
|
|
fxSense?.ASCQ != 0x00 &&
|
|
|
|
|
|
fxSense?.ASCQ != 0x04 &&
|
|
|
|
|
|
fxSense?.SenseKey != SenseKeys.IllegalRequest)
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Rewinding, please wait...");
|
2019-04-20 02:43:53 +01:00
|
|
|
|
PulseProgress?.Invoke("Rewinding, please wait...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
// Rewind, let timeout apply
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dev.Rewind(out senseBuf, _dev.Timeout, out duration);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
|
|
|
|
|
// Still rewinding?
|
|
|
|
|
|
// TODO: Pause?
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
2019-04-20 23:05:49 +01:00
|
|
|
|
PulseProgress?.Invoke("Rewinding, please wait...");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dev.RequestSense(out senseBuf, _dev.Timeout, out duration);
|
2017-12-21 14:30:38 +00:00
|
|
|
|
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
} while(fxSense.HasValue &&
|
|
|
|
|
|
fxSense?.ASC == 0x00 &&
|
|
|
|
|
|
(fxSense?.ASCQ == 0x1A || fxSense?.ASCQ != 0x04 || fxSense?.ASCQ != 0x00));
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dev.RequestSense(out senseBuf, _dev.Timeout, out duration);
|
2017-12-21 14:30:38 +00:00
|
|
|
|
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
|
|
|
|
|
// And yet, did not rewind!
|
2019-11-10 00:48:32 +00:00
|
|
|
|
if(fxSense.HasValue &&
|
2019-12-25 18:07:05 +00:00
|
|
|
|
((fxSense?.ASC == 0x00 && fxSense?.ASCQ != 0x04 && fxSense?.ASCQ != 0x00) || fxSense?.ASC != 0x00))
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
2019-04-20 02:43:53 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Drive could not rewind, please correct. Sense follows..." +
|
|
|
|
|
|
Environment.NewLine + strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Drive could not rewind, please correct. Sense follows...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h", fxSense?.SenseKey,
|
|
|
|
|
|
fxSense?.ASC, fxSense?.ASCQ);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check position
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.ReadPosition(out byte[] cmdBuf, out senseBuf, SscPositionForms.Short, _dev.Timeout,
|
|
|
|
|
|
out duration);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
|
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
|
|
|
|
|
// READ POSITION is mandatory starting SCSI-2, so do not cry if the drive does not recognize the command (SCSI-1 or earlier)
|
|
|
|
|
|
// Anyway, <=SCSI-1 tapes do not support partitions
|
2017-12-21 14:30:38 +00:00
|
|
|
|
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
|
2017-06-05 15:57:10 +01:00
|
|
|
|
|
2019-11-10 00:48:32 +00:00
|
|
|
|
if(fxSense.HasValue &&
|
2019-12-25 18:07:05 +00:00
|
|
|
|
((fxSense?.ASC == 0x20 && fxSense?.ASCQ != 0x00) ||
|
|
|
|
|
|
(fxSense?.ASC != 0x20 && fxSense?.SenseKey != SenseKeys.IllegalRequest)))
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
2019-04-20 02:43:53 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Could not get position. Sense follows..." + Environment.NewLine +
|
|
|
|
|
|
strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Could not get position. Sense follows...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h", fxSense?.SenseKey,
|
|
|
|
|
|
fxSense?.ASC, fxSense?.ASCQ);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// Not in partition 0
|
|
|
|
|
|
if(cmdBuf[1] != 0)
|
|
|
|
|
|
{
|
2019-04-20 02:43:53 +01:00
|
|
|
|
UpdateStatus?.Invoke("Drive not in partition 0. Rewinding, please wait...");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Drive not in partition 0. Rewinding, please wait...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
// Rewind, let timeout apply
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.Locate(out senseBuf, false, 0, 0, _dev.Timeout, out duration);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-04-20 02:43:53 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Drive could not rewind, please correct. Sense follows..." +
|
|
|
|
|
|
Environment.NewLine +
|
|
|
|
|
|
strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Drive could not rewind, please correct. Sense follows...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h", fxSense?.SenseKey,
|
|
|
|
|
|
fxSense?.ASC, fxSense?.ASCQ);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Still rewinding?
|
|
|
|
|
|
// TODO: Pause?
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
|
Thread.Sleep(1000);
|
2019-04-20 23:05:49 +01:00
|
|
|
|
PulseProgress?.Invoke("Rewinding, please wait...");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dev.RequestSense(out senseBuf, _dev.Timeout, out duration);
|
2017-12-21 14:30:38 +00:00
|
|
|
|
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
} while(fxSense.HasValue &&
|
|
|
|
|
|
fxSense?.ASC == 0x00 &&
|
|
|
|
|
|
(fxSense?.ASCQ == 0x1A || fxSense?.ASCQ == 0x19));
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
|
|
|
|
|
// And yet, did not rewind!
|
2019-11-10 00:48:32 +00:00
|
|
|
|
if(fxSense.HasValue &&
|
2019-12-25 18:07:05 +00:00
|
|
|
|
((fxSense?.ASC == 0x00 && fxSense?.ASCQ != 0x04 && fxSense?.ASCQ != 0x00) ||
|
|
|
|
|
|
fxSense?.ASC != 0x00))
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
2019-04-20 02:43:53 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Drive could not rewind, please correct. Sense follows..." +
|
|
|
|
|
|
Environment.NewLine +
|
|
|
|
|
|
strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Drive could not rewind, please correct. Sense follows...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h", fxSense?.SenseKey,
|
|
|
|
|
|
fxSense?.ASC, fxSense?.ASCQ);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.ReadPosition(out cmdBuf, out senseBuf, SscPositionForms.Short, _dev.Timeout,
|
|
|
|
|
|
out duration);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
|
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-04-20 02:43:53 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Drive could not rewind, please correct. Sense follows..." +
|
|
|
|
|
|
Environment.NewLine +
|
|
|
|
|
|
strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Drive could not rewind, please correct. Sense follows...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h", fxSense?.SenseKey,
|
|
|
|
|
|
fxSense?.ASC, fxSense?.ASCQ);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Still not in partition 0!!!?
|
|
|
|
|
|
if(cmdBuf[1] != 0)
|
|
|
|
|
|
{
|
2019-04-20 02:43:53 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Drive could not rewind to partition 0 but no error occurred...");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Drive could not rewind to partition 0 but no error occurred...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-20 02:43:53 +01:00
|
|
|
|
EndProgress?.Invoke();
|
|
|
|
|
|
|
2019-05-02 00:48:03 +01:00
|
|
|
|
byte scsiMediumTypeTape = 0;
|
|
|
|
|
|
byte scsiDensityCodeTape = 0;
|
|
|
|
|
|
byte[] mode6Data = null;
|
|
|
|
|
|
byte[] mode10Data = null;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-04-20 02:43:53 +01:00
|
|
|
|
UpdateStatus?.Invoke("Requesting MODE SENSE (10).");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.ModeSense10(out cmdBuf, out senseBuf, false, true, ScsiModeSensePageControl.Current, 0x3F,
|
|
|
|
|
|
0xFF, 5, out duration);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
|
|
|
|
|
if(!sense ||
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dev.Error)
|
|
|
|
|
|
sense = _dev.ModeSense10(out cmdBuf, out senseBuf, false, true, ScsiModeSensePageControl.Current, 0x3F,
|
|
|
|
|
|
0x00, 5, out duration);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2017-12-21 14:30:38 +00:00
|
|
|
|
Modes.DecodedMode? decMode = null;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-11-10 00:48:32 +00:00
|
|
|
|
if(!sense &&
|
2019-12-25 18:07:05 +00:00
|
|
|
|
!_dev.Error)
|
|
|
|
|
|
if(Modes.DecodeMode10(cmdBuf, _dev.ScsiType).HasValue)
|
|
|
|
|
|
decMode = Modes.DecodeMode10(cmdBuf, _dev.ScsiType);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-04-20 02:43:53 +01:00
|
|
|
|
UpdateStatus?.Invoke("Requesting MODE SENSE (6).");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.ModeSense6(out cmdBuf, out senseBuf, false, ScsiModeSensePageControl.Current, 0x3F, 0x00, 5,
|
|
|
|
|
|
out duration);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(sense || _dev.Error)
|
|
|
|
|
|
sense = _dev.ModeSense6(out cmdBuf, out senseBuf, false, ScsiModeSensePageControl.Current, 0x3F, 0x00,
|
|
|
|
|
|
5, out duration);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(sense || _dev.Error)
|
|
|
|
|
|
sense = _dev.ModeSense(out cmdBuf, out senseBuf, 5, out duration);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
|
|
|
|
|
if(!sense &&
|
2019-12-25 18:07:05 +00:00
|
|
|
|
!_dev.Error)
|
|
|
|
|
|
if(Modes.DecodeMode6(cmdBuf, _dev.ScsiType).HasValue)
|
|
|
|
|
|
decMode = Modes.DecodeMode6(cmdBuf, _dev.ScsiType);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
|
|
|
|
|
// TODO: Check partitions page
|
|
|
|
|
|
if(decMode.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
scsiMediumTypeTape = (byte)decMode.Value.Header.MediumType;
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
|
|
|
|
|
if(decMode.Value.Header.BlockDescriptors != null &&
|
|
|
|
|
|
decMode.Value.Header.BlockDescriptors.Length >= 1)
|
2017-05-31 01:00:58 +01:00
|
|
|
|
scsiDensityCodeTape = (byte)decMode.Value.Header.BlockDescriptors[0].Density;
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-01 01:19:37 +01:00
|
|
|
|
blockSize = decMode.Value.Header.BlockDescriptors?[0].BlockLength ?? 0;
|
2019-04-30 21:32:43 +01:00
|
|
|
|
|
2019-04-20 02:43:53 +01:00
|
|
|
|
UpdateStatus?.Invoke($"Device reports {blocks} blocks ({blocks * blockSize} bytes).");
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
2019-11-10 00:48:32 +00:00
|
|
|
|
else
|
|
|
|
|
|
blockSize = 1;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(!_dev.ReadBlockLimits(out cmdBuf, out senseBuf, _dev.Timeout, out _))
|
2019-11-10 00:48:32 +00:00
|
|
|
|
{
|
|
|
|
|
|
BlockLimits.BlockLimitsData? blockLimits = BlockLimits.Decode(cmdBuf);
|
|
|
|
|
|
|
|
|
|
|
|
if(blockLimits != null &&
|
|
|
|
|
|
blockLimits.Value.minBlockLen > blockSize)
|
|
|
|
|
|
{
|
|
|
|
|
|
blockSize = blockLimits.Value.minBlockLen;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(blockSize == 0)
|
|
|
|
|
|
blockSize = 1;
|
2019-04-30 21:32:43 +01:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
if(dskType == MediaType.Unknown)
|
2019-12-25 18:07:05 +00:00
|
|
|
|
dskType = MediaTypeFromScsi.Get((byte)_dev.ScsiType, _dev.Manufacturer, _dev.Model, scsiMediumTypeTape,
|
2017-12-19 20:33:03 +00:00
|
|
|
|
scsiDensityCodeTape, blocks, blockSize);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
|
|
|
|
|
if(dskType == MediaType.Unknown)
|
|
|
|
|
|
dskType = MediaType.UnknownTape;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
UpdateStatus?.Invoke($"SCSI device type: {_dev.ScsiType}.");
|
2019-04-20 02:43:53 +01:00
|
|
|
|
UpdateStatus?.Invoke($"SCSI medium type: {scsiMediumTypeTape}.");
|
|
|
|
|
|
UpdateStatus?.Invoke($"SCSI density type: {scsiDensityCodeTape}.");
|
|
|
|
|
|
UpdateStatus?.Invoke($"Media identified as {dskType}.");
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("SCSI device type: {0}.", _dev.ScsiType);
|
|
|
|
|
|
_dumpLog.WriteLine("SCSI medium type: {0}.", scsiMediumTypeTape);
|
|
|
|
|
|
_dumpLog.WriteLine("SCSI density type: {0}.", scsiDensityCodeTape);
|
|
|
|
|
|
_dumpLog.WriteLine("Media identified as {0}.", dskType);
|
2017-11-20 05:07:16 +00:00
|
|
|
|
|
2019-04-30 23:49:36 +01:00
|
|
|
|
bool endOfMedia = false;
|
|
|
|
|
|
ulong currentBlock = 0;
|
|
|
|
|
|
uint currentFile = 0;
|
|
|
|
|
|
byte currentPartition = 0;
|
|
|
|
|
|
byte totalPartitions = 1; // TODO: Handle partitions.
|
|
|
|
|
|
bool fixedLen = false;
|
|
|
|
|
|
uint transferLen = blockSize;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-04-30 21:32:43 +01:00
|
|
|
|
firstRead:
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.Read6(out cmdBuf, out senseBuf, false, fixedLen, transferLen, blockSize, _dev.Timeout,
|
|
|
|
|
|
out duration);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-06-05 15:57:10 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
|
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-06-05 15:57:10 +01:00
|
|
|
|
if(fxSense.HasValue)
|
2019-05-16 23:29:54 +01:00
|
|
|
|
if(fxSense?.SenseKey == SenseKeys.IllegalRequest)
|
2017-06-05 15:57:10 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.Space(out senseBuf, SscSpaceCodes.LogicalBlock, -1, _dev.Timeout, out duration);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-06-05 15:57:10 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
|
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
|
|
|
|
|
if(!fxSense.HasValue ||
|
|
|
|
|
|
!fxSense?.EOM == true)
|
2017-06-05 15:57:10 +01:00
|
|
|
|
{
|
2019-04-20 02:43:53 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Drive could not return back. Sense follows..." +
|
|
|
|
|
|
Environment.NewLine +
|
|
|
|
|
|
strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Drive could not return back. Sense follows...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Device not ready. Sense {0} ASC {1:X2}h ASCQ {2:X2}h",
|
|
|
|
|
|
fxSense?.SenseKey, fxSense?.ASC, fxSense?.ASCQ);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-06-05 15:57:10 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-29 01:26:58 +00:00
|
|
|
|
fixedLen = true;
|
2017-06-05 15:57:10 +01:00
|
|
|
|
transferLen = 1;
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.Read6(out cmdBuf, out senseBuf, false, fixedLen, transferLen, blockSize,
|
|
|
|
|
|
_dev.Timeout, out duration);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-06-05 15:57:10 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-04-30 21:32:43 +01:00
|
|
|
|
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-04-20 02:43:53 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Drive could not read. Sense follows..." +
|
|
|
|
|
|
Environment.NewLine + strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Drive could not read. Sense follows...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Device not ready. Sense {0} ASC {1:X2}h ASCQ {2:X2}h",
|
|
|
|
|
|
fxSense?.SenseKey, fxSense?.ASC, fxSense?.ASCQ);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-06-05 15:57:10 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-11-10 00:48:32 +00:00
|
|
|
|
else if(fxSense?.ASC == 0x00 &&
|
|
|
|
|
|
fxSense?.ASCQ == 0x00 &&
|
|
|
|
|
|
fxSense?.ILI == true &&
|
2019-05-16 23:29:54 +01:00
|
|
|
|
fxSense?.InformationValid == true)
|
2019-04-30 21:32:43 +01:00
|
|
|
|
{
|
|
|
|
|
|
blockSize = (uint)((int)blockSize -
|
|
|
|
|
|
BitConverter.ToInt32(BitConverter.GetBytes(fxSense.Value.Information), 0));
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-04-30 21:32:43 +01:00
|
|
|
|
transferLen = blockSize;
|
|
|
|
|
|
|
|
|
|
|
|
UpdateStatus?.Invoke($"Blocksize changed to {blockSize} bytes at block {currentBlock}");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Blocksize changed to {0} bytes at block {1}", blockSize, currentBlock);
|
2019-04-30 21:32:43 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.Space(out senseBuf, SscSpaceCodes.LogicalBlock, -1, _dev.Timeout, out duration);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-04-30 21:32:43 +01:00
|
|
|
|
totalDuration += duration;
|
|
|
|
|
|
|
|
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
|
|
|
|
|
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-04-30 21:32:43 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Drive could not go back one block. Sense follows..." +
|
|
|
|
|
|
Environment.NewLine +
|
|
|
|
|
|
strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Drive could not go back one block. Sense follows...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h",
|
|
|
|
|
|
fxSense?.SenseKey, fxSense?.ASC, fxSense?.ASCQ);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-04-30 21:32:43 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
goto firstRead;
|
|
|
|
|
|
}
|
2017-06-05 15:57:10 +01:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-04-20 02:43:53 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Drive could not read. Sense follows..." + Environment.NewLine +
|
|
|
|
|
|
strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Drive could not read. Sense follows...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Device not ready. Sense {0} ASC {1:X2}h ASCQ {2:X2}h", fxSense?.SenseKey,
|
|
|
|
|
|
fxSense?.ASC, fxSense?.ASCQ);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-06-05 15:57:10 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-04-20 02:43:53 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Cannot read device, don't know why, exiting...");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot read device, don't know why, exiting...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-06-05 15:57:10 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.Space(out senseBuf, SscSpaceCodes.LogicalBlock, -1, _dev.Timeout, out duration);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-06-05 15:57:10 +01:00
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
|
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
|
|
|
|
|
if(!fxSense.HasValue ||
|
|
|
|
|
|
!fxSense?.EOM == true)
|
2017-06-05 15:57:10 +01:00
|
|
|
|
{
|
2019-04-20 02:43:53 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Drive could not return back. Sense follows..." + Environment.NewLine +
|
|
|
|
|
|
strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Drive could not return back. Sense follows...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Device not ready. Sense {0} ASC {1:X2}h ASCQ {2:X2}h", fxSense?.SenseKey,
|
|
|
|
|
|
fxSense?.ASC, fxSense?.ASCQ);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-06-05 15:57:10 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-01 01:19:37 +01:00
|
|
|
|
DumpHardwareType currentTry = null;
|
|
|
|
|
|
ExtentsULong extents = null;
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
ResumeSupport.Process(true, _dev.IsRemovable, blocks, _dev.Manufacturer, _dev.Model, _dev.Serial,
|
|
|
|
|
|
_dev.PlatformId, ref _resume, ref currentTry, ref extents, true);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
|
|
|
|
|
if(currentTry == null ||
|
|
|
|
|
|
extents == null)
|
2019-05-01 18:56:19 +01:00
|
|
|
|
{
|
|
|
|
|
|
StoppingErrorMessage?.Invoke("Could not process resume file, not continuing...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-01 18:56:19 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2019-05-01 01:19:37 +01:00
|
|
|
|
|
2019-05-01 19:37:44 +01:00
|
|
|
|
bool canLocateLong = false;
|
|
|
|
|
|
bool canLocate = false;
|
|
|
|
|
|
|
|
|
|
|
|
UpdateStatus?.Invoke("Positioning tape to block 1.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Positioning tape to block 1");
|
2019-05-01 19:37:44 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.Locate16(out senseBuf, 1, _dev.Timeout, out _);
|
2019-05-01 19:37:44 +01:00
|
|
|
|
|
|
|
|
|
|
if(!sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.ReadPositionLong(out cmdBuf, out senseBuf, _dev.Timeout, out _);
|
2019-05-01 19:37:44 +01:00
|
|
|
|
|
|
|
|
|
|
if(!sense)
|
|
|
|
|
|
{
|
|
|
|
|
|
ulong position = Swapping.Swap(BitConverter.ToUInt64(cmdBuf, 8));
|
|
|
|
|
|
|
|
|
|
|
|
if(position == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
canLocateLong = true;
|
|
|
|
|
|
UpdateStatus?.Invoke("LOCATE LONG works.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("LOCATE LONG works.");
|
2019-05-01 19:37:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-11-10 00:48:32 +00:00
|
|
|
|
else
|
|
|
|
|
|
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
|
2019-05-01 19:37:44 +01:00
|
|
|
|
}
|
2019-11-10 00:48:32 +00:00
|
|
|
|
else
|
|
|
|
|
|
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
|
2019-05-01 19:37:44 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.Locate(out senseBuf, 1, _dev.Timeout, out _);
|
2019-05-01 19:37:44 +01:00
|
|
|
|
|
|
|
|
|
|
if(!sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.ReadPosition(out cmdBuf, out senseBuf, _dev.Timeout, out _);
|
2019-05-01 19:37:44 +01:00
|
|
|
|
|
|
|
|
|
|
if(!sense)
|
|
|
|
|
|
{
|
2019-05-07 01:22:18 +01:00
|
|
|
|
ulong position = Swapping.Swap(BitConverter.ToUInt32(cmdBuf, 4));
|
2019-05-01 19:37:44 +01:00
|
|
|
|
|
|
|
|
|
|
if(position == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
canLocate = true;
|
|
|
|
|
|
UpdateStatus?.Invoke("LOCATE works.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("LOCATE works.");
|
2019-05-01 19:37:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-11-10 00:48:32 +00:00
|
|
|
|
else
|
|
|
|
|
|
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
|
2019-05-01 19:37:44 +01:00
|
|
|
|
}
|
2019-11-10 00:48:32 +00:00
|
|
|
|
else
|
|
|
|
|
|
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
|
2019-05-01 19:37:44 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_resume.NextBlock > 0)
|
2019-05-01 01:19:37 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
UpdateStatus?.Invoke($"Positioning tape to block {_resume.NextBlock}.");
|
|
|
|
|
|
_dumpLog.WriteLine("Positioning tape to block {0}.", _resume.NextBlock);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-01 19:37:44 +01:00
|
|
|
|
if(canLocateLong)
|
2019-05-01 01:19:37 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.Locate16(out senseBuf, _resume.NextBlock, _dev.Timeout, out _);
|
2019-05-01 01:19:37 +01:00
|
|
|
|
|
|
|
|
|
|
if(!sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.ReadPositionLong(out cmdBuf, out senseBuf, _dev.Timeout, out _);
|
2019-05-01 01:19:37 +01:00
|
|
|
|
|
|
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(!_force)
|
2019-05-01 01:19:37 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.
|
2019-11-10 00:48:32 +00:00
|
|
|
|
WriteLine("Could not check current position, unable to resume. If you want to continue use force.");
|
|
|
|
|
|
|
|
|
|
|
|
StoppingErrorMessage?.
|
|
|
|
|
|
Invoke("Could not check current position, unable to resume. If you want to continue use force.");
|
|
|
|
|
|
|
2019-05-01 19:37:44 +01:00
|
|
|
|
return;
|
2019-05-01 01:19:37 +01:00
|
|
|
|
}
|
2019-05-01 19:37:44 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.
|
2019-11-10 00:48:32 +00:00
|
|
|
|
WriteLine("Could not check current position, unable to resume. Dumping from the start.");
|
|
|
|
|
|
|
|
|
|
|
|
ErrorMessage?.
|
|
|
|
|
|
Invoke("Could not check current position, unable to resume. Dumping from the start.");
|
|
|
|
|
|
|
2019-05-01 19:37:44 +01:00
|
|
|
|
canLocateLong = false;
|
2019-05-01 01:19:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
ulong position = Swapping.Swap(BitConverter.ToUInt64(cmdBuf, 8));
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(position != _resume.NextBlock)
|
2019-05-01 01:19:37 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(!_force)
|
2019-05-01 01:19:37 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.
|
2019-11-10 00:48:32 +00:00
|
|
|
|
WriteLine("Current position is not as expected, unable to resume. If you want to continue use force.");
|
|
|
|
|
|
|
|
|
|
|
|
StoppingErrorMessage?.
|
|
|
|
|
|
Invoke("Current position is not as expected, unable to resume. If you want to continue use force.");
|
|
|
|
|
|
|
2019-05-01 19:37:44 +01:00
|
|
|
|
return;
|
2019-05-01 17:46:56 +01:00
|
|
|
|
}
|
2019-05-01 19:37:44 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.
|
2019-11-10 00:48:32 +00:00
|
|
|
|
WriteLine("Current position is not as expected, unable to resume. Dumping from the start.");
|
|
|
|
|
|
|
|
|
|
|
|
ErrorMessage?.
|
|
|
|
|
|
Invoke("Current position is not as expected, unable to resume. Dumping from the start.");
|
|
|
|
|
|
|
2019-05-01 19:37:44 +01:00
|
|
|
|
canLocateLong = false;
|
2019-05-01 17:46:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(!_force)
|
2019-05-01 17:46:56 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.
|
2019-11-10 00:48:32 +00:00
|
|
|
|
WriteLine("Cannot reposition tape, unable to resume. If you want to continue use force.");
|
|
|
|
|
|
|
|
|
|
|
|
StoppingErrorMessage?.
|
|
|
|
|
|
Invoke("Cannot reposition tape, unable to resume. If you want to continue use force.");
|
|
|
|
|
|
|
2019-05-01 19:37:44 +01:00
|
|
|
|
return;
|
2019-05-01 17:46:56 +01:00
|
|
|
|
}
|
2019-05-01 19:37:44 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot reposition tape, unable to resume. Dumping from the start.");
|
2019-05-01 19:37:44 +01:00
|
|
|
|
ErrorMessage?.Invoke("Cannot reposition tape, unable to resume. Dumping from the start.");
|
|
|
|
|
|
canLocateLong = false;
|
2019-05-01 17:46:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-05-01 19:37:44 +01:00
|
|
|
|
else if(canLocate)
|
2019-05-01 17:46:56 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.Locate(out senseBuf, (uint)_resume.NextBlock, _dev.Timeout, out _);
|
2019-05-01 17:46:56 +01:00
|
|
|
|
|
|
|
|
|
|
if(!sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.ReadPosition(out cmdBuf, out senseBuf, _dev.Timeout, out _);
|
2019-05-01 17:46:56 +01:00
|
|
|
|
|
|
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(!_force)
|
2019-05-01 17:46:56 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.
|
2019-11-10 00:48:32 +00:00
|
|
|
|
WriteLine("Could not check current position, unable to resume. If you want to continue use force.");
|
|
|
|
|
|
|
|
|
|
|
|
StoppingErrorMessage?.
|
|
|
|
|
|
Invoke("Could not check current position, unable to resume. If you want to continue use force.");
|
|
|
|
|
|
|
2019-05-01 19:37:44 +01:00
|
|
|
|
return;
|
2019-05-01 17:46:56 +01:00
|
|
|
|
}
|
2019-05-01 19:37:44 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.
|
2019-11-10 00:48:32 +00:00
|
|
|
|
WriteLine("Could not check current position, unable to resume. Dumping from the start.");
|
|
|
|
|
|
|
|
|
|
|
|
ErrorMessage?.
|
|
|
|
|
|
Invoke("Could not check current position, unable to resume. Dumping from the start.");
|
|
|
|
|
|
|
2019-05-01 19:37:44 +01:00
|
|
|
|
canLocate = false;
|
2019-05-01 17:46:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
ulong position = Swapping.Swap(BitConverter.ToUInt32(cmdBuf, 4));
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(position != _resume.NextBlock)
|
2019-05-01 17:46:56 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(!_force)
|
2019-05-01 17:46:56 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.
|
2019-11-10 00:48:32 +00:00
|
|
|
|
WriteLine("Current position is not as expected, unable to resume. If you want to continue use force.");
|
|
|
|
|
|
|
|
|
|
|
|
StoppingErrorMessage?.
|
|
|
|
|
|
Invoke("Current position is not as expected, unable to resume. If you want to continue use force.");
|
|
|
|
|
|
|
2019-05-01 19:37:44 +01:00
|
|
|
|
return;
|
2019-05-01 01:19:37 +01:00
|
|
|
|
}
|
2019-05-01 19:37:44 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.
|
2019-11-10 00:48:32 +00:00
|
|
|
|
WriteLine("Current position is not as expected, unable to resume. Dumping from the start.");
|
|
|
|
|
|
|
|
|
|
|
|
ErrorMessage?.
|
|
|
|
|
|
Invoke("Current position is not as expected, unable to resume. Dumping from the start.");
|
|
|
|
|
|
|
2019-05-01 19:37:44 +01:00
|
|
|
|
canLocate = false;
|
2019-05-01 01:19:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(!_force)
|
2019-05-01 01:19:37 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.
|
2019-11-10 00:48:32 +00:00
|
|
|
|
WriteLine("Cannot reposition tape, unable to resume. If you want to continue use force.");
|
|
|
|
|
|
|
|
|
|
|
|
StoppingErrorMessage?.
|
|
|
|
|
|
Invoke("Cannot reposition tape, unable to resume. If you want to continue use force.");
|
|
|
|
|
|
|
2019-05-01 19:37:44 +01:00
|
|
|
|
return;
|
2019-05-01 01:19:37 +01:00
|
|
|
|
}
|
2019-05-01 19:37:44 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot reposition tape, unable to resume. Dumping from the start.");
|
2019-05-01 19:37:44 +01:00
|
|
|
|
ErrorMessage?.Invoke("Cannot reposition tape, unable to resume. Dumping from the start.");
|
|
|
|
|
|
canLocate = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(!_force)
|
2019-05-01 19:37:44 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.
|
2019-11-10 00:48:32 +00:00
|
|
|
|
WriteLine("Cannot reposition tape, unable to resume. If you want to continue use force.");
|
|
|
|
|
|
|
|
|
|
|
|
StoppingErrorMessage?.
|
|
|
|
|
|
Invoke("Cannot reposition tape, unable to resume. If you want to continue use force.");
|
|
|
|
|
|
|
2019-05-01 19:37:44 +01:00
|
|
|
|
return;
|
2019-05-01 01:19:37 +01:00
|
|
|
|
}
|
2019-05-01 19:37:44 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Cannot reposition tape, unable to resume. Dumping from the start.");
|
2019-05-01 19:37:44 +01:00
|
|
|
|
ErrorMessage?.Invoke("Cannot reposition tape, unable to resume. Dumping from the start.");
|
|
|
|
|
|
canLocate = false;
|
2019-05-01 01:19:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-05-01 23:21:16 +01:00
|
|
|
|
else
|
2019-05-01 01:19:37 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = canLocateLong ? _dev.Locate16(out senseBuf, false, 0, 0, _dev.Timeout, out duration)
|
|
|
|
|
|
: _dev.Locate(out senseBuf, false, 0, 0, _dev.Timeout, out duration);
|
2019-05-01 01:19:37 +01:00
|
|
|
|
|
2019-05-01 23:21:16 +01:00
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
PulseProgress?.Invoke("Rewinding, please wait...");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dev.RequestSense(out senseBuf, _dev.Timeout, out duration);
|
2019-05-01 23:21:16 +01:00
|
|
|
|
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
} while(fxSense.HasValue &&
|
|
|
|
|
|
fxSense?.ASC == 0x00 &&
|
|
|
|
|
|
(fxSense?.ASCQ == 0x1A || fxSense?.ASCQ == 0x19));
|
2019-05-01 23:21:16 +01:00
|
|
|
|
|
|
|
|
|
|
// And yet, did not rewind!
|
2019-11-10 00:48:32 +00:00
|
|
|
|
if(fxSense.HasValue &&
|
2019-12-25 18:07:05 +00:00
|
|
|
|
((fxSense?.ASC == 0x00 && fxSense?.ASCQ != 0x00 && fxSense?.ASCQ != 0x04) || fxSense?.ASC != 0x00))
|
2019-05-01 23:21:16 +01:00
|
|
|
|
{
|
|
|
|
|
|
StoppingErrorMessage?.Invoke("Drive could not rewind, please correct. Sense follows..." +
|
|
|
|
|
|
Environment.NewLine + strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Drive could not rewind, please correct. Sense follows...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h", fxSense?.SenseKey,
|
|
|
|
|
|
fxSense?.ASC, fxSense?.ASCQ);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-01 23:21:16 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2019-05-01 01:19:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
bool ret = (_outputPlugin as IWritableTapeImage).SetTape();
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-01 18:09:33 +01:00
|
|
|
|
// Cannot set image to tape mode
|
|
|
|
|
|
if(!ret)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Error setting output image in tape mode, not continuing.");
|
|
|
|
|
|
_dumpLog.WriteLine(_outputPlugin.ErrorMessage);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-01 18:56:19 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Error setting output image in tape mode, not continuing." +
|
|
|
|
|
|
Environment.NewLine +
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.ErrorMessage);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-01 18:09:33 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
ret = _outputPlugin.Create(_outputPath, dskType, _formatOptions, 0, 0);
|
2019-04-30 23:33:33 +01:00
|
|
|
|
|
|
|
|
|
|
// Cannot create image
|
|
|
|
|
|
if(!ret)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Error creating output image, not continuing.");
|
|
|
|
|
|
_dumpLog.WriteLine(_outputPlugin.ErrorMessage);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-04-30 23:33:33 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Error creating output image, not continuing." + Environment.NewLine +
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.ErrorMessage);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-04-30 23:33:33 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
start = DateTime.UtcNow;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
var mhddLog = new MhddLog(_outputPrefix + ".mhddlog.bin", _dev, blocks, blockSize, 1);
|
|
|
|
|
|
var ibgLog = new IbgLog(_outputPrefix + ".ibg", 0x0008);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-11-10 00:48:32 +00:00
|
|
|
|
var currentTapeFile = new TapeFile
|
|
|
|
|
|
{
|
|
|
|
|
|
File = currentFile, FirstBlock = currentBlock, Partition = currentPartition
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var currentTapePartition = new TapePartition
|
|
|
|
|
|
{
|
|
|
|
|
|
Number = currentPartition, FirstBlock = currentBlock
|
|
|
|
|
|
};
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-11-10 00:48:32 +00:00
|
|
|
|
if((canLocate || canLocateLong) &&
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_resume.NextBlock > 0)
|
2019-05-02 00:24:56 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
currentBlock = _resume.NextBlock;
|
2019-05-02 00:24:56 +01:00
|
|
|
|
|
|
|
|
|
|
currentTapeFile =
|
2019-12-25 18:07:05 +00:00
|
|
|
|
(_outputPlugin as IWritableTapeImage).Files.FirstOrDefault(f => f.LastBlock ==
|
|
|
|
|
|
(_outputPlugin as IWritableTapeImage
|
|
|
|
|
|
)?.Files.Max(g => g.LastBlock));
|
2019-05-02 00:24:56 +01:00
|
|
|
|
|
|
|
|
|
|
currentTapePartition =
|
2019-12-25 18:07:05 +00:00
|
|
|
|
(_outputPlugin as IWritableTapeImage).TapePartitions.FirstOrDefault(p => p.LastBlock ==
|
|
|
|
|
|
(_outputPlugin as
|
|
|
|
|
|
IWritableTapeImage)?.
|
|
|
|
|
|
TapePartitions.
|
|
|
|
|
|
Max(g => g.LastBlock));
|
2019-05-02 00:24:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-10 00:48:32 +00:00
|
|
|
|
if(mode6Data != null)
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.WriteMediaTag(mode6Data, MediaTagType.SCSI_MODESENSE_6);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
|
|
|
|
|
if(mode10Data != null)
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.WriteMediaTag(mode10Data, MediaTagType.SCSI_MODESENSE_10);
|
2019-05-02 00:48:03 +01:00
|
|
|
|
|
2019-05-01 18:56:19 +01:00
|
|
|
|
DateTime timeSpeedStart = DateTime.UtcNow;
|
|
|
|
|
|
ulong currentSpeedSize = 0;
|
|
|
|
|
|
double imageWriteDuration = 0;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-04-20 02:43:53 +01:00
|
|
|
|
InitProgress?.Invoke();
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
while(currentPartition < totalPartitions)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_aborted)
|
2017-11-20 05:07:16 +00:00
|
|
|
|
{
|
2019-05-01 18:56:19 +01:00
|
|
|
|
currentTry.Extents = ExtentsConverter.ToMetadata(extents);
|
2019-04-20 02:43:53 +01:00
|
|
|
|
UpdateStatus?.Invoke("Aborted!");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Aborted!");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
break;
|
2017-11-20 05:07:16 +00:00
|
|
|
|
}
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
|
|
|
|
|
if(endOfMedia)
|
|
|
|
|
|
{
|
2019-04-20 02:43:53 +01:00
|
|
|
|
UpdateStatus?.Invoke($"Finished partition {currentPartition}");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Finished partition {0}", currentPartition);
|
2019-04-30 23:45:13 +01:00
|
|
|
|
|
|
|
|
|
|
currentTapeFile.LastBlock = currentBlock - 1;
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-02 20:25:53 +01:00
|
|
|
|
if(currentTapeFile.LastBlock > currentTapeFile.FirstBlock)
|
2019-12-25 18:07:05 +00:00
|
|
|
|
(_outputPlugin as IWritableTapeImage).AddFile(currentTapeFile);
|
2019-04-30 23:45:13 +01:00
|
|
|
|
|
2019-04-30 23:49:36 +01:00
|
|
|
|
currentTapePartition.LastBlock = currentBlock - 1;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
(_outputPlugin as IWritableTapeImage).AddPartition(currentTapePartition);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
|
|
|
|
|
currentPartition++;
|
|
|
|
|
|
|
|
|
|
|
|
if(currentPartition < totalPartitions)
|
|
|
|
|
|
{
|
|
|
|
|
|
currentFile++;
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-04-30 23:45:13 +01:00
|
|
|
|
currentTapeFile = new TapeFile
|
2017-06-08 21:12:05 +01:00
|
|
|
|
{
|
2019-04-30 23:45:13 +01:00
|
|
|
|
File = currentFile, FirstBlock = currentBlock, Partition = currentPartition
|
2017-06-08 21:12:05 +01:00
|
|
|
|
};
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
|
|
|
|
|
currentTapePartition = new TapePartition
|
|
|
|
|
|
{
|
|
|
|
|
|
Number = currentPartition, FirstBlock = currentBlock
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-04-20 02:43:53 +01:00
|
|
|
|
UpdateStatus?.Invoke($"Seeking to partition {currentPartition}");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dev.Locate(out senseBuf, false, currentPartition, 0, _dev.Timeout, out duration);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
totalDuration += duration;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-29 01:26:58 +00:00
|
|
|
|
#pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
|
2019-11-10 00:48:32 +00:00
|
|
|
|
if(currentSpeed > maxSpeed &&
|
|
|
|
|
|
currentSpeed != 0)
|
|
|
|
|
|
maxSpeed = currentSpeed;
|
|
|
|
|
|
|
|
|
|
|
|
if(currentSpeed < minSpeed &&
|
|
|
|
|
|
currentSpeed != 0)
|
|
|
|
|
|
minSpeed = currentSpeed;
|
2017-12-29 01:26:58 +00:00
|
|
|
|
#pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-04-20 23:05:49 +01:00
|
|
|
|
PulseProgress?.Invoke($"Reading block {currentBlock} ({currentSpeed:F3} MiB/sec.)");
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.Read6(out cmdBuf, out senseBuf, false, fixedLen, transferLen, blockSize, _dev.Timeout,
|
|
|
|
|
|
out duration);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
totalDuration += duration;
|
|
|
|
|
|
|
2019-11-10 00:48:32 +00:00
|
|
|
|
if(sense &&
|
|
|
|
|
|
senseBuf?.Length != 0 &&
|
|
|
|
|
|
!ArrayHelpers.ArrayIsNullOrEmpty(senseBuf))
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
|
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
|
2019-05-16 23:29:54 +01:00
|
|
|
|
|
2019-11-10 00:48:32 +00:00
|
|
|
|
if(fxSense?.ASC == 0x00 &&
|
|
|
|
|
|
fxSense?.ASCQ == 0x00 &&
|
|
|
|
|
|
fxSense?.ILI == true &&
|
2019-05-16 23:29:54 +01:00
|
|
|
|
fxSense?.InformationValid == true)
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
blockSize = (uint)((int)blockSize -
|
|
|
|
|
|
BitConverter.ToInt32(BitConverter.GetBytes(fxSense.Value.Information), 0));
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
|
|
|
|
|
if(!fixedLen)
|
|
|
|
|
|
transferLen = blockSize;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-04-20 02:43:53 +01:00
|
|
|
|
UpdateStatus?.Invoke($"Blocksize changed to {blockSize} bytes at block {currentBlock}");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Blocksize changed to {0} bytes at block {1}", blockSize, currentBlock);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.Space(out senseBuf, SscSpaceCodes.LogicalBlock, -1, _dev.Timeout, out duration);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
totalDuration += duration;
|
|
|
|
|
|
|
|
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2017-12-21 14:30:38 +00:00
|
|
|
|
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-04-20 02:43:53 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Drive could not go back one block. Sense follows..." +
|
|
|
|
|
|
Environment.NewLine +
|
|
|
|
|
|
strSense);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.Close();
|
|
|
|
|
|
_dumpLog.WriteLine("Drive could not go back one block. Sense follows...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h",
|
|
|
|
|
|
fxSense?.SenseKey, fxSense?.ASC, fxSense?.ASCQ);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-16 23:29:54 +01:00
|
|
|
|
switch(fxSense?.SenseKey)
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
case SenseKeys.BlankCheck when currentBlock == 0:
|
2019-04-20 02:43:53 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Cannot dump a blank tape...");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.Close();
|
|
|
|
|
|
_dumpLog.WriteLine("Cannot dump a blank tape...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
return;
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
// For sure this is an end-of-tape/partition
|
2019-05-16 23:29:54 +01:00
|
|
|
|
case SenseKeys.BlankCheck when fxSense?.ASC == 0x00 &&
|
|
|
|
|
|
(fxSense?.ASCQ == 0x02 || fxSense?.ASCQ == 0x05 ||
|
|
|
|
|
|
fxSense?.EOM == true):
|
2017-05-31 01:00:58 +01:00
|
|
|
|
// TODO: Detect end of partition
|
|
|
|
|
|
endOfMedia = true;
|
2019-04-20 02:43:53 +01:00
|
|
|
|
UpdateStatus?.Invoke("Found end-of-tape/partition...");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Found end-of-tape/partition...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
continue;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
case SenseKeys.BlankCheck:
|
2019-04-20 02:43:53 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Blank block found, end of tape?...");
|
2018-06-22 08:08:38 +01:00
|
|
|
|
endOfMedia = true;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Blank block found, end of tape?...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
continue;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-16 23:29:54 +01:00
|
|
|
|
if((fxSense?.SenseKey == SenseKeys.NoSense ||
|
|
|
|
|
|
fxSense?.SenseKey == SenseKeys.RecoveredError) &&
|
|
|
|
|
|
(fxSense?.ASCQ == 0x02 || fxSense?.ASCQ == 0x05 || fxSense?.EOM == true))
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
|
|
|
|
|
// TODO: Detect end of partition
|
|
|
|
|
|
endOfMedia = true;
|
2019-04-20 02:43:53 +01:00
|
|
|
|
UpdateStatus?.Invoke("Found end-of-tape/partition...");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Found end-of-tape/partition...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-16 23:29:54 +01:00
|
|
|
|
if((fxSense?.SenseKey == SenseKeys.NoSense || fxSense?.SenseKey == SenseKeys.RecoveredError) &&
|
|
|
|
|
|
(fxSense?.ASCQ == 0x01 || fxSense?.Filemark == true))
|
2017-05-31 01:00:58 +01:00
|
|
|
|
{
|
2019-04-30 23:45:13 +01:00
|
|
|
|
currentTapeFile.LastBlock = currentBlock - 1;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
(_outputPlugin as IWritableTapeImage).AddFile(currentTapeFile);
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
|
|
|
|
|
currentFile++;
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-04-30 23:45:13 +01:00
|
|
|
|
currentTapeFile = new TapeFile
|
2017-06-08 21:12:05 +01:00
|
|
|
|
{
|
2019-04-30 23:45:13 +01:00
|
|
|
|
File = currentFile, FirstBlock = currentBlock, Partition = currentPartition
|
2017-06-08 21:12:05 +01:00
|
|
|
|
};
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-04-20 02:43:53 +01:00
|
|
|
|
UpdateStatus?.Invoke($"Changed to file {currentFile} at block {currentBlock}");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Changed to file {0} at block {1}", currentFile, currentBlock);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2017-05-31 01:00:58 +01:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-16 23:29:54 +01:00
|
|
|
|
if(fxSense is null)
|
|
|
|
|
|
{
|
2019-11-10 00:48:32 +00:00
|
|
|
|
StoppingErrorMessage?.
|
|
|
|
|
|
Invoke($"Drive could not read block ${currentBlock}. Sense cannot be decoded, look at log for dump...");
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine($"Drive could not read block ${currentBlock}. Sense bytes follow...");
|
|
|
|
|
|
_dumpLog.WriteLine(PrintHex.ByteArrayToHexArrayString(senseBuf, 32));
|
2019-05-16 23:29:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-11-10 00:48:32 +00:00
|
|
|
|
StoppingErrorMessage?.
|
|
|
|
|
|
Invoke($"Drive could not read block ${currentBlock}. Sense follows...\n{fxSense?.SenseKey} {strSense}");
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine($"Drive could not read block ${currentBlock}. Sense follows...");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h", fxSense?.SenseKey,
|
|
|
|
|
|
fxSense?.ASC, fxSense?.ASCQ);
|
2019-05-16 23:29:54 +01:00
|
|
|
|
}
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-05-01 18:56:19 +01:00
|
|
|
|
// TODO: Reset device after X errors
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_stopOnError)
|
2019-11-10 00:48:32 +00:00
|
|
|
|
return; // TODO: Return more cleanly
|
2019-05-01 18:56:19 +01:00
|
|
|
|
|
|
|
|
|
|
// Write empty data
|
|
|
|
|
|
DateTime writeStart = DateTime.Now;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.WriteSector(new byte[blockSize], currentBlock);
|
2019-05-01 18:56:19 +01:00
|
|
|
|
imageWriteDuration += (DateTime.Now - writeStart).TotalSeconds;
|
|
|
|
|
|
|
|
|
|
|
|
mhddLog.Write(currentBlock, duration < 500 ? 65535 : duration);
|
|
|
|
|
|
ibgLog.Write(currentBlock, 0);
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_resume.BadBlocks.Add(currentBlock);
|
2019-05-01 18:56:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
mhddLog.Write(currentBlock, duration);
|
|
|
|
|
|
ibgLog.Write(currentBlock, currentSpeed * 1024);
|
|
|
|
|
|
DateTime writeStart = DateTime.Now;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.WriteSector(cmdBuf, currentBlock);
|
2019-05-01 18:56:19 +01:00
|
|
|
|
imageWriteDuration += (DateTime.Now - writeStart).TotalSeconds;
|
|
|
|
|
|
extents.Add(currentBlock, 1, true);
|
|
|
|
|
|
}
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
|
|
|
|
|
currentBlock++;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_resume.NextBlock++;
|
2019-04-30 23:49:36 +01:00
|
|
|
|
currentSpeedSize += blockSize;
|
2019-01-27 17:47:40 +00:00
|
|
|
|
|
|
|
|
|
|
double elapsed = (DateTime.UtcNow - timeSpeedStart).TotalSeconds;
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
|
|
|
|
|
if(elapsed < 1)
|
|
|
|
|
|
continue;
|
2019-01-27 17:47:40 +00:00
|
|
|
|
|
|
|
|
|
|
currentSpeed = currentSpeedSize / (1048576 * elapsed);
|
|
|
|
|
|
currentSpeedSize = 0;
|
|
|
|
|
|
timeSpeedStart = DateTime.UtcNow;
|
2017-05-31 01:00:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-01 18:56:19 +01:00
|
|
|
|
blocks = currentBlock + 1;
|
|
|
|
|
|
end = DateTime.UtcNow;
|
2019-04-20 02:43:53 +01:00
|
|
|
|
|
2019-05-02 20:25:53 +01:00
|
|
|
|
// If not aborted this is added at the end of medium
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_aborted)
|
2019-05-02 20:25:53 +01:00
|
|
|
|
{
|
|
|
|
|
|
currentTapeFile.LastBlock = currentBlock - 1;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
(_outputPlugin as IWritableTapeImage).AddFile(currentTapeFile);
|
2019-05-02 20:25:53 +01:00
|
|
|
|
|
|
|
|
|
|
currentTapePartition.LastBlock = currentBlock - 1;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
(_outputPlugin as IWritableTapeImage).AddPartition(currentTapePartition);
|
2019-05-02 20:25:53 +01:00
|
|
|
|
}
|
2019-04-30 23:45:13 +01:00
|
|
|
|
|
2019-05-01 18:56:19 +01:00
|
|
|
|
EndProgress?.Invoke();
|
|
|
|
|
|
mhddLog.Close();
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
ibgLog.Close(_dev, blocks, blockSize, (end - start).TotalSeconds, currentSpeed * 1024,
|
|
|
|
|
|
(blockSize * (double)(blocks + 1)) / 1024 / (totalDuration / 1000),
|
|
|
|
|
|
_devicePath);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-01 18:56:19 +01:00
|
|
|
|
UpdateStatus?.Invoke($"Dump finished in {(end - start).TotalSeconds} seconds.");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
|
|
|
|
|
UpdateStatus?.
|
2019-12-25 18:07:05 +00:00
|
|
|
|
Invoke($"Average dump speed {((double)blockSize * (double)(blocks + 1)) / 1024 / (totalDuration / 1000):F3} KiB/sec.");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
|
|
|
|
|
UpdateStatus?.
|
2019-12-25 18:07:05 +00:00
|
|
|
|
Invoke($"Average write speed {((double)blockSize * (double)(blocks + 1)) / 1024 / imageWriteDuration:F3} KiB/sec.");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Dump finished in {0} seconds.", (end - start).TotalSeconds);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Average dump speed {0:F3} KiB/sec.",
|
|
|
|
|
|
((double)blockSize * (double)(blocks + 1)) / 1024 / (totalDuration / 1000));
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Average write speed {0:F3} KiB/sec.",
|
|
|
|
|
|
((double)blockSize * (double)(blocks + 1)) / 1024 / imageWriteDuration);
|
2019-05-01 18:56:19 +01:00
|
|
|
|
|
|
|
|
|
|
#region Error handling
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_resume.BadBlocks.Count > 0 &&
|
|
|
|
|
|
!_aborted &&
|
|
|
|
|
|
_retryPasses > 0 &&
|
2019-11-10 00:48:32 +00:00
|
|
|
|
(canLocate || canLocateLong))
|
2019-05-01 18:56:19 +01:00
|
|
|
|
{
|
|
|
|
|
|
int pass = 1;
|
|
|
|
|
|
bool forward = false;
|
|
|
|
|
|
bool runningPersistent = false;
|
|
|
|
|
|
|
|
|
|
|
|
Modes.ModePage? currentModePage = null;
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_persistent)
|
2019-05-01 18:56:19 +01:00
|
|
|
|
{
|
|
|
|
|
|
// TODO: Implement persistent
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InitProgress?.Invoke();
|
|
|
|
|
|
repeatRetry:
|
2019-12-25 18:07:05 +00:00
|
|
|
|
ulong[] tmpArray = _resume.BadBlocks.ToArray();
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-01 18:56:19 +01:00
|
|
|
|
foreach(ulong badBlock in tmpArray)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_aborted)
|
2019-05-01 18:56:19 +01:00
|
|
|
|
{
|
|
|
|
|
|
currentTry.Extents = ExtentsConverter.ToMetadata(extents);
|
|
|
|
|
|
UpdateStatus?.Invoke("Aborted!");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Aborted!");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-01 18:56:19 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PulseProgress?.Invoke(string.Format("Retrying block {0}, pass {1}, {3}{2}", badBlock, pass,
|
|
|
|
|
|
forward ? "forward" : "reverse",
|
|
|
|
|
|
runningPersistent ? "recovering partial data, " : ""));
|
|
|
|
|
|
|
|
|
|
|
|
UpdateStatus?.Invoke($"Positioning tape to block {badBlock}.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine($"Positioning tape to block {badBlock}.");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-01 19:37:44 +01:00
|
|
|
|
if(canLocateLong)
|
2019-05-01 18:56:19 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.Locate16(out senseBuf, _resume.NextBlock, _dev.Timeout, out _);
|
2019-05-01 18:56:19 +01:00
|
|
|
|
|
|
|
|
|
|
if(!sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.ReadPositionLong(out cmdBuf, out senseBuf, _dev.Timeout, out _);
|
2019-05-01 18:56:19 +01:00
|
|
|
|
|
|
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Could not check current position, continuing.");
|
2019-05-01 18:56:19 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Could not check current position, continuing.");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-01 18:56:19 +01:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ulong position = Swapping.Swap(BitConverter.ToUInt64(cmdBuf, 8));
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(position != _resume.NextBlock)
|
2019-05-01 18:56:19 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Current position is not as expected, continuing.");
|
2019-05-01 18:56:19 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Current position is not as expected, continuing.");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-01 18:56:19 +01:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine($"Cannot position tape to block {badBlock}.");
|
2019-05-01 18:56:19 +01:00
|
|
|
|
ErrorMessage?.Invoke($"Cannot position tape to block {badBlock}.");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-01 18:56:19 +01:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.Locate(out senseBuf, (uint)_resume.NextBlock, _dev.Timeout, out _);
|
2019-05-01 18:56:19 +01:00
|
|
|
|
|
|
|
|
|
|
if(!sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.ReadPosition(out cmdBuf, out senseBuf, _dev.Timeout, out _);
|
2019-05-01 18:56:19 +01:00
|
|
|
|
|
|
|
|
|
|
if(sense)
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Could not check current position, continuing.");
|
2019-05-01 18:56:19 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Could not check current position, continuing.");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-01 18:56:19 +01:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ulong position = Swapping.Swap(BitConverter.ToUInt32(cmdBuf, 4));
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(position != _resume.NextBlock)
|
2019-05-01 18:56:19 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Current position is not as expected, continuing.");
|
2019-05-01 18:56:19 +01:00
|
|
|
|
StoppingErrorMessage?.Invoke("Current position is not as expected, continuing.");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-01 18:56:19 +01:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine($"Cannot position tape to block {badBlock}.");
|
2019-05-01 18:56:19 +01:00
|
|
|
|
ErrorMessage?.Invoke($"Cannot position tape to block {badBlock}.");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-01 18:56:19 +01:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sense = _dev.Read6(out cmdBuf, out senseBuf, false, fixedLen, transferLen, blockSize, _dev.Timeout,
|
|
|
|
|
|
out duration);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-01 18:56:19 +01:00
|
|
|
|
totalDuration += duration;
|
|
|
|
|
|
|
2019-11-10 00:48:32 +00:00
|
|
|
|
if(!sense &&
|
2019-12-25 18:07:05 +00:00
|
|
|
|
!_dev.Error)
|
2019-05-01 18:56:19 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_resume.BadBlocks.Remove(badBlock);
|
2019-05-01 18:56:19 +01:00
|
|
|
|
extents.Add(badBlock);
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.WriteSector(cmdBuf, badBlock);
|
2019-05-01 18:56:19 +01:00
|
|
|
|
UpdateStatus?.Invoke($"Correctly retried block {badBlock} in pass {pass}.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Correctly retried block {0} in pass {1}.", badBlock, pass);
|
2019-05-01 18:56:19 +01:00
|
|
|
|
}
|
2019-11-10 00:48:32 +00:00
|
|
|
|
else if(runningPersistent)
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.WriteSector(cmdBuf, badBlock);
|
2019-05-01 18:56:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(pass < _retryPasses &&
|
|
|
|
|
|
!_aborted &&
|
|
|
|
|
|
_resume.BadBlocks.Count > 0)
|
2019-05-01 18:56:19 +01:00
|
|
|
|
{
|
|
|
|
|
|
pass++;
|
|
|
|
|
|
forward = !forward;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_resume.BadBlocks.Sort();
|
|
|
|
|
|
_resume.BadBlocks.Reverse();
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-01 18:56:19 +01:00
|
|
|
|
goto repeatRetry;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(runningPersistent && currentModePage.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
// TODO: Persistent mode
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EndProgress?.Invoke();
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion Error handling
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_resume.BadBlocks.Sort();
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
foreach(ulong bad in _resume.BadBlocks)
|
|
|
|
|
|
_dumpLog.WriteLine("Block {0} could not be read.", bad);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-01 18:56:19 +01:00
|
|
|
|
currentTry.Extents = ExtentsConverter.ToMetadata(extents);
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.SetDumpHardware(_resume.Tries);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_preSidecar != null)
|
|
|
|
|
|
_outputPlugin.SetCicmMetadata(_preSidecar);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Closing output file.");
|
2019-04-30 23:33:33 +01:00
|
|
|
|
UpdateStatus?.Invoke("Closing output file.");
|
|
|
|
|
|
DateTime closeStart = DateTime.Now;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_outputPlugin.Close();
|
2019-04-30 23:33:33 +01:00
|
|
|
|
DateTime closeEnd = DateTime.Now;
|
|
|
|
|
|
UpdateStatus?.Invoke($"Closed in {(closeEnd - closeStart).TotalSeconds} seconds.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Closed in {0} seconds.", (closeEnd - closeStart).TotalSeconds);
|
2019-04-30 23:33:33 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_aborted)
|
2019-05-01 18:56:19 +01:00
|
|
|
|
{
|
|
|
|
|
|
UpdateStatus?.Invoke("Aborted!");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Aborted!");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-01 18:56:19 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_aborted)
|
2019-05-03 00:24:30 +01:00
|
|
|
|
{
|
|
|
|
|
|
UpdateStatus?.Invoke("Aborted!");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Aborted!");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-03 00:24:30 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double totalChkDuration = 0;
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(!_nometadata)
|
2019-05-03 00:24:30 +01:00
|
|
|
|
{
|
|
|
|
|
|
UpdateStatus?.Invoke("Creating sidecar.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Creating sidecar.");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
var filters = new FiltersList();
|
2019-12-25 18:07:05 +00:00
|
|
|
|
IFilter filter = filters.GetFilter(_outputPath);
|
2019-05-03 00:24:30 +01:00
|
|
|
|
IMediaImage inputPlugin = ImageFormat.Detect(filter);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-03 00:24:30 +01:00
|
|
|
|
if(!inputPlugin.Open(filter))
|
|
|
|
|
|
{
|
|
|
|
|
|
StoppingErrorMessage?.Invoke("Could not open created image.");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-03 00:24:30 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DateTime chkStart = DateTime.UtcNow;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_sidecarClass = new Sidecar(inputPlugin, _outputPath, filter.Id, _encoding);
|
|
|
|
|
|
_sidecarClass.InitProgressEvent += InitProgress;
|
|
|
|
|
|
_sidecarClass.UpdateProgressEvent += UpdateProgress;
|
|
|
|
|
|
_sidecarClass.EndProgressEvent += EndProgress;
|
|
|
|
|
|
_sidecarClass.InitProgressEvent2 += InitProgress2;
|
|
|
|
|
|
_sidecarClass.UpdateProgressEvent2 += UpdateProgress2;
|
|
|
|
|
|
_sidecarClass.EndProgressEvent2 += EndProgress2;
|
|
|
|
|
|
_sidecarClass.UpdateStatusEvent += UpdateStatus;
|
|
|
|
|
|
CICMMetadataType sidecar = _sidecarClass.Create();
|
2019-05-03 00:24:30 +01:00
|
|
|
|
end = DateTime.UtcNow;
|
|
|
|
|
|
|
|
|
|
|
|
totalChkDuration = (end - chkStart).TotalMilliseconds;
|
|
|
|
|
|
UpdateStatus?.Invoke($"Sidecar created in {(end - chkStart).TotalSeconds} seconds.");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
|
|
|
|
|
UpdateStatus?.
|
2019-12-25 18:07:05 +00:00
|
|
|
|
Invoke($"Average checksum speed {((double)blockSize * (double)(blocks + 1)) / 1024 / (totalChkDuration / 1000):F3} KiB/sec.");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Sidecar created in {0} seconds.", (end - chkStart).TotalSeconds);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Average checksum speed {0:F3} KiB/sec.",
|
|
|
|
|
|
((double)blockSize * (double)(blocks + 1)) / 1024 / (totalChkDuration / 1000));
|
2019-05-03 00:24:30 +01:00
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_preSidecar != null)
|
2019-05-03 00:24:30 +01:00
|
|
|
|
{
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_preSidecar.BlockMedia = sidecar.BlockMedia;
|
|
|
|
|
|
sidecar = _preSidecar;
|
2019-05-03 00:24:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<(ulong start, string type)> filesystems = new List<(ulong start, string type)>();
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-03 00:24:30 +01:00
|
|
|
|
if(sidecar.BlockMedia[0].FileSystemInformation != null)
|
|
|
|
|
|
filesystems.AddRange(from partition in sidecar.BlockMedia[0].FileSystemInformation
|
2019-11-10 00:48:32 +00:00
|
|
|
|
where partition.FileSystems != null from fileSystem in partition.FileSystems
|
2019-05-03 00:24:30 +01:00
|
|
|
|
select (partition.StartSector, fileSystem.Type));
|
|
|
|
|
|
|
|
|
|
|
|
if(filesystems.Count > 0)
|
2019-11-10 00:48:32 +00:00
|
|
|
|
foreach(var filesystem in filesystems.Select(o => new
|
|
|
|
|
|
{
|
|
|
|
|
|
o.start, o.type
|
|
|
|
|
|
}).Distinct())
|
2019-05-03 00:24:30 +01:00
|
|
|
|
{
|
|
|
|
|
|
UpdateStatus?.Invoke($"Found filesystem {filesystem.type} at sector {filesystem.start}");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
_dumpLog.WriteLine("Found filesystem {0} at sector {1}", filesystem.type, filesystem.start);
|
2019-05-03 00:24:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sidecar.BlockMedia[0].Dimensions = Dimensions.DimensionsFromMediaType(dskType);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-11-18 20:59:16 +00:00
|
|
|
|
(string type, string subType) xmlType = CommonTypes.Metadata.MediaType.MediaTypeToString(dskType);
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-11-18 20:59:16 +00:00
|
|
|
|
sidecar.BlockMedia[0].DiskType = xmlType.type;
|
|
|
|
|
|
sidecar.BlockMedia[0].DiskSubType = xmlType.subType;
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-03 00:24:30 +01:00
|
|
|
|
// TODO: Implement device firmware revision
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(!_dev.IsRemovable ||
|
|
|
|
|
|
_dev.IsUsb)
|
|
|
|
|
|
if(_dev.Type == DeviceType.ATAPI)
|
2019-11-10 00:48:32 +00:00
|
|
|
|
sidecar.BlockMedia[0].Interface = "ATAPI";
|
2019-12-25 18:07:05 +00:00
|
|
|
|
else if(_dev.IsUsb)
|
2019-11-10 00:48:32 +00:00
|
|
|
|
sidecar.BlockMedia[0].Interface = "USB";
|
2019-12-25 18:07:05 +00:00
|
|
|
|
else if(_dev.IsFireWire)
|
2019-11-10 00:48:32 +00:00
|
|
|
|
sidecar.BlockMedia[0].Interface = "FireWire";
|
|
|
|
|
|
else
|
|
|
|
|
|
sidecar.BlockMedia[0].Interface = "SCSI";
|
|
|
|
|
|
|
2019-05-03 00:24:30 +01:00
|
|
|
|
sidecar.BlockMedia[0].LogicalBlocks = blocks;
|
2019-12-25 18:07:05 +00:00
|
|
|
|
sidecar.BlockMedia[0].Manufacturer = _dev.Manufacturer;
|
|
|
|
|
|
sidecar.BlockMedia[0].Model = _dev.Model;
|
|
|
|
|
|
sidecar.BlockMedia[0].Serial = _dev.Serial;
|
2019-05-03 00:24:30 +01:00
|
|
|
|
sidecar.BlockMedia[0].Size = blocks * blockSize;
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
if(_dev.IsRemovable)
|
|
|
|
|
|
sidecar.BlockMedia[0].DumpHardwareArray = _resume.Tries.ToArray();
|
2019-05-03 00:24:30 +01:00
|
|
|
|
|
|
|
|
|
|
UpdateStatus?.Invoke("Writing metadata sidecar");
|
|
|
|
|
|
|
2019-12-25 18:07:05 +00:00
|
|
|
|
var xmlFs = new FileStream(_outputPrefix + ".cicm.xml", FileMode.Create);
|
2019-05-03 00:24:30 +01:00
|
|
|
|
|
2019-11-10 00:48:32 +00:00
|
|
|
|
var xmlSer = new XmlSerializer(typeof(CICMMetadataType));
|
2019-05-03 00:24:30 +01:00
|
|
|
|
xmlSer.Serialize(xmlFs, sidecar);
|
|
|
|
|
|
xmlFs.Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UpdateStatus?.Invoke("");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
|
|
|
|
|
UpdateStatus?.
|
|
|
|
|
|
Invoke($"Took a total of {(end - start).TotalSeconds:F3} seconds ({totalDuration / 1000:F3} processing commands, {totalChkDuration / 1000:F3} checksumming, {imageWriteDuration:F3} writing, {(closeEnd - closeStart).TotalSeconds:F3} closing).");
|
|
|
|
|
|
|
|
|
|
|
|
UpdateStatus?.
|
2019-12-25 18:07:05 +00:00
|
|
|
|
Invoke($"Average speed: {((double)blockSize * (double)(blocks + 1)) / 1048576 / (totalDuration / 1000):F3} MiB/sec.");
|
2019-11-10 00:48:32 +00:00
|
|
|
|
|
2019-05-03 00:24:30 +01:00
|
|
|
|
UpdateStatus?.Invoke($"Fastest speed burst: {maxSpeed:F3} MiB/sec.");
|
|
|
|
|
|
UpdateStatus?.Invoke($"Slowest speed burst: {minSpeed:F3} MiB/sec.");
|
2019-12-25 18:07:05 +00:00
|
|
|
|
UpdateStatus?.Invoke($"{_resume.BadBlocks.Count} sectors could not be read.");
|
2019-05-03 00:24:30 +01:00
|
|
|
|
UpdateStatus?.Invoke("");
|
2017-05-31 01:00:58 +01:00
|
|
|
|
|
|
|
|
|
|
Statistics.AddMedia(dskType, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|