boot: Move disk_get_part_uuid into part-discovery.c
authorJan Janssen <medhefgo@web.de>
Sat, 7 Jan 2023 10:21:56 +0000 (11:21 +0100)
committerJan Janssen <medhefgo@web.de>
Wed, 22 Feb 2023 20:54:11 +0000 (21:54 +0100)
Thematically, they are similar and disk.c is awfully small to warrant
the separation.

src/boot/efi/boot.c
src/boot/efi/disk.c [deleted file]
src/boot/efi/disk.h [deleted file]
src/boot/efi/meson.build
src/boot/efi/part-discovery.c
src/boot/efi/part-discovery.h
src/boot/efi/stub.c

index ea19dd82d2c79e038a0308645ed839fd7d9f7df1..3bd3469f821a6c415c071df5b70c7dab0a6c4918 100644 (file)
@@ -4,7 +4,6 @@
 #include "bootspec-fundamental.h"
 #include "console.h"
 #include "devicetree.h"
-#include "disk.h"
 #include "drivers.h"
 #include "efivars-fundamental.h"
 #include "graphics.h"
@@ -2542,7 +2541,6 @@ static void export_variables(
                 0;
 
         _cleanup_free_ char16_t *infostr = NULL, *typestr = NULL;
-        char16_t uuid[37];
 
         assert(loaded_image);
 
@@ -2561,7 +2559,8 @@ static void export_variables(
         efivar_set(MAKE_GUID_PTR(LOADER), u"LoaderImageIdentifier", loaded_image_path, 0);
 
         /* export the device path this image is started from */
-        if (disk_get_part_uuid(loaded_image->DeviceHandle, uuid) == EFI_SUCCESS)
+        _cleanup_free_ char16_t *uuid = disk_get_part_uuid(loaded_image->DeviceHandle);
+        if (uuid)
                 efivar_set(MAKE_GUID_PTR(LOADER), u"LoaderDevicePartUUID", uuid, 0);
 }
 
diff --git a/src/boot/efi/disk.c b/src/boot/efi/disk.c
deleted file mode 100644 (file)
index 44be323..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-
-#include "disk.h"
-#include "proto/device-path.h"
-#include "util.h"
-
-EFI_STATUS disk_get_part_uuid(EFI_HANDLE *handle, char16_t uuid[static 37]) {
-        EFI_STATUS err;
-        EFI_DEVICE_PATH *dp;
-
-        /* export the device path this image is started from */
-
-        if (!handle)
-                return EFI_NOT_FOUND;
-
-        err = BS->HandleProtocol(handle, MAKE_GUID_PTR(EFI_DEVICE_PATH_PROTOCOL), (void **) &dp);
-        if (err != EFI_SUCCESS)
-                return err;
-
-        for (; !IsDevicePathEnd(dp); dp = NextDevicePathNode(dp)) {
-                if (DevicePathType(dp) != MEDIA_DEVICE_PATH)
-                        continue;
-                if (DevicePathSubType(dp) != MEDIA_HARDDRIVE_DP)
-                        continue;
-
-                /* The HD device path may be misaligned. */
-                HARDDRIVE_DEVICE_PATH hd;
-                memcpy(&hd, dp, MIN(sizeof(hd), (size_t) DevicePathNodeLength(dp)));
-
-                if (hd.SignatureType != SIGNATURE_TYPE_GUID)
-                        continue;
-
-                _cleanup_free_ char16_t *tmp = xasprintf(
-                                "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
-                                hd.Signature[3],
-                                hd.Signature[2],
-                                hd.Signature[1],
-                                hd.Signature[0],
-
-                                hd.Signature[5],
-                                hd.Signature[4],
-                                hd.Signature[7],
-                                hd.Signature[6],
-
-                                hd.Signature[8],
-                                hd.Signature[9],
-                                hd.Signature[10],
-                                hd.Signature[11],
-                                hd.Signature[12],
-                                hd.Signature[13],
-                                hd.Signature[14],
-                                hd.Signature[15]);
-                strcpy16(uuid, tmp);
-                return EFI_SUCCESS;
-        }
-
-        return EFI_NOT_FOUND;
-}
diff --git a/src/boot/efi/disk.h b/src/boot/efi/disk.h
deleted file mode 100644 (file)
index 2da5bca..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-#pragma once
-
-#include "efi.h"
-
-EFI_STATUS disk_get_part_uuid(EFI_HANDLE *handle, char16_t uuid[static 37]);
index 8d85dac84448bfeccaa2ef247f6703aa23db33f9..e6166075be1c0eef2f8a956fb2faa3a5108f75b4 100644 (file)
@@ -333,7 +333,6 @@ efi_headers = files(
         'console.h',
         'cpio.h',
         'devicetree.h',
-        'disk.h',
         'drivers.h',
         'efi-string.h',
         'efi.h',
@@ -369,7 +368,6 @@ common_sources = files(
         'console.c',
         'devicetree.c',
         'drivers.c',
-        'disk.c',
         'efi-string.c',
         'graphics.c',
         'initrd.c',
index e25905ff48284a367ca118b6324b91e5163f439f..5d3999550990e8e8be77a33549e4e5f6b3b16c88 100644 (file)
@@ -295,3 +295,54 @@ EFI_STATUS partition_open(const EFI_GUID *type, EFI_HANDLE *device, EFI_HANDLE *
         *ret_root_dir = root_dir;
         return EFI_SUCCESS;
 }
+
+char16_t *disk_get_part_uuid(EFI_HANDLE *handle) {
+        EFI_STATUS err;
+        EFI_DEVICE_PATH *dp;
+
+        /* export the device path this image is started from */
+
+        if (!handle)
+                return NULL;
+
+        err = BS->HandleProtocol(handle, MAKE_GUID_PTR(EFI_DEVICE_PATH_PROTOCOL), (void **) &dp);
+        if (err != EFI_SUCCESS)
+                return NULL;
+
+        for (; !IsDevicePathEnd(dp); dp = NextDevicePathNode(dp)) {
+                if (DevicePathType(dp) != MEDIA_DEVICE_PATH)
+                        continue;
+                if (DevicePathSubType(dp) != MEDIA_HARDDRIVE_DP)
+                        continue;
+
+                /* The HD device path may be misaligned. */
+                HARDDRIVE_DEVICE_PATH hd;
+                memcpy(&hd, dp, MIN(sizeof(hd), (size_t) DevicePathNodeLength(dp)));
+
+                if (hd.SignatureType != SIGNATURE_TYPE_GUID)
+                        continue;
+
+                return xasprintf(
+                                "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+                                hd.Signature[3],
+                                hd.Signature[2],
+                                hd.Signature[1],
+                                hd.Signature[0],
+
+                                hd.Signature[5],
+                                hd.Signature[4],
+                                hd.Signature[7],
+                                hd.Signature[6],
+
+                                hd.Signature[8],
+                                hd.Signature[9],
+                                hd.Signature[10],
+                                hd.Signature[11],
+                                hd.Signature[12],
+                                hd.Signature[13],
+                                hd.Signature[14],
+                                hd.Signature[15]);
+        }
+
+        return NULL;
+}
index 597ded3b3ea30d60b346b92949df972feadab147..bbc87ffe36ed020d9415f2cd26d6fd4240512cc4 100644 (file)
@@ -9,3 +9,4 @@
         { 0xc12a7328, 0xf81f, 0x11d2, { 0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b } }
 
 EFI_STATUS partition_open(const EFI_GUID *type, EFI_HANDLE *device, EFI_HANDLE *ret_device, EFI_FILE **ret_root_dir);
+char16_t *disk_get_part_uuid(EFI_HANDLE *handle);
index d85424ceaeb244620f2d69721b6b8bb0aa25a337..4b8e1e69d90b6cd51d8487a83b2724e9c2ee73e4 100644 (file)
@@ -2,7 +2,6 @@
 
 #include "cpio.h"
 #include "devicetree.h"
-#include "disk.h"
 #include "graphics.h"
 #include "linux.h"
 #include "measure.h"
@@ -87,14 +86,14 @@ static void export_variables(EFI_LOADED_IMAGE_PROTOCOL *loaded_image) {
                 EFI_STUB_FEATURE_RANDOM_SEED |              /* We pass a random seed to the kernel */
                 0;
 
-        char16_t uuid[37];
-
         assert(loaded_image);
 
         /* Export the device path this image is started from, if it's not set yet */
-        if (efivar_get_raw(MAKE_GUID_PTR(LOADER), u"LoaderDevicePartUUID", NULL, NULL) != EFI_SUCCESS)
-                if (disk_get_part_uuid(loaded_image->DeviceHandle, uuid) == EFI_SUCCESS)
+        if (efivar_get_raw(MAKE_GUID_PTR(LOADER), u"LoaderDevicePartUUID", NULL, NULL) != EFI_SUCCESS) {
+                _cleanup_free_ char16_t *uuid = disk_get_part_uuid(loaded_image->DeviceHandle);
+                if (uuid)
                         efivar_set(MAKE_GUID_PTR(LOADER), u"LoaderDevicePartUUID", uuid, 0);
+        }
 
         /* If LoaderImageIdentifier is not set, assume the image with this stub was loaded directly from the
          * UEFI firmware without any boot loader, and hence set the LoaderImageIdentifier ourselves. Note