⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fs86iobuff.c

📁 我今天开始上传5份TI、NXP、MTK的手机开发全套资料。希望对大家有很大的帮助
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifdef FSS_FTR#define ACCESS_RIGHTS_INTERNAL_FS#define FS86IOBUFF_C#include "Fs.h"#undef  FILE_NUMBER#define FILE_NUMBER 86 /* Local variables *//*-----------------*/t_IOBuffer * pp_FirstFlushTimer;	/* List of IO buffers in timer list *//* Calculates the new position of the IO buffer in the file by taking in account		old position and buffer configuration 	it returns the new position but updates not buffer position */#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 1s32 Fs86_01BFCalcNewBuffPos( t_fsFILE * pp_FileStream, s32 vp_NewFilePosition ){   register t_IOBuffer * pl_IOBuffer = (t_IOBuffer *) pp_FileStream->p_IoBuff;    /* If buffer empty it is placed at current file position except if file size is 		less than or equal to buffer size then it is the beginning of the file */    if ( pl_IOBuffer->v_ValidSize == 0 )     {	if ( pp_FileStream->v_FileSize <= pl_IOBuffer->v_BuffSize  ) return ( 0 );        else return ( pp_FileStream->v_FilePosition);    }    else /* If file position goes back new buffer position is file position */    {	if ( vp_NewFilePosition < pl_IOBuffer->v_IndexInFile ) return (vp_NewFilePosition);	else 	{	    /* If new position is in buffer buffer position is unchanged */ 	    if (pl_IOBuffer->v_IndexInFile + pl_IOBuffer->v_BuffSize > vp_NewFilePosition )				 return (pl_IOBuffer->v_IndexInFile);	    /* Else is new position more far as the configurated displacement 		if yes new position = file position 		else new position = old position + displacement */	    if ( pl_IOBuffer->v_IndexInFile + pl_IOBuffer->s_FileIOBuffMngt.v_ForwardDisplacement				 >=    vp_NewFilePosition) 			return ( vp_NewFilePosition);	    else 		return ( pl_IOBuffer->v_IndexInFile				 + pl_IOBuffer->s_FileIOBuffMngt.v_ForwardDisplacement); 	}    }}/* Allocates of configurated an IO buffer to a file   ( is only called by file open ) */#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 2s32 Fs86_02BFAllocateInternalBuff( t_fsFILE * pp_FileStream, s32 vp_NewFilePosition){   register t_IOBuffer * pl_IOBuffer = ( t_IOBuffer *) pp_FileStream->p_IoBuff;   s32 			vl_BuffSize;   s32			vl_Status = FS_OK;   /* Point on IO buffer management in volume configuration */   t_VolIOBuffMngt * pl_VolIOBuffMngt = (t_VolIOBuffMngt *) pp_FileStream->p_VolOfFile->p_IOBuffMngt;    /* Is a buffer management possible ( not possiblr for serial lines .....) */    if ( pl_VolIOBuffMngt->u_VolMngtFlags.v_BufferEnabled == FALSE )    {	/* Update pointer on IO buffer management structure to NIL */    	pp_FileStream->p_IoBuff = NIL;    	return ( 1 );    }        /* Take default volume buffer size */    vl_BuffSize = pl_VolIOBuffMngt->v_AutoallocBuffSize;    /* If null no buffer allocation */    if ( vl_BuffSize == 0 ) return ( 1 ) ;    /* If no buffer structure reserved do it */     pp_FileStream->p_IoBuff = MC_FS_GET_MEMORY(sizeof(t_IOBuffer));     pl_IOBuffer = (t_IOBuffer*) pp_FileStream->p_IoBuff;	    /* Update buffer size */    pl_IOBuffer->v_BuffSize = vl_BuffSize;    /* Clear stream pointer to indicates that timer is out of active timer list */    pl_IOBuffer->p_Stream = 0;    /* Allocated IO buffer */    pl_IOBuffer->p_BuffPtr = (ascii*) MC_FS_GET_MEMORY ( vl_BuffSize );     /* Note that buffer allocation is internal */    pl_IOBuffer->v_BuffIntAlloc = 1;    /* The buffer configuration is function of buffer size it must be update from				lower layers */    MC_FS_LL_UPDATE_IOBUFF_CONF( vl_BuffSize, &((( t_IOBuffer*) (pl_IOBuffer))->s_FileIOBuffMngt), 							&vl_Status );    /* Buffers must be set to null */    pl_IOBuffer->v_ValidSize = 0;    /* Update buffer from file */    Fs86_05BFUpdateIOBuffFromFile( pp_FileStream, vp_NewFilePosition);    /* Update pointer on IO buffer management structure */    pp_FileStream->p_IoBuff = NIL;    return(0);}#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 3s32 Fs86_03BFAllocateExternalBuff( t_fsFILE * pp_FileStream, ascii * pp_Buff, s32 vp_BuffMode, 							t_fs_size_t vp_Size, s32 * pp_Status ){   /* Point on IO buffer management in volume configuration */   t_VolIOBuffMngt * pl_VolIOBuffMngt = (t_VolIOBuffMngt *) pp_FileStream->p_VolOfFile->p_IOBuffMngt;   s32 vl_Status = FS_OK;    /* Is a buffer management possible ( not possible for serial lines .....) */    if ( pl_VolIOBuffMngt->u_VolMngtFlags.v_BufferEnabled == FALSE )    {	switch ( vp_BuffMode )    	{	    case FS_IOFBF: * pp_Status = FS_ENOTSUP;  return ( -1 );	    case FS_IONBF: return (0) ;	    default: * pp_Status = FS_EINVAL; return ( -1 );	}    }      /* A buffer association is possible we must see buffer mode */    switch ( vp_BuffMode )    {	case FS_IOFBF:	      {		register t_IOBuffer * pl_IOBuffer;		/* Is buffer size greather than 0 */		if ( vp_Size <= 0 )	  	{		    /* Set status to invalid argument */		    * pp_Status = FS_EINVAL;		    return (-1);		}    		/* If a buffer was already allocated free it */    		Fs86_04BFFreeBuff( pp_FileStream);		/* If no buffer structure reserved do it */		pp_FileStream->p_IoBuff = MC_FS_GET_MEMORY(sizeof(t_IOBuffer));		pl_IOBuffer = (t_IOBuffer *) pp_FileStream->p_IoBuff;		/* Update buffer size */		pl_IOBuffer->v_BuffSize = vp_Size;		/* Clear stream pointer to indicates that timer is out of active timer list */   		pl_IOBuffer->p_Stream = NIL;		/* Is the buffer allocated by FS or application */		if ( pp_Buff == NIL )		{		    /* Buffer allocated by FS */		    pl_IOBuffer->p_BuffPtr = (ascii*) MC_FS_GET_MEMORY ( vp_Size ); 		    /* Note that buffer allocation is internal */    		    pl_IOBuffer->v_BuffIntAlloc = TRUE;		}		else		{		    /* Buffer allocated by application */		    pl_IOBuffer->p_BuffPtr = pp_Buff;		    /* Note that buffer allocation is external */    		    pl_IOBuffer->v_BuffIntAlloc = FALSE;			}		/* The buffer configuration is function of buffer size it we must update from				lower layers */		MC_FS_LL_UPDATE_IOBUFF_CONF( vp_Size, &((( t_IOBuffer*) 						(pl_IOBuffer))->s_FileIOBuffMngt), &vl_Status );							/* Buffers must be set to null */		pl_IOBuffer->v_ValidSize = 0;		/* Update buffer from file */		Fs86_05BFUpdateIOBuffFromFile( pp_FileStream, pp_FileStream->v_FilePosition);		/* Update pointer on IO buffer management structure */		pp_FileStream->p_IoBuff = NIL;	      }	   break;	case FS_IONBF:     		/* If a buffer was already allocated free it */    		Fs86_04BFFreeBuff( pp_FileStream);	   break;	default:		/* Set status to invalid argument and return */		* pp_Status = FS_EINVAL;		return ( -1 );    }    return (0);}/* Frees the IO buffer of the file if allocated from FS */ #undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 4void Fs86_04BFFreeBuff( t_fsFILE * pp_FileStream){   register t_IOBuffer * pl_IOBuffer = (t_IOBuffer *) pp_FileStream->p_IoBuff;   /* Is an IO buffer allocated to stream */   if ( pl_IOBuffer == NIL ) return;   /* Would the IO buffer allocated internal if yes free it else it must be made by application */   if ( pl_IOBuffer->v_BuffIntAlloc) MC_FS_FREE_MEMORY (pl_IOBuffer->p_BuffPtr);   /* Free the IO buffer structure */   MC_FS_FREE_MEMORY ( pl_IOBuffer );   pp_FileStream->p_IoBuff = NIL; }/* If an IO buffer exist load data from the file and update the buffer */#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 5void Fs86_05BFUpdateIOBuffFromFile( t_fsFILE * pp_FileStream, s32 vp_NewFilePosition ){   register t_IOBuffer * pl_IOBuffer = (t_IOBuffer *) pp_FileStream->p_IoBuff;   s32 vl_Status = FS_OK;   /* If no IO buffer associated to the stream return */   if ( pl_IOBuffer == NIL ) return ;   /* Point file position out of buffer */   if ( ( pp_FileStream->v_FilePosition > pl_IOBuffer->v_IndexInFile + pl_IOBuffer->v_BuffSize)					||	( pp_FileStream->v_FilePosition < pl_IOBuffer->v_IndexInFile )      )   {      s32 vl_NewBuffIndexInFile;	/* Calculate new buffer position in file */	vl_NewBuffIndexInFile = Fs86_01BFCalcNewBuffPos( pp_FileStream, vp_NewFilePosition );	/* If some data of the buffer was not writen to device and is out of new buffer 		a flush must be made */	if ( pl_IOBuffer->v_MinModifiedIndex != -1 )	{	  register s32 vl_MinPos, vl_MaxPos;	   vl_MinPos = pl_IOBuffer->v_IndexInFile + pl_IOBuffer->v_MinModifiedIndex;	   vl_MaxPos = pl_IOBuffer->v_IndexInFile + pl_IOBuffer->v_MaxModifiedIndex;	   if ( ( vl_MinPos < vl_NewBuffIndexInFile ) 				||	     ( vl_MaxPos > vl_NewBuffIndexInFile + pl_IOBuffer->v_BuffSize))	   {		Fs86_09BFFlush( pp_FileStream, &vl_Status );	   }	}        /* Invalidate buffer content so it will be updated */	pl_IOBuffer->v_ValidSize = 0;    }   /* File position point in IO buffer we must verify if buffer is update */   {      s32 vl_SizeToLoad , vl_SizeInBuffer;	vl_SizeInBuffer = pp_FileStream->v_FileSize - pl_IOBuffer->v_IndexInFile;	/* Is buffer totaly full */        if ( pl_IOBuffer->v_ValidSize == vl_SizeInBuffer ) return;	/* Calculate size which can be load in buffer */	if ( vl_SizeInBuffer > pl_IOBuffer->v_BuffSize ) vl_SizeInBuffer = pl_IOBuffer->v_BuffSize;		/* if size less than or equal to valid size nothing to do */	if ( vl_SizeInBuffer <= pl_IOBuffer->v_ValidSize ) return;	/* We must load remaining size */	vl_SizeToLoad = vl_SizeInBuffer - pl_IOBuffer->v_ValidSize;	MC_FS_LL_READ( pp_FileStream->v_FileID, &pl_IOBuffer->p_BuffPtr[pl_IOBuffer->v_ValidSize],				pl_IOBuffer->v_IndexInFile + pl_IOBuffer->v_ValidSize,				vl_SizeInBuffer - pl_IOBuffer->v_ValidSize, &vl_Status);	/* Update valid size in buffer */	pl_IOBuffer->v_ValidSize = vl_SizeInBuffer;       }}#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 7#ifdef SYNCHRONOUS_FILE_SYSTEM_FTRs32  Fs86_07BFWriteData (t_fsFILE * pp_FileStream, ascii * pp_Buff, s32 vp_Size,			 s32 vp_NewFileSize, u8 vp_NoDelayFlag, s32 * pp_Status)#elses32  Fs86_07BFWriteData (t_fsFILE * pp_FileStream, ascii * pp_Buff, s32 vp_Size,			 s32 vp_NewFileSize, s32 * pp_Status)    #endif /* SYNCHRONOUS_FILE_SYSTEM_FTR */{   register t_IOBuffer * pl_IOBuffer = (t_IOBuffer *) pp_FileStream->p_IoBuff;   u32 vl_SizeWriten = vp_Size;   u16 vl_FsOffsetInFile = pp_FileStream->p_VolOfFile->v_FsOffsetInFile;   /* 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 write */      t_WriteHeader	sl_WriteHeader;      t_WriteCmdStruct1 sl_CmdSet;	/* Initialize write header */    	sl_WriteHeader.v_FinalFileSize = vp_NewFileSize + vl_FsOffsetInFile;    	sl_WriteHeader.v_DestFileId = pp_FileStream->v_FileID;	sl_WriteHeader.p_NextWriteCmdHeader = (t_WriteCmdHeader*)&sl_CmdSet;#ifdef SYNCHRONOUS_FILE_SYSTEM_FTR	sl_WriteHeader.v_NoDelayFlag = vp_NoDelayFlag;#endif    	sl_CmdSet.s_WriteCmdHeader.v_NbrCmds = 1;	sl_CmdSet.s_WriteCmdHeader.p_NextWriteCmdHeader = NIL;	sl_CmdSet.s_WriteCmdHeader.v_OffsetInFile = vl_FsOffsetInFile;    	sl_CmdSet.s_WriteCmd[0].v_TypeOfCmd = FS_SRC_ADR_DST_INDEX;    	sl_CmdSet.s_WriteCmd[0].v_SizeCopied = 0;    	sl_CmdSet.s_WriteCmd[0].v_Size = vp_Size;    	sl_CmdSet.s_WriteCmd[0].u_Srce.p_Srce = pp_Buff;    	sl_CmdSet.s_WriteCmd[0].u_Dest.v_DestIndex = pp_FileStream->v_FilePosition;     	sl_CmdSet.s_WriteCmd[0].v_SrceFileId = pp_FileStream->v_FileID;    	/* Makes write in device */	MC_FS_LL_WRITE_COMPLEX( &sl_WriteHeader, pp_Status );	if ( * pp_Status != FS_OK ) vl_SizeWriten = 0;   }   else  /* A buffer is available */   {      s32 vl_IndexInBuffer = pp_FileStream->v_FilePosition - pl_IOBuffer->v_IndexInFile;	/* If the totality of the write can be made in the IO buffer */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -