+\r
+/**\r
+ Function to find the file name associated with a LoadedImageProtocol.\r
+\r
+ @param[in] LoadedImage An instance of LoadedImageProtocol.\r
+\r
+ @retval A string representation of the file name associated\r
+ with LoadedImage, or NULL if no name can be found.\r
+**/\r
+CHAR16*\r
+FindLoadedImageFileName (\r
+ IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage\r
+ )\r
+{\r
+ EFI_GUID *NameGuid;\r
+ EFI_STATUS Status;\r
+ EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r
+ VOID *Buffer;\r
+ UINTN BufferSize;\r
+ UINT32 AuthenticationStatus;\r
+\r
+ if ((LoadedImage == NULL) || (LoadedImage->FilePath == NULL)) {\r
+ return NULL;\r
+ }\r
+\r
+ NameGuid = EfiGetNameGuidFromFwVolDevicePathNode((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)LoadedImage->FilePath);\r
+\r
+ if (NameGuid == NULL) {\r
+ return NULL;\r
+ }\r
+\r
+ //\r
+ // Get the FirmwareVolume2Protocol of the device handle that this image was loaded from.\r
+ //\r
+ Status = gBS->HandleProtocol (LoadedImage->DeviceHandle, &gEfiFirmwareVolume2ProtocolGuid, (VOID**) &Fv);\r
+\r
+ //\r
+ // FirmwareVolume2Protocol is PI, and is not required to be available.\r
+ //\r
+ if (EFI_ERROR (Status)) {\r
+ return NULL;\r
+ }\r
+\r
+ //\r
+ // Read the user interface section of the image.\r
+ //\r
+ Buffer = NULL;\r
+ Status = Fv->ReadSection(Fv, NameGuid, EFI_SECTION_USER_INTERFACE, 0, &Buffer, &BufferSize, &AuthenticationStatus);\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ return NULL;\r
+ }\r
+\r
+ //\r
+ // ReadSection returns just the section data, without any section header. For\r
+ // a user interface section, the only data is the file name.\r
+ //\r
+ return Buffer;\r
+}\r
+\r