OcDevicePathLib: Add deduplicate DP instance append API

This commit is contained in:
Download-Fritz 2019-07-15 09:16:53 +02:00
parent bcaaed8641
commit 8c7bc280bf
2 changed files with 51 additions and 0 deletions

View File

@ -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.

View File

@ -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);
}