xref: /reactos/base/setup/lib/utils/bldrsup.h (revision 99f8ccdc)
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
18     BldrTypeMax
19 } BOOT_STORE_TYPE;
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;
35     ULONG Timeout;
36     ULONG_PTR CurrentBootEntryKey;
37     // ULONG_PTR NextBootEntryKey;
38     // WCHAR HeadlessRedirection[1];
39 } BOOT_STORE_OPTIONS, *PBOOT_STORE_OPTIONS;
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  */
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...)
70     UCHAR OsOptions[ANYSIZE_ARRAY];
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  */
79 } BOOT_STORE_ENTRY, *PBOOT_STORE_ENTRY;
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  */
96 } NTOS_OPTIONS, *PNTOS_OPTIONS;
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;
106     PCWSTR Drive;
107     PCWSTR Partition;
108     PCWSTR BootSectorFileName;
109 } BOOT_SECTOR_OPTIONS, *PBOOT_SECTOR_OPTIONS;
110 
111 #define BOOT_SECTOR_OPTIONS_SIGNATURE "BootSect"
112 
113 
114 typedef NTSTATUS
115 (NTAPI *PENUM_BOOT_ENTRIES_ROUTINE)(
116     IN BOOT_STORE_TYPE Type,
117     IN PBOOT_STORE_ENTRY BootEntry,
118     IN PVOID Parameter OPTIONAL);
119 
120 
121 NTSTATUS
122 FindBootStore( // By handle
123     IN HANDLE PartitionDirectoryHandle, // OPTIONAL
124     IN BOOT_STORE_TYPE Type,
125     OUT PULONG VersionNumber OPTIONAL);
126 
127 
128 NTSTATUS
129 OpenBootStoreByHandle(
130     OUT PVOID* Handle,
131     IN HANDLE PartitionDirectoryHandle, // OPTIONAL
132     IN BOOT_STORE_TYPE Type,
133     IN BOOLEAN CreateNew);
134 
135 NTSTATUS
136 OpenBootStore_UStr(
137     OUT PVOID* Handle,
138     IN PUNICODE_STRING SystemPartitionPath,
139     IN BOOT_STORE_TYPE Type,
140     IN BOOLEAN CreateNew);
141 
142 NTSTATUS
143 OpenBootStore(
144     OUT PVOID* Handle,
145     IN PCWSTR SystemPartition,
146     IN BOOT_STORE_TYPE Type,
147     IN BOOLEAN CreateNew);
148 
149 NTSTATUS
150 CloseBootStore(
151     IN PVOID Handle);
152 
153 NTSTATUS
154 AddBootStoreEntry(
155     IN PVOID Handle,
156     IN PBOOT_STORE_ENTRY BootEntry,
157     IN ULONG_PTR BootEntryKey);
158 
159 NTSTATUS
160 DeleteBootStoreEntry(
161     IN PVOID Handle,
162     IN ULONG_PTR BootEntryKey);
163 
164 NTSTATUS
165 ModifyBootStoreEntry(
166     IN PVOID Handle,
167     IN PBOOT_STORE_ENTRY BootEntry);
168 
169 NTSTATUS
170 QueryBootStoreEntry(
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
176 QueryBootStoreOptions(
177     IN PVOID Handle,
178     IN OUT PBOOT_STORE_OPTIONS BootOptions
179 /* , IN PULONG BootOptionsLength */ );
180 
181 NTSTATUS
182 SetBootStoreOptions(
183     IN PVOID Handle,
184     IN PBOOT_STORE_OPTIONS BootOptions,
185     IN ULONG FieldsToChange);
186 
187 NTSTATUS
188 EnumerateBootStoreEntries(
189     IN PVOID Handle,
190 //  IN ULONG Flags, // Determine which data to retrieve
191     IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine,
192     IN PVOID Parameter OPTIONAL);
193 
194 /* EOF */
195