Reactos
at listview 218 lines 6.6 kB view raw
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 18 BldrTypeMax 19} BOOT_STORE_TYPE; 20 21/* 22 * Some references about EFI boot entries: 23 * https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/overview-of-boot-options-in-efi 24 * https://learn.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]; 38} BOOT_STORE_OPTIONS, *PBOOT_STORE_OPTIONS; 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...) 74 UCHAR OsOptions[ANYSIZE_ARRAY]; 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 */ 83} BOOT_STORE_ENTRY, *PBOOT_STORE_ENTRY; 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 */ 100} NTOS_OPTIONS, *PNTOS_OPTIONS; 101 102#define NTOS_OPTIONS_SIGNATURE "NTOS_5\0\0" 103 104/* Options for boot-sector boot entries */ 105typedef struct _BOOTSECTOR_OPTIONS 106{ 107 UCHAR Signature[8]; // "BootSect" 108 // ULONG Version; 109 // ULONG Length; 110 PCWSTR BootPath; 111 PCWSTR FileName; 112} BOOTSECTOR_OPTIONS, *PBOOTSECTOR_OPTIONS; 113 114#define BOOTSECTOR_OPTIONS_SIGNATURE "BootSect" 115 116 117typedef NTSTATUS 118(NTAPI *PENUM_BOOT_ENTRIES_ROUTINE)( 119 IN BOOT_STORE_TYPE Type, 120 IN PBOOT_STORE_ENTRY BootEntry, 121 IN PVOID Parameter OPTIONAL); 122 123 124NTSTATUS 125FindBootStore( // By handle 126 IN HANDLE PartitionDirectoryHandle, // OPTIONAL 127 IN BOOT_STORE_TYPE Type, 128 OUT PULONG VersionNumber OPTIONAL); 129 130 131typedef enum _BOOT_STORE_OPENMODE 132{ 133 BS_CheckExisting = 0, // See FindBootStore() 134 BS_CreateNew = 1, // BS_CreateOnly 135 BS_OpenExisting = 2, // BS_OpenOnly 136 BS_OpenAlways = 3, 137 BS_RecreateExisting = 4, // BS_RecreateOnly 138 BS_CreateAlways = 5, 139} BOOT_STORE_OPENMODE; 140 141typedef enum _BOOT_STORE_ACCESS 142{ 143 // BS_NoAccess = 0, 144 BS_ReadAccess = 1, 145 BS_WriteAccess = 2, 146 BS_ReadWriteAccess = (BS_ReadAccess | BS_WriteAccess) 147} BOOT_STORE_ACCESS; 148 149NTSTATUS 150OpenBootStoreByHandle( 151 _Out_ PVOID* Handle, 152 _In_ HANDLE PartitionDirectoryHandle, // _In_opt_ 153 _In_ BOOT_STORE_TYPE Type, 154 _In_ BOOT_STORE_OPENMODE OpenMode, 155 _In_ BOOT_STORE_ACCESS Access); 156 157NTSTATUS 158OpenBootStore_UStr( 159 _Out_ PVOID* Handle, 160 _In_ PUNICODE_STRING SystemPartitionPath, 161 _In_ BOOT_STORE_TYPE Type, 162 _In_ BOOT_STORE_OPENMODE OpenMode, 163 _In_ BOOT_STORE_ACCESS Access); 164 165NTSTATUS 166OpenBootStore( 167 _Out_ PVOID* Handle, 168 _In_ PCWSTR SystemPartition, 169 _In_ BOOT_STORE_TYPE Type, 170 _In_ BOOT_STORE_OPENMODE OpenMode, 171 _In_ BOOT_STORE_ACCESS Access); 172 173NTSTATUS 174CloseBootStore( 175 _In_ PVOID Handle); 176 177NTSTATUS 178AddBootStoreEntry( 179 IN PVOID Handle, 180 IN PBOOT_STORE_ENTRY BootEntry, 181 IN ULONG_PTR BootEntryKey); 182 183NTSTATUS 184DeleteBootStoreEntry( 185 IN PVOID Handle, 186 IN ULONG_PTR BootEntryKey); 187 188NTSTATUS 189ModifyBootStoreEntry( 190 IN PVOID Handle, 191 IN PBOOT_STORE_ENTRY BootEntry); 192 193NTSTATUS 194QueryBootStoreEntry( 195 IN PVOID Handle, 196 IN ULONG_PTR BootEntryKey, 197 OUT PBOOT_STORE_ENTRY BootEntry); // Technically this should be PBOOT_STORE_ENTRY* 198 199NTSTATUS 200QueryBootStoreOptions( 201 IN PVOID Handle, 202 IN OUT PBOOT_STORE_OPTIONS BootOptions 203/* , IN PULONG BootOptionsLength */ ); 204 205NTSTATUS 206SetBootStoreOptions( 207 IN PVOID Handle, 208 IN PBOOT_STORE_OPTIONS BootOptions, 209 IN ULONG FieldsToChange); 210 211NTSTATUS 212EnumerateBootStoreEntries( 213 IN PVOID Handle, 214// IN ULONG Flags, // Determine which data to retrieve 215 IN PENUM_BOOT_ENTRIES_ROUTINE EnumBootEntriesRoutine, 216 IN PVOID Parameter OPTIONAL); 217 218/* EOF */