mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Add support for negative sectors to read and write sector calls in images.
This commit is contained in:
@@ -489,11 +489,13 @@ public sealed partial class Vhdx
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ErrorNumber ReadSector(ulong sectorAddress, out byte[] buffer, out SectorStatus sectorStatus)
|
||||
public ErrorNumber ReadSector(ulong sectorAddress, bool negative, out byte[] buffer, out SectorStatus sectorStatus)
|
||||
{
|
||||
buffer = null;
|
||||
sectorStatus = SectorStatus.NotDumped;
|
||||
|
||||
if(negative) return ErrorNumber.NotSupported;
|
||||
|
||||
if(sectorAddress > _imageInfo.Sectors - 1) return ErrorNumber.OutOfRange;
|
||||
|
||||
if(_sectorCache.TryGetValue(sectorAddress, out buffer)) return ErrorNumber.NoError;
|
||||
@@ -516,7 +518,7 @@ public sealed partial class Vhdx
|
||||
switch(blkFlags & BAT_FLAGS_MASK)
|
||||
{
|
||||
case PAYLOAD_BLOCK_NOT_PRESENT:
|
||||
if(_hasParent) return _parentImage.ReadSector(sectorAddress, out buffer, out sectorStatus);
|
||||
if(_hasParent) return _parentImage.ReadSector(sectorAddress, false, out buffer, out sectorStatus);
|
||||
|
||||
buffer = new byte[_logicalSectorSize];
|
||||
|
||||
@@ -532,7 +534,7 @@ public sealed partial class Vhdx
|
||||
bool partialBlock = (blkFlags & BAT_FLAGS_MASK) == PAYLOAD_BLOCK_PARTIALLY_PRESENT;
|
||||
|
||||
if(partialBlock && _hasParent && !CheckBitmap(sectorAddress))
|
||||
return _parentImage.ReadSector(sectorAddress, out buffer, out sectorStatus);
|
||||
return _parentImage.ReadSector(sectorAddress, false, out buffer, out sectorStatus);
|
||||
|
||||
if(!_blockCache.TryGetValue(blkPtr & BAT_FILE_OFFSET_MASK, out byte[] block))
|
||||
{
|
||||
@@ -556,11 +558,14 @@ public sealed partial class Vhdx
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ErrorNumber ReadSectors(ulong sectorAddress, uint length, out byte[] buffer, out SectorStatus[] sectorStatus)
|
||||
public ErrorNumber ReadSectors(ulong sectorAddress, bool negative, uint length, out byte[] buffer,
|
||||
out SectorStatus[] sectorStatus)
|
||||
{
|
||||
buffer = null;
|
||||
sectorStatus = null;
|
||||
|
||||
if(negative) return ErrorNumber.NotSupported;
|
||||
|
||||
if(sectorAddress > _imageInfo.Sectors - 1) return ErrorNumber.OutOfRange;
|
||||
|
||||
if(sectorAddress + length > _imageInfo.Sectors) return ErrorNumber.OutOfRange;
|
||||
@@ -570,7 +575,7 @@ public sealed partial class Vhdx
|
||||
|
||||
for(uint i = 0; i < length; i++)
|
||||
{
|
||||
ErrorNumber errno = ReadSector(sectorAddress + i, out byte[] sector, out SectorStatus status);
|
||||
ErrorNumber errno = ReadSector(sectorAddress + i, false, out byte[] sector, out SectorStatus status);
|
||||
|
||||
if(errno != ErrorNumber.NoError) return errno;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user