ReactOS 0.4.15-dev-8093-g3285f69
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 Length;
34 ULONG Timeout; //< Timeout in seconds before the default boot entry is started.
35 ULONG_PTR CurrentBootEntryKey; //< Selected boot entry for the current boot (informative only).
36 ULONG_PTR NextBootEntryKey; //< The boot entry for the next boot.
37 // WCHAR HeadlessRedirection[ANYSIZE_ARRAY];
39
40/* FieldsToChange flags for SetBootStoreOptions() */
41#define BOOT_OPTIONS_TIMEOUT 1
42#define BOOT_OPTIONS_NEXT_BOOTENTRY_KEY 2
43// #define BOOT_OPTIONS_HEADLESS_REDIRECTION 4
44
45/*
46 * These macros are used to set a value for the BootEntryKey member of a
47 * BOOT_STORE_ENTRY structure, much in the same idea as MAKEINTRESOURCE and
48 * IS_INTRESOURCE macros for Win32 resources.
49 *
50 * A key consists of either a boot ID number, comprised between 0 and
51 * MAXUSHORT == 0xFFFF == 65535, or can be a pointer to a human-readable
52 * string (section name), as in the case of FreeLDR, or to a GUID, as in the
53 * case of BOOTMGR.
54 *
55 * If IS_INTKEY(BootEntryKey) == TRUE, i.e. the key is <= 65535, this means
56 * the key is a boot ID number, otherwise it is typically a pointer to a string.
57 */
58#define MAKESTRKEY(i) ((ULONG_PTR)(i))
59#define MAKEINTKEY(i) ((ULONG_PTR)((USHORT)(i)))
60#define IS_INTKEY(i) (((ULONG_PTR)(i) >> 16) == 0)
61
62/*
63 * This structure is inspired from the EFI boot entry structures
64 * BOOT_ENTRY and FILE_PATH that are defined in ndk/iotypes.h .
65 */
66typedef struct _BOOT_STORE_ENTRY
67{
68 ULONG Version; // BOOT_STORE_TYPE value
69 // ULONG Length;
70 ULONG_PTR BootEntryKey; //< Boot entry "key"
71 PCWSTR FriendlyName; //< Human-readable boot entry description // LoadIdentifier
72 PCWSTR BootFilePath; //< Path to e.g. osloader.exe, or winload.efi // EfiOsLoaderFilePath
73 ULONG OsOptionsLength; //< Loader-specific options blob (can be a string, or a binary structure...)
75/*
76 * In packed form, this structure would contain offsets to 'FriendlyName'
77 * and 'BootFilePath' strings and, after the OsOptions blob, there would
78 * be the following data:
79 *
80 * WCHAR FriendlyName[ANYSIZE_ARRAY];
81 * FILE_PATH BootFilePath;
82 */
84
85/* "NTOS" (aka. ReactOS or MS Windows NT) <= 5.x options */
86typedef struct _NTOS_OPTIONS
87{
88 UCHAR Signature[8]; // "NTOS_5\0\0"
89 // ULONG Version;
90 // ULONG Length;
91 PCWSTR OsLoadPath; // The OS SystemRoot path // OsLoaderFilePath // OsFilePath
92 PCWSTR OsLoadOptions; // OsLoadOptions
93/*
94 * In packed form, this structure would contain an offset to the 'OsLoadPath'
95 * string, and the 'OsLoadOptions' member would be:
96 * WCHAR OsLoadOptions[ANYSIZE_ARRAY];
97 * followed by:
98 * FILE_PATH OsLoadPath;
99 */
101
102#define NTOS_OPTIONS_SIGNATURE "NTOS_5\0\0"
103
104/* Options for boot-sector boot entries */
106{
107 UCHAR Signature[8]; // "BootSect"
108 // ULONG Version;
109 // ULONG Length;
113
114#define BOOTSECTOR_OPTIONS_SIGNATURE "BootSect"
115
116
117typedef NTSTATUS
120 IN PBOOT_STORE_ENTRY BootEntry,
122
123
125FindBootStore( // By handle
126 IN HANDLE PartitionDirectoryHandle, // OPTIONAL
128 OUT PULONG VersionNumber OPTIONAL);
129
130
132{
133 BS_CheckExisting = 0, // See FindBootStore()
134 BS_CreateNew = 1, // BS_CreateOnly
135 BS_OpenExisting = 2, // BS_OpenOnly
137 BS_RecreateExisting = 4, // BS_RecreateOnly
140
142{
143 // BS_NoAccess = 0,
148
152 _In_ HANDLE PartitionDirectoryHandle, // _In_opt_
154 _In_ BOOT_STORE_OPENMODE OpenMode,
155 _In_ BOOT_STORE_ACCESS Access);
156
160 _In_ PUNICODE_STRING SystemPartitionPath,
162 _In_ BOOT_STORE_OPENMODE OpenMode,
163 _In_ BOOT_STORE_ACCESS Access);
164
170 _In_ BOOT_STORE_OPENMODE OpenMode,
171 _In_ BOOT_STORE_ACCESS Access);
172
176
180 IN PBOOT_STORE_ENTRY BootEntry,
181 IN ULONG_PTR BootEntryKey);
182
186 IN ULONG_PTR BootEntryKey);
187
191 IN PBOOT_STORE_ENTRY BootEntry);
192
196 IN ULONG_PTR BootEntryKey,
197 OUT PBOOT_STORE_ENTRY BootEntry); // Technically this should be PBOOT_STORE_ENTRY*
198
203/* , IN PULONG BootOptionsLength */ );
204
209 IN ULONG FieldsToChange);
210
214// IN ULONG Flags, // Determine which data to retrieve
215 IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine,
217
218/* EOF */
Type
Definition: Type.h:7
LONG NTSTATUS
Definition: precomp.h:26
@ BootOptions
Definition: bl.h:898
_BOOT_STORE_ACCESS
Definition: bldrsup.h:142
@ BS_WriteAccess
Definition: bldrsup.h:145
@ BS_ReadWriteAccess
Definition: bldrsup.h:146
@ BS_ReadAccess
Definition: bldrsup.h:144
struct _BOOTSECTOR_OPTIONS BOOTSECTOR_OPTIONS
struct _BOOT_STORE_OPTIONS * PBOOT_STORE_OPTIONS
struct _NTOS_OPTIONS NTOS_OPTIONS
NTSTATUS DeleteBootStoreEntry(IN PVOID Handle, IN ULONG_PTR BootEntryKey)
Definition: bldrsup.c:1192
enum _BOOT_STORE_ACCESS BOOT_STORE_ACCESS
NTSTATUS OpenBootStoreByHandle(_Out_ PVOID *Handle, _In_ HANDLE PartitionDirectoryHandle, _In_ BOOT_STORE_TYPE Type, _In_ BOOT_STORE_OPENMODE OpenMode, _In_ BOOT_STORE_ACCESS Access)
Definition: bldrsup.c:897
NTSTATUS QueryBootStoreEntry(IN PVOID Handle, IN ULONG_PTR BootEntryKey, OUT PBOOT_STORE_ENTRY BootEntry)
Definition: bldrsup.c:1260
_BOOT_STORE_TYPE
Definition: bldrsup.h:14
@ NtLdr
Definition: bldrsup.h:16
@ BldrTypeMax
Definition: bldrsup.h:18
@ FreeLdr
Definition: bldrsup.h:15
NTSTATUS OpenBootStore(_Out_ PVOID *Handle, _In_ PCWSTR SystemPartition, _In_ BOOT_STORE_TYPE Type, _In_ BOOT_STORE_OPENMODE OpenMode, _In_ BOOT_STORE_ACCESS Access)
Definition: bldrsup.c:997
NTSTATUS OpenBootStore_UStr(_Out_ PVOID *Handle, _In_ PUNICODE_STRING SystemPartitionPath, _In_ BOOT_STORE_TYPE Type, _In_ BOOT_STORE_OPENMODE OpenMode, _In_ BOOT_STORE_ACCESS Access)
Definition: bldrsup.c:940
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:1356
_BOOT_STORE_OPENMODE
Definition: bldrsup.h:132
@ BS_OpenAlways
Definition: bldrsup.h:136
@ BS_OpenExisting
Definition: bldrsup.h:135
@ BS_CreateAlways
Definition: bldrsup.h:138
@ BS_CheckExisting
Definition: bldrsup.h:133
@ BS_CreateNew
Definition: bldrsup.h:134
@ BS_RecreateExisting
Definition: bldrsup.h:137
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:118
NTSTATUS AddBootStoreEntry(IN PVOID Handle, IN PBOOT_STORE_ENTRY BootEntry, IN ULONG_PTR BootEntryKey)
Definition: bldrsup.c:1094
enum _BOOT_STORE_OPENMODE BOOT_STORE_OPENMODE
NTSTATUS CloseBootStore(_In_ PVOID Handle)
Definition: bldrsup.c:1014
struct _BOOTSECTOR_OPTIONS * PBOOTSECTOR_OPTIONS
NTSTATUS ModifyBootStoreEntry(IN PVOID Handle, IN PBOOT_STORE_ENTRY BootEntry)
Definition: bldrsup.c:1226
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:1703
struct _BOOT_STORE_ENTRY BOOT_STORE_ENTRY
NTSTATUS QueryBootStoreOptions(IN PVOID Handle, IN OUT PBOOT_STORE_OPTIONS BootOptions)
Definition: bldrsup.c:1295
NTSTATUS FindBootStore(IN HANDLE PartitionDirectoryHandle, IN BOOT_STORE_TYPE Type, OUT PULONG VersionNumber OPTIONAL)
Definition: bldrsup.c:151
#define NTSTATUS
Definition: precomp.h:21
ULONG Handle
Definition: gdb_input.c:15
#define _Out_
Definition: ms_sal.h:345
#define _In_
Definition: ms_sal.h:308
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
UCHAR Signature[8]
Definition: bldrsup.h:107
Definition: bldrsup.h:67
ULONG Version
Definition: bldrsup.h:68
PCWSTR BootFilePath
Definition: bldrsup.h:72
ULONG OsOptionsLength
Definition: bldrsup.h:73
ULONG_PTR BootEntryKey
Definition: bldrsup.h:70
UCHAR OsOptions[ANYSIZE_ARRAY]
Definition: bldrsup.h:74
PCWSTR FriendlyName
Definition: bldrsup.h:71
ULONG_PTR NextBootEntryKey
Definition: bldrsup.h:36
ULONG_PTR CurrentBootEntryKey
Definition: bldrsup.h:35
PCWSTR OsLoadOptions
Definition: bldrsup.h:92
UCHAR Signature[8]
Definition: bldrsup.h:88
PCWSTR OsLoadPath
Definition: bldrsup.h:91
#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