Files
Aaru/Aaru.Core/Devices/Report/SSC.cs

257 lines
11 KiB
C#
Raw Normal View History

// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : SSC.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Core algorithms.
//
// --[ Description ] ----------------------------------------------------------
//
// Creates reports 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/>.
//
// ----------------------------------------------------------------------------
2020-01-03 17:51:30 +00:00
// Copyright © 2011-2020 Natalia Portillo
// ****************************************************************************/
using System.Linq;
2020-02-27 00:33:26 +00:00
using Aaru.CommonTypes.Metadata;
using Aaru.Console;
using Aaru.Decoders.SCSI;
using Aaru.Decoders.SCSI.SSC;
using Aaru.Devices;
2020-02-27 00:33:26 +00:00
namespace Aaru.Core.Devices.Report
{
2020-07-22 13:20:25 +01:00
public sealed partial class DeviceReport
{
public Ssc ReportScsiSsc()
{
2019-12-27 18:00:03 +00:00
var report = new Ssc();
2020-02-27 23:48:41 +00:00
AaruConsole.WriteLine("Querying SCSI READ BLOCK LIMITS...");
bool sense = _dev.ReadBlockLimits(out byte[] buffer, out byte[] _, _dev.Timeout, out _);
2019-12-27 18:00:03 +00:00
if(!sense)
{
2017-12-21 14:30:38 +00:00
BlockLimits.BlockLimitsData? decBl = BlockLimits.Decode(buffer);
2019-12-27 18:00:03 +00:00
2020-07-22 13:20:25 +01:00
if(decBl?.granularity > 0)
report.BlockSizeGranularity = decBl.Value.granularity;
2018-06-22 08:08:38 +01:00
2020-07-22 13:20:25 +01:00
if(decBl?.maxBlockLen > 0)
report.MaxBlockLength = decBl.Value.maxBlockLen;
2018-06-22 08:08:38 +01:00
2020-07-22 13:20:25 +01:00
if(decBl?.minBlockLen > 0)
report.MinBlockLength = decBl.Value.minBlockLen;
}
2020-02-27 23:48:41 +00:00
AaruConsole.WriteLine("Querying SCSI REPORT DENSITY SUPPORT...");
sense = _dev.ReportDensitySupport(out buffer, out byte[] _, false, false, _dev.Timeout, out _);
2019-12-27 18:00:03 +00:00
if(!sense)
{
DensitySupport.DensitySupportHeader? dsh = DensitySupport.DecodeDensity(buffer);
2019-12-27 18:00:03 +00:00
if(dsh.HasValue)
{
SupportedDensity[] array = new SupportedDensity[dsh.Value.descriptors.Length];
2019-12-27 18:00:03 +00:00
for(int i = 0; i < dsh.Value.descriptors.Length; i++)
array[i] = new SupportedDensity
{
BitsPerMm = dsh.Value.descriptors[i].bpmm,
Capacity = dsh.Value.descriptors[i].capacity,
DefaultDensity = dsh.Value.descriptors[i].defaultDensity,
Description = dsh.Value.descriptors[i].description,
2020-07-20 04:34:16 +01:00
Duplicate = dsh.Value.descriptors[i].duplicate,
Name = dsh.Value.descriptors[i].name,
Organization = dsh.Value.descriptors[i].organization,
PrimaryCode = dsh.Value.descriptors[i].primaryCode,
SecondaryCode = dsh.Value.descriptors[i].secondaryCode,
2020-07-20 04:34:16 +01:00
Tracks = dsh.Value.descriptors[i].tracks,
Width = dsh.Value.descriptors[i].width,
Writable = dsh.Value.descriptors[i].writable
};
report.SupportedDensities = array.ToList();
}
}
2020-02-27 23:48:41 +00:00
AaruConsole.WriteLine("Querying SCSI REPORT DENSITY SUPPORT for medium types...");
sense = _dev.ReportDensitySupport(out buffer, out byte[] _, true, false, _dev.Timeout, out _);
2019-12-27 18:00:03 +00:00
if(sense)
return report;
DensitySupport.MediaTypeSupportHeader? mtsh = DensitySupport.DecodeMediumType(buffer);
2019-12-27 18:00:03 +00:00
if(!mtsh.HasValue)
return report;
SscSupportedMedia[] array2 = new SscSupportedMedia[mtsh.Value.descriptors.Length];
2019-12-27 18:00:03 +00:00
for(int i = 0; i < mtsh.Value.descriptors.Length; i++)
{
array2[i] = new SscSupportedMedia
{
2020-07-20 04:34:16 +01:00
Description = mtsh.Value.descriptors[i].description,
Length = mtsh.Value.descriptors[i].length,
MediumType = mtsh.Value.descriptors[i].mediumType,
Name = mtsh.Value.descriptors[i].name,
Organization = mtsh.Value.descriptors[i].organization,
Width = mtsh.Value.descriptors[i].width
};
2019-12-27 18:00:03 +00:00
if(mtsh.Value.descriptors[i].densityCodes == null)
continue;
DensityCode[] array3 = new DensityCode[mtsh.Value.descriptors[i].densityCodes.Length];
2019-12-27 18:00:03 +00:00
for(int j = 0; j < mtsh.Value.descriptors[i].densityCodes.Length; j++)
2019-12-27 18:00:03 +00:00
array3[j] = new DensityCode
{
Code = mtsh.Value.descriptors[i].densityCodes[j]
};
array2[i].DensityCodes = array3.Distinct().ToList();
}
report.SupportedMediaTypes = array2.ToList();
return report;
}
public TestedSequentialMedia ReportSscMedia()
{
2019-12-27 18:00:03 +00:00
var seqTest = new TestedSequentialMedia();
Modes.DecodedMode? decMode = null;
2020-02-27 23:48:41 +00:00
AaruConsole.WriteLine("Querying SCSI MODE SENSE (10)...");
2019-12-27 18:00:03 +00:00
bool sense = _dev.ModeSense10(out byte[] buffer, out byte[] _, false, true,
ScsiModeSensePageControl.Current, 0x3F, 0x00, _dev.Timeout, out _);
if(!sense &&
!_dev.Error)
{
2019-12-27 18:00:03 +00:00
decMode = Modes.DecodeMode10(buffer, _dev.ScsiType);
seqTest.ModeSense10Data = buffer;
}
2020-02-27 23:48:41 +00:00
AaruConsole.WriteLine("Querying SCSI MODE SENSE...");
sense = _dev.ModeSense(out buffer, out byte[] _, _dev.Timeout, out _);
2019-12-27 18:00:03 +00:00
if(!sense &&
!_dev.Error)
{
2020-07-22 13:20:25 +01:00
decMode ??= Modes.DecodeMode6(buffer, _dev.ScsiType);
2019-12-27 18:00:03 +00:00
seqTest.ModeSense6Data = buffer;
}
if(decMode.HasValue)
{
seqTest.MediumType = (byte)decMode.Value.Header.MediumType;
2019-12-27 18:00:03 +00:00
if(decMode.Value.Header.BlockDescriptors != null &&
decMode.Value.Header.BlockDescriptors.Length > 0)
seqTest.Density = (byte)decMode.Value.Header.BlockDescriptors[0].Density;
}
2020-02-27 23:48:41 +00:00
AaruConsole.WriteLine("Querying SCSI REPORT DENSITY SUPPORT for current media...");
sense = _dev.ReportDensitySupport(out buffer, out byte[] _, false, true, _dev.Timeout, out _);
2019-12-27 18:00:03 +00:00
if(!sense)
{
DensitySupport.DensitySupportHeader? dsh = DensitySupport.DecodeDensity(buffer);
2019-12-27 18:00:03 +00:00
if(dsh.HasValue)
{
SupportedDensity[] array = new SupportedDensity[dsh.Value.descriptors.Length];
2019-12-27 18:00:03 +00:00
for(int i = 0; i < dsh.Value.descriptors.Length; i++)
array[i] = new SupportedDensity
{
BitsPerMm = dsh.Value.descriptors[i].bpmm,
Capacity = dsh.Value.descriptors[i].capacity,
DefaultDensity = dsh.Value.descriptors[i].defaultDensity,
Description = dsh.Value.descriptors[i].description,
2020-07-20 04:34:16 +01:00
Duplicate = dsh.Value.descriptors[i].duplicate,
Name = dsh.Value.descriptors[i].name,
Organization = dsh.Value.descriptors[i].organization,
PrimaryCode = dsh.Value.descriptors[i].primaryCode,
SecondaryCode = dsh.Value.descriptors[i].secondaryCode,
2020-07-20 04:34:16 +01:00
Tracks = dsh.Value.descriptors[i].tracks,
Width = dsh.Value.descriptors[i].width,
Writable = dsh.Value.descriptors[i].writable
};
seqTest.SupportedDensities = array.ToList();
}
}
2020-02-27 23:48:41 +00:00
AaruConsole.WriteLine("Querying SCSI REPORT DENSITY SUPPORT for medium types for current media...");
sense = _dev.ReportDensitySupport(out buffer, out byte[] _, true, true, _dev.Timeout, out _);
2019-12-27 18:00:03 +00:00
if(!sense)
{
DensitySupport.MediaTypeSupportHeader? mtsh = DensitySupport.DecodeMediumType(buffer);
2019-12-27 18:00:03 +00:00
if(mtsh.HasValue)
{
SscSupportedMedia[] array = new SscSupportedMedia[mtsh.Value.descriptors.Length];
2019-12-27 18:00:03 +00:00
for(int i = 0; i < mtsh.Value.descriptors.Length; i++)
{
array[i] = new SscSupportedMedia
{
Description = mtsh.Value.descriptors[i].description,
Length = mtsh.Value.descriptors[i].length,
2020-07-20 04:34:16 +01:00
MediumType = mtsh.Value.descriptors[i].mediumType,
Name = mtsh.Value.descriptors[i].name,
Organization = mtsh.Value.descriptors[i].organization,
Width = mtsh.Value.descriptors[i].width
};
2019-12-27 18:00:03 +00:00
if(mtsh.Value.descriptors[i].densityCodes == null)
continue;
DensityCode[] array2 = new DensityCode[mtsh.Value.descriptors[i].densityCodes.Length];
2019-12-27 18:00:03 +00:00
for(int j = 0; j < mtsh.Value.descriptors[i].densityCodes.Length; j++)
2019-12-27 18:00:03 +00:00
array2[j] = new DensityCode
{
Code = mtsh.Value.descriptors[i].densityCodes[j]
};
array[i].DensityCodes = array2.Distinct().ToList();
}
seqTest.SupportedMediaTypes = array.ToList();
}
}
2017-12-19 20:33:03 +00:00
2020-02-27 23:48:41 +00:00
AaruConsole.WriteLine("Trying SCSI READ MEDIA SERIAL NUMBER...");
seqTest.CanReadMediaSerial = !_dev.ReadMediaSerialNumber(out buffer, out byte[] _, _dev.Timeout, out _);
return seqTest;
}
}
2017-12-19 20:33:03 +00:00
}