Files
Aaru/DiscImageChef.Core/Devices/Dumping/SSC.cs

690 lines
35 KiB
C#
Raw Normal View History

// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : SSC.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Core algorithms.
//
// --[ Description ] ----------------------------------------------------------
//
// Dumps media from SCSI Streaming devices.
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2011-2018 Natalia Portillo
// ****************************************************************************/
using System;
using System.Collections.Generic;
using System.IO;
2017-12-21 14:30:38 +00:00
using System.Threading;
using System.Xml.Serialization;
using DiscImageChef.CommonTypes;
using DiscImageChef.Console;
using DiscImageChef.Core.Logging;
2017-12-21 14:30:38 +00:00
using DiscImageChef.Decoders.SCSI;
using DiscImageChef.Devices;
2017-12-21 14:30:38 +00:00
using DiscImageChef.Metadata;
using Schemas;
2017-12-21 14:30:38 +00:00
using MediaType = DiscImageChef.CommonTypes.MediaType;
using Version = DiscImageChef.Metadata.Version;
namespace DiscImageChef.Core.Devices.Dumping
{
static class Ssc
{
/// <summary>
/// Dumps the tape from a SCSI Streaming device
/// </summary>
/// <param name="dev">Device</param>
/// <param name="devicePath">Path to the device</param>
/// <param name="outputPrefix">Prefix for output data files</param>
/// <param name="resume">Information for dump resuming</param>
/// <param name="dumpLog">Dump logger</param>
/// <param name="sidecar">Partially filled initialized sidecar</param>
2017-12-19 20:33:03 +00:00
internal static void Dump(Device dev, string outputPrefix, string devicePath, ref CICMMetadataType sidecar,
2017-12-29 01:26:58 +00:00
ref Resume resume,
ref DumpLog dumpLog)
{
2017-12-21 14:30:38 +00:00
FixedSense? fxSense;
2017-12-29 01:26:58 +00:00
bool aborted;
bool sense;
ulong blocks = 0;
uint blockSize;
MediaType dskType = MediaType.Unknown;
DateTime start;
DateTime end;
double totalDuration = 0;
double totalChkDuration = 0;
double currentSpeed = 0;
double maxSpeed = double.MinValue;
double minSpeed = double.MaxValue;
2017-06-08 21:12:05 +01: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-12-21 14:30:38 +00:00
if(fxSense.HasValue && fxSense.Value.SenseKey != SenseKeys.NoSense)
{
2017-12-19 20:33:03 +00:00
dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h", fxSense.Value.SenseKey,
fxSense.Value.ASC, fxSense.Value.ASCQ);
DicConsole.ErrorWriteLine("Drive has status error, please correct. Sense follows...");
DicConsole.ErrorWriteLine("{0}", strSense);
return;
}
// Not in BOM/P
2017-12-29 01:26:58 +00:00
if(fxSense.HasValue && fxSense.Value.ASC == 0x00 && fxSense.Value.ASCQ != 0x00 &&
fxSense.Value.ASCQ != 0x04 && fxSense.Value.SenseKey != SenseKeys.IllegalRequest)
{
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Rewinding, please wait...");
DicConsole.Write("Rewinding, please wait...");
// Rewind, let timeout apply
dev.Rewind(out senseBuf, dev.Timeout, out duration);
// Still rewinding?
// TODO: Pause?
do
{
DicConsole.Write("\rRewinding, please wait...");
dev.RequestSense(out senseBuf, dev.Timeout, out duration);
2017-12-21 14:30:38 +00:00
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
}
2017-12-19 20:33:03 +00:00
while(fxSense.HasValue && fxSense.Value.ASC == 0x00 &&
2017-12-29 01:26:58 +00:00
(fxSense.Value.ASCQ == 0x1A || fxSense.Value.ASCQ != 0x04));
dev.RequestSense(out senseBuf, dev.Timeout, out duration);
2017-12-21 14:30:38 +00:00
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
// And yet, did not rewind!
2017-12-29 01:26:58 +00:00
if(fxSense.HasValue &&
(fxSense.Value.ASC == 0x00 && fxSense.Value.ASCQ != 0x04 || fxSense.Value.ASC != 0x00))
{
DicConsole.WriteLine();
DicConsole.ErrorWriteLine("Drive could not rewind, please correct. Sense follows...");
DicConsole.ErrorWriteLine("{0}", strSense);
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Drive could not rewind, please correct. Sense follows...");
2017-12-19 20:33:03 +00:00
dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h", fxSense.Value.SenseKey,
fxSense.Value.ASC, fxSense.Value.ASCQ);
return;
}
DicConsole.WriteLine();
}
// Check position
2017-12-19 20:33:03 +00:00
sense = dev.ReadPosition(out byte[] cmdBuf, out senseBuf, SscPositionForms.Short, dev.Timeout,
out duration);
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-12-29 01:26:58 +00:00
if(fxSense.HasValue && (fxSense.Value.ASC == 0x20 && fxSense.Value.ASCQ != 0x00 ||
fxSense.Value.ASC != 0x20 &&
fxSense.Value.SenseKey != SenseKeys.IllegalRequest))
{
DicConsole.ErrorWriteLine("Could not get position. Sense follows...");
DicConsole.ErrorWriteLine("{0}", strSense);
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Could not get position. Sense follows...");
2017-12-19 20:33:03 +00:00
dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h", fxSense.Value.SenseKey,
fxSense.Value.ASC, fxSense.Value.ASCQ);
return;
}
}
else
{
// Not in partition 0
if(cmdBuf[1] != 0)
{
DicConsole.Write("Drive not in partition 0. Rewinding, please wait...");
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Drive not in partition 0. Rewinding, please wait...");
// Rewind, let timeout apply
sense = dev.Locate(out senseBuf, false, 0, 0, dev.Timeout, out duration);
if(sense)
{
DicConsole.WriteLine();
DicConsole.ErrorWriteLine("Drive could not rewind, please correct. Sense follows...");
DicConsole.ErrorWriteLine("{0}", strSense);
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Drive could not rewind, please correct. Sense follows...");
2017-12-19 20:33:03 +00:00
dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h",
fxSense.Value.SenseKey, fxSense.Value.ASC, fxSense.Value.ASCQ);
return;
}
// Still rewinding?
// TODO: Pause?
do
{
2017-12-21 14:30:38 +00:00
Thread.Sleep(1000);
DicConsole.Write("\rRewinding, please wait...");
dev.RequestSense(out senseBuf, dev.Timeout, out duration);
2017-12-21 14:30:38 +00:00
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
}
2017-12-19 20:33:03 +00:00
while(fxSense.HasValue && fxSense.Value.ASC == 0x00 &&
2017-12-29 01:26:58 +00:00
(fxSense.Value.ASCQ == 0x1A || fxSense.Value.ASCQ == 0x19));
// And yet, did not rewind!
if(fxSense.HasValue && (fxSense.Value.ASC == 0x00 && fxSense.Value.ASCQ != 0x04 ||
2017-12-19 20:33:03 +00:00
fxSense.Value.ASC != 0x00))
{
DicConsole.WriteLine();
DicConsole.ErrorWriteLine("Drive could not rewind, please correct. Sense follows...");
DicConsole.ErrorWriteLine("{0}", strSense);
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Drive could not rewind, please correct. Sense follows...");
2017-12-19 20:33:03 +00:00
dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h",
fxSense.Value.SenseKey, fxSense.Value.ASC, fxSense.Value.ASCQ);
return;
}
2017-12-19 20:33:03 +00:00
sense = dev.ReadPosition(out cmdBuf, out senseBuf, SscPositionForms.Short, dev.Timeout,
out duration);
if(sense)
{
2017-12-21 14:30:38 +00:00
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
DicConsole.ErrorWriteLine("Drive could not rewind, please correct. Sense follows...");
DicConsole.ErrorWriteLine("{0}", strSense);
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Drive could not rewind, please correct. Sense follows...");
2017-12-19 20:33:03 +00:00
dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h",
fxSense.Value.SenseKey, fxSense.Value.ASC, fxSense.Value.ASCQ);
return;
}
// Still not in partition 0!!!?
if(cmdBuf[1] != 0)
{
DicConsole.ErrorWriteLine("Drive could not rewind to partition 0 but no error occurred...");
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Drive could not rewind to partition 0 but no error occurred...");
return;
}
DicConsole.WriteLine();
}
}
2017-12-29 01:26:58 +00:00
sidecar.BlockMedia = new BlockMediaType[1];
sidecar.BlockMedia[0] = new BlockMediaType {SCSI = new SCSIType()};
byte scsiMediumTypeTape = 0;
byte scsiDensityCodeTape = 0;
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Requesting MODE SENSE (10).");
2017-12-19 20:33:03 +00:00
sense = dev.ModeSense10(out cmdBuf, out senseBuf, false, true, ScsiModeSensePageControl.Current, 0x3F, 0xFF,
5, out duration);
if(!sense || dev.Error)
2017-12-19 20:33:03 +00:00
sense = dev.ModeSense10(out cmdBuf, out senseBuf, false, true, ScsiModeSensePageControl.Current, 0x3F,
0x00, 5, out duration);
2017-12-21 14:30:38 +00:00
Modes.DecodedMode? decMode = null;
if(!sense && !dev.Error)
2017-12-21 14:30:38 +00:00
if(Modes.DecodeMode10(cmdBuf, dev.ScsiType).HasValue)
{
2017-12-29 01:26:58 +00:00
decMode = Modes.DecodeMode10(cmdBuf, dev.ScsiType);
2017-06-08 21:12:05 +01:00
sidecar.BlockMedia[0].SCSI.ModeSense10 = new DumpType
{
2017-12-29 01:26:58 +00:00
Image = outputPrefix + ".modesense10.bin",
Size = cmdBuf.Length,
2017-06-08 21:12:05 +01:00
Checksums = Checksum.GetChecksums(cmdBuf).ToArray()
};
DataFile.WriteTo("SCSI Dump", sidecar.BlockMedia[0].SCSI.ModeSense10.Image, cmdBuf);
}
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Requesting MODE SENSE (6).");
2017-12-19 20:33:03 +00:00
sense = dev.ModeSense6(out cmdBuf, out senseBuf, false, ScsiModeSensePageControl.Current, 0x3F, 0x00, 5,
out duration);
if(sense || dev.Error)
2017-12-19 20:33:03 +00:00
sense = dev.ModeSense6(out cmdBuf, out senseBuf, false, ScsiModeSensePageControl.Current, 0x3F, 0x00, 5,
out duration);
if(sense || dev.Error) sense = dev.ModeSense(out cmdBuf, out senseBuf, 5, out duration);
if(!sense && !dev.Error)
2017-12-21 14:30:38 +00:00
if(Modes.DecodeMode6(cmdBuf, dev.ScsiType).HasValue)
{
2017-12-29 01:26:58 +00:00
decMode = Modes.DecodeMode6(cmdBuf, dev.ScsiType);
2017-06-08 21:12:05 +01:00
sidecar.BlockMedia[0].SCSI.ModeSense = new DumpType
{
2017-12-29 01:26:58 +00:00
Image = outputPrefix + ".modesense.bin",
Size = cmdBuf.Length,
2017-06-08 21:12:05 +01:00
Checksums = Checksum.GetChecksums(cmdBuf).ToArray()
};
DataFile.WriteTo("SCSI Dump", sidecar.BlockMedia[0].SCSI.ModeSense.Image, cmdBuf);
}
// TODO: Check partitions page
if(decMode.HasValue)
{
scsiMediumTypeTape = (byte)decMode.Value.Header.MediumType;
if(decMode.Value.Header.BlockDescriptors != null && decMode.Value.Header.BlockDescriptors.Length >= 1)
scsiDensityCodeTape = (byte)decMode.Value.Header.BlockDescriptors[0].Density;
2017-12-29 01:26:58 +00:00
blockSize = decMode.Value.Header.BlockDescriptors[0].BlockLength;
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Device reports {0} blocks ({1} bytes).", blocks, blocks * blockSize);
}
2017-12-19 20:33:03 +00:00
else blockSize = 1;
if(dskType == MediaType.Unknown)
dskType = MediaTypeFromScsi.Get((byte)dev.ScsiType, dev.Manufacturer, dev.Model, scsiMediumTypeTape,
2017-12-19 20:33:03 +00:00
scsiDensityCodeTape, blocks, blockSize);
DicConsole.WriteLine("Media identified as {0}", dskType);
2017-12-29 01:26:58 +00:00
dumpLog.WriteLine("SCSI device type: {0}.", dev.ScsiType);
dumpLog.WriteLine("SCSI medium type: {0}.", scsiMediumTypeTape);
dumpLog.WriteLine("SCSI density type: {0}.", scsiDensityCodeTape);
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Media identified as {0}.", dskType);
2017-12-29 01:26:58 +00:00
bool endOfMedia = false;
ulong currentBlock = 0;
ulong currentFile = 0;
byte currentPartition = 0;
byte totalPartitions = 1; // TODO: Handle partitions.
ulong currentSize = 0;
ulong currentPartitionSize = 0;
2017-12-29 01:26:58 +00:00
ulong currentFileSize = 0;
2017-12-29 01:26:58 +00:00
bool fixedLen = false;
uint transferLen = blockSize;
2017-12-19 20:33:03 +00:00
sense = dev.Read6(out cmdBuf, out senseBuf, false, fixedLen, transferLen, blockSize, dev.Timeout,
out duration);
if(sense)
{
2017-12-21 14:30:38 +00:00
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
if(fxSense.HasValue)
2017-12-21 14:30:38 +00:00
if(fxSense.Value.SenseKey == SenseKeys.IllegalRequest)
{
sense = dev.Space(out senseBuf, SscSpaceCodes.LogicalBlock, -1, dev.Timeout, out duration);
if(sense)
{
2017-12-21 14:30:38 +00:00
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
if(!fxSense.HasValue || !fxSense.Value.EOM)
{
DicConsole.WriteLine();
DicConsole.ErrorWriteLine("Drive could not return back. Sense follows...");
DicConsole.ErrorWriteLine("{0}", strSense);
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Drive could not return back. Sense follows...");
2017-12-19 20:33:03 +00:00
dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h",
fxSense.Value.SenseKey, fxSense.Value.ASC, fxSense.Value.ASCQ);
return;
}
}
2017-12-29 01:26:58 +00:00
fixedLen = true;
transferLen = 1;
2017-12-29 01:26:58 +00:00
sense = dev.Read6(out cmdBuf, out senseBuf, false, fixedLen, transferLen, blockSize,
dev.Timeout, out duration);
if(sense)
{
DicConsole.WriteLine();
DicConsole.ErrorWriteLine("Drive could not read. Sense follows...");
DicConsole.ErrorWriteLine("{0}", strSense);
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Drive could not read. Sense follows...");
2017-12-19 20:33:03 +00:00
dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h",
fxSense.Value.SenseKey, fxSense.Value.ASC, fxSense.Value.ASCQ);
return;
}
}
else
{
DicConsole.WriteLine();
DicConsole.ErrorWriteLine("Drive could not read. Sense follows...");
DicConsole.ErrorWriteLine("{0}", strSense);
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Drive could not read. Sense follows...");
2017-12-19 20:33:03 +00:00
dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h",
fxSense.Value.SenseKey, fxSense.Value.ASC, fxSense.Value.ASCQ);
return;
}
else
{
DicConsole.WriteLine();
DicConsole.ErrorWriteLine("Cannot read device, don't know why, exiting...");
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Cannot read device, don't know why, exiting...");
return;
}
}
sense = dev.Space(out senseBuf, SscSpaceCodes.LogicalBlock, -1, dev.Timeout, out duration);
if(sense)
{
2017-12-21 14:30:38 +00:00
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
if(!fxSense.HasValue || !fxSense.Value.EOM)
{
DicConsole.WriteLine();
DicConsole.ErrorWriteLine("Drive could not return back. Sense follows...");
DicConsole.ErrorWriteLine("{0}", strSense);
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Drive could not return back. Sense follows...");
2017-12-19 20:33:03 +00:00
dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h", fxSense.Value.SenseKey,
fxSense.Value.ASC, fxSense.Value.ASCQ);
return;
}
}
List<TapePartitionType> partitions = new List<TapePartitionType>();
2017-12-29 01:26:58 +00:00
List<TapeFileType> files = new List<TapeFileType>();
DicConsole.WriteLine();
DataFile dumpFile = new DataFile(outputPrefix + ".bin");
2017-12-29 01:26:58 +00:00
Checksum dataChk = new Checksum();
start = DateTime.UtcNow;
MhddLog mhddLog = new MhddLog(outputPrefix + ".mhddlog.bin", dev, blocks, blockSize, 1);
IbgLog ibgLog = new IbgLog(outputPrefix + ".ibg", 0x0008);
TapeFileType currentTapeFile = new TapeFileType
2017-06-08 21:12:05 +01:00
{
Image = new ImageType
{
2017-12-29 01:26:58 +00:00
format = "BINARY",
offset = (long)currentSize,
2017-06-08 21:12:05 +01:00
offsetSpecified = true,
2017-12-29 01:26:58 +00:00
Value = outputPrefix + ".bin"
2017-06-08 21:12:05 +01:00
},
2017-12-29 01:26:58 +00:00
Sequence = (long)currentFile,
2017-06-08 21:12:05 +01:00
StartBlock = (long)currentBlock,
2017-12-29 01:26:58 +00:00
BlockSize = blockSize
2017-06-08 21:12:05 +01:00
};
2017-12-29 01:26:58 +00:00
Checksum fileChk = new Checksum();
TapePartitionType currentTapePartition = new TapePartitionType
2017-06-08 21:12:05 +01:00
{
Image = new ImageType
{
2017-12-29 01:26:58 +00:00
format = "BINARY",
offset = (long)currentSize,
2017-06-08 21:12:05 +01:00
offsetSpecified = true,
2017-12-29 01:26:58 +00:00
Value = outputPrefix + ".bin"
2017-06-08 21:12:05 +01:00
},
2017-12-29 01:26:58 +00:00
Sequence = currentPartition,
2017-06-08 21:12:05 +01:00
StartBlock = (long)currentBlock
};
Checksum partitionChk = new Checksum();
2017-12-29 01:26:58 +00:00
aborted = false;
System.Console.CancelKeyPress += (sender, e) => e.Cancel = aborted = true;
while(currentPartition < totalPartitions)
{
if(aborted)
2017-11-20 05:07:16 +00:00
{
dumpLog.WriteLine("Aborted!");
break;
2017-11-20 05:07:16 +00:00
}
if(endOfMedia)
{
DicConsole.WriteLine();
DicConsole.WriteLine("Finished partition {0}", currentPartition);
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Finished partition {0}", currentPartition);
2017-12-29 01:26:58 +00:00
currentTapePartition.File = files.ToArray();
currentTapePartition.Checksums = partitionChk.End().ToArray();
2017-12-29 01:26:58 +00:00
currentTapePartition.EndBlock = (long)(currentBlock - 1);
currentTapePartition.Size = (long)currentPartitionSize;
partitions.Add(currentTapePartition);
currentPartition++;
if(currentPartition < totalPartitions)
{
currentFile++;
2017-06-08 21:12:05 +01:00
currentTapeFile = new TapeFileType
{
Image = new ImageType
{
2017-12-29 01:26:58 +00:00
format = "BINARY",
offset = (long)currentSize,
2017-06-08 21:12:05 +01:00
offsetSpecified = true,
2017-12-29 01:26:58 +00:00
Value = outputPrefix + ".bin"
2017-06-08 21:12:05 +01:00
},
2017-12-29 01:26:58 +00:00
Sequence = (long)currentFile,
2017-06-08 21:12:05 +01:00
StartBlock = (long)currentBlock,
2017-12-29 01:26:58 +00:00
BlockSize = blockSize
2017-06-08 21:12:05 +01:00
};
2017-12-29 01:26:58 +00:00
currentFileSize = 0;
fileChk = new Checksum();
files = new List<TapeFileType>();
2017-06-08 21:12:05 +01:00
currentTapePartition = new TapePartitionType
{
Image = new ImageType
{
2017-12-29 01:26:58 +00:00
format = "BINARY",
offset = (long)currentSize,
2017-06-08 21:12:05 +01:00
offsetSpecified = true,
2017-12-29 01:26:58 +00:00
Value = outputPrefix + ".bin"
2017-06-08 21:12:05 +01:00
},
2017-12-29 01:26:58 +00:00
Sequence = currentPartition,
2017-06-08 21:12:05 +01:00
StartBlock = (long)currentBlock
};
currentPartitionSize = 0;
2017-12-29 01:26:58 +00:00
partitionChk = new Checksum();
DicConsole.WriteLine("Seeking to partition {0}", currentPartition);
dev.Locate(out senseBuf, false, currentPartition, 0, dev.Timeout, out duration);
totalDuration += duration;
}
continue;
}
2017-12-29 01:26:58 +00:00
#pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
2017-12-19 20:33:03 +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
DicConsole.Write("\rReading block {0} ({1:F3} MiB/sec.)", currentBlock, currentSpeed);
2017-12-19 20:33:03 +00:00
sense = dev.Read6(out cmdBuf, out senseBuf, false, fixedLen, transferLen, blockSize, dev.Timeout,
out duration);
totalDuration += duration;
if(sense)
{
2017-12-21 14:30:38 +00:00
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
2017-12-19 20:33:03 +00:00
if(fxSense.Value.ASC == 0x00 && fxSense.Value.ASCQ == 0x00 && fxSense.Value.ILI &&
fxSense.Value.InformationValid)
{
2017-12-19 20:33:03 +00:00
blockSize = (uint)((int)blockSize -
BitConverter.ToInt32(BitConverter.GetBytes(fxSense.Value.Information), 0));
currentTapeFile.BlockSize = blockSize;
DicConsole.WriteLine();
DicConsole.WriteLine("Blocksize changed to {0} bytes at block {1}", blockSize, currentBlock);
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Blocksize changed to {0} bytes at block {1}", blockSize, currentBlock);
2017-12-29 01:26:58 +00:00
sense = dev.Space(out senseBuf, SscSpaceCodes.LogicalBlock, -1, dev.Timeout,
out duration);
totalDuration += duration;
if(sense)
{
2017-12-21 14:30:38 +00:00
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
DicConsole.WriteLine();
DicConsole.ErrorWriteLine("Drive could not go back one block. Sense follows...");
DicConsole.ErrorWriteLine("{0}", strSense);
dumpFile.Close();
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Drive could not go back one block. Sense follows...");
2017-12-19 20:33:03 +00:00
dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h",
fxSense.Value.SenseKey, fxSense.Value.ASC, fxSense.Value.ASCQ);
return;
}
continue;
}
2017-12-21 14:30:38 +00:00
if(fxSense.Value.SenseKey == SenseKeys.BlankCheck)
{
if(currentBlock == 0)
{
DicConsole.WriteLine();
DicConsole.ErrorWriteLine("Cannot dump a blank tape...");
dumpFile.Close();
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Cannot dump a blank tape...");
return;
}
// For sure this is an end-of-tape/partition
2017-12-29 01:26:58 +00:00
if(fxSense.Value.ASC == 0x00 &&
2017-12-19 20:33:03 +00:00
(fxSense.Value.ASCQ == 0x02 || fxSense.Value.ASCQ == 0x05 || fxSense.Value.EOM))
{
// TODO: Detect end of partition
endOfMedia = true;
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Found end-of-tape/partition...");
continue;
}
DicConsole.WriteLine();
DicConsole.WriteLine("Blank block found, end of tape?");
endOfMedia = true;
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Blank block found, end of tape?...");
continue;
}
2017-12-21 14:30:38 +00:00
if((fxSense.Value.SenseKey == SenseKeys.NoSense ||
fxSense.Value.SenseKey == SenseKeys.RecoveredError) &&
2017-12-29 01:26:58 +00:00
(fxSense.Value.ASCQ == 0x02 || fxSense.Value.ASCQ == 0x05 || fxSense.Value.EOM))
{
// TODO: Detect end of partition
endOfMedia = true;
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Found end-of-tape/partition...");
continue;
}
2017-12-21 14:30:38 +00:00
if((fxSense.Value.SenseKey == SenseKeys.NoSense ||
fxSense.Value.SenseKey == SenseKeys.RecoveredError) &&
2017-12-29 01:26:58 +00:00
(fxSense.Value.ASCQ == 0x01 || fxSense.Value.Filemark))
{
currentTapeFile.Checksums = fileChk.End().ToArray();
2017-12-29 01:26:58 +00:00
currentTapeFile.EndBlock = (long)(currentBlock - 1);
currentTapeFile.Size = (long)currentFileSize;
files.Add(currentTapeFile);
currentFile++;
2017-06-08 21:12:05 +01:00
currentTapeFile = new TapeFileType
{
Image = new ImageType
{
2017-12-29 01:26:58 +00:00
format = "BINARY",
offset = (long)currentSize,
2017-06-08 21:12:05 +01:00
offsetSpecified = true,
2017-12-29 01:26:58 +00:00
Value = outputPrefix + ".bin"
2017-06-08 21:12:05 +01:00
},
2017-12-29 01:26:58 +00:00
Sequence = (long)currentFile,
2017-06-08 21:12:05 +01:00
StartBlock = (long)currentBlock,
2017-12-29 01:26:58 +00:00
BlockSize = blockSize
2017-06-08 21:12:05 +01:00
};
currentFileSize = 0;
2017-12-29 01:26:58 +00:00
fileChk = new Checksum();
DicConsole.WriteLine();
DicConsole.WriteLine("Changed to file {0} at block {1}", currentFile, currentBlock);
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Changed to file {0} at block {1}", currentFile, currentBlock);
continue;
}
// TODO: Add error recovering for tapes
2017-12-21 14:30:38 +00:00
fxSense = Sense.DecodeFixed(senseBuf, out strSense);
DicConsole.ErrorWriteLine("Drive could not read block. Sense follows...");
DicConsole.ErrorWriteLine("{0} {1}", fxSense.Value.SenseKey, strSense);
2017-11-20 05:07:16 +00:00
dumpLog.WriteLine("Drive could not read block. Sense follows...");
2017-12-19 20:33:03 +00:00
dumpLog.WriteLine("Device not ready. Sense {0}h ASC {1:X2}h ASCQ {2:X2}h", fxSense.Value.SenseKey,
fxSense.Value.ASC, fxSense.Value.ASCQ);
return;
}
mhddLog.Write(currentBlock, duration);
ibgLog.Write(currentBlock, currentSpeed * 1024);
dumpFile.Write(cmdBuf);
DateTime chkStart = DateTime.UtcNow;
dataChk.Update(cmdBuf);
fileChk.Update(cmdBuf);
partitionChk.Update(cmdBuf);
2017-12-29 01:26:58 +00:00
DateTime chkEnd = DateTime.UtcNow;
double chkDuration = (chkEnd - chkStart).TotalMilliseconds;
totalChkDuration += chkDuration;
if(currentBlock % 10 == 0)
{
2017-12-29 01:26:58 +00:00
double newSpeed = blockSize / (double)1048576 / (duration / 1000);
if(!double.IsInfinity(newSpeed)) currentSpeed = newSpeed;
}
2017-12-29 01:26:58 +00:00
currentBlock++;
2017-12-29 01:26:58 +00:00
currentSize += blockSize;
currentFileSize += blockSize;
currentPartitionSize += blockSize;
}
blocks = currentBlock + 1;
DicConsole.WriteLine();
end = DateTime.UtcNow;
mhddLog.Close();
2017-12-19 20:33:03 +00:00
ibgLog.Close(dev, blocks, blockSize, (end - start).TotalSeconds, currentSpeed * 1024,
2017-12-29 01:26:58 +00:00
blockSize * (double)(blocks + 1) /
1024 / (totalDuration / 1000), devicePath);
dumpLog.WriteLine("Dump finished in {0} seconds.",
(end - start).TotalSeconds);
2017-12-19 20:33:03 +00:00
dumpLog.WriteLine("Average dump speed {0:F3} KiB/sec.",
(double)blockSize * (double)(blocks + 1) / 1024 / (totalDuration / 1000));
2017-12-19 20:33:03 +00:00
dumpLog.WriteLine("Average checksum speed {0:F3} KiB/sec.",
(double)blockSize * (double)(blocks + 1) / 1024 / (totalChkDuration / 1000));
2017-12-19 20:33:03 +00:00
DicConsole.WriteLine("Took a total of {0:F3} seconds ({1:F3} processing commands, {2:F3} checksumming).",
(end - start).TotalSeconds, totalDuration / 1000, totalChkDuration / 1000);
DicConsole.WriteLine("Avegare speed: {0:F3} MiB/sec.",
(double)blockSize * (double)(blocks + 1) / 1048576 / (totalDuration / 1000));
DicConsole.WriteLine("Fastest speed burst: {0:F3} MiB/sec.", maxSpeed);
DicConsole.WriteLine("Slowest speed burst: {0:F3} MiB/sec.", minSpeed);
2017-12-29 01:26:58 +00:00
sidecar.BlockMedia[0].Checksums = dataChk.End().ToArray();
2017-12-21 14:30:38 +00:00
sidecar.BlockMedia[0].Dimensions = Dimensions.DimensionsFromMediaType(dskType);
2017-06-08 21:12:05 +01:00
Metadata.MediaType.MediaTypeToString(dskType, out string xmlDskTyp, out string xmlDskSubTyp);
2017-12-29 01:26:58 +00:00
sidecar.BlockMedia[0].DiskType = xmlDskTyp;
sidecar.BlockMedia[0].DiskSubType = xmlDskSubTyp;
// TODO: Implement device firmware revision
2017-06-08 21:12:05 +01:00
sidecar.BlockMedia[0].Image = new ImageType
{
format = "Raw disk image (sector by sector copy)",
2017-12-29 01:26:58 +00:00
Value = outputPrefix + ".bin"
2017-06-08 21:12:05 +01:00
};
2017-12-29 01:26:58 +00:00
sidecar.BlockMedia[0].LogicalBlocks = (long)blocks;
sidecar.BlockMedia[0].Size = (long)currentSize;
sidecar.BlockMedia[0].DumpHardwareArray = new DumpHardwareType[1];
sidecar.BlockMedia[0].DumpHardwareArray[0] =
new DumpHardwareType {Extents = new ExtentType[1]};
sidecar.BlockMedia[0].DumpHardwareArray[0].Extents[0] =
new ExtentType {Start = 0, End = blocks - 1};
sidecar.BlockMedia[0].DumpHardwareArray[0].Manufacturer = dev.Manufacturer;
2017-12-29 01:26:58 +00:00
sidecar.BlockMedia[0].DumpHardwareArray[0].Model = dev.Model;
sidecar.BlockMedia[0].DumpHardwareArray[0].Revision = dev.Revision;
sidecar.BlockMedia[0].DumpHardwareArray[0].Serial = dev.Serial;
sidecar.BlockMedia[0].DumpHardwareArray[0].Software = Version.GetSoftwareType();
2017-12-29 01:26:58 +00:00
sidecar.BlockMedia[0].TapeInformation = partitions.ToArray();
if(!aborted)
{
DicConsole.WriteLine("Writing metadata sidecar");
2017-12-19 20:33:03 +00:00
FileStream xmlFs = new FileStream(outputPrefix + ".cicm.xml", FileMode.Create);
XmlSerializer xmlSer = new XmlSerializer(typeof(CICMMetadataType));
xmlSer.Serialize(xmlFs, sidecar);
xmlFs.Close();
}
Statistics.AddMedia(dskType, true);
}
}
2017-12-19 20:33:03 +00:00
}