Author: hbelusca
Date: Thu Jun  8 02:19:14 2017
New Revision: 74952

URL: http://svn.reactos.org/svn/reactos?rev=74952&view=rev
Log:
[SETUPLIB]: Make the NTOS_BOOT_ENTRY structure (that should actually be 
renamed...) more generic, so that it can wrap around either actual NTOS boot 
entry options, or FreeLdr-like boot-sector options.
In a sense, the NTOS_BOOT_ENTRY structure now looks much more like the NT 
structure "BOOT_ENTRY".
- Adapt the code in bldrsup.c to these modifications, and re-enable 
FreeLdr-like boot-sector-file support code that was commented out.
More code cleaning-up will follow later.

Modified:
    branches/setup_improvements/base/setup/lib/bldrsup.c
    branches/setup_improvements/base/setup/lib/bldrsup.h

Modified: branches/setup_improvements/base/setup/lib/bldrsup.c
URL: 
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/lib/bldrsup.c?rev=74952&r1=74951&r2=74952&view=diff
==============================================================================
--- branches/setup_improvements/base/setup/lib/bldrsup.c        [iso-8859-1] 
(original)
+++ branches/setup_improvements/base/setup/lib/bldrsup.c        [iso-8859-1] 
Thu Jun  8 02:19:14 2017
@@ -867,37 +867,52 @@
     /* Create a new section */
     IniSection = IniCacheAppendSection(BootStore->IniCache, Section);
 
-    /* BootType= */
-    IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
-                      L"BootType", BootEntry->Version);
-
-    if (_wcsicmp(BootEntry->Version, L"Windows2003") == 0)
-    {
+    // if (_wcsicmp(BootEntry->Version, L"Windows2003") == 0)
+    if (BootEntry->OsOptionsLength >= sizeof(NTOS_OPTIONS) &&
+        RtlCompareMemory(&BootEntry->OsOptions /* Signature */,
+                         NTOS_OPTIONS_SIGNATURE,
+                         RTL_FIELD_SIZE(NTOS_OPTIONS, Signature)) ==
+                         RTL_FIELD_SIZE(NTOS_OPTIONS, Signature))
+    {
+        PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions;
+
+        /* BootType= */
+        IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
+                          L"BootType", L"Windows2003");
+
         /* SystemPath= */
         IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
-                          L"SystemPath", (PWSTR)BootEntry->OsLoadPath);
+                          L"SystemPath", (PWSTR)Options->OsLoadPath);
 
         /* Options= */
         IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
-                          L"Options", (PWSTR)BootEntry->OsLoadOptions);
+                          L"Options", (PWSTR)Options->OsLoadOptions);
     }
     else
-    if (_wcsicmp(BootEntry->Version, L"BootSector") == 0)
-    {
+    // if (_wcsicmp(BootEntry->Version, L"BootSector") == 0)
+    if (BootEntry->OsOptionsLength >= sizeof(BOOT_SECTOR_OPTIONS) &&
+        RtlCompareMemory(&BootEntry->OsOptions /* Signature */,
+                         BOOT_SECTOR_OPTIONS_SIGNATURE,
+                         RTL_FIELD_SIZE(BOOT_SECTOR_OPTIONS, Signature)) ==
+                         RTL_FIELD_SIZE(BOOT_SECTOR_OPTIONS, Signature))
+    {
+        PBOOT_SECTOR_OPTIONS Options = 
(PBOOT_SECTOR_OPTIONS)&BootEntry->OsOptions;
+
+        /* BootType= */
+        IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
+                          L"BootType", L"BootSector");
+
         /* BootDrive= */
         IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
-                          L"BootDrive",
-                          /*BootDrive*/ (PWSTR)BootEntry->OsLoadPath); // 
OsLoadPath ??
-
-        // /* BootPartition= */
-        // IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
-                          // L"BootPartition",
-                          // BootPartition);       // OsLoadPath
+                          L"BootDrive", (PWSTR)Options->Drive);
+
+        /* BootPartition= */
+        IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
+                          L"BootPartition", (PWSTR)Options->Partition);
 
         /* BootSector= */
         IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
-                          L"BootSectorFile",
-                          /*BootSector*/ (PWSTR)BootEntry->BootFilePath);
+                          L"BootSectorFile", 
(PWSTR)Options->BootSectorFileName);
     }
     else
     {
@@ -940,19 +955,25 @@
     else
     if (BootStore->Type == NtLdr)
     {
+        PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions;
         PWCHAR Buffer;
         ULONG BufferLength;
         PCWSTR InstallName, OsOptions;
         // ULONG InstallNameLength, OsOptionsLength;
 
-        if (_wcsicmp(BootEntry->Version, L"Windows2003") != 0)
+        // if (_wcsicmp(BootEntry->Version, L"Windows2003") != 0)
+        if (BootEntry->OsOptionsLength < sizeof(NTOS_OPTIONS) ||
+            RtlCompareMemory(&BootEntry->OsOptions /* Signature */,
+                             NTOS_OPTIONS_SIGNATURE,
+                             RTL_FIELD_SIZE(NTOS_OPTIONS, Signature)) !=
+                             RTL_FIELD_SIZE(NTOS_OPTIONS, Signature))
         {
             DPRINT1("Unsupported BootType '%S'\n", BootEntry->Version);
             return STATUS_SUCCESS; // STATUS_NOT_SUPPORTED;
         }
 
         InstallName = BootEntry->FriendlyName;
-        OsOptions = BootEntry->OsLoadOptions;
+        OsOptions = Options->OsLoadOptions;
 
         // if (InstallNameLength == 0) InstallName = NULL;
         // if (OsOptionsLength == 0) OsOptions = NULL;
@@ -977,7 +998,7 @@
 
         /* Insert the entry into the "Operating Systems" section */
         IniCacheInsertKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OsIniSection, 
NULL, INSERT_LAST,
-                          (PWSTR)BootEntry->OsLoadPath, Buffer);
+                          (PWSTR)Options->OsLoadPath, Buffer);
 
         RtlFreeHeap(ProcessHeap, 0, Buffer);
         return STATUS_SUCCESS;
@@ -1216,8 +1237,9 @@
     PINICACHEITERATOR Iterator;
     PINICACHESECTION OsIniSection;
     PWCHAR SectionName, KeyData;
-/**/NTOS_BOOT_ENTRY xxBootEntry;/**/
-    PNTOS_BOOT_ENTRY BootEntry = &xxBootEntry;
+    UCHAR xxBootEntry[FIELD_OFFSET(NTOS_BOOT_ENTRY, OsOptions) +
+                      max(sizeof(NTOS_OPTIONS), sizeof(BOOT_SECTOR_OPTIONS))];
+    PNTOS_BOOT_ENTRY BootEntry = (PNTOS_BOOT_ENTRY)&xxBootEntry;
     PWCHAR Buffer;
 
     /* Enumerate all the valid installations listed in the "Operating Systems" 
section */
@@ -1272,10 +1294,8 @@
         BootEntry->Version = NULL;
         BootEntry->BootEntryKey = MAKESTRKEY(SectionName);
         BootEntry->FriendlyName = InstallName;
-        BootEntry->OsLoadPath = NULL;
         BootEntry->BootFilePath = NULL;
-        // BootEntry->OsOptions = NULL;
-        BootEntry->OsLoadOptions = NULL;
+        BootEntry->OsOptionsLength = 0;
 
         /* Search for an existing boot entry section */
         OsIniSection = IniCacheGetSection(BootStore->IniCache, SectionName);
@@ -1296,50 +1316,70 @@
             (_wcsicmp(KeyData, L"\"Windows2003\"") == 0))
         {
             /* BootType is Windows2003 */
+            PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions;
+
             BootEntry->Version = L"Windows2003";
             DPRINT1("This is a '%S' boot entry\n", BootEntry->Version);
+
+            BootEntry->OsOptionsLength = sizeof(NTOS_OPTIONS);
+            RtlCopyMemory(Options->Signature,
+                          NTOS_OPTIONS_SIGNATURE,
+                          RTL_FIELD_SIZE(NTOS_OPTIONS, Signature));
+
+            // BootEntry->BootFilePath = NULL;
 
             /* Check its SystemPath */
             Status = IniCacheGetKey(OsIniSection, L"SystemPath", &KeyData);
             if (!NT_SUCCESS(Status))
-                BootEntry->OsLoadPath = NULL;
+                Options->OsLoadPath = NULL;
             else
-                BootEntry->OsLoadPath = KeyData;
+                Options->OsLoadPath = KeyData;
             // KeyData == SystemRoot;
-
-            BootEntry->BootFilePath = NULL;
-            // BootEntry->OsOptions = NULL;
 
             /* Check the optional Options */
             Status = IniCacheGetKey(OsIniSection, L"Options", &KeyData);
             if (!NT_SUCCESS(Status))
-                BootEntry->OsLoadOptions = NULL;
+                Options->OsLoadOptions = NULL;
             else
-                BootEntry->OsLoadOptions = KeyData;
+                Options->OsLoadOptions = KeyData;
         }
         else
         if ((_wcsicmp(KeyData, L"BootSector")     == 0) ||
             (_wcsicmp(KeyData, L"\"BootSector\"") == 0))
         {
             /* BootType is BootSector */
+            PBOOT_SECTOR_OPTIONS Options = 
(PBOOT_SECTOR_OPTIONS)&BootEntry->OsOptions;
+
             BootEntry->Version = L"BootSector";
             DPRINT1("This is a '%S' boot entry\n", BootEntry->Version);
+
+            BootEntry->OsOptionsLength = sizeof(BOOT_SECTOR_OPTIONS);
+            RtlCopyMemory(Options->Signature,
+                          BOOT_SECTOR_OPTIONS_SIGNATURE,
+                          RTL_FIELD_SIZE(BOOT_SECTOR_OPTIONS, Signature));
+
+            // BootEntry->BootFilePath = NULL;
 
             /* Check its BootDrive */
             Status = IniCacheGetKey(OsIniSection, L"BootDrive", &KeyData);
             if (!NT_SUCCESS(Status))
-                BootEntry->OsLoadPath = NULL;
+                Options->Drive = NULL;
             else
-                BootEntry->OsLoadPath = KeyData;
-
-            /* FIXME: Check its BootPartition ???? */
+                Options->Drive = KeyData;
+
+            /* Check its BootPartition */
+            Status = IniCacheGetKey(OsIniSection, L"BootPartition", &KeyData);
+            if (!NT_SUCCESS(Status))
+                Options->Partition = NULL;
+            else
+                Options->Partition = KeyData;
 
             /* Check its BootSector */
             Status = IniCacheGetKey(OsIniSection, L"BootSectorFile", &KeyData);
             if (!NT_SUCCESS(Status))
-                BootEntry->BootFilePath = NULL;
+                Options->BootSectorFileName = NULL;
             else
-                BootEntry->BootFilePath = KeyData;
+                Options->BootSectorFileName = KeyData;
         }
         else
         {
@@ -1376,8 +1416,9 @@
     NTSTATUS Status = STATUS_SUCCESS;
     PINICACHEITERATOR Iterator;
     PWCHAR SectionName, KeyData;
-/**/NTOS_BOOT_ENTRY xxBootEntry;/**/
-    PNTOS_BOOT_ENTRY BootEntry = &xxBootEntry;
+    UCHAR xxBootEntry[FIELD_OFFSET(NTOS_BOOT_ENTRY, OsOptions) + 
sizeof(NTOS_OPTIONS)];
+    PNTOS_BOOT_ENTRY BootEntry = (PNTOS_BOOT_ENTRY)&xxBootEntry;
+    PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions;
     PWCHAR Buffer;
     ULONG BufferLength;
 
@@ -1472,10 +1513,15 @@
         BootEntry->Version = L"Windows2003";
         BootEntry->BootEntryKey = 0; // FIXME??
         BootEntry->FriendlyName = InstallName;
-        BootEntry->OsLoadPath   = SectionName;
         BootEntry->BootFilePath = NULL;
-        // BootEntry->OsOptions = NULL;
-        BootEntry->OsLoadOptions = OsOptions;
+
+        BootEntry->OsOptionsLength = sizeof(NTOS_OPTIONS);
+        RtlCopyMemory(Options->Signature,
+                      NTOS_OPTIONS_SIGNATURE,
+                      RTL_FIELD_SIZE(NTOS_OPTIONS, Signature));
+
+        Options->OsLoadPath    = SectionName;
+        Options->OsLoadOptions = OsOptions;
 
         /* Call the user enumeration routine callback */
         Status = EnumBootEntriesRoutine(NtLdr, BootEntry, Parameter);

Modified: branches/setup_improvements/base/setup/lib/bldrsup.h
URL: 
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/lib/bldrsup.h?rev=74952&r1=74951&r2=74952&view=diff
==============================================================================
--- branches/setup_improvements/base/setup/lib/bldrsup.h        [iso-8859-1] 
(original)
+++ branches/setup_improvements/base/setup/lib/bldrsup.h        [iso-8859-1] 
Thu Jun  8 02:19:14 2017
@@ -11,7 +11,7 @@
 
 #pragma once
 
-typedef enum _NTOS_BOOT_LOADER_TYPE
+typedef enum _NTOS_BOOT_LOADER_TYPE     // _BOOT_STORE_TYPE
 {
     FreeLdr,    // ReactOS' FreeLoader
     NtLdr,      // Windows <= 2k3 NT "FlexBoot" OS Loader NTLDR
@@ -29,7 +29,7 @@
  * This structure is inspired from the EFI boot entry structure
  * BOOT_OPTIONS that is defined in ndk/iotypes.h .
  */
-typedef struct _NTOS_BOOT_OPTIONS
+typedef struct _NTOS_BOOT_OPTIONS       // _BOOT_STORE_OPTIONS
 {
     // ULONG Version;
     // ULONG Length;
@@ -60,7 +60,7 @@
  * This structure is inspired from the EFI boot entry structures
  * BOOT_ENTRY and FILE_PATH that are defined in ndk/iotypes.h .
  */
-typedef struct _NTOS_BOOT_ENTRY
+typedef struct _NTOS_BOOT_ENTRY         // _BOOT_STORE_ENTRY
 {
     // ULONG Version; // Equivalent of the "BootType" in FreeLdr
     PWCHAR Version; // HACK!!!
@@ -68,10 +68,50 @@
     ULONG_PTR BootEntryKey; // Boot entry "key"
     PCWSTR FriendlyName;    // Human-readable boot entry description        // 
LoadIdentifier
     PCWSTR BootFilePath;    // Path to e.g. osloader.exe, or winload.efi    // 
EfiOsLoaderFilePath
-    PCWSTR OsLoadPath;      // The OS SystemRoot path                       // 
OsLoaderFilePath
-    // PCWSTR OsOptions;                                                    // 
OsLoadOptions
-    PCWSTR OsLoadOptions;
+    ULONG OsOptionsLength;  // Loader-specific options blob (can be a string, 
or a binary structure...)
+    UCHAR OsOptions[ANYSIZE_ARRAY];
+/*
+ * In packed form, this structure would contain offsets to 'FriendlyName'
+ * and 'BootFilePath' strings and, after the OsOptions blob, there would
+ * be the following data:
+ *
+ *  WCHAR FriendlyName[ANYSIZE_ARRAY];
+ *  FILE_PATH BootFilePath;
+ */
 } NTOS_BOOT_ENTRY, *PNTOS_BOOT_ENTRY;
+
+/* "NTOS" (aka. ReactOS or MS Windows NT) <= 5.x options */
+typedef struct _NTOS_OPTIONS
+{
+    UCHAR Signature[8];     // "NTOS_5\0\0"
+    // ULONG Version;
+    // ULONG Length;
+    PCWSTR OsLoadPath;      // The OS SystemRoot path                       // 
OsLoaderFilePath // OsFilePath
+    PCWSTR OsLoadOptions;                                                   // 
OsLoadOptions
+/*
+ * In packed form, this structure would contain an offset to the 'OsLoadPath'
+ * string, and the 'OsLoadOptions' member would be:
+ *  WCHAR OsLoadOptions[ANYSIZE_ARRAY];
+ * followed by:
+ *  FILE_PATH OsLoadPath;
+ */
+} NTOS_OPTIONS, *PNTOS_OPTIONS;
+
+#define NTOS_OPTIONS_SIGNATURE "NTOS_5\0\0"
+
+/* Options for boot-sector boot entries */
+typedef struct _BOOT_SECTOR_OPTIONS
+{
+    UCHAR Signature[8];     // "BootSect"
+    // ULONG Version;
+    // ULONG Length;
+    PCWSTR Drive;
+    PCWSTR Partition;
+    PCWSTR BootSectorFileName;
+} BOOT_SECTOR_OPTIONS, *PBOOT_SECTOR_OPTIONS;
+
+#define BOOT_SECTOR_OPTIONS_SIGNATURE "BootSect"
+
 
 typedef NTSTATUS
 (NTAPI *PENUM_BOOT_ENTRIES_ROUTINE)(


Reply via email to