[SETUPLIB][USETUP] Minor code refactoring, consisting in renaming the "ntos boot loader" stuff into "boot store", since this happens to be functionality that is a bit more general than previously thought.

- Fix the usage of the BootEntry's "Version" member.
- Don't surround with too many quotation marks the "friendly" boot entry name in AddBootStoreEntry().

svn path=/branches/setup_improvements/; revision=74964
This commit is contained in:
Hermès Bélusca-Maïto 2017-06-08 17:30:23 +00:00
parent e589513b46
commit a28461124b
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
4 changed files with 174 additions and 157 deletions

View file

@ -1,8 +1,8 @@
/* /*
* PROJECT: ReactOS Setup Library * PROJECT: ReactOS Setup Library
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
* PURPOSE: NT 5.x family (MS Windows <= 2003, and ReactOS) * PURPOSE: Boot Stores Management functionality, with support for
* boot loaders management. * NT 5.x family (MS Windows <= 2003, and ReactOS) bootloaders.
* COPYRIGHT: Copyright 2017-2018 Hermes Belusca-Maito * COPYRIGHT: Copyright 2017-2018 Hermes Belusca-Maito
*/ */
@ -26,7 +26,7 @@ typedef NTSTATUS
(*POPEN_BOOT_STORE)( (*POPEN_BOOT_STORE)(
OUT PVOID* Handle, OUT PVOID* Handle,
IN HANDLE PartitionDirectoryHandle, // OPTIONAL IN HANDLE PartitionDirectoryHandle, // OPTIONAL
IN NTOS_BOOT_LOADER_TYPE Type, IN BOOT_STORE_TYPE Type,
IN BOOLEAN CreateNew); IN BOOLEAN CreateNew);
typedef NTSTATUS typedef NTSTATUS
@ -42,7 +42,7 @@ typedef NTSTATUS
typedef struct _NTOS_BOOT_LOADER_FILES typedef struct _NTOS_BOOT_LOADER_FILES
{ {
NTOS_BOOT_LOADER_TYPE Type; BOOT_STORE_TYPE Type;
PCZZWSTR LoaderExecutables; PCZZWSTR LoaderExecutables;
PCWSTR LoaderConfigurationFile; PCWSTR LoaderConfigurationFile;
POPEN_BOOT_STORE OpenBootStore; POPEN_BOOT_STORE OpenBootStore;
@ -56,7 +56,7 @@ typedef struct _NTOS_BOOT_LOADER_FILES
*/ */
typedef struct _BOOT_STORE_CONTEXT typedef struct _BOOT_STORE_CONTEXT
{ {
NTOS_BOOT_LOADER_TYPE Type; BOOT_STORE_TYPE Type;
// PNTOS_BOOT_LOADER_FILES ?? // PNTOS_BOOT_LOADER_FILES ??
/* /*
PVOID PrivateData; PVOID PrivateData;
@ -95,7 +95,7 @@ static NTSTATUS
OpenIniBootLoaderStore( OpenIniBootLoaderStore(
OUT PVOID* Handle, OUT PVOID* Handle,
IN HANDLE PartitionDirectoryHandle, // OPTIONAL IN HANDLE PartitionDirectoryHandle, // OPTIONAL
IN NTOS_BOOT_LOADER_TYPE Type, IN BOOT_STORE_TYPE Type,
IN BOOLEAN CreateNew); IN BOOLEAN CreateNew);
static NTSTATUS static NTSTATUS
@ -134,10 +134,10 @@ C_ASSERT(_countof(NtosBootLoaders) == BldrTypeMax);
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
NTSTATUS NTSTATUS
FindNTOSBootLoader( // By handle FindBootStore( // By handle
IN HANDLE PartitionDirectoryHandle, // OPTIONAL IN HANDLE PartitionDirectoryHandle, // OPTIONAL
IN NTOS_BOOT_LOADER_TYPE Type, IN BOOT_STORE_TYPE Type,
OUT PULONG Version OPTIONAL) OUT PULONG VersionNumber OPTIONAL)
// OUT PHANDLE ConfigFileHande OPTIONAL ???? // OUT PHANDLE ConfigFileHande OPTIONAL ????
{ {
PCWSTR LoaderExecutable; PCWSTR LoaderExecutable;
@ -146,8 +146,8 @@ FindNTOSBootLoader( // By handle
if (Type >= BldrTypeMax) if (Type >= BldrTypeMax)
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
if (Version) if (VersionNumber)
*Version = 0; *VersionNumber = 0;
/* Check whether any of the loader executables exist */ /* Check whether any of the loader executables exist */
LoaderExecutable = NtosBootLoaders[Type].LoaderExecutables; LoaderExecutable = NtosBootLoaders[Type].LoaderExecutables;
@ -172,10 +172,10 @@ FindNTOSBootLoader( // By handle
} }
/* Check for loader version if needed */ /* Check for loader version if needed */
if (Version) if (VersionNumber)
{ {
*Version = 0; *VersionNumber = 0;
// TODO: Check for BLDR version ONLY if Version != NULL // TODO: Check for BLDR version!
} }
/* Check whether the loader configuration file exists */ /* Check whether the loader configuration file exists */
@ -340,7 +340,7 @@ static NTSTATUS
OpenIniBootLoaderStore( OpenIniBootLoaderStore(
OUT PVOID* Handle, OUT PVOID* Handle,
IN HANDLE PartitionDirectoryHandle, // OPTIONAL IN HANDLE PartitionDirectoryHandle, // OPTIONAL
IN NTOS_BOOT_LOADER_TYPE Type, IN BOOT_STORE_TYPE Type,
IN BOOLEAN CreateNew) IN BOOLEAN CreateNew)
{ {
NTSTATUS Status; NTSTATUS Status;
@ -733,10 +733,10 @@ Quit:
NTSTATUS NTSTATUS
OpenNTOSBootLoaderStoreByHandle( OpenBootStoreByHandle(
OUT PVOID* Handle, OUT PVOID* Handle,
IN HANDLE PartitionDirectoryHandle, // OPTIONAL IN HANDLE PartitionDirectoryHandle, // OPTIONAL
IN NTOS_BOOT_LOADER_TYPE Type, IN BOOT_STORE_TYPE Type,
IN BOOLEAN CreateNew) IN BOOLEAN CreateNew)
{ {
/* /*
@ -760,10 +760,10 @@ OpenNTOSBootLoaderStoreByHandle(
} }
NTSTATUS NTSTATUS
OpenNTOSBootLoaderStore_UStr( OpenBootStore_UStr(
OUT PVOID* Handle, OUT PVOID* Handle,
IN PUNICODE_STRING SystemPartitionPath, IN PUNICODE_STRING SystemPartitionPath,
IN NTOS_BOOT_LOADER_TYPE Type, IN BOOT_STORE_TYPE Type,
IN BOOLEAN CreateNew) IN BOOLEAN CreateNew)
{ {
NTSTATUS Status; NTSTATUS Status;
@ -803,7 +803,7 @@ OpenNTOSBootLoaderStore_UStr(
return Status; return Status;
} }
Status = OpenNTOSBootLoaderStoreByHandle(Handle, PartitionDirectoryHandle, Type, CreateNew); Status = OpenBootStoreByHandle(Handle, PartitionDirectoryHandle, Type, CreateNew);
/* Done! */ /* Done! */
NtClose(PartitionDirectoryHandle); NtClose(PartitionDirectoryHandle);
@ -811,19 +811,19 @@ OpenNTOSBootLoaderStore_UStr(
} }
NTSTATUS NTSTATUS
OpenNTOSBootLoaderStore( OpenBootStore(
OUT PVOID* Handle, OUT PVOID* Handle,
IN PCWSTR SystemPartition, IN PCWSTR SystemPartition,
IN NTOS_BOOT_LOADER_TYPE Type, IN BOOT_STORE_TYPE Type,
IN BOOLEAN CreateNew) IN BOOLEAN CreateNew)
{ {
UNICODE_STRING SystemPartitionPath; UNICODE_STRING SystemPartitionPath;
RtlInitUnicodeString(&SystemPartitionPath, SystemPartition); RtlInitUnicodeString(&SystemPartitionPath, SystemPartition);
return OpenNTOSBootLoaderStore_UStr(Handle, &SystemPartitionPath, Type, CreateNew); return OpenBootStore_UStr(Handle, &SystemPartitionPath, Type, CreateNew);
} }
NTSTATUS NTSTATUS
CloseNTOSBootLoaderStore( CloseBootStore(
IN PVOID Handle) IN PVOID Handle)
{ {
PBOOT_STORE_CONTEXT BootStore = (PBOOT_STORE_CONTEXT)Handle; PBOOT_STORE_CONTEXT BootStore = (PBOOT_STORE_CONTEXT)Handle;
@ -855,7 +855,7 @@ NTSTATUS
CreateNTOSEntry( CreateNTOSEntry(
IN PBOOT_STORE_INI_CONTEXT BootStore, IN PBOOT_STORE_INI_CONTEXT BootStore,
IN ULONG_PTR BootEntryKey, IN ULONG_PTR BootEntryKey,
IN PNTOS_BOOT_ENTRY BootEntry) IN PBOOT_STORE_ENTRY BootEntry)
{ {
PINICACHESECTION IniSection; PINICACHESECTION IniSection;
PWCHAR Section = (PWCHAR)BootEntryKey; PWCHAR Section = (PWCHAR)BootEntryKey;
@ -867,7 +867,6 @@ CreateNTOSEntry(
/* Create a new section */ /* Create a new section */
IniSection = IniCacheAppendSection(BootStore->IniCache, Section); IniSection = IniCacheAppendSection(BootStore->IniCache, Section);
// if (_wcsicmp(BootEntry->Version, L"Windows2003") == 0)
if (BootEntry->OsOptionsLength >= sizeof(NTOS_OPTIONS) && if (BootEntry->OsOptionsLength >= sizeof(NTOS_OPTIONS) &&
RtlCompareMemory(&BootEntry->OsOptions /* Signature */, RtlCompareMemory(&BootEntry->OsOptions /* Signature */,
NTOS_OPTIONS_SIGNATURE, NTOS_OPTIONS_SIGNATURE,
@ -889,7 +888,6 @@ CreateNTOSEntry(
L"Options", (PWSTR)Options->OsLoadOptions); L"Options", (PWSTR)Options->OsLoadOptions);
} }
else else
// if (_wcsicmp(BootEntry->Version, L"BootSector") == 0)
if (BootEntry->OsOptionsLength >= sizeof(BOOT_SECTOR_OPTIONS) && if (BootEntry->OsOptionsLength >= sizeof(BOOT_SECTOR_OPTIONS) &&
RtlCompareMemory(&BootEntry->OsOptions /* Signature */, RtlCompareMemory(&BootEntry->OsOptions /* Signature */,
BOOT_SECTOR_OPTIONS_SIGNATURE, BOOT_SECTOR_OPTIONS_SIGNATURE,
@ -916,16 +914,18 @@ CreateNTOSEntry(
} }
else else
{ {
DPRINT1("Unsupported BootType '%S'\n", BootEntry->Version); // DPRINT1("Unsupported BootType %lu/'%*.s'\n",
// BootEntry->OsOptionsLength, 8, &BootEntry->OsOptions);
DPRINT1("Unsupported BootType %lu\n", BootEntry->OsOptionsLength);
} }
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
NTSTATUS NTSTATUS
AddNTOSBootEntry( AddBootStoreEntry(
IN PVOID Handle, IN PVOID Handle,
IN PNTOS_BOOT_ENTRY BootEntry, IN PBOOT_STORE_ENTRY BootEntry,
IN ULONG_PTR BootEntryKey) IN ULONG_PTR BootEntryKey)
{ {
PBOOT_STORE_CONTEXT BootStore = (PBOOT_STORE_CONTEXT)Handle; PBOOT_STORE_CONTEXT BootStore = (PBOOT_STORE_CONTEXT)Handle;
@ -949,6 +949,9 @@ AddNTOSBootEntry(
if (BootStore->Type == FreeLdr) if (BootStore->Type == FreeLdr)
{ {
if (BootEntry->Version != FreeLdr)
return STATUS_INVALID_PARAMETER;
return CreateNTOSEntry((PBOOT_STORE_INI_CONTEXT)BootStore, return CreateNTOSEntry((PBOOT_STORE_INI_CONTEXT)BootStore,
BootEntryKey, BootEntry); BootEntryKey, BootEntry);
} }
@ -960,15 +963,19 @@ AddNTOSBootEntry(
ULONG BufferLength; ULONG BufferLength;
PCWSTR InstallName, OsOptions; PCWSTR InstallName, OsOptions;
// ULONG InstallNameLength, OsOptionsLength; // ULONG InstallNameLength, OsOptionsLength;
BOOLEAN IsNameNotQuoted;
if (BootEntry->Version != NtLdr)
return STATUS_INVALID_PARAMETER;
// if (_wcsicmp(BootEntry->Version, L"Windows2003") != 0)
if (BootEntry->OsOptionsLength < sizeof(NTOS_OPTIONS) || if (BootEntry->OsOptionsLength < sizeof(NTOS_OPTIONS) ||
RtlCompareMemory(&BootEntry->OsOptions /* Signature */, RtlCompareMemory(&BootEntry->OsOptions /* Signature */,
NTOS_OPTIONS_SIGNATURE, NTOS_OPTIONS_SIGNATURE,
RTL_FIELD_SIZE(NTOS_OPTIONS, Signature)) != RTL_FIELD_SIZE(NTOS_OPTIONS, Signature)) !=
RTL_FIELD_SIZE(NTOS_OPTIONS, Signature)) RTL_FIELD_SIZE(NTOS_OPTIONS, Signature))
{ {
DPRINT1("Unsupported BootType '%S'\n", BootEntry->Version); // DPRINT1("Unsupported BootType '%S'\n", BootEntry->Version);
DPRINT1("Unsupported BootType %lu\n", BootEntry->OsOptionsLength);
return STATUS_SUCCESS; // STATUS_NOT_SUPPORTED; return STATUS_SUCCESS; // STATUS_NOT_SUPPORTED;
} }
@ -978,7 +985,9 @@ AddNTOSBootEntry(
// if (InstallNameLength == 0) InstallName = NULL; // if (InstallNameLength == 0) InstallName = NULL;
// if (OsOptionsLength == 0) OsOptions = NULL; // if (OsOptionsLength == 0) OsOptions = NULL;
BufferLength = 2 /* Quotes for FriendlyName*/ + wcslen(InstallName); IsNameNotQuoted = (InstallName[0] != L'\"' || InstallName[wcslen(InstallName)-1] != L'\"');
BufferLength = (IsNameNotQuoted ? 2 /* Quotes for FriendlyName*/ : 0) + wcslen(InstallName);
if (OsOptions) if (OsOptions)
BufferLength += 1 /* Space between FriendlyName and options */ + wcslen(OsOptions); BufferLength += 1 /* Space between FriendlyName and options */ + wcslen(OsOptions);
BufferLength++; /* NULL-termination */ BufferLength++; /* NULL-termination */
@ -987,13 +996,14 @@ AddNTOSBootEntry(
if (!Buffer) if (!Buffer)
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
wcscpy(Buffer, L"\""); *Buffer = UNICODE_NULL;
wcscat(Buffer, InstallName); if (IsNameNotQuoted) RtlStringCchCatW(Buffer, BufferLength, L"\"");
wcscat(Buffer, L"\""); RtlStringCchCatW(Buffer, BufferLength, InstallName);
if (IsNameNotQuoted) RtlStringCchCatW(Buffer, BufferLength, L"\"");
if (OsOptions) if (OsOptions)
{ {
wcscat(Buffer, L" "); RtlStringCchCatW(Buffer, BufferLength, L" ");
wcscat(Buffer, OsOptions); RtlStringCchCatW(Buffer, BufferLength, OsOptions);
} }
/* Insert the entry into the "Operating Systems" section */ /* Insert the entry into the "Operating Systems" section */
@ -1011,7 +1021,7 @@ AddNTOSBootEntry(
} }
NTSTATUS NTSTATUS
DeleteNTOSBootEntry( DeleteBootStoreEntry(
IN PVOID Handle, IN PVOID Handle,
IN ULONG_PTR BootEntryKey) IN ULONG_PTR BootEntryKey)
{ {
@ -1045,9 +1055,9 @@ DeleteNTOSBootEntry(
} }
NTSTATUS NTSTATUS
ModifyNTOSBootEntry( ModifyBootStoreEntry(
IN PVOID Handle, IN PVOID Handle,
IN PNTOS_BOOT_ENTRY BootEntry) IN PBOOT_STORE_ENTRY BootEntry)
{ {
PBOOT_STORE_CONTEXT BootStore = (PBOOT_STORE_CONTEXT)Handle; PBOOT_STORE_CONTEXT BootStore = (PBOOT_STORE_CONTEXT)Handle;
@ -1079,10 +1089,10 @@ ModifyNTOSBootEntry(
} }
NTSTATUS NTSTATUS
QueryNTOSBootEntry( QueryBootStoreEntry(
IN PVOID Handle, IN PVOID Handle,
IN ULONG_PTR BootEntryKey, IN ULONG_PTR BootEntryKey,
OUT PNTOS_BOOT_ENTRY BootEntry) // Technically this should be PNTOS_BOOT_ENTRY* OUT PBOOT_STORE_ENTRY BootEntry) // Technically this should be PBOOT_STORE_ENTRY*
{ {
PBOOT_STORE_CONTEXT BootStore = (PBOOT_STORE_CONTEXT)Handle; PBOOT_STORE_CONTEXT BootStore = (PBOOT_STORE_CONTEXT)Handle;
@ -1114,9 +1124,9 @@ QueryNTOSBootEntry(
} }
NTSTATUS NTSTATUS
QueryNTOSBootOptions( QueryBootStoreOptions(
IN PVOID Handle, IN PVOID Handle,
IN OUT PNTOS_BOOT_OPTIONS BootOptions IN OUT PBOOT_STORE_OPTIONS BootOptions
/* , IN PULONG BootOptionsLength */ ) /* , IN PULONG BootOptionsLength */ )
{ {
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
@ -1147,6 +1157,8 @@ QueryNTOSBootOptions(
if (BootStore->Type == FreeLdr) if (BootStore->Type == FreeLdr)
{ {
BootOptions->Version = FreeLdr;
Status = IniCacheGetKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection, Status = IniCacheGetKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection,
L"DefaultOS", (PWCHAR*)&BootOptions->CurrentBootEntryKey); L"DefaultOS", (PWCHAR*)&BootOptions->CurrentBootEntryKey);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
@ -1161,6 +1173,8 @@ QueryNTOSBootOptions(
} }
else if (BootStore->Type == NtLdr) else if (BootStore->Type == NtLdr)
{ {
BootOptions->Version = NtLdr;
Status = IniCacheGetKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection, Status = IniCacheGetKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection,
L"default", (PWCHAR*)&BootOptions->CurrentBootEntryKey); L"default", (PWCHAR*)&BootOptions->CurrentBootEntryKey);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
@ -1178,9 +1192,9 @@ QueryNTOSBootOptions(
} }
NTSTATUS NTSTATUS
SetNTOSBootOptions( SetBootStoreOptions(
IN PVOID Handle, IN PVOID Handle,
IN PNTOS_BOOT_OPTIONS BootOptions, IN PBOOT_STORE_OPTIONS BootOptions,
IN ULONG FieldsToChange) IN ULONG FieldsToChange)
{ {
PBOOT_STORE_CONTEXT BootStore = (PBOOT_STORE_CONTEXT)Handle; PBOOT_STORE_CONTEXT BootStore = (PBOOT_STORE_CONTEXT)Handle;
@ -1208,6 +1222,9 @@ SetNTOSBootOptions(
return STATUS_NOT_SUPPORTED; return STATUS_NOT_SUPPORTED;
} }
if (BootOptions->Version != FreeLdr)
return STATUS_INVALID_PARAMETER;
// //
// TODO: Depending on the flags set in 'FieldsToChange', // TODO: Depending on the flags set in 'FieldsToChange',
// change either one or both these bootloader options. // change either one or both these bootloader options.
@ -1216,7 +1233,7 @@ SetNTOSBootOptions(
NULL, INSERT_LAST, NULL, INSERT_LAST,
L"DefaultOS", (PWCHAR)BootOptions->CurrentBootEntryKey); L"DefaultOS", (PWCHAR)BootOptions->CurrentBootEntryKey);
StringCchPrintfW(TimeoutStr, ARRAYSIZE(TimeoutStr), L"%d", BootOptions->Timeout); RtlStringCchPrintfW(TimeoutStr, ARRAYSIZE(TimeoutStr), L"%d", BootOptions->Timeout);
IniCacheInsertKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection, IniCacheInsertKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection,
NULL, INSERT_LAST, NULL, INSERT_LAST,
L"TimeOut", TimeoutStr); L"TimeOut", TimeoutStr);
@ -1237,9 +1254,9 @@ FreeLdrEnumerateBootEntries(
PINICACHEITERATOR Iterator; PINICACHEITERATOR Iterator;
PINICACHESECTION OsIniSection; PINICACHESECTION OsIniSection;
PWCHAR SectionName, KeyData; PWCHAR SectionName, KeyData;
UCHAR xxBootEntry[FIELD_OFFSET(NTOS_BOOT_ENTRY, OsOptions) + UCHAR xxBootEntry[FIELD_OFFSET(BOOT_STORE_ENTRY, OsOptions) +
max(sizeof(NTOS_OPTIONS), sizeof(BOOT_SECTOR_OPTIONS))]; max(sizeof(NTOS_OPTIONS), sizeof(BOOT_SECTOR_OPTIONS))];
PNTOS_BOOT_ENTRY BootEntry = (PNTOS_BOOT_ENTRY)&xxBootEntry; PBOOT_STORE_ENTRY BootEntry = (PBOOT_STORE_ENTRY)&xxBootEntry;
PWCHAR Buffer; PWCHAR Buffer;
/* Enumerate all the valid installations listed in the "Operating Systems" section */ /* Enumerate all the valid installations listed in the "Operating Systems" section */
@ -1291,7 +1308,7 @@ FreeLdrEnumerateBootEntries(
DPRINT1("Boot entry '%S' in OS section '%S'\n", InstallName, SectionName); DPRINT1("Boot entry '%S' in OS section '%S'\n", InstallName, SectionName);
BootEntry->Version = NULL; BootEntry->Version = FreeLdr;
BootEntry->BootEntryKey = MAKESTRKEY(SectionName); BootEntry->BootEntryKey = MAKESTRKEY(SectionName);
BootEntry->FriendlyName = InstallName; BootEntry->FriendlyName = InstallName;
BootEntry->BootFilePath = NULL; BootEntry->BootFilePath = NULL;
@ -1318,8 +1335,7 @@ FreeLdrEnumerateBootEntries(
/* BootType is Windows2003 */ /* BootType is Windows2003 */
PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions; PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions;
BootEntry->Version = L"Windows2003"; DPRINT1("This is a '%S' boot entry\n", KeyData);
DPRINT1("This is a '%S' boot entry\n", BootEntry->Version);
BootEntry->OsOptionsLength = sizeof(NTOS_OPTIONS); BootEntry->OsOptionsLength = sizeof(NTOS_OPTIONS);
RtlCopyMemory(Options->Signature, RtlCopyMemory(Options->Signature,
@ -1350,8 +1366,7 @@ FreeLdrEnumerateBootEntries(
/* BootType is BootSector */ /* BootType is BootSector */
PBOOT_SECTOR_OPTIONS Options = (PBOOT_SECTOR_OPTIONS)&BootEntry->OsOptions; PBOOT_SECTOR_OPTIONS Options = (PBOOT_SECTOR_OPTIONS)&BootEntry->OsOptions;
BootEntry->Version = L"BootSector"; DPRINT1("This is a '%S' boot entry\n", KeyData);
DPRINT1("This is a '%S' boot entry\n", BootEntry->Version);
BootEntry->OsOptionsLength = sizeof(BOOT_SECTOR_OPTIONS); BootEntry->OsOptionsLength = sizeof(BOOT_SECTOR_OPTIONS);
RtlCopyMemory(Options->Signature, RtlCopyMemory(Options->Signature,
@ -1384,7 +1399,6 @@ FreeLdrEnumerateBootEntries(
else else
{ {
DPRINT1("Unrecognized BootType value '%S'\n", KeyData); DPRINT1("Unrecognized BootType value '%S'\n", KeyData);
// BootEntry->Version = KeyData;
// goto DoEnum; // goto DoEnum;
} }
@ -1416,8 +1430,8 @@ NtLdrEnumerateBootEntries(
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
PINICACHEITERATOR Iterator; PINICACHEITERATOR Iterator;
PWCHAR SectionName, KeyData; PWCHAR SectionName, KeyData;
UCHAR xxBootEntry[FIELD_OFFSET(NTOS_BOOT_ENTRY, OsOptions) + sizeof(NTOS_OPTIONS)]; UCHAR xxBootEntry[FIELD_OFFSET(BOOT_STORE_ENTRY, OsOptions) + sizeof(NTOS_OPTIONS)];
PNTOS_BOOT_ENTRY BootEntry = (PNTOS_BOOT_ENTRY)&xxBootEntry; PBOOT_STORE_ENTRY BootEntry = (PBOOT_STORE_ENTRY)&xxBootEntry;
PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions; PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions;
PWCHAR Buffer; PWCHAR Buffer;
ULONG BufferLength; ULONG BufferLength;
@ -1510,7 +1524,7 @@ NtLdrEnumerateBootEntries(
DPRINT1("Boot entry '%S' in OS section (path) '%S'\n", InstallName, SectionName); DPRINT1("Boot entry '%S' in OS section (path) '%S'\n", InstallName, SectionName);
// SectionName == SystemRoot; // SectionName == SystemRoot;
BootEntry->Version = L"Windows2003"; BootEntry->Version = NtLdr;
BootEntry->BootEntryKey = 0; // FIXME?? BootEntry->BootEntryKey = 0; // FIXME??
BootEntry->FriendlyName = InstallName; BootEntry->FriendlyName = InstallName;
BootEntry->BootFilePath = NULL; BootEntry->BootFilePath = NULL;
@ -1541,7 +1555,7 @@ NtLdrEnumerateBootEntries(
} }
NTSTATUS NTSTATUS
EnumerateNTOSBootEntries( EnumerateBootStoreEntries(
IN PVOID Handle, IN PVOID Handle,
// IN ULONG Flags, // Determine which data to retrieve // IN ULONG Flags, // Determine which data to retrieve
IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine, IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine,

View file

@ -1,8 +1,8 @@
/* /*
* PROJECT: ReactOS Setup Library * PROJECT: ReactOS Setup Library
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
* PURPOSE: NT 5.x family (MS Windows <= 2003, and ReactOS) * PURPOSE: Boot Stores Management functionality, with support for
* boot loaders management. * NT 5.x family (MS Windows <= 2003, and ReactOS) bootloaders.
* COPYRIGHT: Copyright 2017-2018 Hermes Belusca-Maito * COPYRIGHT: Copyright 2017-2018 Hermes Belusca-Maito
*/ */
@ -10,13 +10,13 @@
#pragma once #pragma once
typedef enum _NTOS_BOOT_LOADER_TYPE // _BOOT_STORE_TYPE typedef enum _BOOT_STORE_TYPE
{ {
FreeLdr, // ReactOS' FreeLoader FreeLdr, // ReactOS' FreeLoader
NtLdr, // Windows <= 2k3 NT "FlexBoot" OS Loader NTLDR NtLdr, // Windows <= 2k3 NT "FlexBoot" OS Loader NTLDR
// BootMgr, // Vista+ BCD-oriented BOOTMGR // BootMgr, // Vista+ BCD-oriented BOOTMGR
BldrTypeMax BldrTypeMax
} NTOS_BOOT_LOADER_TYPE; } BOOT_STORE_TYPE;
/* /*
* Some references about EFI boot entries: * Some references about EFI boot entries:
@ -28,25 +28,25 @@ typedef enum _NTOS_BOOT_LOADER_TYPE // _BOOT_STORE_TYPE
* This structure is inspired from the EFI boot entry structure * This structure is inspired from the EFI boot entry structure
* BOOT_OPTIONS that is defined in ndk/iotypes.h . * BOOT_OPTIONS that is defined in ndk/iotypes.h .
*/ */
typedef struct _NTOS_BOOT_OPTIONS // _BOOT_STORE_OPTIONS typedef struct _BOOT_STORE_OPTIONS
{ {
// ULONG Version; ULONG Version; // BOOT_STORE_TYPE value
// ULONG Length; // ULONG Length;
ULONG Timeout; ULONG Timeout;
ULONG_PTR CurrentBootEntryKey; ULONG_PTR CurrentBootEntryKey;
// ULONG_PTR NextBootEntryKey; // ULONG_PTR NextBootEntryKey;
// WCHAR HeadlessRedirection[1]; // WCHAR HeadlessRedirection[1];
} NTOS_BOOT_OPTIONS, *PNTOS_BOOT_OPTIONS; } BOOT_STORE_OPTIONS, *PBOOT_STORE_OPTIONS;
/* /*
* These macros are used to set a value for the BootEntryKey member of a * These macros are used to set a value for the BootEntryKey member of a
* NTOS_BOOT_ENTRY structure, much in the same idea as MAKEINTRESOURCE and * BOOT_STORE_ENTRY structure, much in the same idea as MAKEINTRESOURCE and
* IS_INTRESOURCE macros for Win32 resources. * IS_INTRESOURCE macros for Win32 resources.
* *
* A key consists of either a boot ID number, * A key consists of either a boot ID number, comprised between 0 and
* comprised between 0 and MAX_USHORT == 0xFFFF == 65535, or can be a pointer * MAX_USHORT == 0xFFFF == 65535, or can be a pointer to a human-readable
* to a human-readable string (section name), as in the case of FreeLDR, or * string (section name), as in the case of FreeLDR, or to a GUID, as in the
* to a GUID, as in the case of BOOTMGR. * case of BOOTMGR.
* *
* If IS_INTKEY(BootEntryKey) == TRUE, i.e. the key is <= 65535, this means * If IS_INTKEY(BootEntryKey) == TRUE, i.e. the key is <= 65535, this means
* the key is a boot ID number, otherwise it is typically a pointer to a string. * the key is a boot ID number, otherwise it is typically a pointer to a string.
@ -59,10 +59,9 @@ typedef struct _NTOS_BOOT_OPTIONS // _BOOT_STORE_OPTIONS
* This structure is inspired from the EFI boot entry structures * This structure is inspired from the EFI boot entry structures
* BOOT_ENTRY and FILE_PATH that are defined in ndk/iotypes.h . * BOOT_ENTRY and FILE_PATH that are defined in ndk/iotypes.h .
*/ */
typedef struct _NTOS_BOOT_ENTRY // _BOOT_STORE_ENTRY typedef struct _BOOT_STORE_ENTRY
{ {
// ULONG Version; // Equivalent of the "BootType" in FreeLdr ULONG Version; // BOOT_STORE_TYPE value
PWCHAR Version; // HACK!!!
// ULONG Length; // ULONG Length;
ULONG_PTR BootEntryKey; // Boot entry "key" ULONG_PTR BootEntryKey; // Boot entry "key"
PCWSTR FriendlyName; // Human-readable boot entry description // LoadIdentifier PCWSTR FriendlyName; // Human-readable boot entry description // LoadIdentifier
@ -77,7 +76,7 @@ typedef struct _NTOS_BOOT_ENTRY // _BOOT_STORE_ENTRY
* WCHAR FriendlyName[ANYSIZE_ARRAY]; * WCHAR FriendlyName[ANYSIZE_ARRAY];
* FILE_PATH BootFilePath; * FILE_PATH BootFilePath;
*/ */
} NTOS_BOOT_ENTRY, *PNTOS_BOOT_ENTRY; } BOOT_STORE_ENTRY, *PBOOT_STORE_ENTRY;
/* "NTOS" (aka. ReactOS or MS Windows NT) <= 5.x options */ /* "NTOS" (aka. ReactOS or MS Windows NT) <= 5.x options */
typedef struct _NTOS_OPTIONS typedef struct _NTOS_OPTIONS
@ -85,8 +84,8 @@ typedef struct _NTOS_OPTIONS
UCHAR Signature[8]; // "NTOS_5\0\0" UCHAR Signature[8]; // "NTOS_5\0\0"
// ULONG Version; // ULONG Version;
// ULONG Length; // ULONG Length;
PCWSTR OsLoadPath; // The OS SystemRoot path // OsLoaderFilePath // OsFilePath PCWSTR OsLoadPath; // The OS SystemRoot path // OsLoaderFilePath // OsFilePath
PCWSTR OsLoadOptions; // OsLoadOptions PCWSTR OsLoadOptions; // OsLoadOptions
/* /*
* In packed form, this structure would contain an offset to the 'OsLoadPath' * In packed form, this structure would contain an offset to the 'OsLoadPath'
* string, and the 'OsLoadOptions' member would be: * string, and the 'OsLoadOptions' member would be:
@ -114,79 +113,79 @@ typedef struct _BOOT_SECTOR_OPTIONS
typedef NTSTATUS typedef NTSTATUS
(NTAPI *PENUM_BOOT_ENTRIES_ROUTINE)( (NTAPI *PENUM_BOOT_ENTRIES_ROUTINE)(
IN NTOS_BOOT_LOADER_TYPE Type, IN BOOT_STORE_TYPE Type,
IN PNTOS_BOOT_ENTRY BootEntry, IN PBOOT_STORE_ENTRY BootEntry,
IN PVOID Parameter OPTIONAL); IN PVOID Parameter OPTIONAL);
NTSTATUS NTSTATUS
FindNTOSBootLoader( // By handle FindBootStore( // By handle
IN HANDLE PartitionDirectoryHandle, // OPTIONAL IN HANDLE PartitionDirectoryHandle, // OPTIONAL
IN NTOS_BOOT_LOADER_TYPE Type, IN BOOT_STORE_TYPE Type,
OUT PULONG Version); OUT PULONG VersionNumber OPTIONAL);
NTSTATUS NTSTATUS
OpenNTOSBootLoaderStoreByHandle( OpenBootStoreByHandle(
OUT PVOID* Handle, OUT PVOID* Handle,
IN HANDLE PartitionDirectoryHandle, // OPTIONAL IN HANDLE PartitionDirectoryHandle, // OPTIONAL
IN NTOS_BOOT_LOADER_TYPE Type, IN BOOT_STORE_TYPE Type,
IN BOOLEAN CreateNew); IN BOOLEAN CreateNew);
NTSTATUS NTSTATUS
OpenNTOSBootLoaderStore_UStr( OpenBootStore_UStr(
OUT PVOID* Handle, OUT PVOID* Handle,
IN PUNICODE_STRING SystemPartitionPath, IN PUNICODE_STRING SystemPartitionPath,
IN NTOS_BOOT_LOADER_TYPE Type, IN BOOT_STORE_TYPE Type,
IN BOOLEAN CreateNew); IN BOOLEAN CreateNew);
NTSTATUS NTSTATUS
OpenNTOSBootLoaderStore( OpenBootStore(
OUT PVOID* Handle, OUT PVOID* Handle,
IN PCWSTR SystemPartition, IN PCWSTR SystemPartition,
IN NTOS_BOOT_LOADER_TYPE Type, IN BOOT_STORE_TYPE Type,
IN BOOLEAN CreateNew); IN BOOLEAN CreateNew);
NTSTATUS NTSTATUS
CloseNTOSBootLoaderStore( CloseBootStore(
IN PVOID Handle); IN PVOID Handle);
NTSTATUS NTSTATUS
AddNTOSBootEntry( AddBootStoreEntry(
IN PVOID Handle, IN PVOID Handle,
IN PNTOS_BOOT_ENTRY BootEntry, IN PBOOT_STORE_ENTRY BootEntry,
IN ULONG_PTR BootEntryKey); IN ULONG_PTR BootEntryKey);
NTSTATUS NTSTATUS
DeleteNTOSBootEntry( DeleteBootStoreEntry(
IN PVOID Handle, IN PVOID Handle,
IN ULONG_PTR BootEntryKey); IN ULONG_PTR BootEntryKey);
NTSTATUS NTSTATUS
ModifyNTOSBootEntry( ModifyBootStoreEntry(
IN PVOID Handle, IN PVOID Handle,
IN PNTOS_BOOT_ENTRY BootEntry); IN PBOOT_STORE_ENTRY BootEntry);
NTSTATUS NTSTATUS
QueryNTOSBootEntry( QueryBootStoreEntry(
IN PVOID Handle, IN PVOID Handle,
IN ULONG_PTR BootEntryKey, IN ULONG_PTR BootEntryKey,
OUT PNTOS_BOOT_ENTRY BootEntry); // Technically this should be PNTOS_BOOT_ENTRY* OUT PBOOT_STORE_ENTRY BootEntry); // Technically this should be PBOOT_STORE_ENTRY*
NTSTATUS NTSTATUS
QueryNTOSBootOptions( QueryBootStoreOptions(
IN PVOID Handle, IN PVOID Handle,
IN OUT PNTOS_BOOT_OPTIONS BootOptions IN OUT PBOOT_STORE_OPTIONS BootOptions
/* , IN PULONG BootOptionsLength */ ); /* , IN PULONG BootOptionsLength */ );
NTSTATUS NTSTATUS
SetNTOSBootOptions( SetBootStoreOptions(
IN PVOID Handle, IN PVOID Handle,
IN PNTOS_BOOT_OPTIONS BootOptions, IN PBOOT_STORE_OPTIONS BootOptions,
IN ULONG FieldsToChange); IN ULONG FieldsToChange);
NTSTATUS NTSTATUS
EnumerateNTOSBootEntries( EnumerateBootStoreEntries(
IN PVOID Handle, IN PVOID Handle,
// IN ULONG Flags, // Determine which data to retrieve // IN ULONG Flags, // Determine which data to retrieve
IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine, IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine,

View file

@ -68,8 +68,8 @@ typedef struct _ENUM_INSTALLS_DATA
static NTSTATUS static NTSTATUS
NTAPI NTAPI
EnumerateInstallations( EnumerateInstallations(
IN NTOS_BOOT_LOADER_TYPE Type, IN BOOT_STORE_TYPE Type,
IN PNTOS_BOOT_ENTRY BootEntry, IN PBOOT_STORE_ENTRY BootEntry,
IN PVOID Parameter OPTIONAL) IN PVOID Parameter OPTIONAL)
{ {
PENUM_INSTALLS_DATA Data = (PENUM_INSTALLS_DATA)Parameter; PENUM_INSTALLS_DATA Data = (PENUM_INSTALLS_DATA)Parameter;
@ -95,8 +95,10 @@ EnumerateInstallations(
RTL_FIELD_SIZE(NTOS_OPTIONS, Signature)) RTL_FIELD_SIZE(NTOS_OPTIONS, Signature))
{ {
/* This is not a ReactOS entry */ /* This is not a ReactOS entry */
DPRINT1(" An installation '%S' of unsupported type '%S'\n", // DPRINT1(" An installation '%S' of unsupported type '%S'\n",
BootEntry->FriendlyName, BootEntry->Version ? BootEntry->Version : L"n/a"); // BootEntry->FriendlyName, BootEntry->Version ? BootEntry->Version : L"n/a");
DPRINT1(" An installation '%S' of unsupported type %lu\n",
BootEntry->FriendlyName, BootEntry->OsOptionsLength);
/* Continue the enumeration */ /* Continue the enumeration */
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -641,7 +643,7 @@ FindNTOSInstallations(
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
IO_STATUS_BLOCK IoStatusBlock; IO_STATUS_BLOCK IoStatusBlock;
UNICODE_STRING PartitionRootPath; UNICODE_STRING PartitionRootPath;
NTOS_BOOT_LOADER_TYPE Type; BOOT_STORE_TYPE Type;
PVOID BootStoreHandle; PVOID BootStoreHandle;
ENUM_INSTALLS_DATA Data; ENUM_INSTALLS_DATA Data;
ULONG Version; ULONG Version;
@ -678,7 +680,7 @@ FindNTOSInstallations(
/* Try to see whether we recognize some NT boot loaders */ /* Try to see whether we recognize some NT boot loaders */
for (Type = FreeLdr; Type < BldrTypeMax; ++Type) for (Type = FreeLdr; Type < BldrTypeMax; ++Type)
{ {
Status = FindNTOSBootLoader(PartitionDirectoryHandle, Type, &Version); Status = FindBootStore(PartitionDirectoryHandle, Type, &Version);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
/* The loader does not exist, continue with another one */ /* The loader does not exist, continue with another one */
@ -691,15 +693,15 @@ FindNTOSInstallations(
DPRINT1("Analyse the OS installations for loader type '%d' in disk #%d, partition #%d\n", DPRINT1("Analyse the OS installations for loader type '%d' in disk #%d, partition #%d\n",
Type, DiskNumber, PartitionNumber); Type, DiskNumber, PartitionNumber);
Status = OpenNTOSBootLoaderStoreByHandle(&BootStoreHandle, PartitionDirectoryHandle, Type, FALSE); Status = OpenBootStoreByHandle(&BootStoreHandle, PartitionDirectoryHandle, Type, FALSE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("Could not open the NTOS boot store of type '%d' (Status 0x%08lx), continue with another one...\n", DPRINT1("Could not open the NTOS boot store of type '%d' (Status 0x%08lx), continue with another one...\n",
Type, Status); Type, Status);
continue; continue;
} }
EnumerateNTOSBootEntries(BootStoreHandle, EnumerateInstallations, &Data); EnumerateBootStoreEntries(BootStoreHandle, EnumerateInstallations, &Data);
CloseNTOSBootLoaderStore(BootStoreHandle); CloseBootStore(BootStoreHandle);
} }
/* Close the partition */ /* Close the partition */

View file

@ -131,12 +131,12 @@ CreateFreeLoaderReactOSEntries(
IN PVOID BootStoreHandle, IN PVOID BootStoreHandle,
IN PCWSTR ArcPath) IN PCWSTR ArcPath)
{ {
UCHAR xxBootEntry[FIELD_OFFSET(NTOS_BOOT_ENTRY, OsOptions) + sizeof(NTOS_OPTIONS)]; UCHAR xxBootEntry[FIELD_OFFSET(BOOT_STORE_ENTRY, OsOptions) + sizeof(NTOS_OPTIONS)];
PNTOS_BOOT_ENTRY BootEntry = (PNTOS_BOOT_ENTRY)&xxBootEntry; PBOOT_STORE_ENTRY BootEntry = (PBOOT_STORE_ENTRY)&xxBootEntry;
PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions; PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions;
NTOS_BOOT_OPTIONS BootOptions; BOOT_STORE_OPTIONS BootOptions;
BootEntry->Version = L"Windows2003"; BootEntry->Version = FreeLdr;
BootEntry->BootFilePath = NULL; BootEntry->BootFilePath = NULL;
BootEntry->OsOptionsLength = sizeof(NTOS_OPTIONS); BootEntry->OsOptionsLength = sizeof(NTOS_OPTIONS);
@ -150,20 +150,20 @@ CreateFreeLoaderReactOSEntries(
// BootEntry->BootEntryKey = MAKESTRKEY(L"ReactOS"); // BootEntry->BootEntryKey = MAKESTRKEY(L"ReactOS");
BootEntry->FriendlyName = L"\"ReactOS\""; BootEntry->FriendlyName = L"\"ReactOS\"";
Options->OsLoadOptions = NULL; // L""; Options->OsLoadOptions = NULL; // L"";
AddNTOSBootEntry(BootStoreHandle, BootEntry, MAKESTRKEY(L"ReactOS")); AddBootStoreEntry(BootStoreHandle, BootEntry, MAKESTRKEY(L"ReactOS"));
/* ReactOS_Debug */ /* ReactOS_Debug */
// BootEntry->BootEntryKey = MAKESTRKEY(L"ReactOS_Debug"); // BootEntry->BootEntryKey = MAKESTRKEY(L"ReactOS_Debug");
BootEntry->FriendlyName = L"\"ReactOS (Debug)\""; BootEntry->FriendlyName = L"\"ReactOS (Debug)\"";
Options->OsLoadOptions = L"/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS"; Options->OsLoadOptions = L"/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS";
AddNTOSBootEntry(BootStoreHandle, BootEntry, MAKESTRKEY(L"ReactOS_Debug")); AddBootStoreEntry(BootStoreHandle, BootEntry, MAKESTRKEY(L"ReactOS_Debug"));
#ifdef _WINKD_ #ifdef _WINKD_
/* ReactOS_VBoxDebug */ /* ReactOS_VBoxDebug */
// BootEntry->BootEntryKey = MAKESTRKEY(L"ReactOS_VBoxDebug"); // BootEntry->BootEntryKey = MAKESTRKEY(L"ReactOS_VBoxDebug");
BootEntry->FriendlyName = L"\"ReactOS (VBoxDebug)\""; BootEntry->FriendlyName = L"\"ReactOS (VBoxDebug)\"";
Options->OsLoadOptions = L"/DEBUG /DEBUGPORT=VBOX /SOS"; Options->OsLoadOptions = L"/DEBUG /DEBUGPORT=VBOX /SOS";
AddNTOSBootEntry(BootStoreHandle, BootEntry, MAKESTRKEY(L"ReactOS_VBoxDebug")); AddBootStoreEntry(BootStoreHandle, BootEntry, MAKESTRKEY(L"ReactOS_VBoxDebug"));
#endif #endif
#if DBG #if DBG
#ifndef _WINKD_ #ifndef _WINKD_
@ -171,34 +171,34 @@ CreateFreeLoaderReactOSEntries(
// BootEntry->BootEntryKey = MAKESTRKEY(L"ReactOS_KdSerial"); // BootEntry->BootEntryKey = MAKESTRKEY(L"ReactOS_KdSerial");
BootEntry->FriendlyName = L"\"ReactOS (RosDbg)\""; BootEntry->FriendlyName = L"\"ReactOS (RosDbg)\"";
Options->OsLoadOptions = L"/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS /KDSERIAL"; Options->OsLoadOptions = L"/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS /KDSERIAL";
AddNTOSBootEntry(BootStoreHandle, BootEntry, MAKESTRKEY(L"ReactOS_KdSerial")); AddBootStoreEntry(BootStoreHandle, BootEntry, MAKESTRKEY(L"ReactOS_KdSerial"));
#endif #endif
/* ReactOS_Screen */ /* ReactOS_Screen */
// BootEntry->BootEntryKey = MAKESTRKEY(L"ReactOS_Screen"); // BootEntry->BootEntryKey = MAKESTRKEY(L"ReactOS_Screen");
BootEntry->FriendlyName = L"\"ReactOS (Screen)\""; BootEntry->FriendlyName = L"\"ReactOS (Screen)\"";
Options->OsLoadOptions = L"/DEBUG /DEBUGPORT=SCREEN /SOS"; Options->OsLoadOptions = L"/DEBUG /DEBUGPORT=SCREEN /SOS";
AddNTOSBootEntry(BootStoreHandle, BootEntry, MAKESTRKEY(L"ReactOS_Screen")); AddBootStoreEntry(BootStoreHandle, BootEntry, MAKESTRKEY(L"ReactOS_Screen"));
/* ReactOS_LogFile */ /* ReactOS_LogFile */
// BootEntry->BootEntryKey = MAKESTRKEY(L"ReactOS_LogFile"); // BootEntry->BootEntryKey = MAKESTRKEY(L"ReactOS_LogFile");
BootEntry->FriendlyName = L"\"ReactOS (Log file)\""; BootEntry->FriendlyName = L"\"ReactOS (Log file)\"";
Options->OsLoadOptions = L"/DEBUG /DEBUGPORT=FILE /SOS"; Options->OsLoadOptions = L"/DEBUG /DEBUGPORT=FILE /SOS";
AddNTOSBootEntry(BootStoreHandle, BootEntry, MAKESTRKEY(L"ReactOS_LogFile")); AddBootStoreEntry(BootStoreHandle, BootEntry, MAKESTRKEY(L"ReactOS_LogFile"));
/* ReactOS_Ram */ /* ReactOS_Ram */
// BootEntry->BootEntryKey = MAKESTRKEY(L"ReactOS_Ram"); // BootEntry->BootEntryKey = MAKESTRKEY(L"ReactOS_Ram");
BootEntry->FriendlyName = L"\"ReactOS (RAM Disk)\""; BootEntry->FriendlyName = L"\"ReactOS (RAM Disk)\"";
Options->OsLoadPath = L"ramdisk(0)\\ReactOS"; Options->OsLoadPath = L"ramdisk(0)\\ReactOS";
Options->OsLoadOptions = L"/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS /RDPATH=reactos.img /RDIMAGEOFFSET=32256"; Options->OsLoadOptions = L"/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS /RDPATH=reactos.img /RDIMAGEOFFSET=32256";
AddNTOSBootEntry(BootStoreHandle, BootEntry, MAKESTRKEY(L"ReactOS_Ram")); AddBootStoreEntry(BootStoreHandle, BootEntry, MAKESTRKEY(L"ReactOS_Ram"));
/* ReactOS_EMS */ /* ReactOS_EMS */
// BootEntry->BootEntryKey = MAKESTRKEY(L"ReactOS_EMS"); // BootEntry->BootEntryKey = MAKESTRKEY(L"ReactOS_EMS");
BootEntry->FriendlyName = L"\"ReactOS (Emergency Management Services)\""; BootEntry->FriendlyName = L"\"ReactOS (Emergency Management Services)\"";
Options->OsLoadPath = ArcPath; Options->OsLoadPath = ArcPath;
Options->OsLoadOptions = L"/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS /redirect=com2 /redirectbaudrate=115200"; Options->OsLoadOptions = L"/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS /redirect=com2 /redirectbaudrate=115200";
AddNTOSBootEntry(BootStoreHandle, BootEntry, MAKESTRKEY(L"ReactOS_EMS")); AddBootStoreEntry(BootStoreHandle, BootEntry, MAKESTRKEY(L"ReactOS_EMS"));
#endif #endif
@ -234,7 +234,8 @@ CreateFreeLoaderReactOSEntries(
} }
#endif #endif
SetNTOSBootOptions(BootStoreHandle, &BootOptions, 2 | 1); BootOptions.Version = FreeLdr;
SetBootStoreOptions(BootStoreHandle, &BootOptions, 2 | 1);
} }
static NTSTATUS static NTSTATUS
@ -246,7 +247,7 @@ CreateFreeLoaderIniForReactOS(
PVOID BootStoreHandle; PVOID BootStoreHandle;
/* Initialize the INI file and create the common FreeLdr sections */ /* Initialize the INI file and create the common FreeLdr sections */
Status = OpenNTOSBootLoaderStore(&BootStoreHandle, IniPath, FreeLdr, TRUE); Status = OpenBootStore(&BootStoreHandle, IniPath, FreeLdr, TRUE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
return Status; return Status;
@ -254,7 +255,7 @@ CreateFreeLoaderIniForReactOS(
CreateFreeLoaderReactOSEntries(BootStoreHandle, ArcPath); CreateFreeLoaderReactOSEntries(BootStoreHandle, ArcPath);
/* Close the INI file */ /* Close the INI file */
CloseNTOSBootLoaderStore(BootStoreHandle); CloseBootStore(BootStoreHandle);
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -270,19 +271,19 @@ CreateFreeLoaderIniForReactOSAndBootSector(
{ {
NTSTATUS Status; NTSTATUS Status;
PVOID BootStoreHandle; PVOID BootStoreHandle;
UCHAR xxBootEntry[FIELD_OFFSET(NTOS_BOOT_ENTRY, OsOptions) + sizeof(BOOT_SECTOR_OPTIONS)]; UCHAR xxBootEntry[FIELD_OFFSET(BOOT_STORE_ENTRY, OsOptions) + sizeof(BOOT_SECTOR_OPTIONS)];
PNTOS_BOOT_ENTRY BootEntry = (PNTOS_BOOT_ENTRY)&xxBootEntry; PBOOT_STORE_ENTRY BootEntry = (PBOOT_STORE_ENTRY)&xxBootEntry;
PBOOT_SECTOR_OPTIONS Options = (PBOOT_SECTOR_OPTIONS)&BootEntry->OsOptions; PBOOT_SECTOR_OPTIONS Options = (PBOOT_SECTOR_OPTIONS)&BootEntry->OsOptions;
/* Initialize the INI file and create the common FreeLdr sections */ /* Initialize the INI file and create the common FreeLdr sections */
Status = OpenNTOSBootLoaderStore(&BootStoreHandle, IniPath, FreeLdr, TRUE); Status = OpenBootStore(&BootStoreHandle, IniPath, FreeLdr, TRUE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
return Status; return Status;
/* Add the ReactOS entries */ /* Add the ReactOS entries */
CreateFreeLoaderReactOSEntries(BootStoreHandle, ArcPath); CreateFreeLoaderReactOSEntries(BootStoreHandle, ArcPath);
/**/BootEntry->Version = L"BootSector";/**/ BootEntry->Version = FreeLdr;
BootEntry->BootFilePath = NULL; BootEntry->BootFilePath = NULL;
BootEntry->OsOptionsLength = sizeof(BOOT_SECTOR_OPTIONS); BootEntry->OsOptionsLength = sizeof(BOOT_SECTOR_OPTIONS);
@ -296,10 +297,10 @@ CreateFreeLoaderIniForReactOSAndBootSector(
// BootEntry->BootEntryKey = MAKESTRKEY(Section); // BootEntry->BootEntryKey = MAKESTRKEY(Section);
BootEntry->FriendlyName = Description; BootEntry->FriendlyName = Description;
AddNTOSBootEntry(BootStoreHandle, BootEntry, MAKESTRKEY(Section)); AddBootStoreEntry(BootStoreHandle, BootEntry, MAKESTRKEY(Section));
/* Close the INI file */ /* Close the INI file */
CloseNTOSBootLoaderStore(BootStoreHandle); CloseBootStore(BootStoreHandle);
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -322,8 +323,8 @@ typedef struct _ENUM_REACTOS_ENTRIES_DATA
static NTSTATUS static NTSTATUS
NTAPI NTAPI
EnumerateReactOSEntries( EnumerateReactOSEntries(
IN NTOS_BOOT_LOADER_TYPE Type, IN BOOT_STORE_TYPE Type,
IN PNTOS_BOOT_ENTRY BootEntry, IN PBOOT_STORE_ENTRY BootEntry,
IN PVOID Parameter OPTIONAL) IN PVOID Parameter OPTIONAL)
{ {
PENUM_REACTOS_ENTRIES_DATA Data = (PENUM_REACTOS_ENTRIES_DATA)Parameter; PENUM_REACTOS_ENTRIES_DATA Data = (PENUM_REACTOS_ENTRIES_DATA)Parameter;
@ -340,9 +341,10 @@ EnumerateReactOSEntries(
RTL_FIELD_SIZE(NTOS_OPTIONS, Signature)) RTL_FIELD_SIZE(NTOS_OPTIONS, Signature))
{ {
/* This is not a ReactOS entry */ /* This is not a ReactOS entry */
DPRINT1(" An installation '%S' of unsupported type '%S'\n", // DPRINT1(" An installation '%S' of unsupported type '%S'\n",
BootEntry->FriendlyName, // BootEntry->FriendlyName, BootEntry->Version ? BootEntry->Version : L"n/a");
BootEntry->Version ? BootEntry->Version : L"n/a"); DPRINT1(" An installation '%S' of unsupported type %lu\n",
BootEntry->FriendlyName, BootEntry->OsOptionsLength);
/* Continue the enumeration */ /* Continue the enumeration */
goto SkipThisEntry; goto SkipThisEntry;
} }
@ -403,12 +405,12 @@ UpdateFreeLoaderIni(
NTSTATUS Status; NTSTATUS Status;
PVOID BootStoreHandle; PVOID BootStoreHandle;
ENUM_REACTOS_ENTRIES_DATA Data; ENUM_REACTOS_ENTRIES_DATA Data;
UCHAR xxBootEntry[FIELD_OFFSET(NTOS_BOOT_ENTRY, OsOptions) + sizeof(NTOS_OPTIONS)]; UCHAR xxBootEntry[FIELD_OFFSET(BOOT_STORE_ENTRY, OsOptions) + sizeof(NTOS_OPTIONS)];
PNTOS_BOOT_ENTRY BootEntry = (PNTOS_BOOT_ENTRY)&xxBootEntry; PBOOT_STORE_ENTRY BootEntry = (PBOOT_STORE_ENTRY)&xxBootEntry;
PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions; PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions;
/* Open the INI file */ /* Open the INI file */
Status = OpenNTOSBootLoaderStore(&BootStoreHandle, IniPath, FreeLdr, /*TRUE*/ FALSE); Status = OpenBootStore(&BootStoreHandle, IniPath, FreeLdr, /*TRUE*/ FALSE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
return Status; return Status;
@ -420,10 +422,10 @@ UpdateFreeLoaderIni(
RtlStringCchCopyW(Data.OsName, ARRAYSIZE(Data.OsName), L"\"ReactOS\""); RtlStringCchCopyW(Data.OsName, ARRAYSIZE(Data.OsName), L"\"ReactOS\"");
// //
// FIXME: We temporarily use EnumerateNTOSBootEntries, until // FIXME: We temporarily use EnumerateBootStoreEntries, until
// both QueryNTOSBootEntry and ModifyNTOSBootEntry get implemented. // both QueryBootStoreEntry and ModifyBootStoreEntry get implemented.
// //
Status = EnumerateNTOSBootEntries(BootStoreHandle, EnumerateReactOSEntries, &Data); Status = EnumerateBootStoreEntries(BootStoreHandle, EnumerateReactOSEntries, &Data);
/* Create a new "ReactOS" entry if there is none already existing that suits us */ /* Create a new "ReactOS" entry if there is none already existing that suits us */
if (!Data.UseExistingEntry) if (!Data.UseExistingEntry)
@ -431,7 +433,7 @@ UpdateFreeLoaderIni(
// RtlStringCchPrintfW(Data.SectionName, ARRAYSIZE(Data.SectionName), L"ReactOS_%lu", Data.i); // RtlStringCchPrintfW(Data.SectionName, ARRAYSIZE(Data.SectionName), L"ReactOS_%lu", Data.i);
// RtlStringCchPrintfW(Data.OsName, ARRAYSIZE(Data.OsName), L"\"ReactOS %lu\"", Data.i); // RtlStringCchPrintfW(Data.OsName, ARRAYSIZE(Data.OsName), L"\"ReactOS %lu\"", Data.i);
BootEntry->Version = L"Windows2003"; BootEntry->Version = FreeLdr;
BootEntry->BootFilePath = NULL; BootEntry->BootFilePath = NULL;
BootEntry->OsOptionsLength = sizeof(NTOS_OPTIONS); BootEntry->OsOptionsLength = sizeof(NTOS_OPTIONS);
@ -444,11 +446,11 @@ UpdateFreeLoaderIni(
// BootEntry->BootEntryKey = MAKESTRKEY(Data.SectionName); // BootEntry->BootEntryKey = MAKESTRKEY(Data.SectionName);
BootEntry->FriendlyName = Data.OsName; BootEntry->FriendlyName = Data.OsName;
Options->OsLoadOptions = NULL; // L""; Options->OsLoadOptions = NULL; // L"";
AddNTOSBootEntry(BootStoreHandle, BootEntry, MAKESTRKEY(Data.SectionName)); AddBootStoreEntry(BootStoreHandle, BootEntry, MAKESTRKEY(Data.SectionName));
} }
/* Close the INI file */ /* Close the INI file */
CloseNTOSBootLoaderStore(BootStoreHandle); CloseBootStore(BootStoreHandle);
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -464,12 +466,12 @@ UpdateBootIni(
ENUM_REACTOS_ENTRIES_DATA Data; ENUM_REACTOS_ENTRIES_DATA Data;
// NOTE: Technically it would be "BootSector"... // NOTE: Technically it would be "BootSector"...
UCHAR xxBootEntry[FIELD_OFFSET(NTOS_BOOT_ENTRY, OsOptions) + sizeof(NTOS_OPTIONS)]; UCHAR xxBootEntry[FIELD_OFFSET(BOOT_STORE_ENTRY, OsOptions) + sizeof(NTOS_OPTIONS)];
PNTOS_BOOT_ENTRY BootEntry = (PNTOS_BOOT_ENTRY)&xxBootEntry; PBOOT_STORE_ENTRY BootEntry = (PBOOT_STORE_ENTRY)&xxBootEntry;
PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions; PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions;
/* Open the INI file */ /* Open the INI file */
Status = OpenNTOSBootLoaderStore(&BootStoreHandle, IniPath, NtLdr, FALSE); Status = OpenBootStore(&BootStoreHandle, IniPath, NtLdr, FALSE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
return Status; return Status;
@ -481,16 +483,16 @@ UpdateBootIni(
RtlStringCchCopyW(Data.OsName, ARRAYSIZE(Data.OsName), L"\"ReactOS\""); RtlStringCchCopyW(Data.OsName, ARRAYSIZE(Data.OsName), L"\"ReactOS\"");
// //
// FIXME: We temporarily use EnumerateNTOSBootEntries, until // FIXME: We temporarily use EnumerateBootStoreEntries, until
// both QueryNTOSBootEntry and ModifyNTOSBootEntry get implemented. // both QueryBootStoreEntry and ModifyBootStoreEntry get implemented.
// //
Status = EnumerateNTOSBootEntries(BootStoreHandle, EnumerateReactOSEntries, &Data); Status = EnumerateBootStoreEntries(BootStoreHandle, EnumerateReactOSEntries, &Data);
/* If either the key was not found, or contains something else, add a new one */ /* If either the key was not found, or contains something else, add a new one */
if (!Data.UseExistingEntry /* || if (!Data.UseExistingEntry /* ||
( (Status == STATUS_NO_MORE_ENTRIES) && wcscmp(Data.OsName, EntryValue) ) */) ( (Status == STATUS_NO_MORE_ENTRIES) && wcscmp(Data.OsName, EntryValue) ) */)
{ {
BootEntry->Version = L"Windows2003"; // NOTE: See remark above BootEntry->Version = NtLdr;
BootEntry->BootFilePath = NULL; BootEntry->BootFilePath = NULL;
BootEntry->OsOptionsLength = sizeof(NTOS_OPTIONS); BootEntry->OsOptionsLength = sizeof(NTOS_OPTIONS);
@ -504,11 +506,11 @@ UpdateBootIni(
// BootEntry->FriendlyName = Data.OsName; // BootEntry->FriendlyName = Data.OsName;
BootEntry->FriendlyName = EntryValue; BootEntry->FriendlyName = EntryValue;
Options->OsLoadOptions = NULL; // L""; Options->OsLoadOptions = NULL; // L"";
AddNTOSBootEntry(BootStoreHandle, BootEntry, MAKESTRKEY(0 /*Data.SectionName*/)); AddBootStoreEntry(BootStoreHandle, BootEntry, MAKESTRKEY(0 /*Data.SectionName*/));
} }
/* Close the INI file */ /* Close the INI file */
CloseNTOSBootLoaderStore(BootStoreHandle); CloseBootStore(BootStoreHandle);
return STATUS_SUCCESS; // Status; return STATUS_SUCCESS; // Status;
} }
@ -1804,8 +1806,8 @@ InstallFatBootcodeToPartition(
/* Check for NT and other bootloaders */ /* Check for NT and other bootloaders */
// FIXME: Check for Vista+ bootloader! // FIXME: Check for Vista+ bootloader!
/*** Status = FindNTOSBootLoader(PartitionHandle, NtLdr, &Version); ***/ /*** Status = FindBootStore(PartitionHandle, NtLdr, &Version); ***/
/*** Status = FindNTOSBootLoader(PartitionHandle, BootMgr, &Version); ***/ /*** Status = FindBootStore(PartitionHandle, BootMgr, &Version); ***/
if (DoesFileExist_2(SystemRootPath->Buffer, L"NTLDR") == TRUE || if (DoesFileExist_2(SystemRootPath->Buffer, L"NTLDR") == TRUE ||
DoesFileExist_2(SystemRootPath->Buffer, L"BOOT.INI") == TRUE) DoesFileExist_2(SystemRootPath->Buffer, L"BOOT.INI") == TRUE)
{ {