Files
Aaru/Aaru.Images/Alcohol120/Verify.cs

125 lines
4.0 KiB
C#
Raw Normal View History

// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : Verify.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Disk image plugins.
//
// --[ Description ] ----------------------------------------------------------
//
// Verifies Alcohol 120% format disc images.
//
// --[ License ] --------------------------------------------------------------
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
2024-05-01 04:17:32 +01:00
// Copyright © 2011-2024 Natalia Portillo
// ****************************************************************************/
using System;
using System.Collections.Generic;
2020-02-27 00:33:26 +00:00
using Aaru.Checksums;
using Aaru.CommonTypes.Enums;
namespace Aaru.Images;
2022-03-06 13:29:38 +00:00
public sealed partial class Alcohol120
{
2023-10-03 23:34:59 +01:00
#region IWritableOpticalImage Members
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool? VerifySector(ulong sectorAddress)
{
2022-03-06 13:29:38 +00:00
ErrorNumber errno = ReadSectorLong(sectorAddress, out byte[] buffer);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return errno != ErrorNumber.NoError ? null : CdChecksums.CheckCdSector(buffer);
}
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
2023-10-03 23:34:59 +01:00
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
2022-03-06 13:29:38 +00:00
out List<ulong> unknownLbas)
{
2024-05-01 04:39:38 +01:00
failingLbas = [];
unknownLbas = [];
2022-03-06 13:29:38 +00:00
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, out byte[] buffer);
2024-05-01 04:05:22 +01:00
if(errno != ErrorNumber.NoError) return null;
2023-10-03 23:34:59 +01:00
var bps = (int)(buffer.Length / length);
var sector = new byte[bps];
2023-10-03 23:34:59 +01:00
for(var i = 0; i < length; i++)
2022-03-06 13:29:38 +00:00
{
Array.Copy(buffer, i * bps, sector, 0, bps);
bool? sectorStatus = CdChecksums.CheckCdSector(sector);
2022-03-06 13:29:38 +00:00
switch(sectorStatus)
{
case null:
unknownLbas.Add((ulong)i + sectorAddress);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
break;
case false:
failingLbas.Add((ulong)i + sectorAddress);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
break;
}
2022-03-06 13:29:38 +00:00
}
2024-05-01 04:05:22 +01:00
if(unknownLbas.Count > 0) return null;
2022-03-06 13:29:38 +00:00
return failingLbas.Count <= 0;
}
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
2023-10-03 23:34:59 +01:00
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
2022-03-06 13:29:38 +00:00
out List<ulong> unknownLbas)
{
2024-05-01 04:39:38 +01:00
failingLbas = [];
unknownLbas = [];
2022-03-06 13:29:38 +00:00
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, track, out byte[] buffer);
2024-05-01 04:05:22 +01:00
if(errno != ErrorNumber.NoError) return null;
2023-10-03 23:34:59 +01:00
var bps = (int)(buffer.Length / length);
var sector = new byte[bps];
2023-10-03 23:34:59 +01:00
for(var i = 0; i < length; i++)
2022-03-06 13:29:38 +00:00
{
Array.Copy(buffer, i * bps, sector, 0, bps);
bool? sectorStatus = CdChecksums.CheckCdSector(sector);
2022-03-06 13:29:38 +00:00
switch(sectorStatus)
{
case null:
unknownLbas.Add((ulong)i + sectorAddress);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
break;
case false:
failingLbas.Add((ulong)i + sectorAddress);
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
break;
}
2022-03-06 13:29:38 +00:00
}
2024-05-01 04:05:22 +01:00
if(unknownLbas.Count > 0) return null;
2022-03-06 13:29:38 +00:00
return failingLbas.Count <= 0;
}
2023-10-03 23:34:59 +01:00
#endregion
}