Reclaim work space when the remaining space size is even not enough to contain one header + one record.

Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14005 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
lzeng14 2012-12-17 03:18:16 +00:00
parent 95830a117a
commit d379cbc75d
1 changed files with 10 additions and 1 deletions

View File

@ -166,6 +166,7 @@ WorkSpaceRefresh (
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINTN Length; UINTN Length;
UINTN RemainingSpaceSize;
// //
// Initialize WorkSpace as FTW_ERASED_BYTE // Initialize WorkSpace as FTW_ERASED_BYTE
@ -198,7 +199,15 @@ WorkSpaceRefresh (
FtwDevice->FtwWorkSpaceSize, FtwDevice->FtwWorkSpaceSize,
&FtwDevice->FtwLastWriteHeader &FtwDevice->FtwLastWriteHeader
); );
if (EFI_ERROR (Status)) { RemainingSpaceSize = FtwDevice->FtwWorkSpaceSize - ((UINTN) FtwDevice->FtwLastWriteHeader - (UINTN) FtwDevice->FtwWorkSpace);
DEBUG ((EFI_D_INFO, "Ftw: Remaining work space size - %x\n", RemainingSpaceSize));
//
// If FtwGetLastWriteHeader() returns error, or the remaining space size is even not enough to contain
// one EFI_FAULT_TOLERANT_WRITE_HEADER + one EFI_FAULT_TOLERANT_WRITE_RECORD(It will cause that the header
// pointed by FtwDevice->FtwLastWriteHeader or record pointed by FtwDevice->FtwLastWriteRecord may contain invalid data),
// it needs to reclaim work space.
//
if (EFI_ERROR (Status) || RemainingSpaceSize < sizeof (EFI_FAULT_TOLERANT_WRITE_HEADER) + sizeof (EFI_FAULT_TOLERANT_WRITE_RECORD)) {
// //
// reclaim work space in working block. // reclaim work space in working block.
// //