[BOOTLIB]:
authorAlex Ionescu <aionescu@gmail.com>
Mon, 5 Oct 2015 01:02:56 +0000 (01:02 +0000)
committerAlex Ionescu <aionescu@gmail.com>
Mon, 5 Oct 2015 01:02:56 +0000 (01:02 +0000)
- Fix BCD bugs.

svn path=/trunk/; revision=69450

reactos/boot/environ/app/bootmgr/bootmgr.c
reactos/boot/environ/app/bootmgr/efiemu.c
reactos/boot/environ/lib/misc/bcd.c

index be19a83..b4468af 100644 (file)
@@ -505,6 +505,7 @@ BmOpenDataStore (
     PVOID FinalBuffer;
     UNICODE_STRING BcdString;
 
     PVOID FinalBuffer;
     UNICODE_STRING BcdString;
 
+    /* Initialize variables */
     PathBuffer = NULL;
     BcdDevice = NULL;
     BcdPath = NULL;
     PathBuffer = NULL;
     BcdDevice = NULL;
     BcdPath = NULL;
@@ -559,6 +560,7 @@ BmOpenDataStore (
 
     /* Otherwise, compute the hardcoded path of the BCD */
     Status = BmpFwGetFullPath(L"\\BCD", &FullPath);
 
     /* Otherwise, compute the hardcoded path of the BCD */
     Status = BmpFwGetFullPath(L"\\BCD", &FullPath);
+    EfiPrintf(L"Status: %lx %s\r\n", Status, FullPath);
     if (!NT_SUCCESS(Status))
     {
         /* User the raw path */
     if (!NT_SUCCESS(Status))
     {
         /* User the raw path */
index 0695a79..268d1f2 100644 (file)
@@ -803,7 +803,7 @@ EfiInitpCreateApplicationEntry (
             /* Calculate where the next option should go */
             Option = (PVOID)((ULONG_PTR)Option + Size);
 
             /* Calculate where the next option should go */
             Option = (PVOID)((ULONG_PTR)Option + Size);
 
-            /* Convert the path oprtion */
+            /* Convert the path option */
             Status = EfiInitpConvertEfiFilePath(OsDevicePath,
                                                 BcdOSLoaderString_SystemRoot,
                                                 Option,
             Status = EfiInitpConvertEfiFilePath(OsDevicePath,
                                                 BcdOSLoaderString_SystemRoot,
                                                 Option,
index 3434681..d62ff7c 100644 (file)
@@ -20,7 +20,7 @@ MiscGetBootOption (
     )
 {
     ULONG_PTR NextOption = 0, ListOption;
     )
 {
     ULONG_PTR NextOption = 0, ListOption;
-    PBL_BCD_OPTION Option;
+    PBL_BCD_OPTION Option, FoundOption;
 
     /* No options, bail out */
     if (!List)
 
     /* No options, bail out */
     if (!List)
@@ -29,12 +29,14 @@ MiscGetBootOption (
     }
 
     /* Loop while we find an option */
     }
 
     /* Loop while we find an option */
-    while (TRUE)
+    FoundOption = NULL;
+    do
     {
         /* Get the next option and see if it matches the type */
         Option = (PBL_BCD_OPTION)((ULONG_PTR)List + NextOption);
         if ((Option->Type == Type) && !(Option->Empty))
         {
     {
         /* Get the next option and see if it matches the type */
         Option = (PBL_BCD_OPTION)((ULONG_PTR)List + NextOption);
         if ((Option->Type == Type) && !(Option->Empty))
         {
+            FoundOption = Option;
             break;
         }
 
             break;
         }
 
@@ -49,21 +51,19 @@ MiscGetBootOption (
             Option = MiscGetBootOption((PBL_BCD_OPTION)((ULONG_PTR)Option +
                                        ListOption),
                                        Type);
             Option = MiscGetBootOption((PBL_BCD_OPTION)((ULONG_PTR)Option +
                                        ListOption),
                                        Type);
-
-            /* Found one, return it */
             if (Option)
             {
             if (Option)
             {
-                return Option;
+                /* Return it */
+                FoundOption = Option;
+                break;
             }
         }
             }
         }
-    }
+    } while (NextOption);
 
 
-    /* We found the option, return it */
-    return Option;
+    /* Return the option that was found, if any */
+    return FoundOption;
 }
 
 }
 
-
-
 /*++
  * @name BlGetBootOptionListSize
  *
 /*++
  * @name BlGetBootOptionListSize
  *
@@ -94,7 +94,7 @@ BlGetBootOptionListSize (
 
         /* Update the offset */
         NextOffset = NextOption->NextEntryOffset;
 
         /* Update the offset */
         NextOffset = NextOption->NextEntryOffset;
-    } while (NextOffset != 0);
+    } while (NextOffset);
 
     /* Return final computed size */
     return Size;
 
     /* Return final computed size */
     return Size;
@@ -119,7 +119,7 @@ BlGetBootOptionSize (
     ULONG Size, Offset;
 
     /* Check if there's any data */
     ULONG Size, Offset;
 
     /* Check if there's any data */
-    if (BcdOption->DataOffset != 0)
+    if (BcdOption->DataOffset)
     {
         /* Add the size of the data */
         Size = BcdOption->DataOffset + BcdOption->DataSize;
     {
         /* Add the size of the data */
         Size = BcdOption->DataOffset + BcdOption->DataSize;
@@ -132,7 +132,7 @@ BlGetBootOptionSize (
 
     /* Any associated options? */
     Offset = BcdOption->ListOffset;
 
     /* Any associated options? */
     Offset = BcdOption->ListOffset;
-    if (Offset != 0)
+    if (Offset)
     {
         /* Go get those too */
         Size += BlGetBootOptionListSize((PVOID)((ULONG_PTR)BcdOption + Offset));
     {
         /* Go get those too */
         Size += BlGetBootOptionListSize((PVOID)((ULONG_PTR)BcdOption + Offset));
@@ -167,11 +167,13 @@ BlGetBootOptionString (
     {
         /* Extract the string */
         String = (PWCHAR)((ULONG_PTR)Option + Option->DataOffset);
     {
         /* Extract the string */
         String = (PWCHAR)((ULONG_PTR)Option + Option->DataOffset);
+        Status = STATUS_SUCCESS;
     }
     else
     {
         /* No string is present */
         String = NULL;
     }
     else
     {
         /* No string is present */
         String = NULL;
+        Status = STATUS_NOT_FOUND;
     }
 
     /* Compute the data size */
     }
 
     /* Compute the data size */
@@ -182,9 +184,7 @@ BlGetBootOptionString (
     AppIdentifier = BlGetApplicationIdentifier();
     Status = BlpBootOptionCallbackString(AppIdentifier, Type, String, StringLength, &String, &StringLength);
 #else
     AppIdentifier = BlGetApplicationIdentifier();
     Status = BlpBootOptionCallbackString(AppIdentifier, Type, String, StringLength, &String, &StringLength);
 #else
-    Status = STATUS_SUCCESS;
 #endif
 #endif
-
     /* Check if we have space for one more character */
     CopyLength = StringLength + 1;
     if (CopyLength < StringLength)
     /* Check if we have space for one more character */
     CopyLength = StringLength + 1;
     if (CopyLength < StringLength)
@@ -193,11 +193,6 @@ BlGetBootOptionString (
         CopyLength = -1;
         Status = STATUS_INTEGER_OVERFLOW;
     }
         CopyLength = -1;
         Status = STATUS_INTEGER_OVERFLOW;
     }
-    else
-    {
-        /* Go ahead */
-        Status = STATUS_SUCCESS;
-    }
 
     /* No overflow? */
     if (NT_SUCCESS(Status))
 
     /* No overflow? */
     if (NT_SUCCESS(Status))
@@ -331,7 +326,6 @@ BlGetBootOptionDevice (
     }
 #else
     /* No secure boot, so the secure descriptors are the standard ones */
     }
 #else
     /* No secure boot, so the secure descriptors are the standard ones */
-    Status = STATUS_SUCCESS;
     SecureDescriptor = DeviceDescriptor;
     SecureListData = ListCopy;
 #endif
     SecureDescriptor = DeviceDescriptor;
     SecureListData = ListCopy;
 #endif
@@ -765,6 +759,7 @@ BcdOpenStoreFromFile (
 
     /* Assume failure */
     LocalHandle = NULL;
 
     /* Assume failure */
     LocalHandle = NULL;
+    EfiPrintf(L"Opening BCD store: %wZ\n", FileName);
 
     /* Allocate a path descriptor */
     Length = FileName->Length + sizeof(*FilePath);
 
     /* Allocate a path descriptor */
     Length = FileName->Length + sizeof(*FilePath);