📄 fs86iobuff.c
字号:
if (pl_IOBuffer->v_BuffSize - vl_IndexInBuffer <= vp_Size) { register s32 vl_IxMin, vl_IxMax; /* Transfert data in buffer */ memcpy( &pl_IOBuffer->p_BuffPtr[vl_IndexInBuffer], pp_Buff, vp_Size ); /* Calculate min and max positions in buffer for current write */ vl_IxMin = pl_IOBuffer->v_IndexInFile - pp_FileStream->v_FilePosition; vl_IxMax = vl_IxMin + vp_Size; /* Update min and max modified addresses and arm autoflush timer */ if ( pl_IOBuffer->v_MinModifiedIndex != -1 ) { /* If new min is less than old, note the new */ if ( vl_IxMin < pl_IOBuffer->v_MinModifiedIndex ) pl_IOBuffer->v_MinModifiedIndex = vl_IxMin; /* If new max is greather than old, note the new */ if (vl_IxMax > pl_IOBuffer->v_MaxModifiedIndex ) pl_IOBuffer->v_MaxModifiedIndex = vl_IxMax; /* Rettrigerate timer */ Fs86_14BFRettrigTimer( pp_FileStream ); /* Insert stream in autoflush timer list */ Fs86_12BFInsertTimerList(pp_FileStream); } else { pl_IOBuffer->v_MinModifiedIndex = vl_IxMin; pl_IOBuffer->v_MaxModifiedIndex = vl_IxMax; /* Insert stream in autoflush timer list */ Fs86_12BFInsertTimerList(pp_FileStream); } } else /* The write goes out of buffer */ { /* Write all modified datas to recording device ( this writen + make flush ) */ /*---------------------------------------------------------------------------*/ /* Is information to flush */ if ( pl_IOBuffer->v_MinModifiedIndex != -1 ) { /* No flush to make, write all data to write to recording device */ /* Hier full the structure of complex commands ??????????? @SRC = pp_Buff IX_DST = pp_FileStream->v_FilePosition SIZE = vl_Size MC_FS_LL_WRITE_COMPLEX( &sl_WriteHeader, pl_Status ); */ } else { /* See part of flushing data to write */ /*------------------------------------*/ /* Note that if a buffer overflow accur the writes go out of buffer so farer than the MaxModified flush index so eventually only the first part of the flush intervalle is to write */ s32 vl_FlushSizeToWrite = pp_FileStream->v_FilePosition - pl_IOBuffer->v_IndexInFile - pl_IOBuffer->v_MinModifiedIndex; if ( vl_FlushSizeToWrite >= 0 ) { /* Hier full the structure of complex command to write flushed data */ /* @SRC = &pl_IOBuffer->p_BuffPtr[pl_IOBuffer->v_MinModifiedIndex] IX_DST = pp_FileStream->v_FilePosition - vl_FlushSizeToWrite; SIZE = vl_FlushSizeToWrite */ } /* Hier full the structure of complex command to write writed data */ /* @SRC = pp_Buff IX_DST = pp_FileStream->v_FilePosition SIZE = vl_Size */ /* Call complex write */ /* MC_FS_LL_WRITE_COMPLEX( &sl_WriteHeader, pp_Status ); */ /* Note that buffer was flushed and extract it from timer list */ pl_IOBuffer->v_MinModifiedIndex = -1; Fs84_13BFExtractTimerList(pp_FileStream); /* Updates the IO buffer on new file position ( makes also flush if needed ) */ Fs86_05BFUpdateIOBuffFromFile( pp_FileStream, pp_FileStream->v_FilePosition + vp_Size); } } } return ( vl_SizeWriten );}#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 8void Fs86_08BFReadData ( t_fsFILE * pp_FileStream, char * pp_Buff, s32 vp_Size, s32 * pp_Status){ register t_IOBuffer * pl_IOBuffer = (t_IOBuffer *) pp_FileStream->p_IoBuff; register s32 vl_NewFilePosition = pp_FileStream->v_FilePosition + vp_Size; /* Is an IO buffer associated to the stream ? */ if ( pl_IOBuffer == 0 ) { /* No so it is only possible to call the lower layers to make the read */ MC_FS_LL_READ ( pp_FileStream->v_FileID, pp_Buff, pp_FileStream->v_FilePosition , vp_Size, pp_Status); } else /* A buffer is available */ { /* Goes the read out of buffer */ if ( pp_FileStream->v_FilePosition + vp_Size > pl_IOBuffer->v_IndexInFile + pl_IOBuffer->v_BuffSize ) { /* Information can be totalely read from IO buffer */ memcpy( &pl_IOBuffer->p_BuffPtr[pp_FileStream->v_FilePosition - pl_IOBuffer->v_IndexInFile], pp_Buff, vp_Size); } else /* Go out of IO buffer -> IO buffer must change position */ { /* Updates destination buffer from information taken direct in recording device */ MC_FS_LL_READ ( pp_FileStream->v_FileID, pp_Buff, pp_FileStream->v_FilePosition, vp_Size, pp_Status); /* Updates the IO buffer on new file position ( makes also flush if needed ) */ Fs86_05BFUpdateIOBuffFromFile( pp_FileStream, pp_FileStream->v_FilePosition + vp_Size); } } /* Updates new file position */ pp_FileStream->v_FilePosition = vl_NewFilePosition;}#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 9void Fs86_09BFFlush( t_fsFILE * pp_FileStream, s32 *pp_Status ){ register t_IOBuffer * pl_IOBuffer = (t_IOBuffer *) pp_FileStream->p_IoBuff; /* Is an IO buffer associated to the stream ? */ if ( pl_IOBuffer == NIL ) return ; /* Would a write made to the buffer if no return */ if ( pl_IOBuffer->v_MinModifiedIndex == -1 ) return; if ( pl_IOBuffer->v_MinModifiedIndex != -1 ) { /* register s32 vl_MinPos, vl_MaxPos, vl_Size; */ /* vl_Size = pl_IOBuffer->v_MaxModifiedIndex - pl_IOBuffer->v_MinModifiedIndex + 1; vl_DstIndex = pp_FileStream->v_FilePosition + pl_IOBuffer->v_MinModifiedIndex; v_SrcAddr = &pl_IOBuffer->p_BuffPtr[pl_IOBuffer->v_MinModifiedIndex]; */ /* Full the structure of complex commands, hier an once cmd */ /* ??????????????????????????? */ /* Makes write in record */ /* MC_FS_LL_WRITE_COMPLEX ( &sl_WriteHeader, pp_Status ); */ /* Extract stream of autoflush timer list */ Fs84_13BFExtractTimerList(pp_FileStream); }}#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 10void Fs86_10BFResizeFile( u32 vp_ObjId, s32 vp_NewSize, s32 *pp_Status ){ t_WriteHeader sl_WriteHeader; /* Initialize write header with file ID and a size equal to new file size */ sl_WriteHeader.v_FinalFileSize = vp_NewSize; sl_WriteHeader.v_DestFileId = vp_ObjId; sl_WriteHeader.p_NextWriteCmdHeader = (t_WriteCmdHeader*)NIL; /* Makes write in device */ MC_FS_LL_WRITE_COMPLEX( &sl_WriteHeader, pp_Status );}/************************************************//* *//* Autoflush timer management *//* *//************************************************//* Called to decrement autoflush timers */#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 11void Fs86_11BFTimeOut( void ){ t_IOBuffer * pl_TimPtr = pp_FirstFlushTimer; s32 vl_Status = FS_OK; /* Timer list empty nothing to do return */ if ( pl_TimPtr == NIL ) return; /* Decrement first timer if not null return */ if ( --pl_TimPtr->v_TimerValue == 0 ) return; /* Extract all expired timers from list and flush associated streams */ while ( pl_TimPtr->v_TimerValue == 0 ) { /* flush stream associated */ Fs86_09BFFlush(pl_TimPtr->p_Stream, &vl_Status); /* Clear stream pointer to indicates that timer is out of active timer list */ pl_TimPtr->p_Stream = NIL; /* Point on next timer */ pl_TimPtr = pl_TimPtr->p_NextPtr; /* if list is empty after extract, clear first timer pointer and return */ if ( pl_TimPtr == NIL ) { /* Clear first timer pointer */ pp_FirstFlushTimer = NIL; return ; } } /* This timer do not expire update its precedent pointer */ pl_TimPtr->p_NextPtr = NIL; /* And update first timer pointer */ pp_FirstFlushTimer = pl_TimPtr; }/* Called at write in IO buffer to arm an autoflush timer */#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 12void Fs86_12BFInsertTimerList(t_fsFILE * pp_FileStream){ register t_IOBuffer * pl_IOBuffer = (t_IOBuffer * )pp_FileStream->p_IoBuff; register u16 vl_TimeOut; /* Place file pointer in timer list */ pl_IOBuffer->p_Stream = pp_FileStream; /* Load time out */ vl_TimeOut = ((t_VolIOBuffMngt *) (pp_FileStream->p_VolOfFile->p_IOBuffMngt))->v_AutoFlushTimeOut; /* Search place to insert timer */ /*------------------------------*/ if ( pp_FirstFlushTimer == NIL ) { /* Timer list is empty */ pp_FirstFlushTimer = pl_IOBuffer; pl_IOBuffer->v_TimerValue = vl_TimeOut; pl_IOBuffer->p_PrecPtr = NIL; pl_IOBuffer->p_NextPtr = NIL; } else /* Timer list not empty */ { u16 vl_TimeCumul = 0; t_IOBuffer * pl_TimPtr = pp_FirstFlushTimer; /* If pointed timer expiration time greater or equal to timer to insert so insert timer in front of this pointed */ for (;;) { /* If next timer value is grether than or equal to timer to insert */ if ( pl_TimPtr->v_TimerValue + vl_TimeCumul >= vl_TimeOut) { /* Is the timer the first of list */ if (pl_TimPtr-> p_PrecPtr == NIL ) { pp_FirstFlushTimer = pl_IOBuffer; pl_IOBuffer->p_PrecPtr = NIL; } else /* Timer is inserted in middle of list */ { pl_TimPtr->p_PrecPtr->p_NextPtr = pl_IOBuffer; pl_IOBuffer->p_PrecPtr = pl_TimPtr->p_PrecPtr; } pl_IOBuffer->p_NextPtr = pl_TimPtr; pl_TimPtr->p_PrecPtr = pl_IOBuffer; pl_IOBuffer->v_TimerValue = vl_TimeOut - vl_TimeCumul; return; } /* Updates cumulate time */ vl_TimeCumul += pl_TimPtr->v_TimerValue; /* End of list reached, insert the timer at end of list */ if ( pl_TimPtr->p_NextPtr == NIL ) { pl_TimPtr->p_NextPtr = pl_IOBuffer; pl_IOBuffer->p_PrecPtr = pl_TimPtr; pl_IOBuffer->p_NextPtr = NIL; pl_IOBuffer->v_TimerValue = vl_TimeOut - vl_TimeCumul; return; } /* Point on next timer */ pl_TimPtr = pl_TimPtr->p_NextPtr; } }}/* Called at flush to extract timer from list ( timer may not exist ) */#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 13void Fs84_13BFExtractTimerList(t_fsFILE * pp_FileStream){ register t_IOBuffer * pl_IOBuffer = ( t_IOBuffer * ) pp_FileStream->p_IoBuff; /* Is timer is not in a timer list return */ if ( pl_IOBuffer->p_Stream == NIL ) return; /* If next timer exist updates its precedent pointer */ if ( pl_IOBuffer-> p_NextPtr != NIL) pl_IOBuffer-> p_NextPtr->p_PrecPtr = pl_IOBuffer->p_PrecPtr; /* If precedent timer exist updates its next pointer else the first timer pointer */ if ( pl_IOBuffer-> p_PrecPtr != 0) pl_IOBuffer-> p_PrecPtr->p_NextPtr = pl_IOBuffer->p_NextPtr; else pp_FirstFlushTimer = pl_IOBuffer->p_NextPtr; /* Clear stream pointer to indicates that timer is out of active timer list */ pl_IOBuffer->p_Stream = NIL;}#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 14void Fs86_14BFRettrigTimer(t_fsFILE * pp_FileStream){ t_VolIOBuffMngt * pl_VolIOBuffMngt = (t_VolIOBuffMngt *) pp_FileStream->p_VolOfFile->p_IOBuffMngt; register t_IOBuffer * pl_IOBuffer = ( t_IOBuffer *) pp_FileStream->p_IoBuff; u32 vl_TimeOut; vl_TimeOut = pl_VolIOBuffMngt->v_AutoFlushTimeOut; /* Is volume of file configured to rettrigerate timers and timer in a timer list */ if ( ( pl_VolIOBuffMngt->u_VolMngtFlags.v_TimerRettriggerable ) && ( pl_IOBuffer->p_Stream != NIL ) ) { }}#endif /* FSS_FTR */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -