+ HandleFilePath = FilePath;\r
+ DeviceHandle = NULL;\r
+ Status = EFI_SUCCESS;\r
+ AuthenticationStatus = 0;\r
+ //\r
+ // If the caller passed a copy of the file, then just use it\r
+ //\r
+ if (SourceBuffer != NULL) {\r
+ FHand.Source = SourceBuffer;\r
+ FHand.SourceSize = SourceSize;\r
+ CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &HandleFilePath, &DeviceHandle);\r
+ if (SourceSize > 0) {\r
+ Status = EFI_SUCCESS;\r
+ } else {\r
+ Status = EFI_LOAD_ERROR;\r
+ }\r
+ } else {\r
+ if (FilePath == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ //\r
+ // Get the source file buffer by its device path.\r
+ //\r
+ FHand.Source = GetFileBufferByFilePath (\r
+ BootPolicy, \r
+ FilePath,\r
+ &FHand.SourceSize,\r
+ &AuthenticationStatus\r
+ );\r
+ if (FHand.Source == NULL) {\r
+ Status = EFI_NOT_FOUND;\r
+ } else {\r
+ //\r
+ // Try to get the image device handle by checking the match protocol.\r
+ //\r
+ FHand.FreeBuffer = TRUE;\r
+ Status = CoreLocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &HandleFilePath, &DeviceHandle);\r
+ if (EFI_ERROR (Status)) {\r
+ HandleFilePath = FilePath;\r
+ Status = CoreLocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &HandleFilePath, &DeviceHandle);\r
+ if (EFI_ERROR (Status)) {\r
+ if (!BootPolicy) {\r
+ HandleFilePath = FilePath;\r
+ Status = CoreLocateDevicePath (&gEfiLoadFile2ProtocolGuid, &HandleFilePath, &DeviceHandle);\r
+ }\r
+ if (EFI_ERROR (Status)) {\r
+ HandleFilePath = FilePath;\r
+ Status = CoreLocateDevicePath (&gEfiLoadFileProtocolGuid, &HandleFilePath, &DeviceHandle);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r