From a503c517d99084c7448e0024b6fe00e8098cd5d6 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 12 Oct 2025 11:38:21 +0100 Subject: [PATCH] [AaruFormat] Implement WriteSector. --- Aaru.Images/AaruFormat/Unimplemented.cs | 2 -- Aaru.Images/AaruFormat/Write.cs | 32 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 Aaru.Images/AaruFormat/Write.cs diff --git a/Aaru.Images/AaruFormat/Unimplemented.cs b/Aaru.Images/AaruFormat/Unimplemented.cs index 61033fe25..e930c9c01 100644 --- a/Aaru.Images/AaruFormat/Unimplemented.cs +++ b/Aaru.Images/AaruFormat/Unimplemented.cs @@ -36,8 +36,6 @@ public sealed partial class AaruFormat /// public bool WriteMediaTag(byte[] data, MediaTagType tag) => throw new NotImplementedException(); - /// - public bool WriteSector(byte[] data, ulong sectorAddress) => throw new NotImplementedException(); /// public bool WriteSectorLong(byte[] data, ulong sectorAddress) => throw new NotImplementedException(); diff --git a/Aaru.Images/AaruFormat/Write.cs b/Aaru.Images/AaruFormat/Write.cs new file mode 100644 index 000000000..025c1e770 --- /dev/null +++ b/Aaru.Images/AaruFormat/Write.cs @@ -0,0 +1,32 @@ +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace Aaru.Images; + +public sealed partial class AaruFormat +{ +#region IWritableOpticalImage Members + + /// + public bool WriteSector(byte[] data, ulong sectorAddress) + { + Status res = aaruf_write_sector(_context, sectorAddress, false, data, SectorStatus.Dumped, (uint)data.Length); + + if(res == Status.Ok) return true; + + ErrorMessage = StatusToErrorMessage(res); + + return false; + } + +#endregion + + // AARU_EXPORT int32_t AARU_CALL aaruf_write_sector(void *context, uint64_t sector_address, bool negative, + // const uint8_t *data, uint8_t sector_status, uint32_t length) + [LibraryImport("libaaruformat", EntryPoint = "aaruf_write_sector", SetLastError = true)] + [UnmanagedCallConv(CallConvs = [typeof(CallConvStdcall)])] + private static partial Status aaruf_write_sector(IntPtr context, ulong sectorAddress, + [MarshalAs(UnmanagedType.I4)] bool negative, [In] byte[] data, + SectorStatus sectorStatus, uint length); +} \ No newline at end of file