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
9 // TODO: Add support for NT 6.x family! (detection + BCD manipulation).
13 typedef enum _BOOT_STORE_TYPE
15 FreeLdr
, // ReactOS' FreeLoader
16 NtLdr
, // Windows <= 2k3 NT "FlexBoot" OS Loader NTLDR
17 // BootMgr, // Vista+ BCD-oriented BOOTMGR
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
28 * This structure is inspired from the EFI boot entry structure
29 * BOOT_OPTIONS that is defined in ndk/iotypes.h .
31 typedef struct _BOOT_STORE_OPTIONS
33 ULONG Version
; // BOOT_STORE_TYPE value
36 ULONG_PTR CurrentBootEntryKey
;
37 // ULONG_PTR NextBootEntryKey;
38 // WCHAR HeadlessRedirection[1];
39 } BOOT_STORE_OPTIONS
, *PBOOT_STORE_OPTIONS
;
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.
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
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.
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)
59 * This structure is inspired from the EFI boot entry structures
60 * BOOT_ENTRY and FILE_PATH that are defined in ndk/iotypes.h .
62 typedef struct _BOOT_STORE_ENTRY
64 ULONG Version
; // BOOT_STORE_TYPE value
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
];
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:
76 * WCHAR FriendlyName[ANYSIZE_ARRAY];
77 * FILE_PATH BootFilePath;
79 } BOOT_STORE_ENTRY
, *PBOOT_STORE_ENTRY
;
81 /* "NTOS" (aka. ReactOS or MS Windows NT) <= 5.x options */
82 typedef struct _NTOS_OPTIONS
84 UCHAR Signature
[8]; // "NTOS_5\0\0"
87 PCWSTR OsLoadPath
; // The OS SystemRoot path // OsLoaderFilePath // OsFilePath
88 PCWSTR OsLoadOptions
; // OsLoadOptions
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];
94 * FILE_PATH OsLoadPath;
96 } NTOS_OPTIONS
, *PNTOS_OPTIONS
;
98 #define NTOS_OPTIONS_SIGNATURE "NTOS_5\0\0"
100 /* Options for boot-sector boot entries */
101 typedef struct _BOOT_SECTOR_OPTIONS
103 UCHAR Signature
[8]; // "BootSect"
108 PCWSTR BootSectorFileName
;
109 } BOOT_SECTOR_OPTIONS
, *PBOOT_SECTOR_OPTIONS
;
111 #define BOOT_SECTOR_OPTIONS_SIGNATURE "BootSect"
115 (NTAPI
*PENUM_BOOT_ENTRIES_ROUTINE
)(
116 IN BOOT_STORE_TYPE Type
,
117 IN PBOOT_STORE_ENTRY BootEntry
,
118 IN PVOID Parameter OPTIONAL
);
122 FindBootStore( // By handle
123 IN HANDLE PartitionDirectoryHandle
, // OPTIONAL
124 IN BOOT_STORE_TYPE Type
,
125 OUT PULONG VersionNumber OPTIONAL
);
129 OpenBootStoreByHandle(
131 IN HANDLE PartitionDirectoryHandle
, // OPTIONAL
132 IN BOOT_STORE_TYPE Type
,
133 IN BOOLEAN CreateNew
);
138 IN PUNICODE_STRING SystemPartitionPath
,
139 IN BOOT_STORE_TYPE Type
,
140 IN BOOLEAN CreateNew
);
145 IN PCWSTR SystemPartition
,
146 IN BOOT_STORE_TYPE Type
,
147 IN BOOLEAN CreateNew
);
156 IN PBOOT_STORE_ENTRY BootEntry
,
157 IN ULONG_PTR BootEntryKey
);
160 DeleteBootStoreEntry(
162 IN ULONG_PTR BootEntryKey
);
165 ModifyBootStoreEntry(
167 IN PBOOT_STORE_ENTRY BootEntry
);
172 IN ULONG_PTR BootEntryKey
,
173 OUT PBOOT_STORE_ENTRY BootEntry
); // Technically this should be PBOOT_STORE_ENTRY*
176 QueryBootStoreOptions(
178 IN OUT PBOOT_STORE_OPTIONS BootOptions
179 /* , IN PULONG BootOptionsLength */ );
184 IN PBOOT_STORE_OPTIONS BootOptions
,
185 IN ULONG FieldsToChange
);
188 EnumerateBootStoreEntries(
190 // IN ULONG Flags, // Determine which data to retrieve
191 IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine
,
192 IN PVOID Parameter OPTIONAL
);