From a824a4cea020ef49c180ed52599bf6aa66332ede Mon Sep 17 00:00:00 2001 From: dahall Date: Wed, 28 Oct 2020 19:28:36 -0600 Subject: [PATCH] Fixed layout of PARTITION_INFORMATION_GPT so it is blittable (#173) --- PInvoke/Kernel32/WinIOCtl.Structs.cs | 38 ++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/PInvoke/Kernel32/WinIOCtl.Structs.cs b/PInvoke/Kernel32/WinIOCtl.Structs.cs index 623877f2..a5b12147 100644 --- a/PInvoke/Kernel32/WinIOCtl.Structs.cs +++ b/PInvoke/Kernel32/WinIOCtl.Structs.cs @@ -2248,6 +2248,8 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct PARTITION_INFORMATION_GPT { + private const int nameBytes = 36 * 2; + /// /// A GUID that identifies the partition type. /// @@ -2366,9 +2368,41 @@ namespace Vanara.PInvoke /// public GPT_ATTRIBUTE Attributes; + // Little hack to get 72 blittable bytes for 'Name'. + private ulong ul1; + private ulong ul2; + private ulong ul3; + private ulong ul4; + private ulong ul5; + private ulong ul6; + private ulong ul7; + private ulong ul8; + private ulong ul9; + /// A wide-character string that describes the partition. - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 36)] - public string Name; + public string Name + { + get + { + unsafe + { + fixed (ulong* p = &ul1) + { + return Vanara.Extensions.StringHelper.GetString((IntPtr)(void*)p, CharSet.Unicode, nameBytes); + } + } + } + set + { + unsafe + { + fixed (ulong* p = &ul1) + { + Vanara.Extensions.StringHelper.Write(value, (IntPtr)(void*)p, out _, true, CharSet.Unicode, nameBytes); + } + } + } + } } /// Contains partition information specific to master boot record (MBR) disks.