Refactor IMediaImage.ReadSector(s)Long to return error status instead of buffer.

This commit is contained in:
2021-09-20 14:22:22 +01:00
parent 88aeda7240
commit a6690aa121
77 changed files with 1048 additions and 555 deletions

View File

@@ -1352,21 +1352,28 @@ namespace Aaru.DiscImages
}
/// <inheritdoc />
public byte[] ReadSectorLong(ulong sectorAddress) => ReadSectorsLong(sectorAddress, 1);
public ErrorNumber ReadSectorLong(ulong sectorAddress, out byte[] buffer) =>
ReadSectorsLong(sectorAddress, 1, out buffer);
/// <inheritdoc />
public byte[] ReadSectorLong(ulong sectorAddress, uint track) => ReadSectorsLong(sectorAddress, 1, track);
/// <inheritdoc />
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
public ErrorNumber ReadSectorsLong(ulong sectorAddress, uint length, out byte[] buffer)
{
buffer = null;
foreach(KeyValuePair<uint, ulong> kvp in from kvp in _offsetMap where sectorAddress >= kvp.Value
from track in Tracks where track.Sequence == kvp.Key
where sectorAddress - kvp.Value <
track.EndSector - track.StartSector + 1 select kvp)
return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
{
buffer = ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key);
throw new ArgumentOutOfRangeException(nameof(sectorAddress), $"Sector address {sectorAddress} not found");
return buffer is null ? ErrorNumber.NoData : ErrorNumber.NoError;
}
return ErrorNumber.SectorNotFound;
}
/// <inheritdoc />

View File

@@ -33,6 +33,7 @@
using System;
using System.Collections.Generic;
using Aaru.Checksums;
using Aaru.CommonTypes.Enums;
namespace Aaru.DiscImages
{
@@ -41,20 +42,24 @@ namespace Aaru.DiscImages
/// <inheritdoc />
public bool? VerifySector(ulong sectorAddress)
{
byte[] buffer = ReadSectorLong(sectorAddress);
ErrorNumber errno = ReadSectorLong(sectorAddress, out byte[] buffer);
return 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)
{
byte[] buffer = ReadSectorsLong(sectorAddress, length);
int bps = (int)(buffer.Length / length);
byte[] sector = new byte[bps];
failingLbas = new List<ulong>();
unknownLbas = new List<ulong>();
ErrorNumber errno = ReadSectorsLong(sectorAddress, length, out byte[] buffer);
if(errno != ErrorNumber.NoError)
return null;
int bps = (int)(buffer.Length / length);
byte[] sector = new byte[bps];
for(int i = 0; i < length; i++)
{