From: Andreas Reichel <[email protected]>

Get the boot device out of the loaded image's handle and add a
function to compare every environment's device path with this boot
device.

Signed-off-by: Andreas Reichel <[email protected]>
---
 bootguard.c     |  1 +
 include/utils.h |  1 +
 main.c          |  6 ++++++
 utils.c         | 13 +++++++++++++
 4 files changed, 21 insertions(+)

diff --git a/bootguard.c b/bootguard.c
index 0aa95b4..9eea350 100644
--- a/bootguard.c
+++ b/bootguard.c
@@ -18,3 +18,4 @@ EFI_HANDLE this_image;
 
 VOLUME_DESC *volumes = NULL;
 UINTN volume_count = 128;
+CHAR16 *boot_device_path;
diff --git a/include/utils.h b/include/utils.h
index 06721eb..3c97bfa 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -29,6 +29,7 @@ typedef struct _VOLUME_DESC {
 
 typedef enum { DOSFSLABEL, CUSTOMLABEL, NOLABEL } LABELMODE;
 
+BOOLEAN IsOnBootDevice(EFI_DEVICE_PATH *dp);
 CHAR16 *StrRStrip(CHAR16 *input, CHAR16 delim);
 uint32_t calc_crc32(void *data, int32_t size);
 void __noreturn error_exit(CHAR16 *message, EFI_STATUS status);
diff --git a/main.c b/main.c
index 3789319..f1cbf3c 100644
--- a/main.c
+++ b/main.c
@@ -24,6 +24,7 @@
 
 extern const unsigned long init_array_start[];
 extern const unsigned long init_array_end[];
+extern CHAR16 *boot_device_path;
 
 static EFI_STATUS probe_watchdog(EFI_LOADED_IMAGE *loaded_image,
                                 EFI_PCI_IO *pci_io, UINT16 pci_vendor_id,
@@ -123,6 +124,11 @@ EFI_STATUS efi_main(EFI_HANDLE image_handle, 
EFI_SYSTEM_TABLE *system_table)
                           status);
        }
 
+       boot_device_path = DevicePathToStr(DevicePathFromHandle(
+                                          loaded_image->DeviceHandle));
+       boot_device_path = StrRStrip(boot_device_path, L'/');
+       Print(L"Boot device: %s\n", boot_device_path);
+
        status = get_volumes(&volumes, &volume_count);
        if (EFI_ERROR(status)) {
                error_exit(L"Could not get volumes installed on system.\n",
diff --git a/utils.c b/utils.c
index 4f44a37..0477cbc 100644
--- a/utils.c
+++ b/utils.c
@@ -16,6 +16,19 @@
 #include <bootguard.h>
 #include <utils.h>
 
+BOOLEAN IsOnBootDevice(EFI_DEVICE_PATH *dp)
+{
+       extern CHAR16 *boot_device_path;
+       CHAR16 *device_path;
+
+       device_path = DevicePathToStr(dp);
+       device_path = StrRStrip(device_path, L'/');
+       if (StrCmp(device_path, boot_device_path) == 0) {
+               return TRUE;
+       }
+       return FALSE;
+}
+
 CHAR16 *StrRStrip(CHAR16 *input, CHAR16 delim)
 {
        CHAR16 *dst;
-- 
2.17.0

-- 
You received this message because you are subscribed to the Google Groups "EFI 
Boot Guard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/efibootguard-dev/20180525120108.31055-4-andreas.reichel.ext%40siemens.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to