📄 fdi_int.c
字号:
/* Entry Status is in an intermediate state */
else if ((entry_state_mask =
ENTRY_INTERMEDIATE(new_tbl_buff.entry_status)) != 0)
{
#ifdef TEST_MSGS
logMsg("Intermediate entry status found in ScanEntryTables(), 0x%X\n",
new_tbl_buff.entry_status,0,0,0,0,0);
#endif
/* do not increment the entry count so because we need to fix this
intermediate state */
bump_seq_addr = FALSE;
/* Determine mask needed to push out of intermediate state */
new_tbl_buff.entry_status = ENTRY_FIX_INTERMEDIATE(entry_state_mask,
new_tbl_buff.entry_status);
hw_status = FlashDevWrite(&new_tbl_buff.entry_status,
new_tbl_addr +
(tbl_index * sizeof(ENTRY_TABLE)) +
offsetof(ENTRY_TABLE, entry_status),
sizeof(new_tbl_buff.entry_status));
if (hw_status != HW_ERR_NONE)
{
break;
}
}
/* Some header corruption occurred */
else
{
bump_seq_addr = TRUE;
#ifdef TESTING
return ERR_FORMAT;
#endif
}
if (bump_seq_addr == TRUE)
{
/* skip to next table entry. */
tbl_index++;
ENTRY_TABLE_size -= sizeof(ENTRY_TABLE);
}
} while (ENTRY_TABLE_size >= sizeof(ENTRY_TABLE));
if (status == ERR_NONE && hw_status == HW_ERR_NONE)
{
if(invalidate_flag == TRUE)
{
/*
* the first new table entry with status GRP_VALID_ENTRY
* will be marked GRP_INVALID
*/
new_tbl_buff.entry_status &= GRP_INVALID;
hw_status =
FlashDevWrite(&new_tbl_buff.entry_status,
first_seq_tbl_entry_addr +
offsetof(ENTRY_TABLE, entry_status),
sizeof(new_tbl_buff.entry_status));
}
}
mDEBUG_CHECK_ERRCODE(status)
mDEBUG_CHECK_ERRCODE(hw_status)
if(status != ERR_NONE || hw_status != HW_ERR_NONE)
{
return ERR_SYSTEM;
}
else
{
return ERR_NONE;
}
} /* END ScanEntryTables */
#endif /* INCLUDE_FRAGMENTED_DATA */
/*
*############################################################################
*### SearchForIdentifier
*###
*### DESCRIPTION:
*### If the unit_header_status is allocated, scans the entire media
*### to see if an valid identifier of same type exists, and returns its
*### address in if it exists, or a DWORDMAX if no valid sequence table unit
*### header exists. If the unit_header_status is allocating, scans the entire
*### media to invalidate all the unit headers of matching identifier that are
*### not marked valid. If the unit_header_status is invalidating, scans the
*### entire media to invalidate all the unit headers of matching identifier
*### and type that are not marked invalid except the header that is marked
*### invalidating. If more than one header is found in invalidating state,
*### DWORDMAX is returned indicating a format error. Otherwise, the address
*### of the header that is marked invalidating is returned.
*###
*### PARAMETERS:
*### IN:
*### UNIT_HEADER *new_header_pointer
*### DWORD_PTR invalidating_hdr_addr
*###
*### OUT:
*### DWORD: address of the previous valid unit header
*###
*### RETURNS:
*### ERR_CODE: error code
*###
*/
ERR_CODE
SearchForIdentifier(const UNIT_HEADER * new_header_pointer,
DWORD_PTR invalidating_hdr_addr,
WORD current_index,
WORD index,
BYTE flag)
{
UNIT_HEADER unit_header_buffer; /* buffer to store unit header info */
DWORD block_address;
WORD unit_index;
WORD block_index;
WORD state_msk; /* mask to fix intermediate state */
BYTE found = FALSE;
ERR_CODE status = ERR_NONE;
HW_ERROR hw_status = HW_ERR_NONE;
*invalidating_hdr_addr = DWORDMAX;
for (block_index = 0; block_index < MAX_DATA_BLOCKS; block_index++)
{
/* If it is called from the background, take the block table sem. */
if (flag == 0)
{
SEM_MTX_WAIT(SEM_BlockTable);
}
block_address =
BLOCK_ADDRESS(FDI_LogicalBlockTable[block_index].physical_block_number);
/* If it is called from the background, give up the block table sem. */
if (flag == 0)
{
SEM_MTX_POST(SEM_BlockTable);
}
unit_index = 0;
/*
* Scan all the unit headers in this block until an empty unit header is
* found or a matching valid sequence table header is found.
*/
do
{
/* Read the unit header information of a unit. */
hw_status = FlashDevRead((BYTE_PTR) & unit_header_buffer,
block_address + FIRST_HEADER_OFFSET +
(unit_index * sizeof(UNIT_HEADER)),
sizeof(UNIT_HEADER));
if (hw_status != HW_ERR_NONE)
{
return ERR_READ;
}
/* Need to fix intermediate states if SearchForIdentifier was called
* from init and unit header hasn't already been scanned by
* ScanHeaders. All references to the unit header status after this
* will just check left most bit. */
if ((flag != 0) &&
((current_index != unit_index) || (index != block_index)) &&
(CheckAddr(block_address + FIRST_HEADER_OFFSET +
(unit_index * sizeof(UNIT_HEADER)), current_index,
index) == BYTEMAX))
{
/* Determine if status is in an intermediate state */
if ((state_msk = HDR_INTERMEDIATE(unit_header_buffer.status)) != 0)
{
#ifdef TEST_MSGS
logMsg("Intermediate header status found in SearchForIdentifier(), 0x%X\n",
unit_header_buffer.status,0,0,0,0,0);
#endif
/* Determine the mask needed to push out of intermediate state. */
unit_header_buffer.status = HDR_FIX_INTERMEDIATE(state_msk,
unit_header_buffer.status);
/* Push out of intermediate state */
if ((hw_status =
FlashDevWrite((BYTE_PTR)&unit_header_buffer.status,
block_address + FIRST_HEADER_OFFSET +
(unit_index * sizeof(UNIT_HEADER)) +
offsetof(UNIT_HEADER, status),
sizeof(unit_header_buffer.status))) !=
HW_ERR_NONE)
{
mDEBUG_CHECK_ERRCODE(hw_status)
return ERR_WRITE;
}
}
}
/* If no more data exists in this block, scan next block. */
if (HDR_STATE(HDR_EMPTY, unit_header_buffer.status))
{
break;
}
/* If the new_header_pointer->status is allocated, */
if (new_header_pointer->status == HDR_ALLOCATED)
{
/* If a valid matching identifier of same type exists. Also check
* for valid multi instance being returned to cover the case of
* the multi -> single */
if (HDR_STATE(HDR_VALID, unit_header_buffer.status) &&
(unit_header_buffer.identifier ==
new_header_pointer->identifier) &&
((unit_header_buffer.type_attribute ==
new_header_pointer->type_attribute) ||
(((unit_header_buffer.type_attribute & ~ATTRIBUTE_MASK) ==
(new_header_pointer->type_attribute & ~ATTRIBUTE_MASK))
&& ((unit_header_buffer.type_attribute & ATTRIBUTE_MASK) ==
ATTR_MULTI_INST) && ((new_header_pointer->type_attribute &
ATTRIBUTE_MASK) == ATTR_SINGL_INST) ) ))
{
*invalidating_hdr_addr = (block_address + FIRST_HEADER_OFFSET +
(unit_index * sizeof(UNIT_HEADER)));
return ERR_NONE;
}
} /* End of if(
* new_header_pointer->status ==
* ALLOCATED ). */
/* elseIf the new_header_pointer->status is valid, */
/* this happens only when SearchForIdentifier is called from
the background
*/
else if (new_header_pointer->status == HDR_VALID)
{
/* If a valid matching identifier of same type exists. */
if (HDR_STATE(HDR_VALID, unit_header_buffer.status) &&
(unit_header_buffer.identifier ==
new_header_pointer->identifier) &&
(NIBBLE_HIGH(unit_header_buffer.type_attribute) ==
NIBBLE_HIGH(new_header_pointer->type_attribute)) &&
((unit_header_buffer.type_attribute & ATTRIBUTE_MASK) !=
ATTR_DATA_FRAG) &&
((unit_header_buffer.type_attribute & ATTRIBUTE_MASK) !=
ATTR_SEQ_TABLE))
{
*invalidating_hdr_addr = (block_address + FIRST_HEADER_OFFSET +
(unit_index * sizeof(UNIT_HEADER)));
return ERR_NONE;
}
} /* End of if(
* new_header_pointer->status == VALID
* ). */
/* else If the new_header_pointer->status is allocating or valid hdr */
else if ((new_header_pointer->status == HDR_ALLOCATING) ||
(new_header_pointer->status == HDR_VALID_HDR))
{
/*
* If a matching identifier and type that is marked
* allocated, invalidate the unit header.
* The check for HDR_VALID_HDR state will be taken care of in
* ScanHeaders.
*/
if ((HDR_STATE(HDR_ALLOCATED, unit_header_buffer.status)) &&
(unit_header_buffer.identifier ==
new_header_pointer->identifier) &&
(NIBBLE_HIGH(unit_header_buffer.type_attribute) ==
NIBBLE_HIGH(new_header_pointer->type_attribute)))
{
if ( (new_header_pointer->type_attribute & ATTRIBUTE_MASK) !=
ATTR_GRP_TABLE )
{
unit_header_buffer.g_unit_size = WORDMAX;
}
else
{
if(flag && CheckAddr(block_address + FIRST_HEADER_OFFSET +
(unit_index * sizeof(UNIT_HEADER)), current_index,
index) == BYTEMAX)
{
unit_header_buffer.g_unit_size = WORDMAX;
}
}
/* Invalidate the unit header. */
if ((status = WriteUnitHeaderStatus((block_address + FIRST_HEADER_OFFSET +
(unit_index * sizeof(UNIT_HEADER))),
HDR_INVALID, unit_header_buffer.status,
unit_header_buffer.g_unit_size, flag)) !=
ERR_NONE)
{
*invalidating_hdr_addr = DWORDMAX;
return status;
}
}
} /* End of if(
* new_header_pointer->status ==
* HDR_ALLOCATING ). */
/*
* else If the new_header_pointer->status is invalidating, it means
* the data is fragmented.
*/
else if (new_header_pointer->status == HDR_INVALIDATING)
{
/*
* If a matching identifier and type, that is not marked invalid,
* exists.
*/
if ((!INVALID_HDR(unit_header_buffer.status)) &&
(unit_header_buffer.identifier ==
new_header_pointer->identifier) &&
(NIBBLE_HIGH(unit_header_buffer.type_attribute) ==
NIBBLE_HIGH(new_header_pointer->type_attribute)))
{
if (!HDR_STATE(HDR_INVALIDATING, unit_header_buffer.status))
{
if (NIBBLE_LOW(unit_header_buffer.type_attribute) !=
ATTR_GRP_TABLE)
{
if(flag && CheckAddr(block_address + FIRST_HEADER_OFFSET +
(unit_index * sizeof(UNIT_HEADER)), current_index,
index) == BYTEMAX)
{
unit_header_buffer.g_unit_size = WORDMAX;
}
if((status = WriteUnitHeaderStatus(block_address +
FIRST_HEADER_OFFSET + (unit_index *
sizeof(UNIT_HEADER)), HDR_INVALID,
unit_header_buffer.status,
unit_header_buffer.g_unit_size, flag)) != ERR_NONE)
{
/* Invalidate the unit header. */
*invalidating_hdr_addr = DWORDMAX;
return status;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -