diff --git a/Aaru.Images/AaruFormat/Tape.cs b/Aaru.Images/AaruFormat/Tape.cs index 95cc8e4bd..04a8616f4 100644 --- a/Aaru.Images/AaruFormat/Tape.cs +++ b/Aaru.Images/AaruFormat/Tape.cs @@ -118,6 +118,68 @@ public sealed partial class AaruFormat } } + /// + public List 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(); + int count = (int)length / structSize; + + List partitions = new(count); + + for(var i = 0; i < count; i++) + { + var structPtr = IntPtr.Add(buffer, i * structSize); + TapePartitionEntry entry = Marshal.PtrToStructure(structPtr); + + partitions.Add(new TapePartition + { + Number = entry.Number, + FirstBlock = entry.FirstBlock, + LastBlock = entry.LastBlock + }); + } + + return partitions; + } + finally + { + Marshal.FreeHGlobal(buffer); + } + } + } + #endregion // 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)] [UnmanagedCallConv(CallConvs = [typeof(CallConvStdcall)])] 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); } \ No newline at end of file diff --git a/Aaru.Images/AaruFormat/Unimplemented.cs b/Aaru.Images/AaruFormat/Unimplemented.cs index ffcf2e9f5..3c49cc72d 100644 --- a/Aaru.Images/AaruFormat/Unimplemented.cs +++ b/Aaru.Images/AaruFormat/Unimplemented.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using Aaru.CommonTypes; -using TapePartition = Aaru.CommonTypes.Structs.TapePartition; namespace Aaru.Images; @@ -13,12 +12,5 @@ public sealed partial class AaruFormat public bool Create(string path, MediaType mediaType, Dictionary options, ulong sectors, uint sectorSize) => throw new NotImplementedException(); -#endregion - -#region IWritableTapeImage Members - - /// - public List TapePartitions { get; } - #endregion } \ No newline at end of file