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

This commit is contained in:
2021-09-19 21:16:47 +01:00
parent fbccfb2ca9
commit f51d414abd
187 changed files with 4036 additions and 2081 deletions

View File

@@ -1433,7 +1433,8 @@ namespace Aaru.DiscImages
}
/// <inheritdoc />
public byte[] ReadSector(ulong sectorAddress) => ReadSectors(sectorAddress, 1);
public ErrorNumber ReadSector(ulong sectorAddress, out byte[] buffer) =>
ReadSectors(sectorAddress, 1, out buffer);
/// <inheritdoc />
public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag) => ReadSectorsTag(sectorAddress, 1, tag);
@@ -1446,15 +1447,21 @@ namespace Aaru.DiscImages
ReadSectorsTag(sectorAddress, 1, track, tag);
/// <inheritdoc />
public byte[] ReadSectors(ulong sectorAddress, uint length)
public ErrorNumber ReadSectors(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 ReadSectors(sectorAddress - kvp.Value, length, kvp.Key);
{
buffer = ReadSectors(sectorAddress - kvp.Value, length, kvp.Key);
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
return ErrorNumber.NoError;
}
return ErrorNumber.SectorNotFound;
}
/// <inheritdoc />