[BOOT:LIB] Refactor bootlib.c
InitializeLibary() now saves parameters data in BlpApplicationParameters, BlpApplicationEntry, and BlpBootDevice. Moved BlGetBootOptionSize() and BlGetBootOptionListSize() to bootopt.c
This commit is contained in:
parent
de9501aee9
commit
7125a17aca
@ -92,6 +92,12 @@ typedef struct {
|
|||||||
BOOT_APPLICATION_OPTION Options;
|
BOOT_APPLICATION_OPTION Options;
|
||||||
} BOOT_INPUT_APPLICATION_ENTRY, *PBOOT_INPUT_APPLICATION_ENTRY;
|
} BOOT_INPUT_APPLICATION_ENTRY, *PBOOT_INPUT_APPLICATION_ENTRY;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
ULONG Attributes;
|
||||||
|
GUID BcdIdentifier;
|
||||||
|
PBOOT_APPLICATION_OPTION Options;
|
||||||
|
} BOOT_APPLICATION_ENTRY, *PBOOT_APPLICATION_ENTRY;
|
||||||
|
|
||||||
#define BOOT_MEMORY_INFO_VERSION 1
|
#define BOOT_MEMORY_INFO_VERSION 1
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -13,6 +13,7 @@ Abstract:
|
|||||||
|
|
||||||
--*/
|
--*/
|
||||||
|
|
||||||
|
#include <ntrtl.h>
|
||||||
#include "bootlib.h"
|
#include "bootlib.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -25,83 +26,9 @@ Abstract:
|
|||||||
sizeof(BOOT_RETURN_DATA) \
|
sizeof(BOOT_RETURN_DATA) \
|
||||||
)
|
)
|
||||||
|
|
||||||
ULONG
|
PBOOT_INPUT_PARAMETERS BlpApplicationParameters;
|
||||||
BlGetBootOptionListSize (
|
BOOT_APPLICATION_ENTRY BlpApplicationEntry;
|
||||||
IN PBOOT_APPLICATION_OPTION Options
|
PBOOT_DEVICE BlpBootDevice;
|
||||||
);
|
|
||||||
|
|
||||||
ULONG
|
|
||||||
BlGetBootOptionSize (
|
|
||||||
IN PBOOT_APPLICATION_OPTION Option
|
|
||||||
)
|
|
||||||
|
|
||||||
/*++
|
|
||||||
|
|
||||||
Routine Description:
|
|
||||||
|
|
||||||
Gets the size of a boot option.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
|
|
||||||
Option - the boot option to get the size of.
|
|
||||||
|
|
||||||
Return Value:
|
|
||||||
|
|
||||||
The size of the option.
|
|
||||||
|
|
||||||
--*/
|
|
||||||
|
|
||||||
{
|
|
||||||
ULONG TotalSize;
|
|
||||||
|
|
||||||
if (Option->DataOffset != 0) {
|
|
||||||
TotalSize = Option->DataOffset + Option->DataSize;
|
|
||||||
} else {
|
|
||||||
TotalSize = sizeof(BOOT_APPLICATION_OPTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Option->OtherOptionsOffset != 0) {
|
|
||||||
TotalSize += BlGetBootOptionListSize((PBOOT_APPLICATION_OPTION)((PUCHAR)Option + Option->OtherOptionsOffset));
|
|
||||||
}
|
|
||||||
|
|
||||||
return TotalSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
ULONG
|
|
||||||
BlGetBootOptionListSize (
|
|
||||||
IN PBOOT_APPLICATION_OPTION Options
|
|
||||||
)
|
|
||||||
|
|
||||||
/*++
|
|
||||||
|
|
||||||
Routine Description:
|
|
||||||
|
|
||||||
Gets the total size of a list boot options.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
|
|
||||||
Options - the boot option list to get the size of.
|
|
||||||
|
|
||||||
Return Value:
|
|
||||||
|
|
||||||
The size of the options.
|
|
||||||
|
|
||||||
--*/
|
|
||||||
|
|
||||||
{
|
|
||||||
ULONG TotalSize, NextOffset;
|
|
||||||
PBOOT_APPLICATION_OPTION Option;
|
|
||||||
|
|
||||||
TotalSize = 0;
|
|
||||||
NextOffset = 0;
|
|
||||||
do {
|
|
||||||
Option = (PBOOT_APPLICATION_OPTION)((PUCHAR)Options + NextOffset);
|
|
||||||
NextOffset = Option->NextOptionOffset;
|
|
||||||
TotalSize += BlGetBootOptionSize(Option);
|
|
||||||
} while (NextOffset != 0);
|
|
||||||
|
|
||||||
return TotalSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
InitializeLibrary (
|
InitializeLibrary (
|
||||||
@ -130,7 +57,6 @@ Return Value:
|
|||||||
{
|
{
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
PBOOT_INPUT_APPLICATION_ENTRY ApplicationEntry;
|
PBOOT_INPUT_APPLICATION_ENTRY ApplicationEntry;
|
||||||
PBOOT_DEVICE BootDevice;
|
|
||||||
PBOOT_FIRMWARE_DATA FirmwareData;
|
PBOOT_FIRMWARE_DATA FirmwareData;
|
||||||
PBOOT_BLOCK_IDENTIFIER BlockDevice;
|
PBOOT_BLOCK_IDENTIFIER BlockDevice;
|
||||||
PBOOT_APPLICATION_OPTION Option;
|
PBOOT_APPLICATION_OPTION Option;
|
||||||
@ -150,7 +76,7 @@ Return Value:
|
|||||||
// Calculate structure addresses from offsets.
|
// Calculate structure addresses from offsets.
|
||||||
//
|
//
|
||||||
ApplicationEntry = (PBOOT_INPUT_APPLICATION_ENTRY)((PUCHAR)InputParameters + InputParameters->ApplicationEntryOffset);
|
ApplicationEntry = (PBOOT_INPUT_APPLICATION_ENTRY)((PUCHAR)InputParameters + InputParameters->ApplicationEntryOffset);
|
||||||
BootDevice = (PBOOT_DEVICE)((PUCHAR)InputParameters + InputParameters->BootDeviceOffset);
|
BlpBootDevice = (PBOOT_DEVICE)((PUCHAR)InputParameters + InputParameters->BootDeviceOffset);
|
||||||
FirmwareData = (PBOOT_FIRMWARE_DATA)((PUCHAR)InputParameters + InputParameters->FirmwareDataOffset);
|
FirmwareData = (PBOOT_FIRMWARE_DATA)((PUCHAR)InputParameters + InputParameters->FirmwareDataOffset);
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -161,6 +87,21 @@ Return Value:
|
|||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check application entry signature.
|
||||||
|
//
|
||||||
|
if (ApplicationEntry->Signature != BOOT_INPUT_APPLICATION_ENTRY_SIGNATURE) {
|
||||||
|
return STATUS_INVALID_PARAMETER_9;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Save input parameters and application entry data.
|
||||||
|
//
|
||||||
|
BlpApplicationParameters = InputParameters;
|
||||||
|
BlpApplicationEntry.Attributes = ApplicationEntry->Attributes;
|
||||||
|
RtlCopyMemory(&BlpApplicationEntry.BcdIdentifier, &ApplicationEntry->BcdIdentifier, sizeof(GUID));
|
||||||
|
BlpApplicationEntry.Options = &ApplicationEntry->Options;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Print debug information.
|
// Print debug information.
|
||||||
//
|
//
|
||||||
@ -169,18 +110,18 @@ Return Value:
|
|||||||
ConsolePrintf(L"Image size: %x\r\n", InputParameters->ImageSize);
|
ConsolePrintf(L"Image size: %x\r\n", InputParameters->ImageSize);
|
||||||
|
|
||||||
ConsolePrint(L"Boot device type: ");
|
ConsolePrint(L"Boot device type: ");
|
||||||
switch (BootDevice->Type) {
|
switch (BlpBootDevice->Type) {
|
||||||
case BOOT_DEVICE_TYPE_PARTITION:
|
case BOOT_DEVICE_TYPE_PARTITION:
|
||||||
ConsolePrint(L"partition\r\n");
|
ConsolePrint(L"partition\r\n");
|
||||||
BlockDevice = &BootDevice->Partition.Parent;
|
BlockDevice = &BlpBootDevice->Partition.Parent;
|
||||||
break;
|
break;
|
||||||
case BOOT_DEVICE_TYPE_PARTITION_EX:
|
case BOOT_DEVICE_TYPE_PARTITION_EX:
|
||||||
ConsolePrint(L"partition\r\n");
|
ConsolePrint(L"partition\r\n");
|
||||||
BlockDevice = &BootDevice->PartitionEx.Parent;
|
BlockDevice = &BlpBootDevice->PartitionEx.Parent;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ConsolePrint(L"generic block device\r\n");
|
ConsolePrint(L"generic block device\r\n");
|
||||||
BlockDevice = &BootDevice->Block;
|
BlockDevice = &BlpBootDevice->Block;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
89
BOOT/ENVIRON/LIB/bootopt.c
Normal file
89
BOOT/ENVIRON/LIB/bootopt.c
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
/*++
|
||||||
|
|
||||||
|
Copyright (c) 2024, Quinn Stephens.
|
||||||
|
Provided under the BSD 3-Clause license.
|
||||||
|
|
||||||
|
Module Name:
|
||||||
|
|
||||||
|
bootopt.c
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
Provides boot option utilities.
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
#include "bootlib.h"
|
||||||
|
|
||||||
|
ULONG
|
||||||
|
BlGetBootOptionSize (
|
||||||
|
IN PBOOT_APPLICATION_OPTION Option
|
||||||
|
)
|
||||||
|
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Gets the size of a boot option.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Option - the boot option to get the size of.
|
||||||
|
|
||||||
|
Return Value:
|
||||||
|
|
||||||
|
The size of the option.
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
{
|
||||||
|
ULONG TotalSize;
|
||||||
|
|
||||||
|
if (Option->DataOffset != 0) {
|
||||||
|
TotalSize = Option->DataOffset + Option->DataSize;
|
||||||
|
} else {
|
||||||
|
TotalSize = sizeof(BOOT_APPLICATION_OPTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Option->OtherOptionsOffset != 0) {
|
||||||
|
TotalSize += BlGetBootOptionListSize((PBOOT_APPLICATION_OPTION)((PUCHAR)Option + Option->OtherOptionsOffset));
|
||||||
|
}
|
||||||
|
|
||||||
|
return TotalSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
ULONG
|
||||||
|
BlGetBootOptionListSize (
|
||||||
|
IN PBOOT_APPLICATION_OPTION Options
|
||||||
|
)
|
||||||
|
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Gets the total size of a list boot options.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
Options - the boot option list to get the size of.
|
||||||
|
|
||||||
|
Return Value:
|
||||||
|
|
||||||
|
The size of the options.
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
{
|
||||||
|
ULONG TotalSize, NextOffset;
|
||||||
|
PBOOT_APPLICATION_OPTION Option;
|
||||||
|
|
||||||
|
TotalSize = 0;
|
||||||
|
NextOffset = 0;
|
||||||
|
do {
|
||||||
|
Option = (PBOOT_APPLICATION_OPTION)((PUCHAR)Options + NextOffset);
|
||||||
|
NextOffset = Option->NextOptionOffset;
|
||||||
|
TotalSize += BlGetBootOptionSize(Option);
|
||||||
|
} while (NextOffset != 0);
|
||||||
|
|
||||||
|
return TotalSize;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user