ReactOS  0.4.14-dev-317-g96040ec
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 
13 typedef 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  */
31 typedef 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  * MAX_USHORT == 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  */
62 typedef 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 */
82 typedef 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 */
101 typedef struct _BOOT_SECTOR_OPTIONS
102 {
103  UCHAR Signature[8]; // "BootSect"
104  // ULONG Version;
105  // ULONG Length;
110 
111 #define BOOT_SECTOR_OPTIONS_SIGNATURE "BootSect"
112 
113 
114 typedef NTSTATUS
117  IN PBOOT_STORE_ENTRY BootEntry,
119 
120 
121 NTSTATUS
122 FindBootStore( // By handle
123  IN HANDLE PartitionDirectoryHandle, // OPTIONAL
125  OUT PULONG VersionNumber OPTIONAL);
126 
127 
128 NTSTATUS
130  OUT PVOID* Handle,
131  IN HANDLE PartitionDirectoryHandle, // OPTIONAL
133  IN BOOLEAN CreateNew);
134 
135 NTSTATUS
137  OUT PVOID* Handle,
138  IN PUNICODE_STRING SystemPartitionPath,
140  IN BOOLEAN CreateNew);
141 
142 NTSTATUS
144  OUT PVOID* Handle,
147  IN BOOLEAN CreateNew);
148 
149 NTSTATUS
151  IN PVOID Handle);
152 
153 NTSTATUS
155  IN PVOID Handle,
156  IN PBOOT_STORE_ENTRY BootEntry,
157  IN ULONG_PTR BootEntryKey);
158 
159 NTSTATUS
161  IN PVOID Handle,
162  IN ULONG_PTR BootEntryKey);
163 
164 NTSTATUS
166  IN PVOID Handle,
167  IN PBOOT_STORE_ENTRY BootEntry);
168 
169 NTSTATUS
171  IN PVOID Handle,
172  IN ULONG_PTR BootEntryKey,
173  OUT PBOOT_STORE_ENTRY BootEntry); // Technically this should be PBOOT_STORE_ENTRY*
174 
175 NTSTATUS
177  IN PVOID Handle,
179 /* , IN PULONG BootOptionsLength */ );
180 
181 NTSTATUS
183  IN PVOID Handle,
185  IN ULONG FieldsToChange);
186 
187 NTSTATUS
189  IN PVOID Handle,
190 // IN ULONG Flags, // Determine which data to retrieve
191  IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine,
193 
194 /* EOF */
struct _BOOT_STORE_OPTIONS BOOT_STORE_OPTIONS
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define IN
Definition: typedefs.h:38
NTSTATUS OpenBootStoreByHandle(OUT PVOID *Handle, IN HANDLE PartitionDirectoryHandle, IN BOOT_STORE_TYPE Type, IN BOOLEAN CreateNew)
Definition: bldrsup.c:737
Type
Definition: Type.h:6
struct _BOOT_SECTOR_OPTIONS BOOT_SECTOR_OPTIONS
ULONG_PTR BootEntryKey
Definition: bldrsup.h:66
struct _BOOT_STORE_OPTIONS * PBOOT_STORE_OPTIONS
#define ANYSIZE_ARRAY
Definition: typedefs.h:45
UCHAR OsOptions[ANYSIZE_ARRAY]
Definition: bldrsup.h:70
NTSTATUS CloseBootStore(IN PVOID Handle)
Definition: bldrsup.c:827
LONG NTSTATUS
Definition: precomp.h:26
_In_ PVOID Parameter
Definition: ldrtypes.h:241
ULONG_PTR CurrentBootEntryKey
Definition: bldrsup.h:36
NTSTATUS EnumerateBootStoreEntries(IN PVOID Handle, IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine, IN PVOID Parameter OPTIONAL)
Definition: bldrsup.c:1559
struct _BOOT_STORE_ENTRY * PBOOT_STORE_ENTRY
NTSTATUS AddBootStoreEntry(IN PVOID Handle, IN PBOOT_STORE_ENTRY BootEntry, IN ULONG_PTR BootEntryKey)
Definition: bldrsup.c:927
uint32_t ULONG_PTR
Definition: typedefs.h:63
struct _BOOT_STORE_ENTRY BOOT_STORE_ENTRY
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
PCWSTR BootSectorFileName
Definition: bldrsup.h:108
UCHAR Signature[8]
Definition: bldrsup.h:103
struct _NTOS_OPTIONS NTOS_OPTIONS
NTSTATUS(NTAPI * PENUM_BOOT_ENTRIES_ROUTINE)(IN BOOT_STORE_TYPE Type, IN PBOOT_STORE_ENTRY BootEntry, IN PVOID Parameter OPTIONAL)
Definition: bldrsup.h:115
unsigned char BOOLEAN
NTSTATUS QueryBootStoreOptions(IN PVOID Handle, IN OUT PBOOT_STORE_OPTIONS BootOptions)
Definition: bldrsup.c:1128
PCWSTR BootFilePath
Definition: bldrsup.h:68
Definition: bldrsup.h:16
_In_ HANDLE Handle
Definition: extypes.h:390
ULONG OsOptionsLength
Definition: bldrsup.h:69
NTSTATUS QueryBootStoreEntry(IN PVOID Handle, IN ULONG_PTR BootEntryKey, OUT PBOOT_STORE_ENTRY BootEntry)
Definition: bldrsup.c:1093
NTSTATUS FindBootStore(IN HANDLE PartitionDirectoryHandle, IN BOOT_STORE_TYPE Type, OUT PULONG VersionNumber OPTIONAL)
Definition: bldrsup.c:137
static PPARTENTRY SystemPartition
Definition: usetup.c:61
NTSTATUS SetBootStoreOptions(IN PVOID Handle, IN PBOOT_STORE_OPTIONS BootOptions, IN ULONG FieldsToChange)
Definition: bldrsup.c:1196
unsigned char UCHAR
Definition: xmlstorage.h:181
#define NTSTATUS
Definition: precomp.h:20
NTSTATUS OpenBootStore_UStr(OUT PVOID *Handle, IN PUNICODE_STRING SystemPartitionPath, IN BOOT_STORE_TYPE Type, IN BOOLEAN CreateNew)
Definition: bldrsup.c:764
enum _BOOT_STORE_TYPE BOOT_STORE_TYPE
UCHAR Signature[8]
Definition: bldrsup.h:84
ULONG Version
Definition: bldrsup.h:64
#define OPTIONAL
Definition: typedefs.h:40
unsigned int * PULONG
Definition: retypes.h:1
NTSTATUS OpenBootStore(OUT PVOID *Handle, IN PCWSTR SystemPartition, IN BOOT_STORE_TYPE Type, IN BOOLEAN CreateNew)
Definition: bldrsup.c:815
_BOOT_STORE_TYPE
Definition: bldrsup.h:13
struct _NTOS_OPTIONS * PNTOS_OPTIONS
NTSTATUS DeleteBootStoreEntry(IN PVOID Handle, IN ULONG_PTR BootEntryKey)
Definition: bldrsup.c:1025
#define OUT
Definition: typedefs.h:39
struct _BOOT_SECTOR_OPTIONS * PBOOT_SECTOR_OPTIONS
PCWSTR FriendlyName
Definition: bldrsup.h:67
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS ModifyBootStoreEntry(IN PVOID Handle, IN PBOOT_STORE_ENTRY BootEntry)
Definition: bldrsup.c:1059
PCWSTR OsLoadPath
Definition: bldrsup.h:87
PCWSTR OsLoadOptions
Definition: bldrsup.h:88
Definition: bldrsup.h:62
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68