📄 mfm80mngtdirfile.c
字号:
if ( pl_WriteCmd1->v_Size != 0 ) { sl_CmdSet.s_WriteCmdHeader.v_NbrCmds++; pl_WriteCmd1->v_TypeOfCmd = FS_SRC_INDEX_DST_INDEX; } } } /* Update all other info in write commands */ for ( vl_CmdNo = 0; vl_CmdNo < sl_CmdSet.s_WriteCmdHeader.v_NbrCmds; vl_CmdNo++) { sl_CmdSet.s_WriteCmd[vl_CmdNo].v_SizeCopied = 0; sl_CmdSet.s_WriteCmd[vl_CmdNo].v_SrceFileId = vp_DirId; } } /* Write it via lower layers */ MC_MFM_LL_WRITE_COMPLEX( &sl_WriteHeader, pp_Status ); /* If status not OK return */ if ( *pp_Status != FS_OK) return; /* Directory content have change update all contextes opened for the same directory */ mFm80_08CorrectDirCtx( FM_INSERT + FM_DELETE, vp_DirId, pp_LayerCtx, pp_DelDirFileInfo->v_PositionInFile, pp_DelDirFileInfo->v_EntryLenght, pp_InsDirFileInfo->v_PositionInFile, vl_InsEntryLenght);}#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 8void mFm80_08CorrectDirCtx( u8 vp_Oper, u16 vp_DirId, t_mFmLayerContext * pp_LayerCtx, u32 vp_DelPosition, u32 vp_DelEntryLenght, u32 vp_InsPosition, u32 vp_InsEntryLenght){ t_OpenedDirCtx * pl_DirCtx = pp_LayerCtx->p_First; while ( pl_DirCtx != NIL ) { if ( pl_DirCtx->v_DirId == vp_DirId ) { /* If the operation indicates an insert in directory */ if ( vp_Oper & FM_INSERT ) { /* Updates file size */ pl_DirCtx->v_FileSize += vp_InsEntryLenght; /* If insert is before current position update position */ if ( vp_InsPosition < pl_DirCtx->v_Position ) { pl_DirCtx->v_Position += vp_InsEntryLenght; } /* If insert is made before the delete entry the position has to be updated */ if ( vp_InsPosition < vp_DelPosition ) vp_DelPosition += vp_InsEntryLenght; /* If the insert is the position is after the current clear end of file indicator */ if ( pl_DirCtx->v_Position < pl_DirCtx->v_FileSize ) pl_DirCtx->v_EndOfFile = FALSE; } /* If the operation indicates a delete from directory */ if ( vp_Oper & FM_DELETE ) { /* Updates file size */ pl_DirCtx->v_FileSize -= vp_DelEntryLenght; /* If the insert is the position is after the current clear end of file indicator */ if ( vp_DelPosition < pl_DirCtx->v_Position) pl_DirCtx->v_Position -= vp_DelEntryLenght; /* If current position is at end of file set flag */ if ( pl_DirCtx->v_Position >= pl_DirCtx->v_FileSize) pl_DirCtx->v_EndOfFile = TRUE; } } /* Point on next context in list */ pl_DirCtx = pl_DirCtx->p_Next; } }#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 9void mFm80_09InsertCtx( t_mFmLayerContext * pp_LayerContext, t_OpenedDirCtx * pp_DirCtx ){ /* If list not empty update previous pointer of object in top of queue */ /* If list is not empty previous pointer of element in top of queue is to pdate */ if ( pp_LayerContext->p_First != NIL ) pp_LayerContext->p_First->p_Prec = pp_DirCtx; /* Next pointers is set to pointer on linked list value */ pp_DirCtx->p_Next = pp_LayerContext->p_First; /* Like the insert is in top of list previous pointer is set to NIL */ pp_DirCtx->p_Prec = NIL; /* pointer in volume structure point on the file structure */ pp_LayerContext->p_First = pp_DirCtx;}#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 10void mFm80_10ExtractCtx( t_mFmLayerContext * pp_LayerContext, t_OpenedDirCtx * pp_DirCtx ){ /* If object to delete in top of list updates list pointer else next pointer of previous object */ if ( pp_DirCtx-> p_Prec == NIL ) pp_LayerContext->p_First = pp_DirCtx-> p_Next; else pp_DirCtx-> p_Prec->p_Next = pp_DirCtx-> p_Next; /* If object to delete not last of the queue updates previous pointer of next object */ if ( pp_DirCtx-> p_Next != NIL ) pp_DirCtx->p_Next->p_Prec = pp_DirCtx->p_Prec;}/* + LMSqa27027 removed */#if 0/* LMSqa01565 - 19/01/04 - tcmc_wbm *//*S(*************************************************************************** * Semantic name : mFm80_11ValidateDirectoryContent * Object : Ignore the directory content if found corrupted. * * Transition : *----------------------------------------------------------------------------* * Used variables : * ------------------- * None * * Used procedures : * ------------------- * None * *----------------------------------------------------------------------------* *----------------------------------------------------------------------------* * DESCRIPTION * Read the content of the directory, search for pairs (id, name). * If there is an entry which does not match, the content there after * (including the not matching entry) is ignored. A new entry is created with * only valid entries. Note that, in this case the address of the directory is * changed. *----------------------------------------------------------------------------* ***************************************************************************)S*/#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 11void mFm80_11ValidateDirectoryContent(u16 vl_DirID, u16 vl_DirSize, void *pp_LayerContext){ t_WriteHeader sl_WriteHeader; u16 vl_ActualSize = vl_DirSize; u16 vl_LeftSize = vl_ActualSize; u16 vl_NewSize = 0; s32 pl_Status; ascii *pl_Buff; pl_Status = FS_OK; if (vl_ActualSize) /* process only if not empty */ { pl_Buff = (ascii*) MC_MFM_GET_MEMORY(vl_ActualSize + 1); /* Read data of file in buffer */ MC_MFM_LL_READ( vl_DirID, pl_Buff, 0, vl_DirSize, (s32 *) &pl_Status ); if ( pl_Status != FS_OK) { MC_MFM_FREE_MEMORY(pl_Buff); return; } } else { return; } while(vl_LeftSize) { u16 vl_NameLength; bool vl_Invalid; vl_NameLength = 0; vl_Invalid = FALSE; if (vl_LeftSize > 2) /* entry must have id, name */ vl_LeftSize -= 2; /* skip file id */ else { vl_Invalid = TRUE; break; } while( *(pl_Buff + vl_ActualSize - vl_LeftSize) != NULL) { vl_NameLength++; if ((vl_LeftSize-1) == 0) /* if end of file reached and no NULL found */ { vl_Invalid = TRUE; break; } else vl_LeftSize--; } if (!vl_NameLength || vl_Invalid == TRUE) /* empty file name or .. */ { break; } vl_LeftSize--; /* skip NULL byte */ /* update the size of the valid content */ vl_NewSize = vl_ActualSize - vl_LeftSize; } /* if content is valid, return */ if (vl_NewSize == vl_ActualSize) { MC_MFM_FREE_MEMORY(pl_Buff); return; } /* retain only vl_NewSize of data in this directory, delete the rest. * this is nothing but the truncate of its content */ /* Initialize write header */ sl_WriteHeader.v_FinalFileSize = vl_NewSize; sl_WriteHeader.v_DestFileId = vl_DirID; sl_WriteHeader.p_NextWriteCmdHeader = NIL; /* Write it via lower layers */ MC_MFM_LL_WRITE_COMPLEX( &sl_WriteHeader, (s32 *) &pl_Status ); /* If status not OK return */ if (pl_Status != FS_OK) { MC_MFM_FREE_MEMORY(pl_Buff); return; } /* Directory content has changed, update all contextes opened for the same directory */ mFm80_08CorrectDirCtx( FM_DELETE, vl_DirID, (void *)pp_LayerContext, 0, vl_NewSize, 0, 0 ); } /* mFm80_11ValidateDirectoryContent *//* End LMSqa01565 */#endif/* - LMSqa27027 removed *//* + LMSqa19443 PATCH JMS 04082004 */#undef PROCEDURE_NUMBER#define PROCEDURE_NUMBER 12void mFm80_12SearchObjNameByIdInDir(u16 vp_FileId, ascii* pp_ObjName){u32 vl_DirectoryId;u32 vl_FileAddress;u16* pl_PushPopStack;u16 vl_ActualSize;u16 vl_Id=0, vl_Decoded, vl_Temp;u16 vl_Offset;u16 i;u16 vl_Adjust;u8 vl_StackIndex ; vl_StackIndex = 0; pl_PushPopStack = (u16 *)MC_RTK_GET_MEMORY(sizeof(u16)*MAX_FILE_NUMBER); pl_PushPopStack[vl_StackIndex++] = 0; /* treat file-0 */ while(1) { /* return if there are no directories left attempted */ /* or if the file ID has been found */ if (vl_StackIndex == 0) { MC_RTK_FREE_MEMORY(pl_PushPopStack); return; } else { u16 vl_LeftSize; /* get the id of the first directory to process, file-0 is first one */ vl_DirectoryId = pl_PushPopStack[--vl_StackIndex]; vl_FileAddress = a_FileAllocationTable[vl_DirectoryId]; vl_ActualSize = MC_FVM_GET_FILE_SIZE(vl_FileAddress); /* process directory only if not empty */ if (vl_ActualSize) { vl_LeftSize = vl_ActualSize; while(vl_LeftSize) { vl_Offset = (u16) (vl_ActualSize - vl_LeftSize); /* get the actual id of the file (decode & unmask) */ if(vl_Offset%2) { vl_Adjust = *((u8*)(MC_FMM_EVEN_ROUND_UP(vl_FileAddress) + FILE_HEADER_SIZE + vl_Offset)); vl_Adjust <<= 8; vl_Adjust += *((u8*)(MC_FMM_EVEN_ROUND_UP(vl_FileAddress) + FILE_HEADER_SIZE + vl_Offset +1)); vl_Id = vl_Adjust; } else { vl_Id = *((u16*)(MC_FMM_EVEN_ROUND_UP(vl_FileAddress) + FILE_HEADER_SIZE + vl_Offset)); /* tcmc_brc: take care of endianess while reading u8 to form u16: PR: LMSdv96955 * The content of a directory is stored as string (eg. memcpy) and FileId is part of * this string. So, when file Id is read from this string, it is assumed to be written * in big endian style. This will fail when little endian is chosen. * Hence, if system is little endian swap the byte order to treat the value. * The problem is due to FSS writing & reading of this in bytes which is used in many * places. */#ifndef __BIG_ENDIAN vl_Temp = vl_Id << 8; vl_Id >>= 8; vl_Id += vl_Temp;#endif /* __BIG_ENDIAN */ } vl_Decoded = vl_Id; vl_Decoded = mFm80_02Decode(vl_Id); vl_Id = (vl_Decoded & 0x7FFF); /* mask directory/file indicator */ /* move to next entry */ vl_LeftSize -= 2; /* size of id */ vl_Offset += 2; if (vl_Decoded & 0x8000) { /* the object is a directory */ /* store the id as the object is a directory */ if (vl_StackIndex < MAX_FILE_NUMBER) pl_PushPopStack[vl_StackIndex++] = vl_Id; } /* skip object name if not the ID file searched */ /* Otherwise save the object name in the buffer pp_ObjName */ i=0; while(*((u8 *)(vl_FileAddress+FILE_HEADER_SIZE+vl_Offset+i)) != 0x00) { if(vl_Id==vp_FileId) pp_ObjName[i] = *((u8 *)(vl_FileAddress+FILE_HEADER_SIZE+vl_Offset+i)); i++; } if (vl_Id == vp_FileId) { MC_RTK_FREE_MEMORY(pl_PushPopStack); return; } vl_LeftSize -= (i+1); /* +1 for last byte */ } } } }}/* - LMSqa19443 PATCH JMS 04082004 */#endif /* FSS_FTR */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -