📄 fdi_int.c
字号:
return ERR_READ;
}
/* Exit if the end of the table has been reached. */
if (new_tbl_buff.entry_status == SEQ_EMPTY)
break;
/*
* IF the entry status is marked GRP_VALID_ENTRY or GRP_VALID, find the
* table unit header associated with the table entry.
*/
else if ((new_tbl_buff.entry_status == GRP_VALID) ||
(new_tbl_buff.entry_status == GRP_VALID_ENTRY))
{
if((first_seq_tbl_entry_addr == DWORDMAX) &&
(new_tbl_buff.entry_status == GRP_VALID_ENTRY))
{
/*
* save the address of the first new table entry
* with status GRP_VALID_ENTRY
*/
first_seq_tbl_entry_addr = new_tbl_addr +
(tbl_index * sizeof(ENTRY_TABLE));
}
unit_index = 0; /* initialize loop counter variables. */
/* Validate the block_number field to check that
it is within the valid range for logical block numbers in this
configuration
*/
if(!VALID_BLOCK_RANGE(new_tbl_buff.block_number))
return ERR_FORMAT;
block_index = FDI_LogicalBlockTable[new_tbl_buff.block_number].
physical_block_number;
block_address = BLOCK_ADDRESS(block_index);
data_instance = new_tbl_buff.entry_instance;
/*
* Until proper instance of the table entry is found, or until no more
* unit header exists, read each unit header at the beginning of the
* block address.
*/
do
{
/*
* Read the unit header information of the refered 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;
}
/* check to see if we are in any intermediate states. If we
are, then correct for them */
if ((header_state_mask =
HDR_INTERMEDIATE(unit_header_buffer.status)) != 0)
{
#ifdef TEST_MSGS
logMsg("Intermediate header status found in ScanEntryTables(), \
0x%X\n", unit_header_buffer.status,0,0,0,0,0);
#endif
/* Determine mask needed to push out of intermediate state */
unit_header_buffer.status = HDR_FIX_INTERMEDIATE
(header_state_mask, unit_header_buffer.status);
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));
if (hw_status != HW_ERR_NONE)
{
mDEBUG_CHECK_ERRCODE(hw_status)
return ERR_WRITE;
}
}
/*
* Look for matching identifier and type and the
* attribute seq table if group table is being scanned and
* attribute fragment if seq table is being scanned,
* to determine when we have reached the appropriate instance.
*/
if ((unit_header_buffer.identifier ==
new_tbl_hdr_ptr->identifier) &&
(NIBBLE_HIGH(unit_header_buffer.type_attribute) ==
NIBBLE_HIGH(new_tbl_hdr_ptr->type_attribute)) &&
(((unit_header_buffer.table_number == seq_tbl_number) &&
(((unit_header_buffer.type_attribute & ATTRIBUTE_MASK) ==
ATTR_DATA_FRAG) ||
((unit_header_buffer.type_attribute & ATTRIBUTE_MASK) ==
ATTR_SINGL_INST)) &&
((new_tbl_hdr_ptr->type_attribute & ATTRIBUTE_MASK) ==
ATTR_SEQ_TABLE)) ||
(((unit_header_buffer.type_attribute & ATTRIBUTE_MASK) ==
ATTR_SEQ_TABLE) &&
((new_tbl_hdr_ptr->type_attribute & ATTRIBUTE_MASK) ==
ATTR_GRP_TABLE))
) &&
(!INVALID_HDR(unit_header_buffer.status)))
{
data_instance--; /* decrment the instance counter */
/* If matching instance found, */
if (data_instance == 0)
{
switch (unit_header_buffer.status)
{
case HDR_VALID:
if ((new_tbl_hdr_ptr->type_attribute &
ATTRIBUTE_MASK) == ATTR_GRP_TABLE)
{
/* mark group table entry GRP_VALID */
if ((status = ScanEntryTables(&unit_header_buffer,
block_address + FIRST_HEADER_OFFSET +
(unit_index * sizeof(UNIT_HEADER)),
current_index,
index, grp_entry_number)) != ERR_NONE)
{
break;
}
grp_entry_number++;
}
else if ((unit_header_buffer.type_attribute &
ATTRIBUTE_MASK) != ATTR_DATA_FRAG)
{
/*
* Convert to ATTR_DATA_FRAG
*/
unit_header_buffer.type_attribute =
BYTEMASK(NIBBLE_HIGH(
unit_header_buffer.type_attribute),
ATTR_DATA_FRAG);
hw_status =
FlashDevWrite(&unit_header_buffer.type_attribute,
block_address +
FIRST_HEADER_OFFSET + (unit_index *
sizeof(UNIT_HEADER) +
offsetof(UNIT_HEADER, type_attribute)),
sizeof(unit_header_buffer.type_attribute));
if(hw_status != HW_ERR_NONE)
{
break;
}
}
if ( new_tbl_buff.entry_status != GRP_VALID)
{
new_tbl_buff.entry_status = GRP_VALID;
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));
}
break;
case HDR_ALLOCATED:
if (invalidate_flag == FALSE)
{
if ((new_tbl_hdr_ptr->type_attribute &
ATTRIBUTE_MASK) == ATTR_GRP_TABLE)
{
if ((status =
ScanEntryTables(&unit_header_buffer,
block_address + FIRST_HEADER_OFFSET +
(unit_index * sizeof(UNIT_HEADER)),
current_index, index,
grp_entry_number)) != ERR_NONE)
{
break;
}
grp_entry_number++;
}
/*
* Mark entry to valid before setting corresponding
* instance to valid, here is for DLPR issue and for
* packet data validation
*/
if (new_tbl_buff.entry_status != GRP_VALID)
{
/* mark the table entry GRP_VALID */
new_tbl_buff.entry_status = GRP_VALID;
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)
{
status = ERR_WRITE;
break;
}
}
/*
* Validate the unit header marked
* HDR_ALLOCATED
*/
status =
WriteUnitHeaderStatus(block_address +
(unit_index * sizeof(UNIT_HEADER)) +
FIRST_HEADER_OFFSET, HDR_VALID,
unit_header_buffer.status,
unit_header_buffer.g_unit_size, 1);
break;
}
/* invalidate_flag == TRUE */
else
{
/* mark the table entry GRP_INVALID */
/*
* do this in 2 steps to avoid dual power loss
* problems
*/
new_tbl_buff.entry_status &= INVALIDATE_ENTRY;
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));
break;
}
case HDR_ALLOCATING:
/* mark the table entry GRP_INVALID */
/*
* do this in 2 steps to avoid dual power loss
* problems
*/
new_tbl_buff.entry_status &= INVALIDATE_ENTRY;
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));
break;
case HDR_VALID_HDR:
if (invalidate_flag == FALSE)
{
/*
* for the first new table entry, whose
* corresponding unit is HDR_VALID_HDR,
* do not invalidate this entry
*/
invalidate_flag = TRUE;
break;
}
/* invalidate_flag = TRUE */
else
{
/* mark the table entry GRP_INVALID */
/*
* do this in 2 steps to avoid dual
* power loss problems
*/
new_tbl_buff.entry_status &= INVALIDATE_ENTRY;
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));
break;
}
default:
break;
} /* ENDSWITCH header.status */
if (status != ERR_NONE || hw_status != HW_ERR_NONE)
{
break;
}
} /* ENDIF data_instance == 0 */
} /* ENDIF header matches this seq */
unit_index++;
} while ((data_instance != 0) &&
(!HDR_STATE(HDR_EMPTY, unit_header_buffer.status)));
mDEBUG_CHECK_ERRCODE(status)
mDEBUG_CHECK_ERRCODE(hw_status)
if(status != ERR_NONE || hw_status != HW_ERR_NONE)
return ERR_SYSTEM;
if (data_instance != 0)
{
/*
* This entry instance not found so mark the table
* entry GRP_INVALID
*/
new_tbl_buff.entry_status &= INVALIDATE_ENTRY;
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;
}
}
} /* ENDIF status == GRP_ALLOCATING */
else if ((new_tbl_buff.entry_status == GRP_ALLOCATING) ||
(INVALID_ENTRY(new_tbl_buff.entry_status)))
{
/*
* This unit instance create not begun, so mark the table entry
* GRP_INVALID
*/
new_tbl_buff.entry_status &= INVALIDATE_ENTRY;
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;
}
} /* ENDIF status == GRP_ALLOCATING */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -