[AaruFormat] Handle when a sector has not been dumped imitating V1 behavior.

This commit is contained in:
2025-10-20 00:56:57 +01:00
parent d5fe51a01e
commit 5ca75cbc3d
2 changed files with 60 additions and 40 deletions

View File

@@ -109,6 +109,11 @@ public sealed partial class AaruFormat
/// </summary>
Ok = 0,
/// <summary>
/// Sector has not been dumped.
/// &lt;remarks&gt;AARUF_STATUS_SECTOR_NOT_DUMPED&lt;/remarks&gt;
/// </summary>
SectorNotDumped = 1,
/// <summary>
/// Input file/stream failed magic or structural validation.
/// &lt;remarks&gt;AARUF_ERROR_NOT_AARUFORMAT&lt;/remarks&gt;
/// </summary>

View File

@@ -10,6 +10,43 @@ namespace Aaru.Images;
public sealed partial class AaruFormat
{
// AARU_EXPORT int32_t AARU_CALL aaruf_read_media_tag(void *context, uint8_t *data, const int32_t tag, uint32_t *length)
[LibraryImport("libaaruformat", EntryPoint = "aaruf_read_media_tag", SetLastError = true)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvStdcall)])]
private static partial Status aaruf_read_media_tag(IntPtr context, byte[] data, MediaTagType tag, ref uint length);
// AARU_EXPORT int32_t AARU_CALL aaruf_read_sector(void *context, const uint64_t sector_address, bool negative,
// uint8_t *data, uint32_t *length, uint8_t *sector_status)
[LibraryImport("libaaruformat", EntryPoint = "aaruf_read_sector", SetLastError = true)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvStdcall)])]
private static partial Status aaruf_read_sector(IntPtr context, ulong sectorAddress,
[MarshalAs(UnmanagedType.I4)] bool negative, byte[] data,
ref uint length, out byte sectorStatus);
// AARU_EXPORT int32_t AARU_CALL aaruf_read_track_sector(void *context, uint8_t *data, const uint64_t sector_address,
// uint32_t *length, const uint8_t track, uint8_t *sector_status)
[LibraryImport("libaaruformat", EntryPoint = "aaruf_read_track_sector", SetLastError = true)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvStdcall)])]
private static partial Status aaruf_read_track_sector(IntPtr context, byte[] data, ulong sectorAddress,
ref uint length, byte track, out byte sectorStatus);
// AARU_EXPORT int32_t AARU_CALL aaruf_read_sector_long(void *context, const uint64_t sector_address, bool negative,
// uint8_t *data, uint32_t *length, uint8_t *sector_status)
[LibraryImport("libaaruformat", EntryPoint = "aaruf_read_sector_long", SetLastError = true)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvStdcall)])]
private static partial Status aaruf_read_sector_long(IntPtr context, ulong sectorAddress,
[MarshalAs(UnmanagedType.I4)] bool negative, byte[] data,
ref uint length, out byte sectorStatus);
// AARU_EXPORT int32_t AARU_CALL aaruf_read_sector_tag(const void *context, const uint64_t sector_address,
// const bool negative, uint8_t *buffer, uint32_t *length,
// const int32_t tag)
[LibraryImport("libaaruformat", EntryPoint = "aaruf_read_sector_tag", SetLastError = true)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvStdcall)])]
private static partial Status aaruf_read_sector_tag(IntPtr context, ulong sectorAddress,
[MarshalAs(UnmanagedType.I4)] bool negative, byte[] buffer,
ref uint length, SectorTagType tag);
#region IWritableOpticalImage Members
/// <inheritdoc />
@@ -45,7 +82,12 @@ public sealed partial class AaruFormat
res = aaruf_read_sector(_context, sectorAddress, false, buffer, ref length, out _);
return StatusToErrorNumber(res);
// Sector not dumped
if(res != Status.SectorNotDumped || length <= 0) return StatusToErrorNumber(res);
buffer = new byte[length];
return ErrorNumber.NoError;
}
/// <inheritdoc />
@@ -62,7 +104,12 @@ public sealed partial class AaruFormat
res = aaruf_read_track_sector(_context, buffer, sectorAddress, ref length, (byte)track, out _);
return StatusToErrorNumber(res);
// Sector not dumped
if(res != Status.SectorNotDumped || length <= 0) return StatusToErrorNumber(res);
buffer = new byte[length];
return ErrorNumber.NoError;
}
/// <inheritdoc />
@@ -79,7 +126,12 @@ public sealed partial class AaruFormat
res = aaruf_read_sector_long(_context, sectorAddress, false, buffer, ref length, out _);
return StatusToErrorNumber(res);
// Sector not dumped
if(res != Status.SectorNotDumped || length <= 0) return StatusToErrorNumber(res);
buffer = new byte[length];
return ErrorNumber.NoError;
}
/// <inheritdoc />
@@ -259,41 +311,4 @@ public sealed partial class AaruFormat
}
#endregion
// AARU_EXPORT int32_t AARU_CALL aaruf_read_media_tag(void *context, uint8_t *data, const int32_t tag, uint32_t *length)
[LibraryImport("libaaruformat", EntryPoint = "aaruf_read_media_tag", SetLastError = true)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvStdcall)])]
private static partial Status aaruf_read_media_tag(IntPtr context, byte[] data, MediaTagType tag, ref uint length);
// AARU_EXPORT int32_t AARU_CALL aaruf_read_sector(void *context, const uint64_t sector_address, bool negative,
// uint8_t *data, uint32_t *length, uint8_t *sector_status)
[LibraryImport("libaaruformat", EntryPoint = "aaruf_read_sector", SetLastError = true)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvStdcall)])]
private static partial Status aaruf_read_sector(IntPtr context, ulong sectorAddress,
[MarshalAs(UnmanagedType.I4)] bool negative, byte[] data,
ref uint length, out byte sectorStatus);
// AARU_EXPORT int32_t AARU_CALL aaruf_read_track_sector(void *context, uint8_t *data, const uint64_t sector_address,
// uint32_t *length, const uint8_t track, uint8_t *sector_status)
[LibraryImport("libaaruformat", EntryPoint = "aaruf_read_track_sector", SetLastError = true)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvStdcall)])]
private static partial Status aaruf_read_track_sector(IntPtr context, byte[] data, ulong sectorAddress,
ref uint length, byte track, out byte sectorStatus);
// AARU_EXPORT int32_t AARU_CALL aaruf_read_sector_long(void *context, const uint64_t sector_address, bool negative,
// uint8_t *data, uint32_t *length, uint8_t *sector_status)
[LibraryImport("libaaruformat", EntryPoint = "aaruf_read_sector_long", SetLastError = true)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvStdcall)])]
private static partial Status aaruf_read_sector_long(IntPtr context, ulong sectorAddress,
[MarshalAs(UnmanagedType.I4)] bool negative, byte[] data,
ref uint length, out byte sectorStatus);
// AARU_EXPORT int32_t AARU_CALL aaruf_read_sector_tag(const void *context, const uint64_t sector_address,
// const bool negative, uint8_t *buffer, uint32_t *length,
// const int32_t tag)
[LibraryImport("libaaruformat", EntryPoint = "aaruf_read_sector_tag", SetLastError = true)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvStdcall)])]
private static partial Status aaruf_read_sector_tag(IntPtr context, ulong sectorAddress,
[MarshalAs(UnmanagedType.I4)] bool negative, byte[] buffer,
ref uint length, SectorTagType tag);
}