[AaruFormat] Implemented VerifySectors.

This commit is contained in:
2025-10-12 14:22:04 +01:00
parent 5066164a3f
commit fa5c39746d
2 changed files with 48 additions and 4 deletions

View File

@@ -24,10 +24,6 @@ public sealed partial class AaruFormat
/// <inheritdoc /> /// <inheritdoc />
public bool SetImageInfo(ImageInfo imageInfo) => throw new NotImplementedException(); public bool SetImageInfo(ImageInfo imageInfo) => throw new NotImplementedException();
/// <inheritdoc />
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
out List<ulong> unknownLbas) => throw new NotImplementedException();
/// <inheritdoc /> /// <inheritdoc />
public ErrorNumber ReadSectorTag(ulong sectorAddress, uint track, SectorTagType tag, out byte[] buffer) => public ErrorNumber ReadSectorTag(ulong sectorAddress, uint track, SectorTagType tag, out byte[] buffer) =>
throw new NotImplementedException(); throw new NotImplementedException();

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Aaru.Checksums; using Aaru.Checksums;
@@ -34,6 +35,53 @@ public sealed partial class AaruFormat
return errno != ErrorNumber.NoError ? null : CdChecksums.CheckCdSector(buffer); return errno != ErrorNumber.NoError ? null : CdChecksums.CheckCdSector(buffer);
} }
/// <inheritdoc />
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
out List<ulong> unknownLbas)
{
failingLbas = [];
unknownLbas = [];
// Right now only CompactDisc sectors are verifiable
if(_imageInfo.MetadataMediaType != MetadataMediaType.OpticalDisc)
{
for(ulong i = sectorAddress; i < sectorAddress + length; i++) unknownLbas.Add(i);
return null;
}
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, out byte[] buffer);
if(errno != ErrorNumber.NoError) return null;
var bps = (int)(buffer.Length / length);
var sector = new byte[bps];
failingLbas = [];
unknownLbas = [];
for(var i = 0; i < length; i++)
{
Array.Copy(buffer, i * bps, sector, 0, bps);
bool? sectorStatus = CdChecksums.CheckCdSector(sector);
switch(sectorStatus)
{
case null:
unknownLbas.Add((ulong)i + sectorAddress);
break;
case false:
failingLbas.Add((ulong)i + sectorAddress);
break;
}
}
if(unknownLbas.Count > 0) return null;
return failingLbas.Count <= 0;
}
#endregion #endregion
// AARU_EXPORT int32_t AARU_CALL aaruf_verify_image(void *context) // AARU_EXPORT int32_t AARU_CALL aaruf_verify_image(void *context)