/* Find a section in a file by type and instance. An instance of 1 is the first instance. The function will return NULL if a matching section cannot be found. GUID-defined sections, if special processing is not needed, are handled in a depth-first manner. */
EFI_STATUS GetSectionByType(IN EFI_FFS_FILE_HEADER *File, IN EFI_SECTION_TYPE SectionType, IN UINTN Instance, OUT EFI_FILE_SECTION_POINTER *Section)
/* Find a section in a file by type and instance. An instance of 1 is the first instance. The function will return NULL if a matching section cannot be found. GUID-defined sections, if special processing is not needed, are handled in a depth-first manner. */
EFI_STATUS GetSectionByType(IN EFI_FFS_FILE_HEADER *File, IN EFI_SECTION_TYPE SectionType, IN UINTN Instance, OUT EFI_FILE_SECTION_POINTER *Section)
{
  EFI_FILE_SECTION_POINTER  CurrentSection;
  EFI_STATUS                Status;
  UINTN                     SectionCount;
  if (File == NULL || Instance == 0) {
    return EFI_INVALID_PARAMETER;
  }
  Status = VerifyFfsFile (File);
  if (EFI_ERROR (Status)) {
    Error (NULL, 0, 0006, "invalid FFS file", NULL);
    return EFI_ABORTED;
  }
  SectionCount = 0;
  CurrentSection.CommonHeader = (EFI_COMMON_SECTION_HEADER *) ((UINTN) File + GetFfsHeaderLength(File));
  Status = SearchSectionByType (
             CurrentSection,
             (UINT8 *) ((UINTN) File + GetFfsFileLength (File)),
             SectionType,
             &SectionCount,
             Instance,
             Section
             );
  if (!EFI_ERROR (Status)) {
    return EFI_SUCCESS;
  } else {
    (*Section).Code16Section = NULL;
    return EFI_NOT_FOUND;
  }
}