fdi_ext.c
来自「FDI Intel开发的FLASH文件系统,功能很强大」· C语言 代码 · 共 1,919 行 · 第 1/5 页
C
1,919 行
#endif /* PACKET_DATA */
/*
* If opening to create, Look into the FDI_DataLookupTable and assign
* the first free identifier to the new data being created.
*/
if (cmd_cntrl->sub_command == OPEN_CREATE)
{
if (cmd_cntrl->identifier == NEW_DATA_STREAM_ID)
{
SEM_MTX_WAIT(SEM_LookupTable);
/* Scan the data lookup table. */
/* Changed ERASE_COUNT_ID to be NUM_TYPE14_PARMS */
start = 0;
/*E.5.0.718.START*/
for (id_index = start; id_index < NUM_PARMS[cmd_cntrl->type];id_index ++)
{
if (EMPTY_LOOKUP_TABLE(cmd_cntrl->type,id_index))
{
cmd_cntrl->identifier = id_index;
break;
}
}
/*E.5.0.718.END*/
SEM_MTX_POST(SEM_LookupTable);
}
/* Maximum identifiers has been reached. */
if (cmd_cntrl->identifier >= NUM_PARMS[cmd_cntrl->type])
{
/*
* unlock the global_sem_cntrl_mutex to give others access to the
* globals
*/
SEM_MTX_POST(SEM_OpenStream);
/* Unlock the API_sem_cntrl_mutex. */
SEM_MTX_POST(SEM_APIMutexSemaphore);
return ERR_MAX_EXISTS;
}
}
/*
* Verify that the data exists and update the FDI_GetDataFound structure
* with appropriate data information.
*/
status = DataFind(cmd_cntrl->identifier, cmd_cntrl->type, GET_MATCHED);
/* If opened to create, verify that the data does not exist already */
if ((status == ERR_NONE) && (cmd_cntrl->sub_command ==
OPEN_CREATE))
{
/*
* unlock the global_sem_cntrl_mutex to give others access to the
* globals
*/
SEM_MTX_POST(SEM_OpenStream);
/* Unlock the API_sem_cntrl_mutex. */
SEM_MTX_POST(SEM_APIMutexSemaphore);
return ERR_EXISTS;
}
/* if ERR_WIP, the file is being deleted by BKGD */
if ( status == ERR_WIP )
{
SEM_MTX_POST(SEM_OpenStream);
SEM_MTX_POST(SEM_APIMutexSemaphore);
if ( cmd_cntrl->sub_command == OPEN_CREATE )
{
return ERR_EXISTS;
} else
{
return ERR_NOTEXISTS;
}
}
/* If opened to access the existing data, verify that the data exists */
else if ((status != ERR_NONE) &&
(cmd_cntrl->sub_command != OPEN_CREATE))
{
/*
* unlock the global_sem_cntrl_mutex to give others access to the
* globals
*/
SEM_MTX_POST(SEM_OpenStream);
/* Unlock the API_sem_cntrl_mutex. */
SEM_MTX_POST(SEM_APIMutexSemaphore);
return status;
}
for (MOF_index = 0; MOF_index < OPEN_ARRAY_SIZE; MOF_index++)
{
if (FDI_OpenParam[MOF_index].identifier == WORDMAX)
{
break;
}
}
if (MOF_index >= OPEN_ARRAY_SIZE)
{
/*
* unlock the global_sem_cntrl_mutex to give others access to the
* globals
*/
SEM_MTX_POST(SEM_OpenStream);
/* Unlock the API_sem_cntrl_mutex. */
SEM_MTX_POST(SEM_APIMutexSemaphore);
return ERR_MAX_OPEN;
}
/*Update the DLT with the MOF_index number into the OpenParam Table*/
/* SET_LOOKUP_TABLE_OSFIELD(cmd_cntrl->type, cmd_cntrl->identifier, MOF_index);*/
FDI_OpenParamPtr = &FDI_OpenParam[MOF_index];
/* Update the FDI_OpenParam structure. */
/* the logical block number of the block to be accesed */
FDI_OpenParamPtr->logical_block = WORDMAX;
/*
* the begin address of the block which has the unit header of the fragment
* unit header
*/
FDI_OpenParamPtr->frag_block_addr = DWORDMAX;
/* offset of the begin of the fragment data unit header */
FDI_OpenParamPtr->b_frag_hdr_offset = DWORDMAX;
/*
* the data offset into the sequence table unit being accessed to begin
* next access
*/
FDI_OpenParamPtr->b_seq_table_entry_offset = DWORDMAX;
/* identifier */
FDI_OpenParamPtr->identifier = cmd_cntrl->identifier;
FDI_OpenParamPtr->table_number = 0;
FDI_OpenParamPtr->b_tabl_hdr_offset = DWORDMAX;
FDI_OpenParamPtr->b_begin_tabl_offset = DWORDMAX;
FDI_OpenParamPtr->b_grp_table_entry_offset = DWORDMAX;
#if (DATA_STREAM == TRUE)
/* data_streaming */
if ( cmd_cntrl->aux == TRUE )
{
FDI_OpenParamPtr->data_streaming = FALSE;
} else
{
FDI_OpenParamPtr->data_streaming = TRUE;
}
#endif
/*
* If the lookup table has a new entry, which means the data is being
* opened for create, fill in the open stream structure to represent the
* begining point of the data write in the flash media.
*/
if (cmd_cntrl->sub_command == OPEN_CREATE)
{
/* File points to the end/begin of the data stream. */
/*
* the data offset into the data stream(file) being accessed to begin
* next access
*/
FDI_OpenParamPtr->b_current_file_offset = 0;
/* the size of the data left remaining in the data unit bytes */
FDI_OpenParamPtr->b_remaining_in_unit = 0;
/*
* the begin address of the block which has the sequence table or single
* instance or multiple instance unit header
*/
FDI_OpenParamPtr->block_addr = DWORDMAX;
/*
* offset of the begin of the sequence table unit header or the single
* instance or the multiple instance data unit header
*/
FDI_OpenParamPtr->b_hdr_offset = DWORDMAX;
/*
* group table unit size or single instance or the multiple instance
* data unit size
*/
FDI_OpenParamPtr->b_unit_size = 0;
FDI_OpenParamPtr->b_total_size = 0;
SEM_MTX_WAIT(SEM_TotalSize);
FDI_OpenTotalSize[MOF_index] = 0;
SEM_MTX_POST(SEM_TotalSize);
/* type and attribute */
FDI_OpenParamPtr->type_attribute =
BYTEMASK(cmd_cntrl->type, BYTEMAX);
/*
* the data offset of the begin of the sequence table unit or single
* instance unit or multiple instance unit being accessed
*/
FDI_OpenParamPtr->b_begin_unit_offset = DWORDMAX;
} else /* sub_command is not OPEN_CREATE */
{
/*
* the begin address of the block which has the group table or single
* instance or multiple instance unit header
*/
hw_status = LookupToHeader(&(FDI_OpenParamPtr->block_addr),
&unit_address,
&(FDI_OpenParamPtr->b_hdr_offset),
&unit_header_information,
&(FDI_OpenParamPtr->logical_block),
cmd_cntrl->identifier, cmd_cntrl->type);
if (hw_status == HW_ERR_NONE)
{
/* type and attribute */
FDI_OpenParamPtr->type_attribute =
unit_header_information.type_attribute;
/*
* the data offset of the begin of the group table unit or single
* instance unit or multiple instance unit being accessed
*/
FDI_OpenParamPtr->b_begin_unit_offset =
(unit_address - FDI_OpenParamPtr->block_addr);
/* If the attribute is a single instance OR a multi-instance */
if ((NIBBLE_LOW(unit_header_information.type_attribute) ==
ATTR_SINGL_INST) ||
(NIBBLE_LOW(unit_header_information.type_attribute) ==
ATTR_MULTI_INST))
{
/* Moved GetDataSize outside of OPEN_MODIFY condition below,
* needed for both modifies and reads */
/*
* the data offset into the data stream(file) being accessed to
* begin next access
*/
status = GetDataSize(&(FDI_OpenParamPtr->b_current_file_offset),
cmd_cntrl->identifier,
cmd_cntrl->type, cmd_cntrl->priority);
if (status != ERR_NONE)
{
/* Clear the Open_Param structure. */
MemorySet((BYTE_PTR)FDI_OpenParamPtr, BYTEMAX,
(DWORD)(sizeof(OPEN_PARAM)));
/*
* unlock the global_sem_cntrl_mutex to give others access
* to the globals
*/
SEM_MTX_POST(SEM_OpenStream);
/* Unlock the API_sem_cntrl_mutex. */
SEM_MTX_POST(SEM_APIMutexSemaphore);
return status;
}
if (cmd_cntrl->sub_command == OPEN_MODIFY)
{
/*the size of the data left remaining in the data unit bytes*/
FDI_OpenParamPtr->b_remaining_in_unit = 0;
} else /* OPEN_READ */
{
/* the size of the data left remaining in the data unit bytes */
FDI_OpenParamPtr->b_remaining_in_unit =
(WORD)FDI_OpenParamPtr->b_current_file_offset;
/*
* the data offset into the data stream(file) being accessed to
* begin next access
*/
FDI_OpenParamPtr->b_current_file_offset = 0;
}
SEM_MTX_WAIT(SEM_TotalSize);
FDI_OpenTotalSize[MOF_index] =
FDI_OpenParamPtr->b_current_file_offset;
SEM_MTX_POST(SEM_TotalSize);
/* sequence table unit size or single instance data unit size */
FDI_OpenParamPtr->b_unit_size =
TO_BYTES(unit_header_information.g_unit_size);
} /* endif single or multi-instance */
#if (INCLUDE_FRAGMENTED_DATA == TRUE)
/* If the attribute is a group table, */
else if (NIBBLE_LOW(unit_header_information.type_attribute) ==
ATTR_GRP_TABLE)
{
/*
* the data offset into the group table unit being accessed
* to begin next access
*/
FDI_OpenParamPtr->b_grp_table_entry_offset =
FDI_OpenParamPtr->b_begin_unit_offset;
/* sequence table unit size or single instance data unit size */
FDI_OpenParamPtr->b_unit_size =
TO_BYTES(unit_header_information.g_unit_size);
/* Read the group table's first entry. */
hw_status = FlashDevRead((BYTE_PTR) &table, unit_address,
sizeof(ENTRY_TABLE));
if (hw_status != HW_ERR_NONE)
{
/* Clear the Open_Param structure. */
MemorySet((BYTE_PTR)FDI_OpenParamPtr, BYTEMAX,
(DWORD)sizeof(OPEN_PARAM));
/*
* unlock the global_sem_cntrl_mutex to give others access to
* the globals
*/
SEM_MTX_POST(SEM_OpenStream);
/* Unlock the API_sem_cntrl_mutex. */
SEM_MTX_POST(SEM_APIMutexSemaphore);
return ERR_READ;
}
/*
* the data offset into the data stream(file) being accessed to
* begin next access
*/
status = GetDataSize(&(FDI_OpenParamPtr->b_total_size),
cmd_cntrl->identifier,
cmd_cntrl->type, cmd_cntrl->priority);
if (status != ERR_NONE)
{
/* Clear the Open_Param structure. */
MemorySet((BYTE_PTR)FDI_OpenParamPtr, BYTEMAX,
(DWORD)sizeof(OPEN_PARAM));
/*
* unlock the global_sem_cntrl_mutex to give others access
* to the globals
*/
SEM_MTX_POST(SEM_OpenStream);
/* Unlock the API_sem_cntrl_mutex. */
SEM_MTX_POST(SEM_APIMutexSemaphore);
return status;
}
SEM_MTX_WAIT(SEM_TotalSize);
FDI_OpenTotalSize[MOF_index] = FDI_OpenParamPtr->b_total_size;
SEM_MTX_POST(SEM_TotalSize);
if (cmd_cntrl->sub_command == OPEN_READ)
{
/*
* the data offset into the data stream(file) being accessed to
* begin next access
*/
FDI_OpenParamPtr->b_current_file_offset = 0;
/*
* Scan the block for a matching instance referred by the first
* group table entry, and get the block address and the
* header offset of the sequence table.
*/
hw_status = FlashDevFindInstance(
&(FDI_OpenParamPtr->tabl_block_addr),
&(FDI_OpenParamPtr->b_tabl_hdr_offset),
&index, cmd_cntrl->identifier,
0, table.entry_instance, table.block_number,
HDR_VALID, cmd_cntrl->type, ATTR_SEQ_TABLE,
FIND_INSTANCE);
if (hw_status != HW_ERR_NONE)
{
/* Clear the Open_Param structure. */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?