/* Calculates the checksum of the header of a file. */
UINT8 CalculateHeaderChecksum(IN EFI_FFS_FILE_HEADER *FileHeader)
/* Calculates the checksum of the header of a file. */
UINT8 CalculateHeaderChecksum(IN EFI_FFS_FILE_HEADER *FileHeader)
{
  UINT8  *ptr;
  UINTN  Index;
  UINT8  Sum;
  UINTN  Size;
  Sum  = 0;
  ptr  = (UINT8 *)FileHeader;
  Size = IS_FFS_FILE2 (FileHeader) ? sizeof (EFI_FFS_FILE_HEADER2) : sizeof (EFI_FFS_FILE_HEADER);
  for (Index = 0; Index < Size - 3; Index += 4) {
    Sum = (UINT8)(Sum + ptr[Index]);
    Sum = (UINT8)(Sum + ptr[Index + 1]);
    Sum = (UINT8)(Sum + ptr[Index + 2]);
    Sum = (UINT8)(Sum + ptr[Index + 3]);
  }
  for ( ; Index < Size; Index++) {
    Sum = (UINT8)(Sum + ptr[Index]);
  }
  Sum = (UINT8)(Sum - FileHeader->State);
  Sum = (UINT8)(Sum - FileHeader->IntegrityCheck.Checksum.File);
  return Sum;
}