[BOOTMGFW]
[reactos.git] / reactos / boot / environ / lib / misc / bcd.c
1 /*
2 * COPYRIGHT: See COPYING.ARM in the top level directory
3 * PROJECT: ReactOS UEFI Boot Library
4 * FILE: boot/environ/lib/misc/bcd.c
5 * PURPOSE: Boot Library BCD Routines
6 * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include "bl.h"
12
13 /* FUNCTIONS *****************************************************************/
14
15 ULONG
16 BlGetBootOptionListSize (
17 _In_ PBOOT_ENTRY_OPTION BcdOption
18 )
19 {
20 ULONG Size = 0, NextOffset = 0;
21 PBOOT_ENTRY_OPTION NextOption;
22
23 /* Loop all the options*/
24 do
25 {
26 /* Move to the next one */
27 NextOption = (PBOOT_ENTRY_OPTION)((ULONG_PTR)BcdOption + NextOffset);
28
29 /* Compute the size of the next one */
30 Size += BlGetBootOptionSize(NextOption);
31
32 /* Update the offset */
33 NextOffset = NextOption->NextEntryOffset;
34 } while (NextOffset != 0);
35
36 /* Return final computed size */
37 return Size;
38 }
39
40 ULONG
41 BlGetBootOptionSize (
42 _In_ PBOOT_ENTRY_OPTION BcdOption
43 )
44 {
45 ULONG Size, Offset;
46
47 /* Check if there's any data */
48 if (BcdOption->DataOffset != 0)
49 {
50 /* Add the size of the data */
51 Size = BcdOption->DataOffset + BcdOption->DataSize;
52 }
53 else
54 {
55 /* No data, just the structure itself */
56 Size = sizeof(*BcdOption);
57 }
58
59 /* Any associated options? */
60 Offset = BcdOption->ListOffset;
61 if (Offset != 0)
62 {
63 /* Go get those too */
64 Size += BlGetBootOptionListSize((PVOID)((ULONG_PTR)BcdOption + Offset));
65 }
66
67 /* Return the final size */
68 return Size;
69 }