]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fundamental: Add EFI_GUID userspace definition 34717/head
authoranonymix007 <48598263+anonymix007@users.noreply.github.com>
Thu, 10 Oct 2024 15:35:30 +0000 (18:35 +0300)
committeranonymix007 <48598263+anonymix007@users.noreply.github.com>
Fri, 11 Oct 2024 12:23:54 +0000 (15:23 +0300)
src/fundamental/efi-fundamental.h [new file with mode: 0644]
src/shared/efi-api.c

diff --git a/src/fundamental/efi-fundamental.h b/src/fundamental/efi-fundamental.h
new file mode 100644 (file)
index 0000000..2862932
--- /dev/null
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#if !SD_BOOT
+#  include <stdint.h>
+/* Matches EFI API definition of the same structure for userspace */
+typedef struct {
+        uint32_t Data1;
+        uint16_t Data2;
+        uint16_t Data3;
+        uint8_t Data4[8];
+} EFI_GUID;
+#endif
index 3ca33efafb796877c65453b53bb5e3bac858c1a1..3b9954be9b4997d212bedeef7f2d78d012708a7f 100644 (file)
@@ -5,6 +5,7 @@
 #include "alloc-util.h"
 #include "dirent-util.h"
 #include "efi-api.h"
+#include "efi-fundamental.h"
 #include "efivars.h"
 #include "fd-util.h"
 #include "fileio.h"
@@ -523,29 +524,22 @@ bool efi_has_tpm2(void) {
 
 #endif
 
-struct efi_guid {
-        uint32_t u1;
-        uint16_t u2;
-        uint16_t u3;
-        uint8_t u4[8];
-} _packed_;
-
 sd_id128_t efi_guid_to_id128(const void *guid) {
-        const struct efi_guid *uuid = ASSERT_PTR(guid); /* cast is safe, because struct efi_guid is packed */
+        const EFI_GUID *uuid = ASSERT_PTR(guid); /* cast is safe, because struct efi_guid is packed */
         sd_id128_t id128;
 
-        id128.bytes[0] = (uuid->u1 >> 24) & 0xff;
-        id128.bytes[1] = (uuid->u1 >> 16) & 0xff;
-        id128.bytes[2] = (uuid->u1 >> 8) & 0xff;
-        id128.bytes[3] = uuid->u1 & 0xff;
+        id128.bytes[0] = (uuid->Data1 >> 24) & 0xff;
+        id128.bytes[1] = (uuid->Data1 >> 16) & 0xff;
+        id128.bytes[2] = (uuid->Data1 >> 8) & 0xff;
+        id128.bytes[3] = uuid->Data1 & 0xff;
 
-        id128.bytes[4] = (uuid->u2 >> 8) & 0xff;
-        id128.bytes[5] = uuid->u2 & 0xff;
+        id128.bytes[4] = (uuid->Data2 >> 8) & 0xff;
+        id128.bytes[5] = uuid->Data2 & 0xff;
 
-        id128.bytes[6] = (uuid->u3 >> 8) & 0xff;
-        id128.bytes[7] = uuid->u3 & 0xff;
+        id128.bytes[6] = (uuid->Data3 >> 8) & 0xff;
+        id128.bytes[7] = uuid->Data3 & 0xff;
 
-        memcpy(&id128.bytes[8], uuid->u4, sizeof(uuid->u4));
+        memcpy(&id128.bytes[8], uuid->Data4, sizeof(uuid->Data4));
 
         return id128;
 }
@@ -553,11 +547,11 @@ sd_id128_t efi_guid_to_id128(const void *guid) {
 void efi_id128_to_guid(sd_id128_t id, void *ret_guid) {
         assert(ret_guid);
 
-        struct efi_guid uuid = {
-                .u1 = id.bytes[0] << 24 | id.bytes[1] << 16 | id.bytes[2] << 8 | id.bytes[3],
-                .u2 = id.bytes[4] << 8 | id.bytes[5],
-                .u3 = id.bytes[6] << 8 | id.bytes[7],
+        EFI_GUID uuid = {
+                .Data1 = id.bytes[0] << 24 | id.bytes[1] << 16 | id.bytes[2] << 8 | id.bytes[3],
+                .Data2 = id.bytes[4] << 8 | id.bytes[5],
+                .Data3 = id.bytes[6] << 8 | id.bytes[7],
         };
-        memcpy(uuid.u4, id.bytes+8, sizeof(uuid.u4));
+        memcpy(uuid.Data4, id.bytes+8, sizeof(uuid.Data4));
         memcpy(ret_guid, &uuid, sizeof(uuid));
 }