[FREELDR] Minor fixes.
[reactos.git] / boot / freeldr / freeldr / ntldr / winldr.c
index 98de7f2..b114adb 100644 (file)
@@ -1,30 +1,15 @@
 /*
- *  FreeLoader
- *
- *  Copyright (C) 1998-2003  Brian Palmer    <brianp@sginet.com>
- *  Copyright (C) 2006       Aleksey Bragin  <aleksey@reactos.org>
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * PROJECT:     FreeLoader
+ * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
+ * PURPOSE:     Windows-compatible NT OS Loader.
+ * COPYRIGHT:   Copyright 2006-2019 Aleksey Bragin <aleksey@reactos.org>
  */
 
 #include <freeldr.h>
+#include <ndk/ldrtypes.h>
 #include "winldr.h"
 #include "registry.h"
 
-#include <ndk/ldrtypes.h>
-
 #include <debug.h>
 DBG_DEFAULT_CHANNEL(WINDOWS);
 
@@ -75,9 +60,9 @@ AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock)
 // Init "phase 1"
 VOID
 WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
-                       LPCSTR Options,
-                       LPCSTR SystemRoot,
-                       LPCSTR BootPath,
+                       PCSTR Options,
+                       PCSTR SystemRoot,
+                       PCSTR BootPath,
                        USHORT VersionToBoot)
 {
     /* Examples of correct options and paths */
@@ -86,7 +71,7 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
     //CHAR    SystemRoot[] = "\\WINNT\\";
     //CHAR    ArcBoot[] = "multi(0)disk(0)rdisk(0)partition(1)";
 
-    LPSTR LoadOptions, NewLoadOptions;
+    PSTR  LoadOptions, NewLoadOptions;
     CHAR  HalPath[] = "\\";
     CHAR  ArcBoot[MAX_PATH+1];
     CHAR  MiscFiles[MAX_PATH+1];
@@ -107,6 +92,23 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
     RtlStringCbCopyA(LoaderBlock->ArcBootDeviceName, sizeof(WinLdrSystemBlock->ArcBootDeviceName), ArcBoot);
     LoaderBlock->ArcBootDeviceName = PaToVa(LoaderBlock->ArcBootDeviceName);
 
+//
+// IMPROVE!!
+// SetupBlock->ArcSetupDeviceName must be the path to the setup **SOURCE**,
+// and not the setup boot path. Indeed they may differ!!
+//
+    /* If we have a setup block, adjust also its ARC path */
+    if (LoaderBlock->SetupLdrBlock)
+    {
+        PSETUP_LOADER_BLOCK SetupBlock = LoaderBlock->SetupLdrBlock;
+
+        /* Matches ArcBoot path */
+        SetupBlock->ArcSetupDeviceName = WinLdrSystemBlock->ArcBootDeviceName;
+        SetupBlock->ArcSetupDeviceName = PaToVa(SetupBlock->ArcSetupDeviceName);
+
+        /* Note: LoaderBlock->SetupLdrBlock is PaToVa'ed at the end of this function */
+    }
+
     /* Fill ARC HalDevice, it matches ArcBoot path */
     LoaderBlock->ArcHalDeviceName = WinLdrSystemBlock->ArcBootDeviceName;
     LoaderBlock->ArcHalDeviceName = PaToVa(LoaderBlock->ArcHalDeviceName);
@@ -221,7 +223,7 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
 
 static BOOLEAN
 WinLdrLoadDeviceDriver(PLIST_ENTRY LoadOrderListHead,
-                       LPCSTR BootPath,
+                       PCSTR BootPath,
                        PUNICODE_STRING FilePath,
                        ULONG Flags,
                        PLDR_DATA_TABLE_ENTRY *DriverDTE)
@@ -292,7 +294,7 @@ WinLdrLoadDeviceDriver(PLIST_ENTRY LoadOrderListHead,
 
 BOOLEAN
 WinLdrLoadBootDrivers(PLOADER_PARAMETER_BLOCK LoaderBlock,
-                      LPCSTR BootPath)
+                      PCSTR BootPath)
 {
     PLIST_ENTRY NextBd;
     PBOOT_DRIVER_LIST_ENTRY BootDriver;
@@ -344,7 +346,7 @@ WinLdrLoadBootDrivers(PLOADER_PARAMETER_BLOCK LoaderBlock,
 
 PVOID
 WinLdrLoadModule(PCSTR ModuleName,
-                 ULONG *Size,
+                 PULONG Size,
                  TYPE_OF_MEMORY MemoryType)
 {
     ULONG FileId;
@@ -369,6 +371,7 @@ WinLdrLoadModule(PCSTR ModuleName,
     if (Status != ESUCCESS)
     {
         /* In case of errors, we just return, without complaining to the user */
+        WARN("Error while opening '%s', Status: %u\n", ModuleName, Status);
         return NULL;
     }
 
@@ -395,6 +398,7 @@ WinLdrLoadModule(PCSTR ModuleName,
     ArcClose(FileId);
     if (Status != ESUCCESS)
     {
+        WARN("Error while reading '%s', Status: %u\n", ModuleName, Status);
         return NULL;
     }
 
@@ -780,15 +784,15 @@ ARC_STATUS
 LoadAndBootWindowsCommon(
     USHORT OperatingSystemVersion,
     PLOADER_PARAMETER_BLOCK LoaderBlock,
-    LPCSTR BootOptions,
-    LPCSTR BootPath,
+    PCSTR BootOptions,
+    PCSTR BootPath,
     BOOLEAN Setup)
 {
     PLOADER_PARAMETER_BLOCK LoaderBlockVA;
     BOOLEAN Success;
     PLDR_DATA_TABLE_ENTRY KernelDTE;
     KERNEL_ENTRY_POINT KiSystemStartup;
-    LPCSTR SystemRoot;
+    PCSTR SystemRoot;
 
     TRACE("LoadAndBootWindowsCommon()\n");