Files
Aaru/Aaru.Core/Devices/Dumping/Sbc/Trim.cs

95 lines
3.4 KiB
C#
Raw Normal View History

// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : Trim.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
2022-02-18 10:02:53 +00:00
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
2022-03-07 07:36:44 +00:00
// ReSharper disable JoinDeclarationAndInitializer
// ReSharper disable InlineOutVariableDeclaration
// ReSharper disable TooWideLocalVariableScope
2022-03-06 13:29:38 +00:00
namespace Aaru.Core.Devices.Dumping;
2022-03-07 07:36:44 +00:00
using Aaru.CommonTypes.Extents;
using Aaru.CommonTypes.Interfaces;
using Schemas;
2022-03-06 13:29:38 +00:00
partial class Dump
{
2022-03-06 13:29:38 +00:00
/// <summary>Trims data when dumping from a SCSI Block Commands compliant device</summary>
/// <param name="scsiReader">SCSI reader</param>
/// <param name="extents">Correctly dump extents</param>
/// <param name="currentTry">Resume information</param>
/// <param name="blankExtents">Blank extents</param>
2022-03-07 07:36:44 +00:00
void TrimSbcData(Reader scsiReader, ExtentsULong extents, DumpHardwareType currentTry, ExtentsULong blankExtents)
{
2022-03-06 13:29:38 +00:00
ulong[] tmpArray = _resume.BadBlocks.ToArray();
bool sense;
bool recoveredError;
bool blankCheck;
byte[] buffer;
2022-03-07 07:36:44 +00:00
var newBlank = false;
2022-03-06 13:29:38 +00:00
var outputFormat = _outputPlugin as IWritableImage;
2022-03-06 13:29:38 +00:00
foreach(ulong badSector in tmpArray)
{
if(_aborted)
{
2022-03-06 13:29:38 +00:00
currentTry.Extents = ExtentsConverter.ToMetadata(extents);
UpdateStatus?.Invoke("Aborted!");
_dumpLog.WriteLine("Aborted!");
2022-03-06 13:29:38 +00:00
break;
}
2022-03-06 13:29:38 +00:00
PulseProgress?.Invoke($"Trimming sector {badSector}");
2022-03-06 13:29:38 +00:00
sense = scsiReader.ReadBlock(out buffer, badSector, out double _, out recoveredError, out blankCheck);
2022-03-06 13:29:38 +00:00
if(blankCheck)
{
blankExtents.Add(badSector, badSector);
newBlank = true;
_resume.BadBlocks.Remove(badSector);
2022-03-06 13:29:38 +00:00
UpdateStatus?.Invoke($"Found blank block {badSector}.");
_dumpLog.WriteLine("Found blank block {0}.", badSector);
2022-03-06 13:29:38 +00:00
continue;
}
2022-03-06 13:29:38 +00:00
if((sense || _dev.Error) &&
!recoveredError)
continue;
_resume.BadBlocks.Remove(badSector);
extents.Add(badSector);
outputFormat.WriteSector(buffer, badSector);
}
2022-03-06 13:29:38 +00:00
if(newBlank)
_resume.BlankExtents = ExtentsConverter.ToMetadata(blankExtents);
}
}