/* Searches the FFS file and counts the number of sections found. The sections are NOT recursed. */
EFI_STATUS FvBufCountSections(IN VOID *FfsFile, IN UINTN *Count)
/* Searches the FFS file and counts the number of sections found. The sections are NOT recursed. */
EFI_STATUS FvBufCountSections(IN VOID *FfsFile, IN UINTN *Count)
{
  EFI_STATUS                 Status;
  UINTN                      Key;
  VOID*                      SectionStart;
  UINTN                      TotalSectionsSize;
  EFI_COMMON_SECTION_HEADER* NextSection;
  SectionStart = (VOID*)((UINTN)FfsFile + FvBufGetFfsHeaderSize(FfsFile));
  TotalSectionsSize =
    FvBufGetFfsFileSize ((EFI_FFS_FILE_HEADER*)FfsFile) -
    FvBufGetFfsHeaderSize(FfsFile);
  Key = 0;
  *Count = 0;
  while (TRUE) {
    Status = FvBufFindNextSection (
               SectionStart,
               TotalSectionsSize,
               &Key,
               (VOID **)&NextSection
               );
    if (Status == EFI_NOT_FOUND) {
      return EFI_SUCCESS;
    } else if (EFI_ERROR (Status)) {
      return Status;
    }
    *Count += 1;
  }
  return EFI_NOT_FOUND;
}