903f1f17ee9ac24377dc94f1529278357deccfc5
[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 /*++
16 * @name BlGetBootOptionListSize
17 *
18 * The BlGetBootOptionListSize routine
19 *
20 * @param BcdOption
21 * UEFI Image Handle for the current loaded application.
22 *
23 * @return Size of the BCD option
24 *
25 *--*/
26 ULONG
27 BlGetBootOptionListSize (
28 _In_ PBL_BCD_OPTION BcdOption
29 )
30 {
31 ULONG Size = 0, NextOffset = 0;
32 PBL_BCD_OPTION NextOption;
33
34 /* Loop all the options*/
35 do
36 {
37 /* Move to the next one */
38 NextOption = (PBL_BCD_OPTION)((ULONG_PTR)BcdOption + NextOffset);
39
40 /* Compute the size of the next one */
41 Size += BlGetBootOptionSize(NextOption);
42
43 /* Update the offset */
44 NextOffset = NextOption->NextEntryOffset;
45 } while (NextOffset != 0);
46
47 /* Return final computed size */
48 return Size;
49 }
50
51 /*++
52 * @name BlGetBootOptionSize
53 *
54 * The BlGetBootOptionSize routine
55 *
56 * @param BcdOption
57 * UEFI Image Handle for the current loaded application.
58 *
59 * @return Size of the BCD option
60 *
61 *--*/
62 ULONG
63 BlGetBootOptionSize (
64 _In_ PBL_BCD_OPTION BcdOption
65 )
66 {
67 ULONG Size, Offset;
68
69 /* Check if there's any data */
70 if (BcdOption->DataOffset != 0)
71 {
72 /* Add the size of the data */
73 Size = BcdOption->DataOffset + BcdOption->DataSize;
74 }
75 else
76 {
77 /* No data, just the structure itself */
78 Size = sizeof(*BcdOption);
79 }
80
81 /* Any associated options? */
82 Offset = BcdOption->ListOffset;
83 if (Offset != 0)
84 {
85 /* Go get those too */
86 Size += BlGetBootOptionListSize((PVOID)((ULONG_PTR)BcdOption + Offset));
87 }
88
89 /* Return the final size */
90 return Size;
91 }