/* Update a bit of state on a block device. The location of the bit is calculated by the (Lba, Offset, bit). Here bit is determined by the the name of a certain bit. */
EFI_STATUS FtwUpdateFvState(IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock, IN UINTN BlockSize, IN EFI_LBA Lba, IN UINTN Offset, IN UINT8 NewBit)
/* Update a bit of state on a block device. The location of the bit is calculated by the (Lba, Offset, bit). Here bit is determined by the the name of a certain bit. */
EFI_STATUS FtwUpdateFvState(IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock, IN UINTN BlockSize, IN EFI_LBA Lba, IN UINTN Offset, IN UINT8 NewBit)
{
  EFI_STATUS  Status;
  UINT8       State;
  UINTN       Length;
  while (Offset >= BlockSize) {
    Offset -= BlockSize;
    Lba++;
  }
  Length = sizeof (UINT8);
  Status = FvBlock->Read (FvBlock, Lba, Offset, &Length, &State);
  if (EFI_ERROR (Status)) {
    return EFI_ABORTED;
  }
  State ^= FTW_POLARITY_REVERT;
  State  = (UINT8)(State | NewBit);
  State ^= FTW_POLARITY_REVERT;
  Length = sizeof (UINT8);
  Status = FvBlock->Write (FvBlock, Lba, Offset, &Length, &State);
  return Status;
}