OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
BdsMisc.c
Go to the documentation of this file.
1
15#include <Library/BaseMemoryLib.h>
16#include <Library/DevicePathLib.h>
17#include <Library/DuetBdsLib.h>
18#include <Library/MemoryAllocationLib.h>
19#include <Library/UefiRuntimeServicesTableLib.h>
20
34VOID *
35EFIAPI
37 IN CHAR16 *Name,
38 IN EFI_GUID *VendorGuid,
39 OUT UINTN *VariableSize
40 )
41{
42 EFI_STATUS Status;
43 UINTN BufferSize;
44 VOID *Buffer;
45
46 Buffer = NULL;
47
48 //
49 // Pass in a zero size buffer to find the required buffer size.
50 //
51 BufferSize = 0;
52 Status = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);
53 if (Status == EFI_BUFFER_TOO_SMALL) {
54 //
55 // Allocate the buffer to return
56 //
57 Buffer = AllocateZeroPool (BufferSize);
58 if (Buffer == NULL) {
59 *VariableSize = 0;
60 return NULL;
61 }
62
63 //
64 // Read variable into the allocated buffer.
65 //
66 Status = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);
67 if (EFI_ERROR (Status)) {
68 FreePool (Buffer);
69 BufferSize = 0;
70 Buffer = NULL;
71 }
72 }
73
74 *VariableSize = BufferSize;
75 return Buffer;
76}
77
91EFI_DEVICE_PATH_PROTOCOL *
92EFIAPI
94 IN EFI_DEVICE_PATH_PROTOCOL *Multi,
95 IN EFI_DEVICE_PATH_PROTOCOL *Single
96 )
97{
98 EFI_DEVICE_PATH_PROTOCOL *Instance;
99 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
100 EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath;
101 UINTN InstanceSize;
102 UINTN SingleDpSize;
103 UINTN Size;
104
105 NewDevicePath = NULL;
106 TempNewDevicePath = NULL;
107
108 if ((Multi == NULL) || (Single == NULL)) {
109 return Multi;
110 }
111
112 Instance = GetNextDevicePathInstance (&Multi, &InstanceSize);
113 SingleDpSize = GetDevicePathSize (Single) - END_DEVICE_PATH_LENGTH;
114 InstanceSize -= END_DEVICE_PATH_LENGTH;
115
116 while (Instance != NULL) {
117 Size = (SingleDpSize < InstanceSize) ? SingleDpSize : InstanceSize;
118
119 if ((CompareMem (Instance, Single, Size) != 0)) {
120 //
121 // Append the device path instance which does not match with Single
122 //
123 TempNewDevicePath = NewDevicePath;
124 NewDevicePath = AppendDevicePathInstance (NewDevicePath, Instance);
125 if (TempNewDevicePath != NULL) {
126 FreePool (TempNewDevicePath);
127 }
128 }
129
130 FreePool (Instance);
131 Instance = GetNextDevicePathInstance (&Multi, &InstanceSize);
132 InstanceSize -= END_DEVICE_PATH_LENGTH;
133 }
134
135 return NewDevicePath;
136}
137
151BOOLEAN
152EFIAPI
154 IN EFI_DEVICE_PATH_PROTOCOL *Multi,
155 IN EFI_DEVICE_PATH_PROTOCOL *Single
156 )
157{
158 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
159 EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;
160 UINTN Size;
161
162 if ((Multi == NULL) || (Single == NULL)) {
163 return FALSE;
164 }
165
166 DevicePath = Multi;
167 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);
168
169 //
170 // Search for the match of 'Single' in 'Multi'
171 //
172 while (DevicePathInst != NULL) {
173 //
174 // If the single device path is found in multiple device paths,
175 // return success
176 //
177 if (CompareMem (Single, DevicePathInst, Size) == 0) {
178 FreePool (DevicePathInst);
179 return TRUE;
180 }
181
182 FreePool (DevicePathInst);
183 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);
184 }
185
186 return FALSE;
187}
EFI_DEVICE_PATH_PROTOCOL *EFIAPI BdsLibDelPartMatchInstance(IN EFI_DEVICE_PATH_PROTOCOL *Multi, IN EFI_DEVICE_PATH_PROTOCOL *Single)
Definition BdsMisc.c:93
BOOLEAN EFIAPI BdsLibMatchDevicePaths(IN EFI_DEVICE_PATH_PROTOCOL *Multi, IN EFI_DEVICE_PATH_PROTOCOL *Single)
Definition BdsMisc.c:153
VOID *EFIAPI BdsLibGetVariableAndSize(IN CHAR16 *Name, IN EFI_GUID *VendorGuid, OUT UINTN *VariableSize)
Definition BdsMisc.c:36
DMG_SIZE_DEVICE_PATH Size
OC_TYPING_BUFFER_ENTRY Buffer[OC_TYPING_BUFFER_SIZE]
Definition OcTypingLib.h:42
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EFI_RUNTIME_SERVICES * gRT