diff --git a/Include/Library/OcDevicePathLib.h b/Include/Library/OcDevicePathLib.h index 956d0447..3d0a1c78 100755 --- a/Include/Library/OcDevicePathLib.h +++ b/Include/Library/OcDevicePathLib.h @@ -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. diff --git a/Library/OcDevicePathLib/OcDevicePathLib.c b/Library/OcDevicePathLib/OcDevicePathLib.c index f6122a0c..3a9ec4d5 100755 --- a/Library/OcDevicePathLib/OcDevicePathLib.c +++ b/Library/OcDevicePathLib/OcDevicePathLib.c @@ -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); +}