[AaruFormat] Implement TapePartitions.get.

This commit is contained in:
2025-10-14 00:05:04 +01:00
parent af036c11a9
commit 5b153cfb89
2 changed files with 67 additions and 8 deletions

View File

@@ -118,6 +118,68 @@ public sealed partial class AaruFormat
} }
} }
/// <inheritdoc />
public List<TapePartition> TapePartitions
{
get
{
if(!IsTape)
{
ErrorMessage = "Image is not a tape";
return null;
}
nuint length = 0;
Status res = aaruf_get_all_tape_partitions(_context, IntPtr.Zero, ref length);
if(res != Status.Ok && res != Status.BufferTooSmall)
{
ErrorMessage = StatusToErrorMessage(res);
return null;
}
IntPtr buffer = Marshal.AllocHGlobal((int)length);
try
{
res = aaruf_get_all_tape_partitions(_context, buffer, ref length);
if(res != Status.Ok)
{
ErrorMessage = StatusToErrorMessage(res);
return null;
}
int structSize = Marshal.SizeOf<TapePartitionEntry>();
int count = (int)length / structSize;
List<TapePartition> partitions = new(count);
for(var i = 0; i < count; i++)
{
var structPtr = IntPtr.Add(buffer, i * structSize);
TapePartitionEntry entry = Marshal.PtrToStructure<TapePartitionEntry>(structPtr);
partitions.Add(new TapePartition
{
Number = entry.Number,
FirstBlock = entry.FirstBlock,
LastBlock = entry.LastBlock
});
}
return partitions;
}
finally
{
Marshal.FreeHGlobal(buffer);
}
}
}
#endregion #endregion
// AARU_EXPORT int32_t AARU_CALL aaruf_set_tape_file(void *context, const uint8_t partition, const uint32_t file, // AARU_EXPORT int32_t AARU_CALL aaruf_set_tape_file(void *context, const uint8_t partition, const uint32_t file,
@@ -138,4 +200,9 @@ public sealed partial class AaruFormat
[LibraryImport("libaaruformat", EntryPoint = "aaruf_get_all_tape_files", SetLastError = true)] [LibraryImport("libaaruformat", EntryPoint = "aaruf_get_all_tape_files", SetLastError = true)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvStdcall)])] [UnmanagedCallConv(CallConvs = [typeof(CallConvStdcall)])]
private static partial Status aaruf_get_all_tape_files(IntPtr context, IntPtr buffer, ref nuint length); private static partial Status aaruf_get_all_tape_files(IntPtr context, IntPtr buffer, ref nuint length);
// AARU_EXPORT int32_t AARU_CALL aaruf_get_all_tape_partitions(const void *context, uint8_t *buffer, size_t *length)
[LibraryImport("libaaruformat", EntryPoint = "aaruf_get_all_tape_partitions", SetLastError = true)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvStdcall)])]
private static partial Status aaruf_get_all_tape_partitions(IntPtr context, IntPtr buffer, ref nuint length);
} }

View File

@@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Aaru.CommonTypes; using Aaru.CommonTypes;
using TapePartition = Aaru.CommonTypes.Structs.TapePartition;
namespace Aaru.Images; namespace Aaru.Images;
@@ -13,12 +12,5 @@ public sealed partial class AaruFormat
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors, public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
uint sectorSize) => throw new NotImplementedException(); uint sectorSize) => throw new NotImplementedException();
#endregion
#region IWritableTapeImage Members
/// <inheritdoc />
public List<TapePartition> TapePartitions { get; }
#endregion #endregion
} }