ReactOS  0.4.11-dev-791-gf6f1255
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_FILES
PNTOS_BOOT_LOADER_FILES
 
typedef struct _BOOT_STORE_CONTEXT BOOT_STORE_CONTEXT
 
typedef struct
_BOOT_STORE_CONTEXT
PBOOT_STORE_CONTEXT
 
typedef struct
_BOOT_STORE_INI_CONTEXT 
BOOT_STORE_INI_CONTEXT
 
typedef struct
_BOOT_STORE_INI_CONTEXT
PBOOT_STORE_INI_CONTEXT
 
typedef struct
_BOOT_STORE_BCDREG_CONTEXT 
BOOT_STORE_BCDREG_CONTEXT
 
typedef struct
_BOOT_STORE_BCDREG_CONTEXT
PBOOT_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

#define NDEBUG

Definition at line 19 of file bldrsup.c.

Typedef Documentation

typedef NTSTATUS(* PCLOSE_BOOT_STORE)(IN PVOID Handle)

Definition at line 33 of file bldrsup.c.

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

Definition at line 37 of file bldrsup.c.

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

Definition at line 26 of file bldrsup.c.

Function Documentation

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

Definition at line 928 of file bldrsup.c.

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

932 {
934 
935  if (!BootStore || !BootEntry)
937 
938  /*
939  * NOTE: Currently we open & map the loader configuration file without
940  * further tests. It's OK as long as we only deal with FreeLdr's freeldr.ini
941  * and NTLDR's boot.ini files. But as soon as we'll implement support for
942  * BOOTMGR detection, the "configuration file" will be the BCD registry
943  * hive and then, we'll have instead to mount the hive & open it.
944  */
945 
946  //
947  // FIXME!!
948  //
949 
950  // if (BootStore->Type >= BldrTypeMax || NtosBootLoaders[BootStore->Type].Type >= BldrTypeMax)
951 
952  if (BootStore->Type == FreeLdr)
953  {
954  if (BootEntry->Version != FreeLdr)
956 
957  return CreateNTOSEntry((PBOOT_STORE_INI_CONTEXT)BootStore,
958  BootEntryKey, BootEntry);
959  }
960  else
961  if (BootStore->Type == NtLdr)
962  {
963  PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions;
964  PWCHAR Buffer;
966  PCWSTR InstallName, OsOptions;
967  // ULONG InstallNameLength, OsOptionsLength;
968  BOOLEAN IsNameNotQuoted;
969 
970  if (BootEntry->Version != NtLdr)
972 
973  if (BootEntry->OsOptionsLength < sizeof(NTOS_OPTIONS) ||
974  RtlCompareMemory(&BootEntry->OsOptions /* Signature */,
978  {
979  // DPRINT1("Unsupported BootType '%S'\n", BootEntry->Version);
980  DPRINT1("Unsupported BootType %lu\n", BootEntry->OsOptionsLength);
981  return STATUS_SUCCESS; // STATUS_NOT_SUPPORTED;
982  }
983 
984  InstallName = BootEntry->FriendlyName;
985  OsOptions = Options->OsLoadOptions;
986 
987  // if (InstallNameLength == 0) InstallName = NULL;
988  // if (OsOptionsLength == 0) OsOptions = NULL;
989 
990  IsNameNotQuoted = (InstallName[0] != L'\"' || InstallName[wcslen(InstallName)-1] != L'\"');
991 
992  BufferLength = (IsNameNotQuoted ? 2 /* Quotes for FriendlyName*/ : 0) + wcslen(InstallName);
993  if (OsOptions)
994  BufferLength += 1 /* Space between FriendlyName and options */ + wcslen(OsOptions);
995  BufferLength++; /* NULL-termination */
996 
998  if (!Buffer)
1000 
1001  *Buffer = UNICODE_NULL;
1002  if (IsNameNotQuoted) RtlStringCchCatW(Buffer, BufferLength, L"\"");
1003  RtlStringCchCatW(Buffer, BufferLength, InstallName);
1004  if (IsNameNotQuoted) RtlStringCchCatW(Buffer, BufferLength, L"\"");
1005  if (OsOptions)
1006  {
1008  RtlStringCchCatW(Buffer, BufferLength, OsOptions);
1009  }
1010 
1011  /* Insert the entry into the "Operating Systems" section */
1012  IniCacheInsertKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OsIniSection, NULL, INSERT_LAST,
1013  (PWSTR)Options->OsLoadPath, Buffer);
1014 
1016  return STATUS_SUCCESS;
1017  }
1018  else
1019  {
1020  DPRINT1("Loader type %d is currently unsupported!\n", NtosBootLoaders[BootStore->Type].Type);
1021  return STATUS_NOT_SUPPORTED;
1022  }
1023 }
#define NTOS_OPTIONS_SIGNATURE
Definition: bldrsup.h:98
#define RTL_FIELD_SIZE(type, field)
Definition: kdb_expr.c:84
PINICACHEKEY IniCacheInsertKey(PINICACHESECTION Section, PINICACHEKEY AnchorKey, INSERTION_TYPE InsertionType, PWCHAR Name, PWCHAR Data)
Definition: inicache.c:826
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
PVOID *typedef PWSTR
Definition: winlogon.h:66
uint16_t * PWCHAR
Definition: typedefs.h:54
enum OPTION_FLAGS Options
Definition: stats.c:44
#define UNICODE_NULL
_In_ ULONG BufferLength
Definition: usbdlib.h:225
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
Definition: bldrsup.h:16
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
_In_ HANDLE Handle
Definition: extypes.h:390
unsigned char BOOLEAN
if(!(yy_init))
Definition: macro.lex.yy.c:717
NTSTRSAFEAPI RtlStringCchCatW(_Inout_updates_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
Definition: ntstrsafe.h:589
static NTSTATUS CreateNTOSEntry(IN PBOOT_STORE_INI_CONTEXT BootStore, IN ULONG_PTR BootEntryKey, IN PBOOT_STORE_ENTRY BootEntry)
Definition: bldrsup.c:857
struct _BOOT_STORE_CONTEXT * PBOOT_STORE_CONTEXT
BOOT_STORE_TYPE Type
Definition: bldrsup.c:45
static const WCHAR L[]
Definition: oid.c:1087
HANDLE ProcessHeap
Definition: servman.c:15
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define DPRINT1
Definition: precomp.h:8
struct _NTOS_OPTIONS * PNTOS_OPTIONS
BOOT_STORE_TYPE Type
Definition: bldrsup.c:59
NTOS_BOOT_LOADER_FILES NtosBootLoaders[]
Definition: bldrsup.c:122
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
const uint16_t * PCWSTR
Definition: typedefs.h:55
PCWSTR OsLoadPath
Definition: bldrsup.h:87
return STATUS_SUCCESS
Definition: btrfs.c:2710
static const WCHAR Signature[]
Definition: parser.c:141
PCWSTR OsLoadOptions
Definition: bldrsup.h:88
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
NTSTATUS CloseBootStore ( IN PVOID  Handle)

Definition at line 828 of file bldrsup.c.

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

830 {
832 
833  if (!BootStore)
835 
836  /*
837  * NOTE: Currently we open & map the loader configuration file without
838  * further tests. It's OK as long as we only deal with FreeLdr's freeldr.ini
839  * and NTLDR's boot.ini files. But as soon as we'll implement support for
840  * BOOTMGR detection, the "configuration file" will be the BCD registry
841  * hive and then, we'll have instead to mount the hive & open it.
842  */
843 
844  if (BootStore->Type >= BldrTypeMax || NtosBootLoaders[BootStore->Type].Type >= BldrTypeMax)
845  {
846  DPRINT1("Loader type %d is currently unsupported!\n", NtosBootLoaders[BootStore->Type].Type);
847  return STATUS_NOT_SUPPORTED;
848  }
849 
850  return NtosBootLoaders[BootStore->Type].CloseBootStore(Handle /* BootStore */);
851 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ HANDLE Handle
Definition: extypes.h:390
struct _BOOT_STORE_CONTEXT * PBOOT_STORE_CONTEXT
PCLOSE_BOOT_STORE CloseBootStore
Definition: bldrsup.c:49
BOOT_STORE_TYPE Type
Definition: bldrsup.c:45
#define DPRINT1
Definition: precomp.h:8
BOOT_STORE_TYPE Type
Definition: bldrsup.c:59
NTOS_BOOT_LOADER_FILES NtosBootLoaders[]
Definition: bldrsup.c:122
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
static NTSTATUS CloseIniBootLoaderStore ( IN PVOID  Handle)
static

Definition at line 677 of file bldrsup.c.

679 {
682  ULONG FileAttribute = 0;
683 
684  // if (!BootStore)
685  // return STATUS_INVALID_PARAMETER;
686 
687  if (BootStore->SectionHandle)
688  {
689  /*
690  * The INI file was already opened because it already existed,
691  * thus (in the case of NTLDR's boot.ini), unprotect it.
692  */
693  if (BootStore->Header.Type == NtLdr)
694  {
695  Status = UnprotectBootIni(BootStore->FileHandle, &FileAttribute);
696  if (!NT_SUCCESS(Status))
697  {
698  DPRINT1("Could not unprotect BOOT.INI ! (Status 0x%08lx)\n", Status);
699  goto Quit;
700  }
701  }
702  }
703 
704  IniCacheSaveByHandle(BootStore->IniCache, BootStore->FileHandle);
705 
706  /* In the case of NTLDR's boot.ini, re-protect the INI file */
707  if (BootStore->Header.Type == NtLdr)
708  {
710  Status = ProtectBootIni(BootStore->FileHandle, FileAttribute);
711  }
712 
713 Quit:
714  IniCacheDestroy(BootStore->IniCache);
715 
716  if (BootStore->SectionHandle)
717  {
718  /* Finally, unmap and close the file */
719  UnMapAndCloseFile(BootStore->FileHandle,
720  BootStore->SectionHandle,
721  BootStore->ViewBase);
722  }
723  else // if (BootStore->FileHandle)
724  {
725  /* Just close the file we have opened for creation */
726  NtClose(BootStore->FileHandle);
727  }
728 
729  /* Finally, free the boot store structure */
730  RtlFreeHeap(ProcessHeap, 0, BootStore);
731 
732  // TODO: Use a correct Status based on the return values of the previous functions...
733  return STATUS_SUCCESS;
734 }
VOID IniCacheDestroy(PINICACHE Cache)
Definition: inicache.c:666
#define FILE_ATTRIBUTE_SYSTEM
Definition: nt_native.h:704
static NTSTATUS UnprotectBootIni(IN HANDLE FileHandle, OUT PULONG Attributes)
Definition: bldrsup.c:605
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
FileAttribute
Definition: scrrun.idl:67
static NTSTATUS ProtectBootIni(IN HANDLE FileHandle, IN ULONG Attributes)
Definition: bldrsup.c:644
PINICACHE IniCache
Definition: bldrsup.c:81
Definition: bldrsup.h:16
_In_ HANDLE Handle
Definition: extypes.h:390
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
BOOT_STORE_CONTEXT Header
Definition: bldrsup.c:68
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3393
HANDLE ProcessHeap
Definition: servman.c:15
Status
Definition: gdiplustypes.h:24
#define UnMapAndCloseFile(FileHandle, SectionHandle, BaseAddress)
Definition: filesup.h:108
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
#define DPRINT1
Definition: precomp.h:8
BOOT_STORE_TYPE Type
Definition: bldrsup.c:59
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2710
NTSTATUS IniCacheSaveByHandle(PINICACHE Cache, HANDLE FileHandle)
Definition: inicache.c:948
struct _BOOT_STORE_INI_CONTEXT * PBOOT_STORE_INI_CONTEXT
static VOID CreateCommonFreeLdrSections ( IN OUT PBOOT_STORE_INI_CONTEXT  BootStore)
static

Definition at line 208 of file bldrsup.c.

Referenced by OpenIniBootLoaderStore().

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=0 */
232  IniCacheInsertKey(BootStore->OptionsIniSection, NULL, INSERT_LAST,
233  // L"TimeOut", L"0"); // FIXME!! There is a bug in the INI parser where a given key can be inserted twice in the same section...
234  L"TimeOut", L"10");
235 
236  /* Create "Display" section */
237  IniSection = IniCacheAppendSection(BootStore->IniCache, L"Display");
238 
239  /* TitleText=ReactOS Boot Manager */
240  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
241  L"TitleText", L"ReactOS Boot Manager");
242 
243  /* StatusBarColor=Cyan */
244  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
245  L"StatusBarColor", L"Cyan");
246 
247  /* StatusBarTextColor=Black */
248  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
249  L"StatusBarTextColor", L"Black");
250 
251  /* BackdropTextColor=White */
252  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
253  L"BackdropTextColor", L"White");
254 
255  /* BackdropColor=Blue */
256  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
257  L"BackdropColor", L"Blue");
258 
259  /* BackdropFillStyle=Medium */
260  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
261  L"BackdropFillStyle", L"Medium");
262 
263  /* TitleBoxTextColor=White */
264  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
265  L"TitleBoxTextColor", L"White");
266 
267  /* TitleBoxColor=Red */
268  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
269  L"TitleBoxColor", L"Red");
270 
271  /* MessageBoxTextColor=White */
272  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
273  L"MessageBoxTextColor", L"White");
274 
275  /* MessageBoxColor=Blue */
276  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
277  L"MessageBoxColor", L"Blue");
278 
279  /* MenuTextColor=White */
280  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
281  L"MenuTextColor", L"Gray");
282 
283  /* MenuColor=Blue */
284  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
285  L"MenuColor", L"Black");
286 
287  /* TextColor=Yellow */
288  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
289  L"TextColor", L"Gray");
290 
291  /* SelectedTextColor=Black */
292  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
293  L"SelectedTextColor", L"Black");
294 
295  /* SelectedColor=Gray */
296  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
297  L"SelectedColor", L"Gray");
298 
299  /* SelectedColor=Gray */
300  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
301  L"ShowTime", L"No");
302 
303  /* SelectedColor=Gray */
304  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
305  L"MenuBox", L"No");
306 
307  /* SelectedColor=Gray */
308  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
309  L"CenterMenu", L"No");
310 
311  /* SelectedColor=Gray */
312  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
313  L"MinimalUI", L"Yes");
314 
315  /* SelectedColor=Gray */
316  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
317  L"TimeText",
318  L"Seconds until highlighted choice will be started automatically: ");
319 
320  /*
321  * Cache the "Operating Systems" section for our future usage.
322  */
323 
324  /* Get the "Operating Systems" section */
325  IniSection = IniCacheGetSection(BootStore->IniCache, L"Operating Systems");
326  if (!IniSection)
327  {
328  /* It does not exist yet, so create it */
329  IniSection = IniCacheAppendSection(BootStore->IniCache, L"Operating Systems");
330  if (!IniSection)
331  {
332  DPRINT1("CreateCommonFreeLdrSections: Failed to create 'Operating Systems' section!\n");
333  }
334  }
335 
336  BootStore->OsIniSection = IniSection;
337 }
PINICACHEKEY IniCacheInsertKey(PINICACHESECTION Section, PINICACHEKEY AnchorKey, INSERTION_TYPE InsertionType, PWCHAR Name, PWCHAR Data)
Definition: inicache.c:826
PINICACHESECTION IniCacheGetSection(PINICACHE Cache, PWCHAR Name)
Definition: inicache.c:683
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR L[]
Definition: oid.c:1087
#define DPRINT1
Definition: precomp.h:8
PINICACHESECTION IniCacheAppendSection(PINICACHE Cache, PWCHAR Name)
Definition: inicache.c:1088
static NTSTATUS CreateNTOSEntry ( IN PBOOT_STORE_INI_CONTEXT  BootStore,
IN ULONG_PTR  BootEntryKey,
IN PBOOT_STORE_ENTRY  BootEntry 
)
static

Definition at line 857 of file bldrsup.c.

Referenced by AddBootStoreEntry().

861 {
862  PINICACHESECTION IniSection;
863  PWCHAR Section = (PWCHAR)BootEntryKey;
864 
865  /* Insert the entry into the "Operating Systems" section */
866  IniCacheInsertKey(BootStore->OsIniSection, NULL, INSERT_LAST,
867  Section, (PWSTR)BootEntry->FriendlyName);
868 
869  /* Create a new section */
870  IniSection = IniCacheAppendSection(BootStore->IniCache, Section);
871 
872  if (BootEntry->OsOptionsLength >= sizeof(NTOS_OPTIONS) &&
873  RtlCompareMemory(&BootEntry->OsOptions /* Signature */,
877  {
878  PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions;
879 
880  /* BootType= */
881  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
882  L"BootType", L"Windows2003");
883 
884  /* SystemPath= */
885  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
886  L"SystemPath", (PWSTR)Options->OsLoadPath);
887 
888  /* Options= */
889  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
890  L"Options", (PWSTR)Options->OsLoadOptions);
891  }
892  else
893  if (BootEntry->OsOptionsLength >= sizeof(BOOT_SECTOR_OPTIONS) &&
894  RtlCompareMemory(&BootEntry->OsOptions /* Signature */,
898  {
899  PBOOT_SECTOR_OPTIONS Options = (PBOOT_SECTOR_OPTIONS)&BootEntry->OsOptions;
900 
901  /* BootType= */
902  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
903  L"BootType", L"BootSector");
904 
905  /* BootDrive= */
906  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
907  L"BootDrive", (PWSTR)Options->Drive);
908 
909  /* BootPartition= */
910  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
911  L"BootPartition", (PWSTR)Options->Partition);
912 
913  /* BootSector= */
914  IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
915  L"BootSectorFile", (PWSTR)Options->BootSectorFileName);
916  }
917  else
918  {
919  // DPRINT1("Unsupported BootType %lu/'%*.s'\n",
920  // BootEntry->OsOptionsLength, 8, &BootEntry->OsOptions);
921  DPRINT1("Unsupported BootType %lu\n", BootEntry->OsOptionsLength);
922  }
923 
924  return STATUS_SUCCESS;
925 }
#define BOOT_SECTOR_OPTIONS_SIGNATURE
Definition: bldrsup.h:111
#define NTOS_OPTIONS_SIGNATURE
Definition: bldrsup.h:98
#define RTL_FIELD_SIZE(type, field)
Definition: kdb_expr.c:84
PINICACHEKEY IniCacheInsertKey(PINICACHESECTION Section, PINICACHEKEY AnchorKey, INSERTION_TYPE InsertionType, PWCHAR Name, PWCHAR Data)
Definition: inicache.c:826
PVOID *typedef PWSTR
Definition: winlogon.h:66
uint16_t * PWCHAR
Definition: typedefs.h:54
enum OPTION_FLAGS Options
Definition: stats.c:44
PCWSTR BootSectorFileName
Definition: bldrsup.h:108
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR L[]
Definition: oid.c:1087
#define DPRINT1
Definition: precomp.h:8
struct _NTOS_OPTIONS * PNTOS_OPTIONS
struct _BOOT_SECTOR_OPTIONS * PBOOT_SECTOR_OPTIONS
PCWSTR OsLoadPath
Definition: bldrsup.h:87
return STATUS_SUCCESS
Definition: btrfs.c:2710
static const WCHAR Signature[]
Definition: parser.c:141
PCWSTR OsLoadOptions
Definition: bldrsup.h:88
PINICACHESECTION IniCacheAppendSection(PINICACHE Cache, PWCHAR Name)
Definition: inicache.c:1088
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
NTSTATUS DeleteBootStoreEntry ( IN PVOID  Handle,
IN ULONG_PTR  BootEntryKey 
)

Definition at line 1026 of file bldrsup.c.

1029 {
1031 
1032  if (!BootStore)
1033  return STATUS_INVALID_PARAMETER;
1034 
1035  /*
1036  * NOTE: Currently we open & map the loader configuration file without
1037  * further tests. It's OK as long as we only deal with FreeLdr's freeldr.ini
1038  * and NTLDR's boot.ini files. But as soon as we'll implement support for
1039  * BOOTMGR detection, the "configuration file" will be the BCD registry
1040  * hive and then, we'll have instead to mount the hive & open it.
1041  */
1042 
1043  //
1044  // FIXME!!
1045  //
1046 
1047  // if (BootStore->Type >= BldrTypeMax || NtosBootLoaders[BootStore->Type].Type >= BldrTypeMax)
1048  if (BootStore->Type != FreeLdr)
1049  {
1050  DPRINT1("Loader type %d is currently unsupported!\n", NtosBootLoaders[BootStore->Type].Type);
1051  return STATUS_NOT_SUPPORTED;
1052  }
1053 
1054  // FIXME! This function needs my INI library rewrite to be implemented!!
1055  UNIMPLEMENTED;
1056  return STATUS_NOT_IMPLEMENTED;
1057 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ HANDLE Handle
Definition: extypes.h:390
struct _BOOT_STORE_CONTEXT * PBOOT_STORE_CONTEXT
BOOT_STORE_TYPE Type
Definition: bldrsup.c:45
#define DPRINT1
Definition: precomp.h:8
BOOT_STORE_TYPE Type
Definition: bldrsup.c:59
NTOS_BOOT_LOADER_FILES NtosBootLoaders[]
Definition: bldrsup.c:122
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
#define UNIMPLEMENTED
Definition: debug.h:114
NTSTATUS EnumerateBootStoreEntries ( IN PVOID  Handle,
IN PENUM_BOOT_ENTRIES_ROUTINE  EnumBootEntriesRoutine,
IN PVOID Parameter  OPTIONAL 
)

Definition at line 1560 of file bldrsup.c.

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

1565 {
1567 
1568  if (!BootStore)
1569  return STATUS_INVALID_PARAMETER;
1570 
1571  if (BootStore->Type >= BldrTypeMax || NtosBootLoaders[BootStore->Type].Type >= BldrTypeMax)
1572  {
1573  DPRINT1("Loader type %d is currently unsupported!\n", NtosBootLoaders[BootStore->Type].Type);
1574  return STATUS_SUCCESS;
1575  // return STATUS_INVALID_PARAMETER;
1576  }
1577 
1578  return NtosBootLoaders[BootStore->Type].EnumBootStoreEntries(
1579  (PBOOT_STORE_INI_CONTEXT)BootStore, // Flags,
1580  EnumBootEntriesRoutine, Parameter);
1581 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ PVOID Parameter
Definition: ldrtypes.h:239
PENUM_BOOT_STORE_ENTRIES EnumBootStoreEntries
Definition: bldrsup.c:50
_In_ HANDLE Handle
Definition: extypes.h:390
struct _BOOT_STORE_CONTEXT * PBOOT_STORE_CONTEXT
BOOT_STORE_TYPE Type
Definition: bldrsup.c:45
#define DPRINT1
Definition: precomp.h:8
BOOT_STORE_TYPE Type
Definition: bldrsup.c:59
NTOS_BOOT_LOADER_FILES NtosBootLoaders[]
Definition: bldrsup.c:122
return STATUS_SUCCESS
Definition: btrfs.c:2710
NTSTATUS FindBootStore ( IN HANDLE  PartitionDirectoryHandle,
IN BOOT_STORE_TYPE  Type,
OUT PULONG VersionNumber  OPTIONAL 
)

Definition at line 137 of file bldrsup.c.

Referenced by FindNTOSInstallations().

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:6
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
HANDLE FileHandle
Definition: stats.c:38
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
#define DoesFileExist(RootDirectory, FileName)
Definition: filesup.h:77
PCZZWSTR LoaderExecutables
Definition: bldrsup.c:46
#define STATUS_NOT_FOUND
Definition: shellext.h:55
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8
NTOS_BOOT_LOADER_FILES NtosBootLoaders[]
Definition: bldrsup.c:122
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
const uint16_t * PCWSTR
Definition: typedefs.h:55
return STATUS_SUCCESS
Definition: btrfs.c:2710
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static NTSTATUS FreeLdrEnumerateBootEntries ( IN PBOOT_STORE_INI_CONTEXT  BootStore,
IN PENUM_BOOT_ENTRIES_ROUTINE  EnumBootEntriesRoutine,
IN PVOID Parameter  OPTIONAL 
)
static

Definition at line 1249 of file bldrsup.c.

1254 {
1256  PINICACHEITERATOR Iterator;
1257  PINICACHESECTION OsIniSection;
1258  PWCHAR SectionName, KeyData;
1259  UCHAR xxBootEntry[FIELD_OFFSET(BOOT_STORE_ENTRY, OsOptions) +
1260  max(sizeof(NTOS_OPTIONS), sizeof(BOOT_SECTOR_OPTIONS))];
1261  PBOOT_STORE_ENTRY BootEntry = (PBOOT_STORE_ENTRY)&xxBootEntry;
1262  PWCHAR Buffer;
1263 
1264  /* Enumerate all the valid installations listed in the "Operating Systems" section */
1265  Iterator = IniCacheFindFirstValue(BootStore->OsIniSection, &SectionName, &KeyData);
1266  if (!Iterator) return STATUS_SUCCESS;
1267  do
1268  {
1269  PWCHAR InstallName;
1270  ULONG InstallNameLength;
1271 
1272  /* Poor-man quotes removal (improvement over bootsup.c:UpdateFreeLoaderIni) */
1273  if (*KeyData == L'"')
1274  {
1275  /* Quoted name, copy up to the closing quote */
1276  PWCHAR End = wcschr(KeyData + 1, L'"');
1277 
1278  if (End)
1279  {
1280  /* Skip the first quote */
1281  InstallName = KeyData + 1;
1282  InstallNameLength = End - InstallName;
1283  }
1284  else // if (!End)
1285  {
1286  /* No corresponding closing quote, so we include the first one in the InstallName */
1287  InstallName = KeyData;
1288  InstallNameLength = wcslen(InstallName);
1289  }
1290  if (InstallNameLength == 0) InstallName = NULL;
1291  }
1292  else
1293  {
1294  /* Non-quoted name, copy everything */
1295  InstallName = KeyData;
1296  InstallNameLength = wcslen(InstallName);
1297  if (InstallNameLength == 0) InstallName = NULL;
1298  }
1299 
1300  /* Allocate the temporary buffer */
1301  Buffer = NULL;
1302  if (InstallNameLength)
1303  Buffer = RtlAllocateHeap(ProcessHeap, HEAP_ZERO_MEMORY, (InstallNameLength + 1) * sizeof(WCHAR));
1304  if (Buffer)
1305  {
1306  RtlCopyMemory(Buffer, InstallName, InstallNameLength * sizeof(WCHAR));
1307  Buffer[InstallNameLength] = UNICODE_NULL;
1308  InstallName = Buffer;
1309  }
1310 
1311  DPRINT("Boot entry '%S' in OS section '%S'\n", InstallName, SectionName);
1312 
1313  BootEntry->Version = FreeLdr;
1314  BootEntry->BootEntryKey = MAKESTRKEY(SectionName);
1315  BootEntry->FriendlyName = InstallName;
1316  BootEntry->BootFilePath = NULL;
1317  BootEntry->OsOptionsLength = 0;
1318 
1319  /* Search for an existing boot entry section */
1320  OsIniSection = IniCacheGetSection(BootStore->IniCache, SectionName);
1321  if (!OsIniSection)
1322  goto DoEnum;
1323 
1324  /* Check for supported boot type "Windows2003" */
1325  Status = IniCacheGetKey(OsIniSection, L"BootType", &KeyData);
1326  if (!NT_SUCCESS(Status) || (KeyData == NULL))
1327  {
1328  /* Certainly not a ReactOS installation */
1329  DPRINT1("No BootType value present!\n");
1330  goto DoEnum;
1331  }
1332 
1333  // TODO: What to do with "Windows" ; "WindowsNT40" ; "ReactOSSetup" ?
1334  if ((_wcsicmp(KeyData, L"Windows2003") == 0) ||
1335  (_wcsicmp(KeyData, L"\"Windows2003\"") == 0))
1336  {
1337  /* BootType is Windows2003 */
1339 
1340  DPRINT("This is a '%S' boot entry\n", KeyData);
1341 
1342  BootEntry->OsOptionsLength = sizeof(NTOS_OPTIONS);
1343  RtlCopyMemory(Options->Signature,
1346 
1347  // BootEntry->BootFilePath = NULL;
1348 
1349  /* Check its SystemPath */
1350  Status = IniCacheGetKey(OsIniSection, L"SystemPath", &KeyData);
1351  if (!NT_SUCCESS(Status))
1352  Options->OsLoadPath = NULL;
1353  else
1354  Options->OsLoadPath = KeyData;
1355  // KeyData == SystemRoot;
1356 
1357  /* Check the optional Options */
1358  Status = IniCacheGetKey(OsIniSection, L"Options", &KeyData);
1359  if (!NT_SUCCESS(Status))
1360  Options->OsLoadOptions = NULL;
1361  else
1362  Options->OsLoadOptions = KeyData;
1363  }
1364  else
1365  if ((_wcsicmp(KeyData, L"BootSector") == 0) ||
1366  (_wcsicmp(KeyData, L"\"BootSector\"") == 0))
1367  {
1368  /* BootType is BootSector */
1369  PBOOT_SECTOR_OPTIONS Options = (PBOOT_SECTOR_OPTIONS)&BootEntry->OsOptions;
1370 
1371  DPRINT("This is a '%S' boot entry\n", KeyData);
1372 
1373  BootEntry->OsOptionsLength = sizeof(BOOT_SECTOR_OPTIONS);
1374  RtlCopyMemory(Options->Signature,
1377 
1378  // BootEntry->BootFilePath = NULL;
1379 
1380  /* Check its BootDrive */
1381  Status = IniCacheGetKey(OsIniSection, L"BootDrive", &KeyData);
1382  if (!NT_SUCCESS(Status))
1383  Options->Drive = NULL;
1384  else
1385  Options->Drive = KeyData;
1386 
1387  /* Check its BootPartition */
1388  Status = IniCacheGetKey(OsIniSection, L"BootPartition", &KeyData);
1389  if (!NT_SUCCESS(Status))
1390  Options->Partition = NULL;
1391  else
1392  Options->Partition = KeyData;
1393 
1394  /* Check its BootSector */
1395  Status = IniCacheGetKey(OsIniSection, L"BootSectorFile", &KeyData);
1396  if (!NT_SUCCESS(Status))
1397  Options->BootSectorFileName = NULL;
1398  else
1399  Options->BootSectorFileName = KeyData;
1400  }
1401  else
1402  {
1403  DPRINT1("Unrecognized BootType value '%S'\n", KeyData);
1404  // goto DoEnum;
1405  }
1406 
1407 DoEnum:
1408  /* Call the user enumeration routine callback */
1409  Status = EnumBootEntriesRoutine(FreeLdr, BootEntry, Parameter);
1410 
1411  /* Free temporary buffers */
1412  if (Buffer)
1413  RtlFreeHeap(ProcessHeap, 0, Buffer);
1414 
1415  /* Stop the enumeration if needed */
1416  if (!NT_SUCCESS(Status))
1417  break;
1418  }
1419  while (IniCacheFindNextValue(Iterator, &SectionName, &KeyData));
1420 
1421  IniCacheFindClose(Iterator);
1422  return Status;
1423 }
#define BOOT_SECTOR_OPTIONS_SIGNATURE
Definition: bldrsup.h:111
#define NTOS_OPTIONS_SIGNATURE
Definition: bldrsup.h:98
#define RTL_FIELD_SIZE(type, field)
Definition: kdb_expr.c:84
#define max(a, b)
Definition: svc.c:63
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
struct _BOOT_SECTOR_OPTIONS BOOT_SECTOR_OPTIONS
ULONG_PTR BootEntryKey
Definition: bldrsup.h:66
#define MAKESTRKEY(i)
Definition: bldrsup.h:54
UCHAR OsOptions[ANYSIZE_ARRAY]
Definition: bldrsup.h:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
PINICACHESECTION IniCacheGetSection(PINICACHE Cache, PWCHAR Name)
Definition: inicache.c:683
uint16_t * PWCHAR
Definition: typedefs.h:54
_In_ PVOID Parameter
Definition: ldrtypes.h:239
BOOLEAN IniCacheFindNextValue(PINICACHEITERATOR Iterator, PWCHAR *KeyName, PWCHAR *KeyData)
Definition: inicache.c:785
enum OPTION_FLAGS Options
Definition: stats.c:44
struct _BOOT_STORE_ENTRY * PBOOT_STORE_ENTRY
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define UNICODE_NULL
PCWSTR BootSectorFileName
Definition: bldrsup.h:108
UCHAR Signature[8]
Definition: bldrsup.h:103
struct _NTOS_OPTIONS NTOS_OPTIONS
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PCWSTR BootFilePath
Definition: bldrsup.h:68
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
ULONG OsOptionsLength
Definition: bldrsup.h:69
NTSTATUS IniCacheGetKey(PINICACHESECTION Section, PWCHAR KeyName, PWCHAR *KeyData)
Definition: inicache.c:716
LONG NTSTATUS
Definition: precomp.h:26
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
unsigned char UCHAR
Definition: xmlstorage.h:181
VOID IniCacheFindClose(PINICACHEITERATOR Iterator)
Definition: inicache.c:815
static const WCHAR L[]
Definition: oid.c:1087
HANDLE ProcessHeap
Definition: servman.c:15
Status
Definition: gdiplustypes.h:24
UCHAR Signature[8]
Definition: bldrsup.h:84
ULONG Version
Definition: bldrsup.h:64
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define DPRINT1
Definition: precomp.h:8
struct _NTOS_OPTIONS * PNTOS_OPTIONS
struct _BOOT_SECTOR_OPTIONS * PBOOT_SECTOR_OPTIONS
PCWSTR FriendlyName
Definition: bldrsup.h:67
unsigned int ULONG
Definition: retypes.h:1
PCWSTR OsLoadPath
Definition: bldrsup.h:87
return STATUS_SUCCESS
Definition: btrfs.c:2710
static const WCHAR Signature[]
Definition: parser.c:141
PCWSTR OsLoadOptions
Definition: bldrsup.h:88
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
Definition: bldrsup.h:62
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
PINICACHEITERATOR IniCacheFindFirstValue(PINICACHESECTION Section, PWCHAR *KeyName, PWCHAR *KeyData)
Definition: inicache.c:744
NTSTATUS ModifyBootStoreEntry ( IN PVOID  Handle,
IN PBOOT_STORE_ENTRY  BootEntry 
)

Definition at line 1060 of file bldrsup.c.

1063 {
1065 
1066  if (!BootStore || !BootEntry)
1067  return STATUS_INVALID_PARAMETER;
1068 
1069  /*
1070  * NOTE: Currently we open & map the loader configuration file without
1071  * further tests. It's OK as long as we only deal with FreeLdr's freeldr.ini
1072  * and NTLDR's boot.ini files. But as soon as we'll implement support for
1073  * BOOTMGR detection, the "configuration file" will be the BCD registry
1074  * hive and then, we'll have instead to mount the hive & open it.
1075  */
1076 
1077  //
1078  // FIXME!!
1079  //
1080 
1081  // if (BootStore->Type >= BldrTypeMax || NtosBootLoaders[BootStore->Type].Type >= BldrTypeMax)
1082  if (BootStore->Type != FreeLdr)
1083  {
1084  DPRINT1("Loader type %d is currently unsupported!\n", NtosBootLoaders[BootStore->Type].Type);
1085  return STATUS_NOT_SUPPORTED;
1086  }
1087 
1088  // FIXME! This function needs my INI library rewrite to operate properly!!
1089  UNIMPLEMENTED;
1090  return STATUS_NOT_IMPLEMENTED;
1091 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ HANDLE Handle
Definition: extypes.h:390
struct _BOOT_STORE_CONTEXT * PBOOT_STORE_CONTEXT
BOOT_STORE_TYPE Type
Definition: bldrsup.c:45
#define DPRINT1
Definition: precomp.h:8
BOOT_STORE_TYPE Type
Definition: bldrsup.c:59
NTOS_BOOT_LOADER_FILES NtosBootLoaders[]
Definition: bldrsup.c:122
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
#define UNIMPLEMENTED
Definition: debug.h:114
static NTSTATUS NtLdrEnumerateBootEntries ( IN PBOOT_STORE_INI_CONTEXT  BootStore,
IN PENUM_BOOT_ENTRIES_ROUTINE  EnumBootEntriesRoutine,
IN PVOID Parameter  OPTIONAL 
)
static

Definition at line 1426 of file bldrsup.c.

1431 {
1433  PINICACHEITERATOR Iterator;
1434  PWCHAR SectionName, KeyData;
1435  UCHAR xxBootEntry[FIELD_OFFSET(BOOT_STORE_ENTRY, OsOptions) + sizeof(NTOS_OPTIONS)];
1436  PBOOT_STORE_ENTRY BootEntry = (PBOOT_STORE_ENTRY)&xxBootEntry;
1437  PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions;
1438  PWCHAR Buffer;
1440 
1441  /* Enumerate all the valid installations */
1442  Iterator = IniCacheFindFirstValue(BootStore->OsIniSection, &SectionName, &KeyData);
1443  if (!Iterator) return STATUS_SUCCESS;
1444  do
1445  {
1446  PWCHAR InstallName, OsOptions;
1447  ULONG InstallNameLength, OsOptionsLength;
1448 
1449  /* Poor-man quotes removal (improvement over bootsup.c:UpdateFreeLoaderIni) */
1450  if (*KeyData == L'"')
1451  {
1452  /* Quoted name, copy up to the closing quote */
1453  OsOptions = wcschr(KeyData + 1, L'"');
1454 
1455  /* Retrieve the starting point of the installation name and the OS options */
1456  if (OsOptions)
1457  {
1458  /* Skip the first quote */
1459  InstallName = KeyData + 1;
1460  InstallNameLength = OsOptions - InstallName;
1461  if (InstallNameLength == 0) InstallName = NULL;
1462 
1463  /* Skip the ending quote (if found) */
1464  ++OsOptions;
1465 
1466  /* Skip any whitespace */
1467  while (iswspace(*OsOptions)) ++OsOptions;
1468  /* Get its final length */
1469  OsOptionsLength = wcslen(OsOptions);
1470  if (OsOptionsLength == 0) OsOptions = NULL;
1471  }
1472  else
1473  {
1474  /* No corresponding closing quote, so we include the first one in the InstallName */
1475  InstallName = KeyData;
1476  InstallNameLength = wcslen(InstallName);
1477  if (InstallNameLength == 0) InstallName = NULL;
1478 
1479  /* There are no OS options */
1480  // OsOptions = NULL;
1481  OsOptionsLength = 0;
1482  }
1483  }
1484  else
1485  {
1486  /* Non-quoted name, copy everything */
1487 
1488  /* Retrieve the starting point of the installation name */
1489  InstallName = KeyData;
1490  InstallNameLength = wcslen(InstallName);
1491  if (InstallNameLength == 0) InstallName = NULL;
1492 
1493  /* There are no OS options */
1494  OsOptions = NULL;
1495  OsOptionsLength = 0;
1496  }
1497 
1498  /* Allocate the temporary buffer */
1499  Buffer = NULL;
1500  BufferLength = (InstallNameLength + OsOptionsLength) * sizeof(WCHAR);
1501  if (BufferLength)
1503  if (Buffer)
1504  {
1505  PWCHAR ptr;
1506 
1507  /* Copy the installation name, and make InstallName point into the buffer */
1508  if (InstallName && InstallNameLength)
1509  {
1510  ptr = Buffer;
1511  RtlCopyMemory(ptr, InstallName, InstallNameLength * sizeof(WCHAR));
1512  ptr[InstallNameLength] = UNICODE_NULL;
1513  InstallName = ptr;
1514  }
1515 
1516  /* Copy the OS options, and make OsOptions point into the buffer */
1517  if (OsOptions && OsOptionsLength)
1518  {
1519  ptr = Buffer + InstallNameLength + 1;
1520  RtlCopyMemory(ptr, OsOptions, OsOptionsLength * sizeof(WCHAR));
1521  ptr[OsOptionsLength] = UNICODE_NULL;
1522  OsOptions = ptr;
1523  }
1524  }
1525 
1526  DPRINT1("Boot entry '%S' in OS section (path) '%S'\n", InstallName, SectionName);
1527  // SectionName == SystemRoot;
1528 
1529  BootEntry->Version = NtLdr;
1530  BootEntry->BootEntryKey = 0; // FIXME??
1531  BootEntry->FriendlyName = InstallName;
1532  BootEntry->BootFilePath = NULL;
1533 
1534  BootEntry->OsOptionsLength = sizeof(NTOS_OPTIONS);
1535  RtlCopyMemory(Options->Signature,
1538 
1539  Options->OsLoadPath = SectionName;
1540  Options->OsLoadOptions = OsOptions;
1541 
1542  /* Call the user enumeration routine callback */
1543  Status = EnumBootEntriesRoutine(NtLdr, BootEntry, Parameter);
1544 
1545  /* Free temporary buffers */
1546  if (Buffer)
1548 
1549  /* Stop the enumeration if needed */
1550  if (!NT_SUCCESS(Status))
1551  break;
1552  }
1553  while (IniCacheFindNextValue(Iterator, &SectionName, &KeyData));
1554 
1555  IniCacheFindClose(Iterator);
1556  return Status;
1557 }
#define NTOS_OPTIONS_SIGNATURE
Definition: bldrsup.h:98
#define RTL_FIELD_SIZE(type, field)
Definition: kdb_expr.c:84
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
uint16_t * PWCHAR
Definition: typedefs.h:54
_In_ PVOID Parameter
Definition: ldrtypes.h:239
BOOLEAN IniCacheFindNextValue(PINICACHEITERATOR Iterator, PWCHAR *KeyName, PWCHAR *KeyData)
Definition: inicache.c:785
enum OPTION_FLAGS Options
Definition: stats.c:44
struct _BOOT_STORE_ENTRY * PBOOT_STORE_ENTRY
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define UNICODE_NULL
_In_ ULONG BufferLength
Definition: usbdlib.h:225
static PVOID ptr
Definition: dispmode.c:27
struct _NTOS_OPTIONS NTOS_OPTIONS
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
Definition: bldrsup.h:16
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
LONG NTSTATUS
Definition: precomp.h:26
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define iswspace(_c)
Definition: ctype.h:669
unsigned char UCHAR
Definition: xmlstorage.h:181
VOID IniCacheFindClose(PINICACHEITERATOR Iterator)
Definition: inicache.c:815
static const WCHAR L[]
Definition: oid.c:1087
HANDLE ProcessHeap
Definition: servman.c:15
Status
Definition: gdiplustypes.h:24
UCHAR Signature[8]
Definition: bldrsup.h:84
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define DPRINT1
Definition: precomp.h:8
struct _NTOS_OPTIONS * PNTOS_OPTIONS
unsigned int ULONG
Definition: retypes.h:1
PCWSTR OsLoadPath
Definition: bldrsup.h:87
return STATUS_SUCCESS
Definition: btrfs.c:2710
static const WCHAR Signature[]
Definition: parser.c:141
PCWSTR OsLoadOptions
Definition: bldrsup.h:88
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
Definition: bldrsup.h:62
PINICACHEITERATOR IniCacheFindFirstValue(PINICACHESECTION Section, PWCHAR *KeyName, PWCHAR *KeyData)
Definition: inicache.c:744
NTSTATUS OpenBootStore ( OUT PVOID Handle,
IN PCWSTR  SystemPartition,
IN BOOT_STORE_TYPE  Type,
IN BOOLEAN  CreateNew 
)

Definition at line 816 of file bldrsup.c.

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

821 {
822  UNICODE_STRING SystemPartitionPath;
823  RtlInitUnicodeString(&SystemPartitionPath, SystemPartition);
824  return OpenBootStore_UStr(Handle, &SystemPartitionPath, Type, CreateNew);
825 }
Type
Definition: Type.h:6
NTSTATUS OpenBootStore_UStr(OUT PVOID *Handle, IN PUNICODE_STRING SystemPartitionPath, IN BOOT_STORE_TYPE Type, IN BOOLEAN CreateNew)
Definition: bldrsup.c:765
_In_ HANDLE Handle
Definition: extypes.h:390
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSTATUS OpenBootStore_UStr ( OUT PVOID Handle,
IN PUNICODE_STRING  SystemPartitionPath,
IN BOOT_STORE_TYPE  Type,
IN BOOLEAN  CreateNew 
)

Definition at line 765 of file bldrsup.c.

Referenced by OpenBootStore().

770 {
774  HANDLE PartitionDirectoryHandle;
775 
776  /*
777  * NOTE: Currently we open & map the loader configuration file without
778  * further tests. It's OK as long as we only deal with FreeLdr's freeldr.ini
779  * and NTLDR's boot.ini files. But as soon as we'll implement support for
780  * BOOTMGR detection, the "configuration file" will be the BCD registry
781  * hive and then, we'll have instead to mount the hive & open it.
782  */
783 
785  {
786  DPRINT1("Loader type %d is currently unsupported!\n", NtosBootLoaders[Type].Type);
787  return STATUS_NOT_SUPPORTED;
788  }
789 
790  /* Open SystemPartition */
791  InitializeObjectAttributes(&ObjectAttributes,
792  SystemPartitionPath,
794  NULL,
795  NULL);
796  Status = NtOpenFile(&PartitionDirectoryHandle,
797  FILE_LIST_DIRECTORY | FILE_ADD_FILE /* | FILE_ADD_SUBDIRECTORY | FILE_TRAVERSE*/ | SYNCHRONIZE,
798  &ObjectAttributes,
799  &IoStatusBlock,
801  FILE_SYNCHRONOUS_IO_NONALERT | FILE_DIRECTORY_FILE /* | FILE_OPEN_FOR_BACKUP_INTENT */);
802  if (!NT_SUCCESS(Status))
803  {
804  DPRINT1("Failed to open SystemPartition '%wZ', Status 0x%08lx\n", SystemPartitionPath, Status);
805  return Status;
806  }
807 
808  Status = OpenBootStoreByHandle(Handle, PartitionDirectoryHandle, Type, CreateNew);
809 
810  /* Done! */
811  NtClose(PartitionDirectoryHandle);
812  return Status;
813 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
Type
Definition: Type.h:6
#define FILE_DIRECTORY_FILE
Definition: constants.h:491
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:125
#define FILE_ADD_FILE
Definition: nt_native.h:632
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
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_LIST_DIRECTORY
Definition: nt_native.h:629
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3393
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define SYNCHRONIZE
Definition: nt_native.h:61
Status
Definition: gdiplustypes.h:24
DWORD *typedef HANDLE
Definition: winlogon.h:61
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define DPRINT1
Definition: precomp.h:8
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
NTOS_BOOT_LOADER_FILES NtosBootLoaders[]
Definition: bldrsup.c:122
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSTATUS OpenBootStoreByHandle(OUT PVOID *Handle, IN HANDLE PartitionDirectoryHandle, IN BOOT_STORE_TYPE Type, IN BOOLEAN CreateNew)
Definition: bldrsup.c:738
NTSTATUS OpenBootStoreByHandle ( OUT PVOID Handle,
IN HANDLE  PartitionDirectoryHandle,
IN BOOT_STORE_TYPE  Type,
IN BOOLEAN  CreateNew 
)

Definition at line 738 of file bldrsup.c.

Referenced by FindNTOSInstallations(), and OpenBootStore_UStr().

743 {
744  /*
745  * NOTE: Currently we open & map the loader configuration file without
746  * further tests. It's OK as long as we only deal with FreeLdr's freeldr.ini
747  * and NTLDR's boot.ini files. But as soon as we'll implement support for
748  * BOOTMGR detection, the "configuration file" will be the BCD registry
749  * hive and then, we'll have instead to mount the hive & open it.
750  */
751 
753  {
754  DPRINT1("Loader type %d is currently unsupported!\n", NtosBootLoaders[Type].Type);
755  return STATUS_NOT_SUPPORTED;
756  }
757 
759  PartitionDirectoryHandle,
760  Type,
761  CreateNew);
762 }
Type
Definition: Type.h:6
POPEN_BOOT_STORE OpenBootStore
Definition: bldrsup.c:48
_In_ HANDLE Handle
Definition: extypes.h:390
#define DPRINT1
Definition: precomp.h:8
NTOS_BOOT_LOADER_FILES NtosBootLoaders[]
Definition: bldrsup.c:122
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
static NTSTATUS OpenIniBootLoaderStore ( OUT PVOID Handle,
IN HANDLE  PartitionDirectoryHandle,
IN BOOT_STORE_TYPE  Type,
IN BOOLEAN  CreateNew 
)
static

Definition at line 340 of file bldrsup.c.

345 {
347  PBOOT_STORE_INI_CONTEXT BootStore;
348 
349  /* Create a boot store structure */
350  BootStore = RtlAllocateHeap(ProcessHeap, HEAP_ZERO_MEMORY, sizeof(*BootStore));
351  if (!BootStore)
353 
354  BootStore->Header.Type = Type;
355 
356  if (CreateNew)
357  {
361 
362  //
363  // WARNING! We "support" the INI creation *ONLY* for FreeLdr, and not for NTLDR!!
364  //
365  if (Type == NtLdr)
366  {
367  DPRINT1("OpenIniBootLoaderStore() unsupported for NTLDR!\n");
368  RtlFreeHeap(ProcessHeap, 0, BootStore);
369  return STATUS_NOT_SUPPORTED;
370  }
371 
372  /* Initialize the INI file */
373  BootStore->IniCache = IniCacheCreate();
374  if (!BootStore->IniCache)
375  {
376  DPRINT1("IniCacheCreate() failed.\n");
377  RtlFreeHeap(ProcessHeap, 0, BootStore);
379  }
380 
381  /*
382  * So far, we only use the INI cache. The file itself is not created
383  * yet, therefore FileHandle, SectionHandle, ViewBase and FileSize
384  * are all NULL. We will use this fact to know that the INI file was
385  * indeed created, and not just opened as an existing file.
386  */
387  // BootStore->FileHandle = NULL;
388  BootStore->SectionHandle = NULL;
389  BootStore->ViewBase = NULL;
390  BootStore->FileSize = 0;
391 
392  /*
393  * The INI file is fresh new, we need to create it now.
394  */
395 
396  RtlInitUnicodeString(&Name, NtosBootLoaders[Type].LoaderConfigurationFile);
397 
398  InitializeObjectAttributes(&ObjectAttributes,
399  &Name,
401  PartitionDirectoryHandle,
402  NULL);
403 
404  Status = NtCreateFile(&BootStore->FileHandle,
405  FILE_GENERIC_READ | FILE_GENERIC_WRITE, // Contains SYNCHRONIZE
406  &ObjectAttributes,
407  &IoStatusBlock,
408  NULL,
410  0,
413  NULL,
414  0);
415  if (!NT_SUCCESS(Status))
416  {
417  DPRINT1("NtCreateFile() failed (Status 0x%08lx)\n", Status);
418  IniCacheDestroy(BootStore->IniCache);
419  RtlFreeHeap(ProcessHeap, 0, BootStore);
420  return Status;
421  }
422 
423  /* Initialize the INI file contents */
424  if (Type == FreeLdr)
425  CreateCommonFreeLdrSections(BootStore);
426  }
427  else
428  {
429  PINICACHESECTION IniSection;
430 
431  /*
432  * Check whether the loader configuration INI file exists,
433  * and open it if so.
434  * TODO: FIXME: What if it doesn't exist yet???
435  */
436  Status = OpenAndMapFile(PartitionDirectoryHandle,
437  NtosBootLoaders[Type].LoaderConfigurationFile,
438  &BootStore->FileHandle,
439  &BootStore->SectionHandle,
440  &BootStore->ViewBase,
441  &BootStore->FileSize,
442  TRUE);
443  if (!NT_SUCCESS(Status))
444  {
445  /* The loader configuration file does not exist */
446  // FIXME: Consider it might be optional??
447  DPRINT1("Loader configuration file '%S' does not exist (Status 0x%08lx)\n",
448  NtosBootLoaders[Type].LoaderConfigurationFile, Status);
449  RtlFreeHeap(ProcessHeap, 0, BootStore);
450  return Status;
451  }
452 
453  /* Open an *existing* INI configuration file */
454  // Status = IniCacheLoad(&BootStore->IniCache, NtosBootLoaders[Type].LoaderConfigurationFile, FALSE);
455  Status = IniCacheLoadFromMemory(&BootStore->IniCache,
456  BootStore->ViewBase,
457  BootStore->FileSize,
458  FALSE);
459  if (!NT_SUCCESS(Status))
460  {
461  DPRINT1("IniCacheLoadFromMemory() failed (Status 0x%08lx)\n", Status);
462 
463  /* Finally, unmap and close the file */
464  UnMapAndCloseFile(BootStore->FileHandle,
465  BootStore->SectionHandle,
466  BootStore->ViewBase);
467 
468  RtlFreeHeap(ProcessHeap, 0, BootStore);
469  return Status;
470  }
471 
472  if (Type == FreeLdr)
473  {
474  /*
475  * Cache the "FREELOADER" section for our future usage.
476  */
477 
478  /* Get the "FREELOADER" section */
479  IniSection = IniCacheGetSection(BootStore->IniCache, L"FREELOADER");
480  if (!IniSection)
481  {
482  /* It does not exist yet, so create it */
483  IniSection = IniCacheAppendSection(BootStore->IniCache, L"FREELOADER");
484  if (!IniSection)
485  {
486  DPRINT1("OpenIniBootLoaderStore: Failed to retrieve 'FREELOADER' section!\n");
487  }
488  }
489 
490  BootStore->OptionsIniSection = IniSection;
491 
492  /*
493  * Cache the "Operating Systems" section for our future usage.
494  */
495 
496  /* Get the "Operating Systems" section */
497  IniSection = IniCacheGetSection(BootStore->IniCache, L"Operating Systems");
498  if (!IniSection)
499  {
500  /* It does not exist yet, so create it */
501  IniSection = IniCacheAppendSection(BootStore->IniCache, L"Operating Systems");
502  if (!IniSection)
503  {
504  DPRINT1("OpenIniBootLoaderStore: Failed to retrieve 'Operating Systems' section!\n");
505  }
506  }
507 
508  BootStore->OsIniSection = IniSection;
509  }
510  else
511  if (Type == NtLdr)
512  {
513  /*
514  * Cache the "boot loader" section for our future usage.
515  */
516  /*
517  * HISTORICAL NOTE:
518  *
519  * While the "operating systems" section acquired its definitive
520  * name already when Windows NT was at its very early beta stage
521  * (NT 3.1 October 1991 Beta, 10-16-1991), this was not the case
522  * for its general settings section "boot loader".
523  *
524  * The following section names were successively introduced:
525  *
526  * - In NT 3.1 October 1991 Beta, 10-16-1991, using OS Loader V1.5,
527  * the section was named "multiboot".
528  *
529  * - In the next public beta version NT 3.10.340 Beta, 10-12-1992,
530  * using OS Loader V2.10, a new name was introduced: "flexboot".
531  * This is around this time that the NT OS Loader was also
532  * introduced as the "Windows NT FlexBoot" loader, as shown by
533  * the Windows NT FAQs that circulated around this time:
534  * http://cd.textfiles.com/cica9308/CIS_LIBS/WINNT/1/NTFAQ.TXT
535  * http://cd.textfiles.com/cica/cica9308/UNZIPPED/NT/NTFAQ/FTP/NEWS/NTFAQ1.TXT
536  * I can only hypothesize that the "FlexBoot" name was chosen
537  * as a marketing coup, possibly to emphasise its "flexibility"
538  * as a simple multiboot-aware boot manager.
539  *
540  * - A bit later, with NT 3.10.404 Beta, 3-7-1993, using an updated
541  * version of OS Loader V2.10, the final section name "boot loader"
542  * was introduced, and was kept since then.
543  *
544  * Due to the necessity to be able to boot and / or upgrade any
545  * Windows NT version at any time, including its NT Loader and the
546  * associated boot.ini file, all versions of NTLDR and the NT installer
547  * understand and parse these three section names, the default one
548  * being "boot loader", and if not present, they successively fall
549  * back to "flexboot" and then to "multiboot".
550  */
551 
552  /* Get the "boot loader" section */
553  IniSection = IniCacheGetSection(BootStore->IniCache, L"boot loader");
554  if (!IniSection)
555  {
556  /* Fall back to "flexboot" */
557  IniSection = IniCacheGetSection(BootStore->IniCache, L"flexboot");
558  if (!IniSection)
559  {
560  /* Fall back to "multiboot" */
561  IniSection = IniCacheGetSection(BootStore->IniCache, L"multiboot");
562  }
563  }
564 #if 0
565  if (!IniSection)
566  {
567  /* It does not exist yet, so create it */
568  IniSection = IniCacheAppendSection(BootStore->IniCache, L"boot loader");
569  if (!IniSection)
570  {
571  DPRINT1("OpenIniBootLoaderStore: Failed to retrieve 'boot loader' section!\n");
572  }
573  }
574 #endif
575 
576  BootStore->OptionsIniSection = IniSection;
577 
578  /*
579  * Cache the "Operating Systems" section for our future usage.
580  */
581 
582  /* Get the "Operating Systems" section */
583  IniSection = IniCacheGetSection(BootStore->IniCache, L"operating systems");
584  if (!IniSection)
585  {
586 #if 0
587  /* It does not exist yet, so create it */
588  IniSection = IniCacheAppendSection(BootStore->IniCache, L"operating systems");
589  if (!IniSection)
590  {
591  DPRINT1("OpenIniBootLoaderStore: Failed to retrieve 'operating systems' section!\n");
592  }
593 #endif
594  }
595 
596  BootStore->OsIniSection = IniSection;
597  }
598  }
599 
600  *Handle = BootStore;
601  return STATUS_SUCCESS;
602 }
#define FILE_GENERIC_READ
Definition: nt_native.h:653
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define FILE_SEQUENTIAL_ONLY
Definition: from_kernel.h:27
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
Type
Definition: Type.h:6
VOID IniCacheDestroy(PINICACHE Cache)
Definition: inicache.c:666
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
NTSTATUS IniCacheLoadFromMemory(PINICACHE *Cache, PCHAR FileBuffer, ULONG FileLength, BOOLEAN String)
Definition: inicache.c:452
PINICACHESECTION IniCacheGetSection(PINICACHE Cache, PWCHAR Name)
Definition: inicache.c:683
PINICACHE IniCache
Definition: bldrsup.c:81
#define FALSE
Definition: types.h:117
PINICACHESECTION OptionsIniSection
Definition: bldrsup.c:82
static VOID CreateCommonFreeLdrSections(IN OUT PBOOT_STORE_INI_CONTEXT BootStore)
Definition: bldrsup.c:208
smooth NULL
Definition: ftsmooth.c:416
Definition: bldrsup.h:16
PINICACHE IniCacheCreate(VOID)
Definition: inicache.c:929
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
_In_ HANDLE Handle
Definition: extypes.h:390
LONG NTSTATUS
Definition: precomp.h:26
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 NT_SUCCESS(StatCode)
Definition: apphelp.c:24
BOOT_STORE_CONTEXT Header
Definition: bldrsup.c:68
PINICACHESECTION OsIniSection
Definition: bldrsup.c:83
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
_In_ PUNICODE_STRING Name
Definition: mrx.h:218
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static const WCHAR L[]
Definition: oid.c:1087
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
HANDLE ProcessHeap
Definition: servman.c:15
Status
Definition: gdiplustypes.h:24
#define FILE_GENERIC_WRITE
Definition: nt_native.h:660
#define UnMapAndCloseFile(FileHandle, SectionHandle, BaseAddress)
Definition: filesup.h:108
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define DPRINT1
Definition: precomp.h:8
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
BOOT_STORE_TYPE Type
Definition: bldrsup.c:59
NTOS_BOOT_LOADER_FILES NtosBootLoaders[]
Definition: bldrsup.c:122
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
#define FILE_SUPERSEDE
Definition: from_kernel.h:53
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
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
return STATUS_SUCCESS
Definition: btrfs.c:2710
PINICACHESECTION IniCacheAppendSection(PINICACHE Cache, PWCHAR Name)
Definition: inicache.c:1088
static NTSTATUS ProtectBootIni ( IN HANDLE  FileHandle,
IN ULONG  Attributes 
)
static

Definition at line 644 of file bldrsup.c.

Referenced by CloseIniBootLoaderStore().

647 {
651 
653  &IoStatusBlock,
654  &FileInfo,
655  sizeof(FILE_BASIC_INFORMATION),
657  if (!NT_SUCCESS(Status))
658  {
659  DPRINT1("NtQueryInformationFile() failed (Status 0x%08lx)\n", Status);
660  return Status;
661  }
662 
663  FileInfo.FileAttributes = FileInfo.FileAttributes | Attributes;
664 
666  &IoStatusBlock,
667  &FileInfo,
668  sizeof(FILE_BASIC_INFORMATION),
670  if (!NT_SUCCESS(Status))
671  DPRINT1("NtSetInformationFile() failed (Status 0x%08lx)\n", Status);
672 
673  return Status;
674 }
HANDLE FileHandle
Definition: stats.c:38
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
NTSTATUS NTAPI NtQueryInformationFile(HANDLE hFile, PIO_STATUS_BLOCK io, PVOID ptr, ULONG len, FILE_INFORMATION_CLASS FileInformationClass)
Status
Definition: gdiplustypes.h:24
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define DPRINT1
Definition: precomp.h:8
struct FileInfo FileInfo
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:2932
struct _ACPI_EFI_FILE_HANDLE CHAR16 UINT64 UINT64 Attributes
Definition: acefiex.h:335
NTSTATUS QueryBootStoreEntry ( IN PVOID  Handle,
IN ULONG_PTR  BootEntryKey,
OUT PBOOT_STORE_ENTRY  BootEntry 
)

Definition at line 1094 of file bldrsup.c.

1098 {
1100 
1101  if (!BootStore)
1102  return STATUS_INVALID_PARAMETER;
1103 
1104  /*
1105  * NOTE: Currently we open & map the loader configuration file without
1106  * further tests. It's OK as long as we only deal with FreeLdr's freeldr.ini
1107  * and NTLDR's boot.ini files. But as soon as we'll implement support for
1108  * BOOTMGR detection, the "configuration file" will be the BCD registry
1109  * hive and then, we'll have instead to mount the hive & open it.
1110  */
1111 
1112  //
1113  // FIXME!!
1114  //
1115 
1116  // if (BootStore->Type >= BldrTypeMax || NtosBootLoaders[BootStore->Type].Type >= BldrTypeMax)
1117  if (BootStore->Type != FreeLdr)
1118  {
1119  DPRINT1("Loader type %d is currently unsupported!\n", NtosBootLoaders[BootStore->Type].Type);
1120  return STATUS_NOT_SUPPORTED;
1121  }
1122 
1123  // FIXME! This function needs my INI library rewrite to be implemented!!
1124  UNIMPLEMENTED;
1125  return STATUS_NOT_IMPLEMENTED;
1126 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ HANDLE Handle
Definition: extypes.h:390
struct _BOOT_STORE_CONTEXT * PBOOT_STORE_CONTEXT
BOOT_STORE_TYPE Type
Definition: bldrsup.c:45
#define DPRINT1
Definition: precomp.h:8
BOOT_STORE_TYPE Type
Definition: bldrsup.c:59
NTOS_BOOT_LOADER_FILES NtosBootLoaders[]
Definition: bldrsup.c:122
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
#define UNIMPLEMENTED
Definition: debug.h:114
NTSTATUS QueryBootStoreOptions ( IN PVOID  Handle,
IN OUT PBOOT_STORE_OPTIONS  BootOptions 
)

Definition at line 1129 of file bldrsup.c.

1133 {
1136  PWCHAR TimeoutStr;
1137 
1138  if (!BootStore || !BootOptions)
1139  return STATUS_INVALID_PARAMETER;
1140 
1141  /*
1142  * NOTE: Currently we open & map the loader configuration file without
1143  * further tests. It's OK as long as we only deal with FreeLdr's freeldr.ini
1144  * and NTLDR's boot.ini files. But as soon as we'll implement support for
1145  * BOOTMGR detection, the "configuration file" will be the BCD registry
1146  * hive and then, we'll have instead to mount the hive & open it.
1147  */
1148 
1149  //
1150  // FIXME!!
1151  //
1152 
1153  // if (BootStore->Type >= BldrTypeMax || NtosBootLoaders[BootStore->Type].Type >= BldrTypeMax)
1154  if (BootStore->Type != FreeLdr || BootStore->Type != NtLdr)
1155  {
1156  DPRINT1("Loader type %d is currently unsupported!\n", NtosBootLoaders[BootStore->Type].Type);
1157  return STATUS_NOT_SUPPORTED;
1158  }
1159 
1160  if (BootStore->Type == FreeLdr)
1161  {
1162  BootOptions->Version = FreeLdr;
1163 
1164  Status = IniCacheGetKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection,
1165  L"DefaultOS", (PWCHAR*)&BootOptions->CurrentBootEntryKey);
1166  if (!NT_SUCCESS(Status))
1167  BootOptions->CurrentBootEntryKey = 0;
1168 
1169  Status = IniCacheGetKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection,
1170  L"TimeOut", &TimeoutStr);
1171  if (NT_SUCCESS(Status) && TimeoutStr)
1172  BootOptions->Timeout = _wtoi(TimeoutStr);
1173  else
1174  BootOptions->Timeout = 0;
1175  }
1176  else if (BootStore->Type == NtLdr)
1177  {
1178  BootOptions->Version = NtLdr;
1179 
1180  Status = IniCacheGetKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection,
1181  L"default", (PWCHAR*)&BootOptions->CurrentBootEntryKey);
1182  if (!NT_SUCCESS(Status))
1183  BootOptions->CurrentBootEntryKey = 0;
1184 
1185  Status = IniCacheGetKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection,
1186  L"timeout", &TimeoutStr);
1187  if (NT_SUCCESS(Status) && TimeoutStr)
1188  BootOptions->Timeout = _wtoi(TimeoutStr);
1189  else
1190  BootOptions->Timeout = 0;
1191  }
1192 
1193  return STATUS_SUCCESS; // FIXME: use Status; instead?
1194 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
uint16_t * PWCHAR
Definition: typedefs.h:54
Definition: bldrsup.h:16
_In_ HANDLE Handle
Definition: extypes.h:390
NTSTATUS IniCacheGetKey(PINICACHESECTION Section, PWCHAR KeyName, PWCHAR *KeyData)
Definition: inicache.c:716
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
struct _BOOT_STORE_CONTEXT * PBOOT_STORE_CONTEXT
BOOT_STORE_TYPE Type
Definition: bldrsup.c:45
static const WCHAR L[]
Definition: oid.c:1087
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8
BOOT_STORE_TYPE Type
Definition: bldrsup.c:59
NTOS_BOOT_LOADER_FILES NtosBootLoaders[]
Definition: bldrsup.c:122
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
return STATUS_SUCCESS
Definition: btrfs.c:2710
NTSTATUS SetBootStoreOptions ( IN PVOID  Handle,
IN PBOOT_STORE_OPTIONS  BootOptions,
IN ULONG  FieldsToChange 
)

Definition at line 1197 of file bldrsup.c.

Referenced by CreateFreeLoaderReactOSEntries().

1201 {
1203  WCHAR TimeoutStr[15];
1204 
1205  if (!BootStore || !BootOptions)
1206  return STATUS_INVALID_PARAMETER;
1207 
1208  /*
1209  * NOTE: Currently we open & map the loader configuration file without
1210  * further tests. It's OK as long as we only deal with FreeLdr's freeldr.ini
1211  * and NTLDR's boot.ini files. But as soon as we'll implement support for
1212  * BOOTMGR detection, the "configuration file" will be the BCD registry
1213  * hive and then, we'll have instead to mount the hive & open it.
1214  */
1215 
1216  //
1217  // FIXME!!
1218  //
1219 
1220  // if (BootStore->Type >= BldrTypeMax || NtosBootLoaders[BootStore->Type].Type >= BldrTypeMax)
1221  if (BootStore->Type != FreeLdr)
1222  {
1223  DPRINT1("Loader type %d is currently unsupported!\n", NtosBootLoaders[BootStore->Type].Type);
1224  return STATUS_NOT_SUPPORTED;
1225  }
1226 
1227  if (BootOptions->Version != FreeLdr)
1228  return STATUS_INVALID_PARAMETER;
1229 
1230  //
1231  // TODO: Depending on the flags set in 'FieldsToChange',
1232  // change either one or both these bootloader options.
1233  //
1234  IniCacheInsertKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection,
1235  NULL, INSERT_LAST,
1236  L"DefaultOS", (PWCHAR)BootOptions->CurrentBootEntryKey);
1237 
1238  RtlStringCchPrintfW(TimeoutStr, ARRAYSIZE(TimeoutStr), L"%d", BootOptions->Timeout);
1239  IniCacheInsertKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection,
1240  NULL, INSERT_LAST,
1241  L"TimeOut", TimeoutStr);
1242 
1243  return STATUS_SUCCESS;
1244 }
PINICACHEKEY IniCacheInsertKey(PINICACHESECTION Section, PINICACHEKEY AnchorKey, INSERTION_TYPE InsertionType, PWCHAR Name, PWCHAR Data)
Definition: inicache.c:826
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
uint16_t * PWCHAR
Definition: typedefs.h:54
smooth NULL
Definition: ftsmooth.c:416
static __inline NTSTATUS RtlStringCchPrintfW(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1064
_In_ HANDLE Handle
Definition: extypes.h:390
struct _BOOT_STORE_CONTEXT * PBOOT_STORE_CONTEXT
BOOT_STORE_TYPE Type
Definition: bldrsup.c:45
static const WCHAR L[]
Definition: oid.c:1087
#define DPRINT1
Definition: precomp.h:8
BOOT_STORE_TYPE Type
Definition: bldrsup.c:59
NTOS_BOOT_LOADER_FILES NtosBootLoaders[]
Definition: bldrsup.c:122
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
return STATUS_SUCCESS
Definition: btrfs.c:2710
static NTSTATUS UnprotectBootIni ( IN HANDLE  FileHandle,
OUT PULONG  Attributes 
)
static

Definition at line 605 of file bldrsup.c.

Referenced by CloseIniBootLoaderStore().

608 {
612 
614  &IoStatusBlock,
615  &FileInfo,
616  sizeof(FILE_BASIC_INFORMATION),
618  if (!NT_SUCCESS(Status))
619  {
620  DPRINT1("NtQueryInformationFile() failed (Status 0x%08lx)\n", Status);
621  return Status;
622  }
623 
624  *Attributes = FileInfo.FileAttributes;
625 
626  /* Delete attributes SYSTEM, HIDDEN and READONLY */
627  FileInfo.FileAttributes = FileInfo.FileAttributes &
631 
633  &IoStatusBlock,
634  &FileInfo,
635  sizeof(FILE_BASIC_INFORMATION),
637  if (!NT_SUCCESS(Status))
638  DPRINT1("NtSetInformationFile() failed (Status 0x%08lx)\n", Status);
639 
640  return Status;
641 }
#define FILE_ATTRIBUTE_SYSTEM
Definition: nt_native.h:704
HANDLE FileHandle
Definition: stats.c:38
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
NTSTATUS NTAPI NtQueryInformationFile(HANDLE hFile, PIO_STATUS_BLOCK io, PVOID ptr, ULONG len, FILE_INFORMATION_CLASS FileInformationClass)
Status
Definition: gdiplustypes.h:24
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
#define DPRINT1
Definition: precomp.h:8
struct FileInfo FileInfo
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:2932
struct _ACPI_EFI_FILE_HANDLE CHAR16 UINT64 UINT64 Attributes
Definition: acefiex.h:335

Variable Documentation

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 OpenIniBootLoaderStore(OUT PVOID *Handle, IN HANDLE PartitionDirectoryHandle, IN BOOT_STORE_TYPE Type, IN BOOLEAN CreateNew)
Definition: bldrsup.c:340
NTSTATUS(* PENUM_BOOT_STORE_ENTRIES)(IN PVOID Handle, IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine, IN PVOID Parameter OPTIONAL)
Definition: bldrsup.c:37
Definition: bldrsup.h:16
static const WCHAR L[]
Definition: oid.c:1087
static NTSTATUS FreeLdrEnumerateBootEntries(IN PBOOT_STORE_INI_CONTEXT BootStore, IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine, IN PVOID Parameter OPTIONAL)
Definition: bldrsup.c:1249
static NTSTATUS NtLdrEnumerateBootEntries(IN PBOOT_STORE_INI_CONTEXT BootStore, IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine, IN PVOID Parameter OPTIONAL)
Definition: bldrsup.c:1426
static NTSTATUS CloseIniBootLoaderStore(IN PVOID Handle)
Definition: bldrsup.c:677

Definition at line 122 of file bldrsup.c.