ReactOS 0.4.15-dev-7842-g558ab78
bldrsup.c File Reference
#include "precomp.h"
#include "bldrsup.h"
#include "filesup.h"
#include "inicache.h"
#include <debug.h>
Include dependency graph for bldrsup.c:

Go to the source code of this file.

Classes

struct  _NTOS_BOOT_LOADER_FILES
 
struct  _BOOT_STORE_CONTEXT
 
struct  _BOOT_STORE_INI_CONTEXT
 
struct  _BOOT_STORE_BCDREG_CONTEXT
 

Macros

#define NDEBUG
 

Typedefs

typedef NTSTATUS(* POPEN_BOOT_STORE) (OUT PVOID *Handle, IN HANDLE PartitionDirectoryHandle, IN BOOT_STORE_TYPE Type, IN BOOLEAN CreateNew)
 
typedef NTSTATUS(* PCLOSE_BOOT_STORE) (IN PVOID Handle)
 
typedef NTSTATUS(* PENUM_BOOT_STORE_ENTRIES) (IN PVOID Handle, IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine, IN PVOID Parameter OPTIONAL)
 
typedef struct _NTOS_BOOT_LOADER_FILES NTOS_BOOT_LOADER_FILES
 
typedef struct _NTOS_BOOT_LOADER_FILESPNTOS_BOOT_LOADER_FILES
 
typedef struct _BOOT_STORE_CONTEXT BOOT_STORE_CONTEXT
 
typedef struct _BOOT_STORE_CONTEXTPBOOT_STORE_CONTEXT
 
typedef struct _BOOT_STORE_INI_CONTEXT BOOT_STORE_INI_CONTEXT
 
typedef struct _BOOT_STORE_INI_CONTEXTPBOOT_STORE_INI_CONTEXT
 
typedef struct _BOOT_STORE_BCDREG_CONTEXT BOOT_STORE_BCDREG_CONTEXT
 
typedef struct _BOOT_STORE_BCDREG_CONTEXTPBOOT_STORE_BCDREG_CONTEXT
 

Functions

static NTSTATUS OpenIniBootLoaderStore (OUT PVOID *Handle, IN HANDLE PartitionDirectoryHandle, IN BOOT_STORE_TYPE Type, IN BOOLEAN CreateNew)
 
static NTSTATUS CloseIniBootLoaderStore (IN PVOID Handle)
 
static NTSTATUS FreeLdrEnumerateBootEntries (IN PBOOT_STORE_INI_CONTEXT BootStore, IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine, IN PVOID Parameter OPTIONAL)
 
static NTSTATUS NtLdrEnumerateBootEntries (IN PBOOT_STORE_INI_CONTEXT BootStore, IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine, IN PVOID Parameter OPTIONAL)
 
 C_ASSERT (_countof(NtosBootLoaders)==BldrTypeMax)
 
NTSTATUS FindBootStore (IN HANDLE PartitionDirectoryHandle, IN BOOT_STORE_TYPE Type, OUT PULONG VersionNumber OPTIONAL)
 
static VOID CreateCommonFreeLdrSections (IN OUT PBOOT_STORE_INI_CONTEXT BootStore)
 
static NTSTATUS UnprotectBootIni (IN HANDLE FileHandle, OUT PULONG Attributes)
 
static NTSTATUS ProtectBootIni (IN HANDLE FileHandle, IN ULONG Attributes)
 
NTSTATUS OpenBootStoreByHandle (OUT PVOID *Handle, IN HANDLE PartitionDirectoryHandle, IN BOOT_STORE_TYPE Type, IN BOOLEAN CreateNew)
 
NTSTATUS OpenBootStore_UStr (OUT PVOID *Handle, IN PUNICODE_STRING SystemPartitionPath, IN BOOT_STORE_TYPE Type, IN BOOLEAN CreateNew)
 
NTSTATUS OpenBootStore (OUT PVOID *Handle, IN PCWSTR SystemPartition, IN BOOT_STORE_TYPE Type, IN BOOLEAN CreateNew)
 
NTSTATUS CloseBootStore (IN PVOID Handle)
 
static NTSTATUS CreateNTOSEntry (IN PBOOT_STORE_INI_CONTEXT BootStore, IN ULONG_PTR BootEntryKey, IN PBOOT_STORE_ENTRY BootEntry)
 
NTSTATUS AddBootStoreEntry (IN PVOID Handle, IN PBOOT_STORE_ENTRY BootEntry, IN ULONG_PTR BootEntryKey)
 
NTSTATUS DeleteBootStoreEntry (IN PVOID Handle, IN ULONG_PTR BootEntryKey)
 
NTSTATUS ModifyBootStoreEntry (IN PVOID Handle, IN PBOOT_STORE_ENTRY BootEntry)
 
NTSTATUS QueryBootStoreEntry (IN PVOID Handle, IN ULONG_PTR BootEntryKey, OUT PBOOT_STORE_ENTRY BootEntry)
 
NTSTATUS QueryBootStoreOptions (IN PVOID Handle, IN OUT PBOOT_STORE_OPTIONS BootOptions)
 
NTSTATUS SetBootStoreOptions (IN PVOID Handle, IN PBOOT_STORE_OPTIONS BootOptions, IN ULONG FieldsToChange)
 
NTSTATUS EnumerateBootStoreEntries (IN PVOID Handle, IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine, IN PVOID Parameter OPTIONAL)
 

Variables

NTOS_BOOT_LOADER_FILES NtosBootLoaders []
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 19 of file bldrsup.c.

Typedef Documentation

◆ BOOT_STORE_BCDREG_CONTEXT

◆ BOOT_STORE_CONTEXT

◆ BOOT_STORE_INI_CONTEXT

◆ NTOS_BOOT_LOADER_FILES

◆ PBOOT_STORE_BCDREG_CONTEXT

◆ PBOOT_STORE_CONTEXT

◆ PBOOT_STORE_INI_CONTEXT

◆ PCLOSE_BOOT_STORE

typedef NTSTATUS(* PCLOSE_BOOT_STORE) (IN PVOID Handle)

Definition at line 32 of file bldrsup.c.

◆ PENUM_BOOT_STORE_ENTRIES

typedef NTSTATUS(* PENUM_BOOT_STORE_ENTRIES) (IN PVOID Handle, IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine, IN PVOID Parameter OPTIONAL)

Definition at line 36 of file bldrsup.c.

◆ PNTOS_BOOT_LOADER_FILES

◆ POPEN_BOOT_STORE

typedef NTSTATUS(* POPEN_BOOT_STORE) (OUT PVOID *Handle, IN HANDLE PartitionDirectoryHandle, IN BOOT_STORE_TYPE Type, IN BOOLEAN CreateNew)

Definition at line 25 of file bldrsup.c.

Function Documentation

◆ AddBootStoreEntry()

NTSTATUS AddBootStoreEntry ( IN PVOID  Handle,
IN PBOOT_STORE_ENTRY  BootEntry,
IN ULONG_PTR  BootEntryKey 
)

Definition at line 854 of file bldrsup.c.

858{
860
861 if (!BootStore || !BootEntry)
863
864 /*
865 * NOTE: Currently we open & map the loader configuration file without
866 * further tests. It's OK as long as we only deal with FreeLdr's freeldr.ini
867 * and NTLDR's boot.ini files. But as soon as we'll implement support for
868 * BOOTMGR detection, the "configuration file" will be the BCD registry
869 * hive and then, we'll have instead to mount the hive & open it.
870 */
871
872 //
873 // FIXME!!
874 //
875
876 // if (BootStore->Type >= BldrTypeMax || NtosBootLoaders[BootStore->Type].Type >= BldrTypeMax)
877
878 if (BootStore->Type == FreeLdr)
879 {
880 if (BootEntry->Version != FreeLdr)
882
884 BootEntryKey, BootEntry);
885 }
886 else
887 if (BootStore->Type == NtLdr)
888 {
889 PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions;
892 PCWSTR InstallName, OsOptions;
893 // ULONG InstallNameLength, OsOptionsLength;
894 BOOLEAN IsNameNotQuoted;
895
896 if (BootEntry->Version != NtLdr)
898
899 if (BootEntry->OsOptionsLength < sizeof(NTOS_OPTIONS) ||
900 RtlCompareMemory(&BootEntry->OsOptions /* Signature */,
904 {
905 // DPRINT1("Unsupported BootType '%S'\n", BootEntry->Version);
906 DPRINT1("Unsupported BootType %lu\n", BootEntry->OsOptionsLength);
907 return STATUS_SUCCESS; // STATUS_NOT_SUPPORTED;
908 }
909
910 InstallName = BootEntry->FriendlyName;
911 OsOptions = Options->OsLoadOptions;
912
913 // if (InstallNameLength == 0) InstallName = NULL;
914 // if (OsOptionsLength == 0) OsOptions = NULL;
915
916 IsNameNotQuoted = (InstallName[0] != L'\"' || InstallName[wcslen(InstallName)-1] != L'\"');
917
918 BufferLength = (IsNameNotQuoted ? 2 /* Quotes for FriendlyName*/ : 0) + wcslen(InstallName);
919 if (OsOptions)
920 BufferLength += 1 /* Space between FriendlyName and options */ + wcslen(OsOptions);
921 BufferLength++; /* NULL-termination */
922
924 if (!Buffer)
926
928 if (IsNameNotQuoted) RtlStringCchCatW(Buffer, BufferLength, L"\"");
929 RtlStringCchCatW(Buffer, BufferLength, InstallName);
930 if (IsNameNotQuoted) RtlStringCchCatW(Buffer, BufferLength, L"\"");
931 if (OsOptions)
932 {
935 }
936
937 /* Insert the entry into the "Operating Systems" section */
938 IniCacheInsertKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OsIniSection, NULL, INSERT_LAST,
939 (PWSTR)Options->OsLoadPath, Buffer);
940
942 return STATUS_SUCCESS;
943 }
944 else
945 {
946 DPRINT1("Loader type %d is currently unsupported!\n", BootStore->Type);
948 }
949}
unsigned char BOOLEAN
HANDLE ProcessHeap
Definition: servman.c:15
#define DPRINT1
Definition: precomp.h:8
static NTSTATUS CreateNTOSEntry(IN PBOOT_STORE_INI_CONTEXT BootStore, IN ULONG_PTR BootEntryKey, IN PBOOT_STORE_ENTRY BootEntry)
Definition: bldrsup.c:783
struct _BOOT_STORE_CONTEXT * PBOOT_STORE_CONTEXT
@ NtLdr
Definition: bldrsup.h:16
@ FreeLdr
Definition: bldrsup.h:15
struct _NTOS_OPTIONS * PNTOS_OPTIONS
#define NTOS_OPTIONS_SIGNATURE
Definition: bldrsup.h:98
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
static const WCHAR Signature[]
Definition: parser.c:141
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
ULONG Handle
Definition: gdb_input.c:15
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
PINICACHEKEY IniCacheInsertKey(PINICACHESECTION Section, PINICACHEKEY AnchorKey, INSERTION_TYPE InsertionType, PWCHAR Name, PWCHAR Data)
Definition: inicache.c:826
@ INSERT_LAST
Definition: inicache.h:51
#define RTL_FIELD_SIZE(type, field)
Definition: kdb_expr.c:86
if(dx< 0)
Definition: linetemp.h:194
#define UNICODE_NULL
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
NTSTRSAFEAPI RtlStringCchCatW(_Inout_updates_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
Definition: ntstrsafe.h:601
#define L(x)
Definition: ntvdm.h:50
#define STATUS_SUCCESS
Definition: shellext.h:65
BOOT_STORE_TYPE Type
Definition: bldrsup.c:59
uint16_t * PWSTR
Definition: typedefs.h:56
const uint16_t * PCWSTR
Definition: typedefs.h:57
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
Definition: wdfdevice.h:3534
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by CreateFreeLoaderIniForReactOSAndBootSector(), CreateFreeLoaderReactOSEntries(), UpdateBootIni(), and UpdateFreeLoaderIni().

◆ C_ASSERT()

◆ CloseBootStore()

NTSTATUS CloseBootStore ( IN PVOID  Handle)

Definition at line 754 of file bldrsup.c.

756{
758
759 if (!BootStore)
761
762 /*
763 * NOTE: Currently we open & map the loader configuration file without
764 * further tests. It's OK as long as we only deal with FreeLdr's freeldr.ini
765 * and NTLDR's boot.ini files. But as soon as we'll implement support for
766 * BOOTMGR detection, the "configuration file" will be the BCD registry
767 * hive and then, we'll have instead to mount the hive & open it.
768 */
769
770 if (BootStore->Type >= BldrTypeMax || NtosBootLoaders[BootStore->Type].Type >= BldrTypeMax)
771 {
772 DPRINT1("Loader type %d is currently unsupported!\n", NtosBootLoaders[BootStore->Type].Type);
774 }
775
776 return NtosBootLoaders[BootStore->Type].CloseBootStore(Handle /* BootStore */);
777}
NTOS_BOOT_LOADER_FILES NtosBootLoaders[]
Definition: bldrsup.c:122
@ BldrTypeMax
Definition: bldrsup.h:18
PCLOSE_BOOT_STORE CloseBootStore
Definition: bldrsup.c:49
BOOT_STORE_TYPE Type
Definition: bldrsup.c:45

Referenced by CreateFreeLoaderIniForReactOS(), CreateFreeLoaderIniForReactOSAndBootSector(), FindNTOSInstallations(), UpdateBootIni(), and UpdateFreeLoaderIni().

◆ CloseIniBootLoaderStore()

static NTSTATUS CloseIniBootLoaderStore ( IN PVOID  Handle)
static

Definition at line 603 of file bldrsup.c.

605{
609
610 // if (!BootStore)
611 // return STATUS_INVALID_PARAMETER;
612
613 if (BootStore->SectionHandle)
614 {
615 /*
616 * The INI file was already opened because it already existed,
617 * thus (in the case of NTLDR's boot.ini), unprotect it.
618 */
619 if (BootStore->Header.Type == NtLdr)
620 {
621 Status = UnprotectBootIni(BootStore->FileHandle, &FileAttribute);
622 if (!NT_SUCCESS(Status))
623 {
624 DPRINT1("Could not unprotect BOOT.INI ! (Status 0x%08lx)\n", Status);
625 goto Quit;
626 }
627 }
628 }
629
630 IniCacheSaveByHandle(BootStore->IniCache, BootStore->FileHandle);
631
632 /* In the case of NTLDR's boot.ini, re-protect the INI file */
633 if (BootStore->Header.Type == NtLdr)
634 {
636 Status = ProtectBootIni(BootStore->FileHandle, FileAttribute);
637 }
638
639Quit:
640 IniCacheDestroy(BootStore->IniCache);
641
642 if (BootStore->SectionHandle)
643 {
644 /* Finally, unmap and close the file */
645 UnMapAndCloseFile(BootStore->FileHandle,
646 BootStore->SectionHandle,
647 BootStore->ViewBase);
648 }
649 else // if (BootStore->FileHandle)
650 {
651 /* Just close the file we have opened for creation */
652 NtClose(BootStore->FileHandle);
653 }
654
655 /* Finally, free the boot store structure */
656 RtlFreeHeap(ProcessHeap, 0, BootStore);
657
658 // TODO: Use a correct Status based on the return values of the previous functions...
659 return STATUS_SUCCESS;
660}
LONG NTSTATUS
Definition: precomp.h:26
static NTSTATUS UnprotectBootIni(IN HANDLE FileHandle, OUT PULONG Attributes)
Definition: bldrsup.c:531
static NTSTATUS ProtectBootIni(IN HANDLE FileHandle, IN ULONG Attributes)
Definition: bldrsup.c:570
struct _BOOT_STORE_INI_CONTEXT * PBOOT_STORE_INI_CONTEXT
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define UnMapAndCloseFile(FileHandle, SectionHandle, BaseAddress)
Definition: filesup.h:108
Status
Definition: gdiplustypes.h:25
NTSTATUS IniCacheSaveByHandle(PINICACHE Cache, HANDLE FileHandle)
Definition: inicache.c:948
VOID IniCacheDestroy(PINICACHE Cache)
Definition: inicache.c:666
FileAttribute
Definition: scrrun.idl:68
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
#define FILE_ATTRIBUTE_SYSTEM
Definition: nt_native.h:704
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
BOOT_STORE_CONTEXT Header
Definition: bldrsup.c:68
PINICACHE IniCache
Definition: bldrsup.c:81

◆ CreateCommonFreeLdrSections()

static VOID CreateCommonFreeLdrSections ( IN OUT PBOOT_STORE_INI_CONTEXT  BootStore)
static

Definition at line 208 of file bldrsup.c.

210{
211 PINICACHESECTION IniSection;
212
213 /*
214 * Cache the "FREELOADER" section for our future usage.
215 */
216
217 /* Get the "FREELOADER" section */
218 IniSection = IniCacheGetSection(BootStore->IniCache, L"FREELOADER");
219 if (!IniSection)
220 {
221 /* It does not exist yet, so create it */
222 IniSection = IniCacheAppendSection(BootStore->IniCache, L"FREELOADER");
223 if (!IniSection)
224 {
225 DPRINT1("CreateCommonFreeLdrSections: Failed to create 'FREELOADER' section!\n");
226 }
227 }
228
229 BootStore->OptionsIniSection = IniSection;
230
231 /* TimeOut */
232 IniCacheInsertKey(BootStore->OptionsIniSection, NULL, INSERT_LAST,
233 L"TimeOut", L"0");
234
235 /* Create "Display" section */
236 IniSection = IniCacheAppendSection(BootStore->IniCache, L"Display");
237
238 /* TitleText */
240 L"TitleText", L"ReactOS Boot Manager");
241
242 /* MinimalUI */
244 L"MinimalUI", L"Yes");
245
246 /*
247 * Cache the "Operating Systems" section for our future usage.
248 */
249
250 /* Get the "Operating Systems" section */
251 IniSection = IniCacheGetSection(BootStore->IniCache, L"Operating Systems");
252 if (!IniSection)
253 {
254 /* It does not exist yet, so create it */
255 IniSection = IniCacheAppendSection(BootStore->IniCache, L"Operating Systems");
256 if (!IniSection)
257 {
258 DPRINT1("CreateCommonFreeLdrSections: Failed to create 'Operating Systems' section!\n");
259 }
260 }
261
262 BootStore->OsIniSection = IniSection;
263}
PINICACHESECTION IniCacheAppendSection(PINICACHE Cache, PWCHAR Name)
Definition: inicache.c:1088
PINICACHESECTION IniCacheGetSection(PINICACHE Cache, PWCHAR Name)
Definition: inicache.c:683

Referenced by OpenIniBootLoaderStore().

◆ CreateNTOSEntry()

static NTSTATUS CreateNTOSEntry ( IN PBOOT_STORE_INI_CONTEXT  BootStore,
IN ULONG_PTR  BootEntryKey,
IN PBOOT_STORE_ENTRY  BootEntry 
)
static

Definition at line 783 of file bldrsup.c.

787{
788 PINICACHESECTION IniSection;
789 PWCHAR Section = (PWCHAR)BootEntryKey;
790
791 /* Insert the entry into the "Operating Systems" section */
792 IniCacheInsertKey(BootStore->OsIniSection, NULL, INSERT_LAST,
793 Section, (PWSTR)BootEntry->FriendlyName);
794
795 /* Create a new section */
796 IniSection = IniCacheAppendSection(BootStore->IniCache, Section);
797
798 if (BootEntry->OsOptionsLength >= sizeof(NTOS_OPTIONS) &&
799 RtlCompareMemory(&BootEntry->OsOptions /* Signature */,
803 {
804 PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions;
805
806 /* BootType */
808 L"BootType", L"Windows2003");
809
810 /* SystemPath */
812 L"SystemPath", (PWSTR)Options->OsLoadPath);
813
814 /* Options */
816 L"Options", (PWSTR)Options->OsLoadOptions);
817 }
818 else
819 if (BootEntry->OsOptionsLength >= sizeof(BOOT_SECTOR_OPTIONS) &&
820 RtlCompareMemory(&BootEntry->OsOptions /* Signature */,
824 {
825 PBOOT_SECTOR_OPTIONS Options = (PBOOT_SECTOR_OPTIONS)&BootEntry->OsOptions;
826
827 /* BootType */
829 L"BootType", L"BootSector");
830
831 /* BootDrive */
833 L"BootDrive", (PWSTR)Options->Drive);
834
835 /* BootPartition */
837 L"BootPartition", (PWSTR)Options->Partition);
838
839 /* BootSector */
841 L"BootSectorFile", (PWSTR)Options->BootSectorFileName);
842 }
843 else
844 {
845 // DPRINT1("Unsupported BootType %lu/'%*.s'\n",
846 // BootEntry->OsOptionsLength, 8, &BootEntry->OsOptions);
847 DPRINT1("Unsupported BootType %lu\n", BootEntry->OsOptionsLength);
848 }
849
850 return STATUS_SUCCESS;
851}
struct _BOOT_SECTOR_OPTIONS * PBOOT_SECTOR_OPTIONS
#define BOOT_SECTOR_OPTIONS_SIGNATURE
Definition: bldrsup.h:111

Referenced by AddBootStoreEntry().

◆ DeleteBootStoreEntry()

NTSTATUS DeleteBootStoreEntry ( IN PVOID  Handle,
IN ULONG_PTR  BootEntryKey 
)

Definition at line 952 of file bldrsup.c.

955{
957
958 if (!BootStore)
960
961 /*
962 * NOTE: Currently we open & map the loader configuration file without
963 * further tests. It's OK as long as we only deal with FreeLdr's freeldr.ini
964 * and NTLDR's boot.ini files. But as soon as we'll implement support for
965 * BOOTMGR detection, the "configuration file" will be the BCD registry
966 * hive and then, we'll have instead to mount the hive & open it.
967 */
968
969 //
970 // FIXME!!
971 //
972
973 // if (BootStore->Type >= BldrTypeMax || NtosBootLoaders[BootStore->Type].Type >= BldrTypeMax)
974 if (BootStore->Type != FreeLdr)
975 {
976 DPRINT1("Loader type %d is currently unsupported!\n", NtosBootLoaders[BootStore->Type].Type);
978 }
979
980 // FIXME! This function needs my INI library rewrite to be implemented!!
983}
#define UNIMPLEMENTED
Definition: debug.h:115
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239

◆ EnumerateBootStoreEntries()

NTSTATUS EnumerateBootStoreEntries ( IN PVOID  Handle,
IN PENUM_BOOT_ENTRIES_ROUTINE  EnumBootEntriesRoutine,
IN PVOID Parameter  OPTIONAL 
)

Definition at line 1486 of file bldrsup.c.

1491{
1493
1494 if (!BootStore)
1496
1497 if (BootStore->Type >= BldrTypeMax || NtosBootLoaders[BootStore->Type].Type >= BldrTypeMax)
1498 {
1499 DPRINT1("Loader type %d is currently unsupported!\n", NtosBootLoaders[BootStore->Type].Type);
1500 return STATUS_SUCCESS;
1501 // return STATUS_INVALID_PARAMETER;
1502 }
1503
1504 return NtosBootLoaders[BootStore->Type].EnumBootStoreEntries(
1505 (PBOOT_STORE_INI_CONTEXT)BootStore, // Flags,
1506 EnumBootEntriesRoutine, Parameter);
1507}
PENUM_BOOT_STORE_ENTRIES EnumBootStoreEntries
Definition: bldrsup.c:50
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:323

Referenced by FindNTOSInstallations(), UpdateBootIni(), and UpdateFreeLoaderIni().

◆ FindBootStore()

NTSTATUS FindBootStore ( IN HANDLE  PartitionDirectoryHandle,
IN BOOT_STORE_TYPE  Type,
OUT PULONG VersionNumber  OPTIONAL 
)

Definition at line 137 of file bldrsup.c.

142{
143 PCWSTR LoaderExecutable;
144 // UINT i;
145
146 if (Type >= BldrTypeMax)
148
149 if (VersionNumber)
150 *VersionNumber = 0;
151
152 /* Check whether any of the loader executables exist */
153 LoaderExecutable = NtosBootLoaders[Type].LoaderExecutables;
154 while (*LoaderExecutable)
155 {
156 if (DoesFileExist(PartitionDirectoryHandle, LoaderExecutable))
157 {
158 /* A loader was found, stop there */
159 DPRINT("Found loader executable '%S'\n", LoaderExecutable);
160 break;
161 }
162
163 /* The loader does not exist, continue with another one */
164 DPRINT("Loader executable '%S' does not exist, continue with another one...\n", LoaderExecutable);
165 LoaderExecutable += wcslen(LoaderExecutable) + 1;
166 }
167 if (!*LoaderExecutable)
168 {
169 /* No loader was found */
170 DPRINT("No loader executable was found\n");
171 return STATUS_NOT_FOUND;
172 }
173
174 /* Check for loader version if needed */
175 if (VersionNumber)
176 {
177 *VersionNumber = 0;
178 // TODO: Check for BLDR version!
179 }
180
181 /* Check whether the loader configuration file exists */
182 if (!DoesFileExist(PartitionDirectoryHandle, NtosBootLoaders[Type].LoaderConfigurationFile))
183 {
184 /* The loader does not exist, continue with another one */
185 // FIXME: Consider it might be optional??
186 DPRINT1("Loader configuration file '%S' does not exist\n", NtosBootLoaders[Type].LoaderConfigurationFile);
187 return STATUS_NOT_FOUND;
188 }
189
190#if 0
191 /* Check whether the loader configuration file exists */
192 Status = OpenAndMapFile(PartitionDirectoryHandle, NtosBootLoaders[Type].LoaderConfigurationFile,
193 &FileHandle, &SectionHandle, &ViewBase, &FileSize, FALSE);
194 if (!NT_SUCCESS(Status))
195 {
196 /* The loader does not exist, continue with another one */
197 // FIXME: Consider it might be optional??
198 DPRINT1("Loader configuration file '%S' does not exist\n", NtosBootLoaders[Type].LoaderConfigurationFile);
199 return STATUS_NOT_FOUND;
200 }
201#endif
202
203 return STATUS_SUCCESS;
204}
Type
Definition: Type.h:7
#define FALSE
Definition: types.h:117
NTSTATUS OpenAndMapFile(IN HANDLE RootDirectory OPTIONAL, IN PCWSTR PathNameToFile, OUT PHANDLE FileHandle, OUT PHANDLE SectionHandle, OUT PVOID *BaseAddress, OUT PULONG FileSize OPTIONAL, IN BOOLEAN ReadWriteAccess)
Definition: filesup.c:858
#define DoesFileExist(RootDirectory, FileName)
Definition: filesup.h:77
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
#define STATUS_NOT_FOUND
Definition: shellext.h:72
#define DPRINT
Definition: sndvol32.h:71
PCZZWSTR LoaderExecutables
Definition: bldrsup.c:46

Referenced by FindNTOSInstallations().

◆ FreeLdrEnumerateBootEntries()

static NTSTATUS FreeLdrEnumerateBootEntries ( IN PBOOT_STORE_INI_CONTEXT  BootStore,
IN PENUM_BOOT_ENTRIES_ROUTINE  EnumBootEntriesRoutine,
IN PVOID Parameter  OPTIONAL 
)
static

Definition at line 1175 of file bldrsup.c.

1180{
1183 PINICACHESECTION OsIniSection;
1184 PWCHAR SectionName, KeyData;
1185 UCHAR xxBootEntry[FIELD_OFFSET(BOOT_STORE_ENTRY, OsOptions) +
1186 max(sizeof(NTOS_OPTIONS), sizeof(BOOT_SECTOR_OPTIONS))];
1187 PBOOT_STORE_ENTRY BootEntry = (PBOOT_STORE_ENTRY)&xxBootEntry;
1188 PWCHAR Buffer;
1189
1190 /* Enumerate all the valid installations listed in the "Operating Systems" section */
1191 Iterator = IniCacheFindFirstValue(BootStore->OsIniSection, &SectionName, &KeyData);
1192 if (!Iterator) return STATUS_SUCCESS;
1193 do
1194 {
1195 PWCHAR InstallName;
1196 ULONG InstallNameLength;
1197
1198 /* Poor-man quotes removal (improvement over bootsup.c:UpdateFreeLoaderIni) */
1199 if (*KeyData == L'"')
1200 {
1201 /* Quoted name, copy up to the closing quote */
1202 PWCHAR End = wcschr(KeyData + 1, L'"');
1203
1204 if (End)
1205 {
1206 /* Skip the first quote */
1207 InstallName = KeyData + 1;
1208 InstallNameLength = End - InstallName;
1209 }
1210 else // if (!End)
1211 {
1212 /* No corresponding closing quote, so we include the first one in the InstallName */
1213 InstallName = KeyData;
1214 InstallNameLength = wcslen(InstallName);
1215 }
1216 if (InstallNameLength == 0) InstallName = NULL;
1217 }
1218 else
1219 {
1220 /* Non-quoted name, copy everything */
1221 InstallName = KeyData;
1222 InstallNameLength = wcslen(InstallName);
1223 if (InstallNameLength == 0) InstallName = NULL;
1224 }
1225
1226 /* Allocate the temporary buffer */
1227 Buffer = NULL;
1228 if (InstallNameLength)
1229 Buffer = RtlAllocateHeap(ProcessHeap, HEAP_ZERO_MEMORY, (InstallNameLength + 1) * sizeof(WCHAR));
1230 if (Buffer)
1231 {
1232 RtlCopyMemory(Buffer, InstallName, InstallNameLength * sizeof(WCHAR));
1233 Buffer[InstallNameLength] = UNICODE_NULL;
1234 InstallName = Buffer;
1235 }
1236
1237 DPRINT("Boot entry '%S' in OS section '%S'\n", InstallName, SectionName);
1238
1239 BootEntry->Version = FreeLdr;
1240 BootEntry->BootEntryKey = MAKESTRKEY(SectionName);
1241 BootEntry->FriendlyName = InstallName;
1242 BootEntry->BootFilePath = NULL;
1243 BootEntry->OsOptionsLength = 0;
1244
1245 /* Search for an existing boot entry section */
1246 OsIniSection = IniCacheGetSection(BootStore->IniCache, SectionName);
1247 if (!OsIniSection)
1248 goto DoEnum;
1249
1250 /* Check for supported boot type "Windows2003" */
1251 Status = IniCacheGetKey(OsIniSection, L"BootType", &KeyData);
1252 if (!NT_SUCCESS(Status) || (KeyData == NULL))
1253 {
1254 /* Certainly not a ReactOS installation */
1255 DPRINT1("No BootType value present!\n");
1256 goto DoEnum;
1257 }
1258
1259 // TODO: What to do with "Windows" ; "WindowsNT40" ; "ReactOSSetup" ?
1260 if ((_wcsicmp(KeyData, L"Windows2003") == 0) ||
1261 (_wcsicmp(KeyData, L"\"Windows2003\"") == 0))
1262 {
1263 /* BootType is Windows2003 */
1265
1266 DPRINT("This is a '%S' boot entry\n", KeyData);
1267
1268 BootEntry->OsOptionsLength = sizeof(NTOS_OPTIONS);
1269 RtlCopyMemory(Options->Signature,
1272
1273 // BootEntry->BootFilePath = NULL;
1274
1275 /* Check its SystemPath */
1276 Status = IniCacheGetKey(OsIniSection, L"SystemPath", &KeyData);
1277 if (!NT_SUCCESS(Status))
1278 Options->OsLoadPath = NULL;
1279 else
1280 Options->OsLoadPath = KeyData;
1281 // KeyData == SystemRoot;
1282
1283 /* Check the optional Options */
1284 Status = IniCacheGetKey(OsIniSection, L"Options", &KeyData);
1285 if (!NT_SUCCESS(Status))
1286 Options->OsLoadOptions = NULL;
1287 else
1288 Options->OsLoadOptions = KeyData;
1289 }
1290 else
1291 if ((_wcsicmp(KeyData, L"BootSector") == 0) ||
1292 (_wcsicmp(KeyData, L"\"BootSector\"") == 0))
1293 {
1294 /* BootType is BootSector */
1296
1297 DPRINT("This is a '%S' boot entry\n", KeyData);
1298
1299 BootEntry->OsOptionsLength = sizeof(BOOT_SECTOR_OPTIONS);
1300 RtlCopyMemory(Options->Signature,
1303
1304 // BootEntry->BootFilePath = NULL;
1305
1306 /* Check its BootDrive */
1307 Status = IniCacheGetKey(OsIniSection, L"BootDrive", &KeyData);
1308 if (!NT_SUCCESS(Status))
1309 Options->Drive = NULL;
1310 else
1311 Options->Drive = KeyData;
1312
1313 /* Check its BootPartition */
1314 Status = IniCacheGetKey(OsIniSection, L"BootPartition", &KeyData);
1315 if (!NT_SUCCESS(Status))
1316 Options->Partition = NULL;
1317 else
1318 Options->Partition = KeyData;
1319
1320 /* Check its BootSector */
1321 Status = IniCacheGetKey(OsIniSection, L"BootSectorFile", &KeyData);
1322 if (!NT_SUCCESS(Status))
1323 Options->BootSectorFileName = NULL;
1324 else
1325 Options->BootSectorFileName = KeyData;
1326 }
1327 else
1328 {
1329 DPRINT1("Unrecognized BootType value '%S'\n", KeyData);
1330 // goto DoEnum;
1331 }
1332
1333DoEnum:
1334 /* Call the user enumeration routine callback */
1335 Status = EnumBootEntriesRoutine(FreeLdr, BootEntry, Parameter);
1336
1337 /* Free temporary buffers */
1338 if (Buffer)
1340
1341 /* Stop the enumeration if needed */
1342 if (!NT_SUCCESS(Status))
1343 break;
1344 }
1345 while (IniCacheFindNextValue(Iterator, &SectionName, &KeyData));
1346
1348 return Status;
1349}
struct _NTOS_OPTIONS NTOS_OPTIONS
#define MAKESTRKEY(i)
Definition: bldrsup.h:54
struct _BOOT_STORE_ENTRY * PBOOT_STORE_ENTRY
struct _BOOT_SECTOR_OPTIONS BOOT_SECTOR_OPTIONS
#define wcschr
Definition: compat.h:17
NTSTATUS IniCacheGetKey(PINICACHESECTION Section, PWCHAR KeyName, PWCHAR *KeyData)
Definition: inicache.c:716
BOOLEAN IniCacheFindNextValue(PINICACHEITERATOR Iterator, PWCHAR *KeyName, PWCHAR *KeyData)
Definition: inicache.c:785
PINICACHEITERATOR IniCacheFindFirstValue(PINICACHESECTION Section, PWCHAR *KeyName, PWCHAR *KeyData)
Definition: inicache.c:744
VOID IniCacheFindClose(PINICACHEITERATOR Iterator)
Definition: inicache.c:815
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
Definition: bldrsup.h:63
ULONG Version
Definition: bldrsup.h:64
PCWSTR BootFilePath
Definition: bldrsup.h:68
ULONG OsOptionsLength
Definition: bldrsup.h:69
ULONG_PTR BootEntryKey
Definition: bldrsup.h:66
UCHAR OsOptions[ANYSIZE_ARRAY]
Definition: bldrsup.h:70
PCWSTR FriendlyName
Definition: bldrsup.h:67
#define max(a, b)
Definition: svc.c:63
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
_In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR Iterator
Definition: wdfchildlist.h:656
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ ModifyBootStoreEntry()

NTSTATUS ModifyBootStoreEntry ( IN PVOID  Handle,
IN PBOOT_STORE_ENTRY  BootEntry 
)

Definition at line 986 of file bldrsup.c.

989{
991
992 if (!BootStore || !BootEntry)
994
995 /*
996 * NOTE: Currently we open & map the loader configuration file without
997 * further tests. It's OK as long as we only deal with FreeLdr's freeldr.ini
998 * and NTLDR's boot.ini files. But as soon as we'll implement support for
999 * BOOTMGR detection, the "configuration file" will be the BCD registry
1000 * hive and then, we'll have instead to mount the hive & open it.
1001 */
1002
1003 //
1004 // FIXME!!
1005 //
1006
1007 // if (BootStore->Type >= BldrTypeMax || NtosBootLoaders[BootStore->Type].Type >= BldrTypeMax)
1008 if (BootStore->Type != FreeLdr)
1009 {
1010 DPRINT1("Loader type %d is currently unsupported!\n", NtosBootLoaders[BootStore->Type].Type);
1011 return STATUS_NOT_SUPPORTED;
1012 }
1013
1014 // FIXME! This function needs my INI library rewrite to operate properly!!
1017}

◆ NtLdrEnumerateBootEntries()

static NTSTATUS NtLdrEnumerateBootEntries ( IN PBOOT_STORE_INI_CONTEXT  BootStore,
IN PENUM_BOOT_ENTRIES_ROUTINE  EnumBootEntriesRoutine,
IN PVOID Parameter  OPTIONAL 
)
static

Definition at line 1352 of file bldrsup.c.

1357{
1360 PWCHAR SectionName, KeyData;
1361 UCHAR xxBootEntry[FIELD_OFFSET(BOOT_STORE_ENTRY, OsOptions) + sizeof(NTOS_OPTIONS)];
1362 PBOOT_STORE_ENTRY BootEntry = (PBOOT_STORE_ENTRY)&xxBootEntry;
1363 PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions;
1364 PWCHAR Buffer;
1366
1367 /* Enumerate all the valid installations */
1368 Iterator = IniCacheFindFirstValue(BootStore->OsIniSection, &SectionName, &KeyData);
1369 if (!Iterator) return STATUS_SUCCESS;
1370 do
1371 {
1372 PWCHAR InstallName, OsOptions;
1373 ULONG InstallNameLength, OsOptionsLength;
1374
1375 /* Poor-man quotes removal (improvement over bootsup.c:UpdateFreeLoaderIni) */
1376 if (*KeyData == L'"')
1377 {
1378 /* Quoted name, copy up to the closing quote */
1379 OsOptions = wcschr(KeyData + 1, L'"');
1380
1381 /* Retrieve the starting point of the installation name and the OS options */
1382 if (OsOptions)
1383 {
1384 /* Skip the first quote */
1385 InstallName = KeyData + 1;
1386 InstallNameLength = OsOptions - InstallName;
1387 if (InstallNameLength == 0) InstallName = NULL;
1388
1389 /* Skip the ending quote (if found) */
1390 ++OsOptions;
1391
1392 /* Skip any whitespace */
1393 while (iswspace(*OsOptions)) ++OsOptions;
1394 /* Get its final length */
1395 OsOptionsLength = wcslen(OsOptions);
1396 if (OsOptionsLength == 0) OsOptions = NULL;
1397 }
1398 else
1399 {
1400 /* No corresponding closing quote, so we include the first one in the InstallName */
1401 InstallName = KeyData;
1402 InstallNameLength = wcslen(InstallName);
1403 if (InstallNameLength == 0) InstallName = NULL;
1404
1405 /* There are no OS options */
1406 // OsOptions = NULL;
1407 OsOptionsLength = 0;
1408 }
1409 }
1410 else
1411 {
1412 /* Non-quoted name, copy everything */
1413
1414 /* Retrieve the starting point of the installation name */
1415 InstallName = KeyData;
1416 InstallNameLength = wcslen(InstallName);
1417 if (InstallNameLength == 0) InstallName = NULL;
1418
1419 /* There are no OS options */
1420 OsOptions = NULL;
1421 OsOptionsLength = 0;
1422 }
1423
1424 /* Allocate the temporary buffer */
1425 Buffer = NULL;
1426 BufferLength = (InstallNameLength + OsOptionsLength) * sizeof(WCHAR);
1427 if (BufferLength)
1429 if (Buffer)
1430 {
1431 PWCHAR ptr;
1432
1433 /* Copy the installation name, and make InstallName point into the buffer */
1434 if (InstallName && InstallNameLength)
1435 {
1436 ptr = Buffer;
1437 RtlCopyMemory(ptr, InstallName, InstallNameLength * sizeof(WCHAR));
1438 ptr[InstallNameLength] = UNICODE_NULL;
1439 InstallName = ptr;
1440 }
1441
1442 /* Copy the OS options, and make OsOptions point into the buffer */
1443 if (OsOptions && OsOptionsLength)
1444 {
1445 ptr = Buffer + InstallNameLength + 1;
1446 RtlCopyMemory(ptr, OsOptions, OsOptionsLength * sizeof(WCHAR));
1447 ptr[OsOptionsLength] = UNICODE_NULL;
1448 OsOptions = ptr;
1449 }
1450 }
1451
1452 DPRINT1("Boot entry '%S' in OS section (path) '%S'\n", InstallName, SectionName);
1453 // SectionName == SystemRoot;
1454
1455 BootEntry->Version = NtLdr;
1456 BootEntry->BootEntryKey = 0; // FIXME??
1457 BootEntry->FriendlyName = InstallName;
1458 BootEntry->BootFilePath = NULL;
1459
1460 BootEntry->OsOptionsLength = sizeof(NTOS_OPTIONS);
1461 RtlCopyMemory(Options->Signature,
1464
1465 Options->OsLoadPath = SectionName;
1466 Options->OsLoadOptions = OsOptions;
1467
1468 /* Call the user enumeration routine callback */
1469 Status = EnumBootEntriesRoutine(NtLdr, BootEntry, Parameter);
1470
1471 /* Free temporary buffers */
1472 if (Buffer)
1474
1475 /* Stop the enumeration if needed */
1476 if (!NT_SUCCESS(Status))
1477 break;
1478 }
1479 while (IniCacheFindNextValue(Iterator, &SectionName, &KeyData));
1480
1482 return Status;
1483}
#define iswspace(_c)
Definition: ctype.h:669
static PVOID ptr
Definition: dispmode.c:27

◆ OpenBootStore()

NTSTATUS OpenBootStore ( OUT PVOID Handle,
IN PCWSTR  SystemPartition,
IN BOOT_STORE_TYPE  Type,
IN BOOLEAN  CreateNew 
)

Definition at line 742 of file bldrsup.c.

747{
748 UNICODE_STRING SystemPartitionPath;
749 RtlInitUnicodeString(&SystemPartitionPath, SystemPartition);
750 return OpenBootStore_UStr(Handle, &SystemPartitionPath, Type, CreateNew);
751}
NTSTATUS OpenBootStore_UStr(OUT PVOID *Handle, IN PUNICODE_STRING SystemPartitionPath, IN BOOT_STORE_TYPE Type, IN BOOLEAN CreateNew)
Definition: bldrsup.c:691
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
static PPARTENTRY SystemPartition
Definition: usetup.c:61

Referenced by CreateFreeLoaderIniForReactOS(), CreateFreeLoaderIniForReactOSAndBootSector(), UpdateBootIni(), and UpdateFreeLoaderIni().

◆ OpenBootStore_UStr()

NTSTATUS OpenBootStore_UStr ( OUT PVOID Handle,
IN PUNICODE_STRING  SystemPartitionPath,
IN BOOT_STORE_TYPE  Type,
IN BOOLEAN  CreateNew 
)

Definition at line 691 of file bldrsup.c.

696{
700 HANDLE PartitionDirectoryHandle;
701
702 /*
703 * NOTE: Currently we open & map the loader configuration file without
704 * further tests. It's OK as long as we only deal with FreeLdr's freeldr.ini
705 * and NTLDR's boot.ini files. But as soon as we'll implement support for
706 * BOOTMGR detection, the "configuration file" will be the BCD registry
707 * hive and then, we'll have instead to mount the hive & open it.
708 */
709
711 {
712 DPRINT1("Loader type %d is currently unsupported!\n", NtosBootLoaders[Type].Type);
714 }
715
716 /* Open SystemPartition */
718 SystemPartitionPath,
720 NULL,
721 NULL);
722 Status = NtOpenFile(&PartitionDirectoryHandle,
723 FILE_LIST_DIRECTORY | FILE_ADD_FILE /* | FILE_ADD_SUBDIRECTORY | FILE_TRAVERSE*/ | SYNCHRONIZE,
727 FILE_SYNCHRONOUS_IO_NONALERT | FILE_DIRECTORY_FILE /* | FILE_OPEN_FOR_BACKUP_INTENT */);
728 if (!NT_SUCCESS(Status))
729 {
730 DPRINT1("Failed to open SystemPartition '%wZ', Status 0x%08lx\n", SystemPartitionPath, Status);
731 return Status;
732 }
733
734 Status = OpenBootStoreByHandle(Handle, PartitionDirectoryHandle, Type, CreateNew);
735
736 /* Done! */
737 NtClose(PartitionDirectoryHandle);
738 return Status;
739}
#define FILE_DIRECTORY_FILE
Definition: constants.h:491
NTSTATUS OpenBootStoreByHandle(OUT PVOID *Handle, IN HANDLE PartitionDirectoryHandle, IN BOOT_STORE_TYPE Type, IN BOOLEAN CreateNew)
Definition: bldrsup.c:664
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define FILE_SHARE_READ
Definition: compat.h:136
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3952
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_LIST_DIRECTORY
Definition: nt_native.h:629
#define FILE_ADD_FILE
Definition: nt_native.h:632

Referenced by OpenBootStore().

◆ OpenBootStoreByHandle()

NTSTATUS OpenBootStoreByHandle ( OUT PVOID Handle,
IN HANDLE  PartitionDirectoryHandle,
IN BOOT_STORE_TYPE  Type,
IN BOOLEAN  CreateNew 
)

Definition at line 664 of file bldrsup.c.

669{
670 /*
671 * NOTE: Currently we open & map the loader configuration file without
672 * further tests. It's OK as long as we only deal with FreeLdr's freeldr.ini
673 * and NTLDR's boot.ini files. But as soon as we'll implement support for
674 * BOOTMGR detection, the "configuration file" will be the BCD registry
675 * hive and then, we'll have instead to mount the hive & open it.
676 */
677
679 {
680 DPRINT1("Loader type %d is currently unsupported!\n", NtosBootLoaders[Type].Type);
682 }
683
685 PartitionDirectoryHandle,
686 Type,
687 CreateNew);
688}
POPEN_BOOT_STORE OpenBootStore
Definition: bldrsup.c:48

Referenced by FindNTOSInstallations(), and OpenBootStore_UStr().

◆ OpenIniBootLoaderStore()

static NTSTATUS OpenIniBootLoaderStore ( OUT PVOID Handle,
IN HANDLE  PartitionDirectoryHandle,
IN BOOT_STORE_TYPE  Type,
IN BOOLEAN  CreateNew 
)
static

Definition at line 266 of file bldrsup.c.

271{
273 PBOOT_STORE_INI_CONTEXT BootStore;
274
275 /* Create a boot store structure */
276 BootStore = RtlAllocateHeap(ProcessHeap, HEAP_ZERO_MEMORY, sizeof(*BootStore));
277 if (!BootStore)
279
280 BootStore->Header.Type = Type;
281
282 if (CreateNew)
283 {
287
288 //
289 // WARNING! We "support" the INI creation *ONLY* for FreeLdr, and not for NTLDR!!
290 //
291 if (Type == NtLdr)
292 {
293 DPRINT1("OpenIniBootLoaderStore() unsupported for NTLDR!\n");
294 RtlFreeHeap(ProcessHeap, 0, BootStore);
296 }
297
298 /* Initialize the INI file */
299 BootStore->IniCache = IniCacheCreate();
300 if (!BootStore->IniCache)
301 {
302 DPRINT1("IniCacheCreate() failed.\n");
303 RtlFreeHeap(ProcessHeap, 0, BootStore);
305 }
306
307 /*
308 * So far, we only use the INI cache. The file itself is not created
309 * yet, therefore FileHandle, SectionHandle, ViewBase and FileSize
310 * are all NULL. We will use this fact to know that the INI file was
311 * indeed created, and not just opened as an existing file.
312 */
313 // BootStore->FileHandle = NULL;
314 BootStore->SectionHandle = NULL;
315 BootStore->ViewBase = NULL;
316 BootStore->FileSize = 0;
317
318 /*
319 * The INI file is fresh new, we need to create it now.
320 */
321
322 RtlInitUnicodeString(&Name, NtosBootLoaders[Type].LoaderConfigurationFile);
323
325 &Name,
327 PartitionDirectoryHandle,
328 NULL);
329
330 Status = NtCreateFile(&BootStore->FileHandle,
331 FILE_GENERIC_READ | FILE_GENERIC_WRITE, // Contains SYNCHRONIZE
334 NULL,
336 0,
339 NULL,
340 0);
341 if (!NT_SUCCESS(Status))
342 {
343 DPRINT1("NtCreateFile() failed (Status 0x%08lx)\n", Status);
344 IniCacheDestroy(BootStore->IniCache);
345 RtlFreeHeap(ProcessHeap, 0, BootStore);
346 return Status;
347 }
348
349 /* Initialize the INI file contents */
350 if (Type == FreeLdr)
352 }
353 else
354 {
355 PINICACHESECTION IniSection;
356
357 /*
358 * Check whether the loader configuration INI file exists,
359 * and open it if so.
360 * TODO: FIXME: What if it doesn't exist yet???
361 */
362 Status = OpenAndMapFile(PartitionDirectoryHandle,
363 NtosBootLoaders[Type].LoaderConfigurationFile,
364 &BootStore->FileHandle,
365 &BootStore->SectionHandle,
366 &BootStore->ViewBase,
367 &BootStore->FileSize,
368 TRUE);
369 if (!NT_SUCCESS(Status))
370 {
371 /* The loader configuration file does not exist */
372 // FIXME: Consider it might be optional??
373 DPRINT1("Loader configuration file '%S' does not exist (Status 0x%08lx)\n",
374 NtosBootLoaders[Type].LoaderConfigurationFile, Status);
375 RtlFreeHeap(ProcessHeap, 0, BootStore);
376 return Status;
377 }
378
379 /* Open an *existing* INI configuration file */
380 // Status = IniCacheLoad(&BootStore->IniCache, NtosBootLoaders[Type].LoaderConfigurationFile, FALSE);
382 BootStore->ViewBase,
383 BootStore->FileSize,
384 FALSE);
385 if (!NT_SUCCESS(Status))
386 {
387 DPRINT1("IniCacheLoadFromMemory() failed (Status 0x%08lx)\n", Status);
388
389 /* Finally, unmap and close the file */
390 UnMapAndCloseFile(BootStore->FileHandle,
391 BootStore->SectionHandle,
392 BootStore->ViewBase);
393
394 RtlFreeHeap(ProcessHeap, 0, BootStore);
395 return Status;
396 }
397
398 if (Type == FreeLdr)
399 {
400 /*
401 * Cache the "FREELOADER" section for our future usage.
402 */
403
404 /* Get the "FREELOADER" section */
405 IniSection = IniCacheGetSection(BootStore->IniCache, L"FREELOADER");
406 if (!IniSection)
407 {
408 /* It does not exist yet, so create it */
409 IniSection = IniCacheAppendSection(BootStore->IniCache, L"FREELOADER");
410 if (!IniSection)
411 {
412 DPRINT1("OpenIniBootLoaderStore: Failed to retrieve 'FREELOADER' section!\n");
413 }
414 }
415
416 BootStore->OptionsIniSection = IniSection;
417
418 /*
419 * Cache the "Operating Systems" section for our future usage.
420 */
421
422 /* Get the "Operating Systems" section */
423 IniSection = IniCacheGetSection(BootStore->IniCache, L"Operating Systems");
424 if (!IniSection)
425 {
426 /* It does not exist yet, so create it */
427 IniSection = IniCacheAppendSection(BootStore->IniCache, L"Operating Systems");
428 if (!IniSection)
429 {
430 DPRINT1("OpenIniBootLoaderStore: Failed to retrieve 'Operating Systems' section!\n");
431 }
432 }
433
434 BootStore->OsIniSection = IniSection;
435 }
436 else
437 if (Type == NtLdr)
438 {
439 /*
440 * Cache the "boot loader" section for our future usage.
441 */
442 /*
443 * HISTORICAL NOTE:
444 *
445 * While the "operating systems" section acquired its definitive
446 * name already when Windows NT was at its very early beta stage
447 * (NT 3.1 October 1991 Beta, 10-16-1991), this was not the case
448 * for its general settings section "boot loader".
449 *
450 * The following section names were successively introduced:
451 *
452 * - In NT 3.1 October 1991 Beta, 10-16-1991, using OS Loader V1.5,
453 * the section was named "multiboot".
454 *
455 * - In the next public beta version NT 3.10.340 Beta, 10-12-1992,
456 * using OS Loader V2.10, a new name was introduced: "flexboot".
457 * This is around this time that the NT OS Loader was also
458 * introduced as the "Windows NT FlexBoot" loader, as shown by
459 * the Windows NT FAQs that circulated around this time:
460 * http://cd.textfiles.com/cica9308/CIS_LIBS/WINNT/1/NTFAQ.TXT
461 * http://cd.textfiles.com/cica/cica9308/UNZIPPED/NT/NTFAQ/FTP/NEWS/NTFAQ1.TXT
462 * I can only hypothesize that the "FlexBoot" name was chosen
463 * as a marketing coup, possibly to emphasise its "flexibility"
464 * as a simple multiboot-aware boot manager.
465 *
466 * - A bit later, with NT 3.10.404 Beta, 3-7-1993, using an updated
467 * version of OS Loader V2.10, the final section name "boot loader"
468 * was introduced, and was kept since then.
469 *
470 * Due to the necessity to be able to boot and / or upgrade any
471 * Windows NT version at any time, including its NT Loader and the
472 * associated boot.ini file, all versions of NTLDR and the NT installer
473 * understand and parse these three section names, the default one
474 * being "boot loader", and if not present, they successively fall
475 * back to "flexboot" and then to "multiboot".
476 */
477
478 /* Get the "boot loader" section */
479 IniSection = IniCacheGetSection(BootStore->IniCache, L"boot loader");
480 if (!IniSection)
481 {
482 /* Fall back to "flexboot" */
483 IniSection = IniCacheGetSection(BootStore->IniCache, L"flexboot");
484 if (!IniSection)
485 {
486 /* Fall back to "multiboot" */
487 IniSection = IniCacheGetSection(BootStore->IniCache, L"multiboot");
488 }
489 }
490#if 0
491 if (!IniSection)
492 {
493 /* It does not exist yet, so create it */
494 IniSection = IniCacheAppendSection(BootStore->IniCache, L"boot loader");
495 if (!IniSection)
496 {
497 DPRINT1("OpenIniBootLoaderStore: Failed to retrieve 'boot loader' section!\n");
498 }
499 }
500#endif
501
502 BootStore->OptionsIniSection = IniSection;
503
504 /*
505 * Cache the "Operating Systems" section for our future usage.
506 */
507
508 /* Get the "Operating Systems" section */
509 IniSection = IniCacheGetSection(BootStore->IniCache, L"operating systems");
510 if (!IniSection)
511 {
512#if 0
513 /* It does not exist yet, so create it */
514 IniSection = IniCacheAppendSection(BootStore->IniCache, L"operating systems");
515 if (!IniSection)
516 {
517 DPRINT1("OpenIniBootLoaderStore: Failed to retrieve 'operating systems' section!\n");
518 }
519#endif
520 }
521
522 BootStore->OsIniSection = IniSection;
523 }
524 }
525
526 *Handle = BootStore;
527 return STATUS_SUCCESS;
528}
struct NameRec_ * Name
Definition: cdprocs.h:460
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
static VOID CreateCommonFreeLdrSections(IN OUT PBOOT_STORE_INI_CONTEXT BootStore)
Definition: bldrsup.c:208
#define TRUE
Definition: types.h:120
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SEQUENTIAL_ONLY
Definition: from_kernel.h:27
#define FILE_SUPERSEDE
Definition: from_kernel.h:53
NTSTATUS IniCacheLoadFromMemory(PINICACHE *Cache, PCHAR FileBuffer, ULONG FileLength, BOOLEAN String)
Definition: inicache.c:452
PINICACHE IniCacheCreate(VOID)
Definition: inicache.c:929
NTSTATUS NTAPI NtCreateFile(OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG CreateDisposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength)
#define FILE_GENERIC_READ
Definition: nt_native.h:653
#define FILE_GENERIC_WRITE
Definition: nt_native.h:660
PINICACHESECTION OptionsIniSection
Definition: bldrsup.c:82
PINICACHESECTION OsIniSection
Definition: bldrsup.c:83

◆ ProtectBootIni()

static NTSTATUS ProtectBootIni ( IN HANDLE  FileHandle,
IN ULONG  Attributes 
)
static

Definition at line 570 of file bldrsup.c.

573{
577
580 &FileInfo,
583 if (!NT_SUCCESS(Status))
584 {
585 DPRINT1("NtQueryInformationFile() failed (Status 0x%08lx)\n", Status);
586 return Status;
587 }
588
589 FileInfo.FileAttributes = FileInfo.FileAttributes | Attributes;
590
593 &FileInfo,
596 if (!NT_SUCCESS(Status))
597 DPRINT1("NtSetInformationFile() failed (Status 0x%08lx)\n", Status);
598
599 return Status;
600}
@ FileBasicInformation
Definition: from_kernel.h:65
NTSYSAPI NTSTATUS NTAPI NtSetInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
Definition: iofunc.c:3096
NTSYSAPI NTSTATUS NTAPI NtQueryInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, OUT PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes

Referenced by CloseIniBootLoaderStore().

◆ QueryBootStoreEntry()

NTSTATUS QueryBootStoreEntry ( IN PVOID  Handle,
IN ULONG_PTR  BootEntryKey,
OUT PBOOT_STORE_ENTRY  BootEntry 
)

Definition at line 1020 of file bldrsup.c.

1024{
1026
1027 if (!BootStore)
1029
1030 /*
1031 * NOTE: Currently we open & map the loader configuration file without
1032 * further tests. It's OK as long as we only deal with FreeLdr's freeldr.ini
1033 * and NTLDR's boot.ini files. But as soon as we'll implement support for
1034 * BOOTMGR detection, the "configuration file" will be the BCD registry
1035 * hive and then, we'll have instead to mount the hive & open it.
1036 */
1037
1038 //
1039 // FIXME!!
1040 //
1041
1042 // if (BootStore->Type >= BldrTypeMax || NtosBootLoaders[BootStore->Type].Type >= BldrTypeMax)
1043 if (BootStore->Type != FreeLdr)
1044 {
1045 DPRINT1("Loader type %d is currently unsupported!\n", NtosBootLoaders[BootStore->Type].Type);
1046 return STATUS_NOT_SUPPORTED;
1047 }
1048
1049 // FIXME! This function needs my INI library rewrite to be implemented!!
1052}

◆ QueryBootStoreOptions()

NTSTATUS QueryBootStoreOptions ( IN PVOID  Handle,
IN OUT PBOOT_STORE_OPTIONS  BootOptions 
)

Definition at line 1055 of file bldrsup.c.

1059{
1062 PWCHAR TimeoutStr;
1063
1064 if (!BootStore || !BootOptions)
1066
1067 /*
1068 * NOTE: Currently we open & map the loader configuration file without
1069 * further tests. It's OK as long as we only deal with FreeLdr's freeldr.ini
1070 * and NTLDR's boot.ini files. But as soon as we'll implement support for
1071 * BOOTMGR detection, the "configuration file" will be the BCD registry
1072 * hive and then, we'll have instead to mount the hive & open it.
1073 */
1074
1075 //
1076 // FIXME!!
1077 //
1078
1079 // if (BootStore->Type >= BldrTypeMax || NtosBootLoaders[BootStore->Type].Type >= BldrTypeMax)
1080 if (BootStore->Type != FreeLdr && BootStore->Type != NtLdr)
1081 {
1082 DPRINT1("Loader type %d is currently unsupported!\n", BootStore->Type);
1083 return STATUS_NOT_SUPPORTED;
1084 }
1085
1086 if (BootStore->Type == FreeLdr)
1087 {
1088 BootOptions->Version = FreeLdr;
1089
1090 Status = IniCacheGetKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection,
1091 L"DefaultOS", (PWCHAR*)&BootOptions->CurrentBootEntryKey);
1092 if (!NT_SUCCESS(Status))
1093 BootOptions->CurrentBootEntryKey = 0;
1094
1095 Status = IniCacheGetKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection,
1096 L"TimeOut", &TimeoutStr);
1097 if (NT_SUCCESS(Status) && TimeoutStr)
1098 BootOptions->Timeout = _wtoi(TimeoutStr);
1099 else
1100 BootOptions->Timeout = 0;
1101 }
1102 else if (BootStore->Type == NtLdr)
1103 {
1104 BootOptions->Version = NtLdr;
1105
1106 Status = IniCacheGetKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection,
1107 L"default", (PWCHAR*)&BootOptions->CurrentBootEntryKey);
1108 if (!NT_SUCCESS(Status))
1109 BootOptions->CurrentBootEntryKey = 0;
1110
1111 Status = IniCacheGetKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection,
1112 L"timeout", &TimeoutStr);
1113 if (NT_SUCCESS(Status) && TimeoutStr)
1114 BootOptions->Timeout = _wtoi(TimeoutStr);
1115 else
1116 BootOptions->Timeout = 0;
1117 }
1118
1119 return STATUS_SUCCESS; // FIXME: use Status; instead?
1120}
@ BootOptions
Definition: bl.h:898
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)

◆ SetBootStoreOptions()

NTSTATUS SetBootStoreOptions ( IN PVOID  Handle,
IN PBOOT_STORE_OPTIONS  BootOptions,
IN ULONG  FieldsToChange 
)

Definition at line 1123 of file bldrsup.c.

1127{
1129 WCHAR TimeoutStr[15];
1130
1131 if (!BootStore || !BootOptions)
1133
1134 /*
1135 * NOTE: Currently we open & map the loader configuration file without
1136 * further tests. It's OK as long as we only deal with FreeLdr's freeldr.ini
1137 * and NTLDR's boot.ini files. But as soon as we'll implement support for
1138 * BOOTMGR detection, the "configuration file" will be the BCD registry
1139 * hive and then, we'll have instead to mount the hive & open it.
1140 */
1141
1142 //
1143 // FIXME!!
1144 //
1145
1146 // if (BootStore->Type >= BldrTypeMax || NtosBootLoaders[BootStore->Type].Type >= BldrTypeMax)
1147 if (BootStore->Type != FreeLdr)
1148 {
1149 DPRINT1("Loader type %d is currently unsupported!\n", NtosBootLoaders[BootStore->Type].Type);
1150 return STATUS_NOT_SUPPORTED;
1151 }
1152
1153 if (BootOptions->Version != FreeLdr)
1155
1156 //
1157 // TODO: Depending on the flags set in 'FieldsToChange',
1158 // change either one or both these bootloader options.
1159 //
1160 IniCacheInsertKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection,
1162 L"DefaultOS", (PWCHAR)BootOptions->CurrentBootEntryKey);
1163
1164 RtlStringCchPrintfW(TimeoutStr, ARRAYSIZE(TimeoutStr), L"%d", BootOptions->Timeout);
1165 IniCacheInsertKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection,
1166 NULL, INSERT_FIRST, // INSERT_LAST, // FIXME!! There is a bug in the INI parser where a given key can be inserted twice in the same section...
1167 L"TimeOut", TimeoutStr);
1168
1169 return STATUS_SUCCESS;
1170}
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
@ INSERT_FIRST
Definition: inicache.h:48
NTSTRSAFEVAPI RtlStringCchPrintfW(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1110

Referenced by CreateFreeLoaderReactOSEntries().

◆ UnprotectBootIni()

static NTSTATUS UnprotectBootIni ( IN HANDLE  FileHandle,
OUT PULONG  Attributes 
)
static

Definition at line 531 of file bldrsup.c.

534{
538
541 &FileInfo,
544 if (!NT_SUCCESS(Status))
545 {
546 DPRINT1("NtQueryInformationFile() failed (Status 0x%08lx)\n", Status);
547 return Status;
548 }
549
550 *Attributes = FileInfo.FileAttributes;
551
552 /* Delete attributes SYSTEM, HIDDEN and READONLY */
553 FileInfo.FileAttributes = FileInfo.FileAttributes &
557
560 &FileInfo,
563 if (!NT_SUCCESS(Status))
564 DPRINT1("NtSetInformationFile() failed (Status 0x%08lx)\n", Status);
565
566 return Status;
567}

Referenced by CloseIniBootLoaderStore().

Variable Documentation

◆ NtosBootLoaders

NTOS_BOOT_LOADER_FILES NtosBootLoaders[]
Initial value:
=
{
{FreeLdr, L"freeldr.sys\0", L"freeldr.ini",
{NtLdr , L"ntldr\0" L"osloader.exe\0", L"boot.ini",
}
static NTSTATUS NtLdrEnumerateBootEntries(IN PBOOT_STORE_INI_CONTEXT BootStore, IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine, IN PVOID Parameter OPTIONAL)
Definition: bldrsup.c:1352
static NTSTATUS OpenIniBootLoaderStore(OUT PVOID *Handle, IN HANDLE PartitionDirectoryHandle, IN BOOT_STORE_TYPE Type, IN BOOLEAN CreateNew)
Definition: bldrsup.c:266
static NTSTATUS FreeLdrEnumerateBootEntries(IN PBOOT_STORE_INI_CONTEXT BootStore, IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine, IN PVOID Parameter OPTIONAL)
Definition: bldrsup.c:1175
static NTSTATUS CloseIniBootLoaderStore(IN PVOID Handle)
Definition: bldrsup.c:603
NTSTATUS(* PENUM_BOOT_STORE_ENTRIES)(IN PVOID Handle, IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine, IN PVOID Parameter OPTIONAL)
Definition: bldrsup.c:37

Definition at line 122 of file bldrsup.c.

Referenced by CloseBootStore(), DeleteBootStoreEntry(), EnumerateBootStoreEntries(), FindBootStore(), ModifyBootStoreEntry(), OpenBootStore_UStr(), OpenBootStoreByHandle(), OpenIniBootLoaderStore(), QueryBootStoreEntry(), and SetBootStoreOptions().