ReactOS 0.4.15-dev-7931-gfd331f1
bldrsup.h
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Setup Library
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Boot Stores Management functionality, with support for
5 * NT 5.x family (MS Windows <= 2003, and ReactOS) bootloaders.
6 * COPYRIGHT: Copyright 2017-2018 Hermes Belusca-Maito
7 */
8
9// TODO: Add support for NT 6.x family! (detection + BCD manipulation).
10
11#pragma once
12
13typedef enum _BOOT_STORE_TYPE
14{
15 FreeLdr, // ReactOS' FreeLoader
16 NtLdr, // Windows <= 2k3 NT "FlexBoot" OS Loader NTLDR
17// BootMgr, // Vista+ BCD-oriented BOOTMGR
20
21/*
22 * Some references about EFI boot entries:
23 * https://docs.microsoft.com/en-us/windows-hardware/drivers/devtest/overview-of-boot-options-in-efi
24 * https://docs.microsoft.com/en-us/windows-hardware/drivers/devtest/identifying-backup-files-for-existing-boot-entries
25 */
26
27/*
28 * This structure is inspired from the EFI boot entry structure
29 * BOOT_OPTIONS that is defined in ndk/iotypes.h .
30 */
31typedef struct _BOOT_STORE_OPTIONS
32{
33 ULONG Version; // BOOT_STORE_TYPE value
34 // ULONG Length;
37 // ULONG_PTR NextBootEntryKey;
38 // WCHAR HeadlessRedirection[1];
40
41/*
42 * These macros are used to set a value for the BootEntryKey member of a
43 * BOOT_STORE_ENTRY structure, much in the same idea as MAKEINTRESOURCE and
44 * IS_INTRESOURCE macros for Win32 resources.
45 *
46 * A key consists of either a boot ID number, comprised between 0 and
47 * MAXUSHORT == 0xFFFF == 65535, or can be a pointer to a human-readable
48 * string (section name), as in the case of FreeLDR, or to a GUID, as in the
49 * case of BOOTMGR.
50 *
51 * If IS_INTKEY(BootEntryKey) == TRUE, i.e. the key is <= 65535, this means
52 * the key is a boot ID number, otherwise it is typically a pointer to a string.
53 */
54#define MAKESTRKEY(i) ((ULONG_PTR)(i))
55#define MAKEINTKEY(i) ((ULONG_PTR)((USHORT)(i)))
56#define IS_INTKEY(i) (((ULONG_PTR)(i) >> 16) == 0)
57
58/*
59 * This structure is inspired from the EFI boot entry structures
60 * BOOT_ENTRY and FILE_PATH that are defined in ndk/iotypes.h .
61 */
62typedef struct _BOOT_STORE_ENTRY
63{
64 ULONG Version; // BOOT_STORE_TYPE value
65 // ULONG Length;
66 ULONG_PTR BootEntryKey; // Boot entry "key"
67 PCWSTR FriendlyName; // Human-readable boot entry description // LoadIdentifier
68 PCWSTR BootFilePath; // Path to e.g. osloader.exe, or winload.efi // EfiOsLoaderFilePath
69 ULONG OsOptionsLength; // Loader-specific options blob (can be a string, or a binary structure...)
71/*
72 * In packed form, this structure would contain offsets to 'FriendlyName'
73 * and 'BootFilePath' strings and, after the OsOptions blob, there would
74 * be the following data:
75 *
76 * WCHAR FriendlyName[ANYSIZE_ARRAY];
77 * FILE_PATH BootFilePath;
78 */
80
81/* "NTOS" (aka. ReactOS or MS Windows NT) <= 5.x options */
82typedef struct _NTOS_OPTIONS
83{
84 UCHAR Signature[8]; // "NTOS_5\0\0"
85 // ULONG Version;
86 // ULONG Length;
87 PCWSTR OsLoadPath; // The OS SystemRoot path // OsLoaderFilePath // OsFilePath
88 PCWSTR OsLoadOptions; // OsLoadOptions
89/*
90 * In packed form, this structure would contain an offset to the 'OsLoadPath'
91 * string, and the 'OsLoadOptions' member would be:
92 * WCHAR OsLoadOptions[ANYSIZE_ARRAY];
93 * followed by:
94 * FILE_PATH OsLoadPath;
95 */
97
98#define NTOS_OPTIONS_SIGNATURE "NTOS_5\0\0"
99
100/* Options for boot-sector boot entries */
102{
103 UCHAR Signature[8]; // "BootSect"
104 // ULONG Version;
105 // ULONG Length;
110
111#define BOOT_SECTOR_OPTIONS_SIGNATURE "BootSect"
112
113
114typedef NTSTATUS
117 IN PBOOT_STORE_ENTRY BootEntry,
119
120
122FindBootStore( // By handle
123 IN HANDLE PartitionDirectoryHandle, // OPTIONAL
125 OUT PULONG VersionNumber OPTIONAL);
126
127
131 IN HANDLE PartitionDirectoryHandle, // OPTIONAL
133 IN BOOLEAN CreateNew);
134
138 IN PUNICODE_STRING SystemPartitionPath,
140 IN BOOLEAN CreateNew);
141
147 IN BOOLEAN CreateNew);
148
151 IN PVOID Handle);
152
156 IN PBOOT_STORE_ENTRY BootEntry,
157 IN ULONG_PTR BootEntryKey);
158
162 IN ULONG_PTR BootEntryKey);
163
167 IN PBOOT_STORE_ENTRY BootEntry);
168
172 IN ULONG_PTR BootEntryKey,
173 OUT PBOOT_STORE_ENTRY BootEntry); // Technically this should be PBOOT_STORE_ENTRY*
174
179/* , IN PULONG BootOptionsLength */ );
180
185 IN ULONG FieldsToChange);
186
190// IN ULONG Flags, // Determine which data to retrieve
191 IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine,
193
194/* EOF */
unsigned char BOOLEAN
Type
Definition: Type.h:7
LONG NTSTATUS
Definition: precomp.h:26
@ BootOptions
Definition: bl.h:898
struct _BOOT_STORE_OPTIONS * PBOOT_STORE_OPTIONS
struct _BOOT_SECTOR_OPTIONS * PBOOT_SECTOR_OPTIONS
NTSTATUS OpenBootStoreByHandle(OUT PVOID *Handle, IN HANDLE PartitionDirectoryHandle, IN BOOT_STORE_TYPE Type, IN BOOLEAN CreateNew)
Definition: bldrsup.c:664
NTSTATUS OpenBootStore(OUT PVOID *Handle, IN PCWSTR SystemPartition, IN BOOT_STORE_TYPE Type, IN BOOLEAN CreateNew)
Definition: bldrsup.c:742
struct _NTOS_OPTIONS NTOS_OPTIONS
NTSTATUS OpenBootStore_UStr(OUT PVOID *Handle, IN PUNICODE_STRING SystemPartitionPath, IN BOOT_STORE_TYPE Type, IN BOOLEAN CreateNew)
Definition: bldrsup.c:691
NTSTATUS DeleteBootStoreEntry(IN PVOID Handle, IN ULONG_PTR BootEntryKey)
Definition: bldrsup.c:952
NTSTATUS QueryBootStoreEntry(IN PVOID Handle, IN ULONG_PTR BootEntryKey, OUT PBOOT_STORE_ENTRY BootEntry)
Definition: bldrsup.c:1020
_BOOT_STORE_TYPE
Definition: bldrsup.h:14
@ NtLdr
Definition: bldrsup.h:16
@ BldrTypeMax
Definition: bldrsup.h:18
@ FreeLdr
Definition: bldrsup.h:15
struct _BOOT_STORE_OPTIONS BOOT_STORE_OPTIONS
struct _NTOS_OPTIONS * PNTOS_OPTIONS
NTSTATUS SetBootStoreOptions(IN PVOID Handle, IN PBOOT_STORE_OPTIONS BootOptions, IN ULONG FieldsToChange)
Definition: bldrsup.c:1123
struct _BOOT_STORE_ENTRY * PBOOT_STORE_ENTRY
NTSTATUS(NTAPI * PENUM_BOOT_ENTRIES_ROUTINE)(IN BOOT_STORE_TYPE Type, IN PBOOT_STORE_ENTRY BootEntry, IN PVOID Parameter OPTIONAL)
Definition: bldrsup.h:115
NTSTATUS AddBootStoreEntry(IN PVOID Handle, IN PBOOT_STORE_ENTRY BootEntry, IN ULONG_PTR BootEntryKey)
Definition: bldrsup.c:854
struct _BOOT_SECTOR_OPTIONS BOOT_SECTOR_OPTIONS
NTSTATUS ModifyBootStoreEntry(IN PVOID Handle, IN PBOOT_STORE_ENTRY BootEntry)
Definition: bldrsup.c:986
enum _BOOT_STORE_TYPE BOOT_STORE_TYPE
NTSTATUS EnumerateBootStoreEntries(IN PVOID Handle, IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine, IN PVOID Parameter OPTIONAL)
Definition: bldrsup.c:1486
struct _BOOT_STORE_ENTRY BOOT_STORE_ENTRY
NTSTATUS QueryBootStoreOptions(IN PVOID Handle, IN OUT PBOOT_STORE_OPTIONS BootOptions)
Definition: bldrsup.c:1055
NTSTATUS FindBootStore(IN HANDLE PartitionDirectoryHandle, IN BOOT_STORE_TYPE Type, OUT PULONG VersionNumber OPTIONAL)
Definition: bldrsup.c:137
NTSTATUS CloseBootStore(IN PVOID Handle)
Definition: bldrsup.c:754
#define NTSTATUS
Definition: precomp.h:21
ULONG Handle
Definition: gdb_input.c:15
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
UCHAR Signature[8]
Definition: bldrsup.h:103
PCWSTR BootSectorFileName
Definition: bldrsup.h:108
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
ULONG_PTR CurrentBootEntryKey
Definition: bldrsup.h:36
PCWSTR OsLoadOptions
Definition: bldrsup.h:88
UCHAR Signature[8]
Definition: bldrsup.h:84
PCWSTR OsLoadPath
Definition: bldrsup.h:87
#define OPTIONAL
Definition: typedefs.h:41
uint32_t * PULONG
Definition: typedefs.h:59
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define ANYSIZE_ARRAY
Definition: typedefs.h:46
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
static PPARTENTRY SystemPartition
Definition: usetup.c:61
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:323
unsigned char UCHAR
Definition: xmlstorage.h:181