mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[AaruFormat] Implement TapePartitions.get.
This commit is contained in:
@@ -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
|
||||
|
||||
// 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);
|
||||
}
|
||||
@@ -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<string, string> options, ulong sectors,
|
||||
uint sectorSize) => throw new NotImplementedException();
|
||||
|
||||
#endregion
|
||||
|
||||
#region IWritableTapeImage Members
|
||||
|
||||
/// <inheritdoc />
|
||||
public List<TapePartition> TapePartitions { get; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user