]> code.delx.au - refind/blobdiff - mok/simple_file.c
Fix for refind-install script to handle a wider range of disk devices,
[refind] / mok / simple_file.c
index 85aa9e654acf2fc2e085b63fd39cab735471333e..263593f1e157bed8effc7bed1e7b31467fc383d3 100644 (file)
@@ -7,10 +7,8 @@
 #include <global.h>
 #include "../include/refit_call_wrapper.h"
 
-#include "console.h"
 #include "simple_file.h"
-//#include "efiauthenticated.h"
-#include "execute.h"    /* for generate_path() */
+//#include "execute.h"    /* for generate_path() */
 
 static EFI_GUID IMAGE_PROTOCOL = LOADED_IMAGE_PROTOCOL;
 static EFI_GUID SIMPLE_FS_PROTOCOL = SIMPLE_FILE_SYSTEM_PROTOCOL;
@@ -45,6 +43,57 @@ simple_file_open_by_handle(EFI_HANDLE device, CHAR16 *name, EFI_FILE **file, UIN
    return efi_status;
 }
 
+// generate_path() from shim by Matthew J. Garrett
+static
+EFI_STATUS
+generate_path(CHAR16* name, EFI_LOADED_IMAGE *li, EFI_DEVICE_PATH **path, CHAR16 **PathName)
+{
+        unsigned int pathlen;
+        EFI_STATUS efi_status = EFI_SUCCESS;
+        CHAR16 *devpathstr = DevicePathToStr(li->FilePath),
+                *found = NULL;
+        int i;
+
+        for (i = 0; i < StrLen(devpathstr); i++) {
+                if (devpathstr[i] == '/')
+                        devpathstr[i] = '\\';
+                if (devpathstr[i] == '\\')
+                        found = &devpathstr[i];
+        }
+        if (!found) {
+                pathlen = 0;
+        } else {
+                while (*(found - 1) == '\\')
+                        --found;
+                *found = '\0';
+                pathlen = StrLen(devpathstr);
+        }
+
+        if (name[0] != '\\')
+                pathlen++;
+
+        *PathName = AllocatePool((pathlen + 1 + StrLen(name))*sizeof(CHAR16));
+
+        if (!*PathName) {
+                Print(L"Failed to allocate path buffer\n");
+                efi_status = EFI_OUT_OF_RESOURCES;
+                goto error;
+        }
+
+        StrCpy(*PathName, devpathstr);
+
+        if (name[0] != '\\')
+                StrCat(*PathName, L"\\");
+        StrCat(*PathName, name);
+
+        *path = FileDevicePath(li->DeviceHandle, *PathName);
+
+error:
+        FreePool(devpathstr);
+
+        return efi_status;
+} // generate_path()
+
 EFI_STATUS
 simple_file_open(EFI_HANDLE image, CHAR16 *name, EFI_FILE **file, UINT64 mode)
 {