mirror of
https://github.com/acidanthera/OpenCorePkg.git
synced 2025-12-08 19:25:01 +00:00
OcDevicePathLib: Add deduplicate DP instance append API
This commit is contained in:
parent
bcaaed8641
commit
8c7bc280bf
@ -157,6 +157,12 @@ OcFileDevicePathNameLen (
|
||||
IN CONST FILEPATH_DEVICE_PATH *FilePath
|
||||
);
|
||||
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
OcAppendDevicePathInstanceDedupe (
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,
|
||||
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Fix Apple Boot Device Path to be compatible with conventional UEFI
|
||||
implementations.
|
||||
|
||||
@ -735,3 +735,48 @@ OcFileDevicePathNameLen (
|
||||
|
||||
return Len;
|
||||
}
|
||||
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
OcAppendDevicePathInstanceDedupe (
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,
|
||||
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL
|
||||
)
|
||||
{
|
||||
INTN CmpResult;
|
||||
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevPathWalker;
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *CurrentInstance;
|
||||
|
||||
UINTN AppendInstanceSize;
|
||||
UINTN CurrentInstanceSize;
|
||||
|
||||
if (DevicePath != NULL && DevicePathInstance != NULL) {
|
||||
AppendInstanceSize = GetDevicePathSize (DevicePathInstance);
|
||||
DevPathWalker = DevicePath;
|
||||
|
||||
while (TRUE) {
|
||||
CurrentInstance = GetNextDevicePathInstance (
|
||||
&DevPathWalker,
|
||||
&CurrentInstanceSize
|
||||
);
|
||||
if (CurrentInstance == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (CurrentInstanceSize != AppendInstanceSize) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CmpResult = CompareMem (
|
||||
CurrentInstance,
|
||||
DevicePathInstance,
|
||||
CurrentInstanceSize
|
||||
);
|
||||
if (CmpResult == 0) {
|
||||
return DuplicateDevicePath (DevicePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return AppendDevicePathInstance (DevicePath, DevicePathInstance);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user