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

📄 mfm80mngtdirfile.c

📁 我今天开始上传5份TI、NXP、MTK的手机开发全套资料。希望对大家有很大的帮助
💻 C
📖 第 1 页 / 共 3 页
字号:
#ifdef FSS_FTR#define ACCESS_RIGHTS_INTERNAL_MFM#define MFM80MNGTDIRFILE_C#include "mFm.h"#undef  FILE_NUMBER#define FILE_NUMBER 80 /* Local parameters *//*------------------*//* Position of the type of an object ( file or directory ) indicator	in a directory file */#define FM_POS_OBJ_TYPE_DIR	15/* Mask used extract type of object from an object ID in a directory file */#define FM_MASK_OBJ_TYPE_DIR	(1<<FM_POS_OBJ_TYPE_DIR)/* Size of object ID */#define FM_SIZE_OF_OBJ_ID	2#define FM_SIZE_OF_OBJ_HEADER	2/* Local prototypes *//*------------------*/void mFm80_08CorrectDirCtx( u8 vp_Oper, u16 vp_DirId, t_mFmLayerContext * pp_LayerCtx, 					u32 vp_DelPosition, u32 vp_DelEntryLenght,					u32 vp_InsPosition, u32 vp_InsEntryLenght);/* + LMSqa27027 removed */#if 0/* LMSqa01565 - 19/01/04 - tcmc_wbm */void mFm80_11ValidateDirectoryContent(u16 vl_DirID, u16 vl_DirSize, void *pp_LayerContext);/* End LMSqa01565 */#endif/* - LMSqa27027 removed *//* Value to encode must be [0..0xFdff] */#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 1u16 mFm80_01Encode( u16 vp_ToEncode ){   register u16 vl_Shifted = vp_ToEncode >> 8;   register u16 vl_Encoded = vp_ToEncode;    if ( vp_ToEncode == 0 ) vl_Encoded = 0xffff;    /* If MSB of value is null [ 0x0001..0x00ff] 	it is shifted in the interval [ 0xfe01.. 0xfeff] */    else if ( vl_Shifted == 0 ) vl_Encoded = 0xfe00 + vp_ToEncode;    /* If LSB of ID is null 0xzz00 it is shifted in the intervalle [0xff01 .. 0xfffe] */    else     {	if ( (vp_ToEncode & 0xff) == 0) vl_Encoded = 0xff00 + vl_Shifted;    }    /* Return encoded ID */    return ( vl_Encoded);}#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 2u16 mFm80_02Decode( u16 vp_IdToDecode){   register u16 vl_Decoded = vp_IdToDecode;    if ( vp_IdToDecode == 0xffff) vl_Decoded = 0;    /* If value to decode is in the intervalle [0xff01..0xffff] 	it is shifted to 0xzz00 */    else if ( vp_IdToDecode >= 0xff01 ) vl_Decoded = (vp_IdToDecode & 0xff ) << 8;    /* If value to decode is in the intervalle [0xfe01..0xfeff] 	it is shifted in the intervalle [0x0001..0x00ff] */    else if ( vp_IdToDecode >= 0xfe01 ) vl_Decoded = vp_IdToDecode &  0xff;    /* Return decoded value */     return(vl_Decoded);   }/**//*P(***************************************************************************//* Procedure name : mFm80_03SearchObjByNameInDir	     	  	      *//* Object :    Search in a dir if an object with the name exist		      *//*----------------------------------------------------------------------------*//* Input parameters  :                                                        *//* -------------------                                                        *//*	u16 vp_VolMngtID: u16 vp_VolMngtID 	    			      *//*									      *//* Output parameters :                                                        *//* -------------------                                                        *//*		none							      *//*									      *//* Used variables    :                                                        *//* -------------------                                                        *//*   							                      *//*                                                                            *//* Used procedures   :                                                        *//* -------------------                                                        *//*                                                                            *//*                                                                            *//*----------------------------------------------------------------------------*//*----------------------------------------------------------------------------*//*                                    DESCRIPTION                             *//*                                                                            *//*		Initializes the low layer module		 	      *//*									      *//*----------------------------------------------------------------------------*//***************************************************************************)P*//* #*//* Lenght of an entry in a directory file ( name + type + ID ) */#define FM_ONE_ENTRY_LENGHT FS_NAME_MAX+5/* Lenght of a buffer used to read data from a directory file to make comparisons */#define FM_BUFF_LENGHT (2 * FM_ONE_ENTRY_LENGHT )#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 3/* + LMSqa27027 removed */#if 0/* LMSqa01565 - 19/01/04 - tcmc_wbm */#endif/* - LMSqa27027 removed */void mFm80_03SearchObjByNameInDir( u16 vp_DirID, ascii * pp_ObjName, u8 vp_NameLenght,/* + LMSqa27027 removed */#if 0					t_DirFileInfo * sp_DirFileInfo, s32 * pp_Status, void *pp_LayerContext  )/* End LMSqa01565 */#endif/* - LMSqa27027 removed *//* + LMSqa27027 new */					t_DirFileInfo * sp_DirFileInfo, s32 * pp_Status )/* - LMSqa27027 new */{    s32 vl_PosMin = 0, vl_PosMax, vl_CurrentPosition;    s32 vl_StrCmp;    s32 vl_SizeToRead, vl_BeginPosOfRead;    u16 vl_IDType;    ascii vl_Buff[FM_BUFF_LENGHT];	/* Reserve buffer to load info */    s32 vl_Index;    /* Updates input parameters as if object not found */    sp_DirFileInfo->v_TypeOfObj = FS_NO_OBJECT;    sp_DirFileInfo->v_Exist = FALSE;    sp_DirFileInfo->v_IdOfObj = 0;    /* Get to lower layer to have size of directory file */    MC_MFM_LL_GET_FILE_SIZE( vp_DirID, &sp_DirFileInfo->v_FileSize, pp_Status);    /* If status not OK return */    if ( *pp_Status != FS_OK) return;	 /* + LMSqa27027 removed */#if 0/* LMSqa01565 - 19/01/04 - tcmc_wbm */    /* validate the content of the directory */    mFm80_11ValidateDirectoryContent(vp_DirID, sp_DirFileInfo->v_FileSize, pp_LayerContext);/* End LMSqa01565 */#endif/* - LMSqa27027 removed */    /* If file size not null search */    if ( sp_DirFileInfo->v_FileSize  != 0 )     {    	/* Update max search position */     	vl_PosMax = sp_DirFileInfo->v_FileSize - 1;    	do {	    /* Determine current search position */	    vl_CurrentPosition = (vl_PosMin + vl_PosMax) >>1;		    /* Determine beginning index of read */	    if ( vl_CurrentPosition - FM_ONE_ENTRY_LENGHT > vl_PosMin ) 				vl_BeginPosOfRead = vl_CurrentPosition - FM_ONE_ENTRY_LENGHT;	    else vl_BeginPosOfRead = vl_PosMin;	    /* Determine size to read */            if ( vl_BeginPosOfRead + FM_BUFF_LENGHT > vl_PosMax ) 			vl_SizeToRead = vl_PosMax - vl_BeginPosOfRead + 1; 	    else vl_SizeToRead = FM_BUFF_LENGHT;	    /* Read data of file in buffer */            MC_MFM_LL_READ( vp_DirID, &vl_Buff[0], vl_BeginPosOfRead, vl_SizeToRead, pp_Status );    	    /* If status not OK return */    	    if ( *pp_Status != FS_OK) return;	    /* From index search back an '\0' character or beginning of file */	    vl_Index = vl_CurrentPosition - vl_BeginPosOfRead;	    do	    {	    	if ( vl_Buff[vl_Index] == '\0') break;	    } while ( -- vl_Index > 0 );	    /* If beginning of file skip object ID  else an \0 was found skip \0 and object ID */   	    if ( vl_Index == 0 )  vl_Index = vl_Index + FM_SIZE_OF_OBJ_ID;	    else 		  vl_Index = vl_Index + FM_SIZE_OF_OBJ_ID + 1;		    /* Compare strings */	    vl_StrCmp = strncmp( pp_ObjName, &vl_Buff[vl_Index], vp_NameLenght);	    /* If strings equal we have found */	    if ( vl_StrCmp == 0 )	    {		/* First part of string are equal, is string in dir file not longer than 			searched string */		if ( vl_Buff[vl_Index+vp_NameLenght] == '\0' )		{		    /* Load ID and type of object which is placed in front of the name */		    vl_IDType =  ((u8)(vl_Buff[vl_Index - FM_SIZE_OF_OBJ_ID]) << 8 )					+				 (u8)(vl_Buff[vl_Index - FM_SIZE_OF_OBJ_ID + 1]);		    /* Decode this ID ( Made to avoid a byte equal to zero which can create				a mismatch with '\0' end of string character */		    vl_IDType = mFm80_02Decode(vl_IDType);		    /* Type of object is in the most significant bit of the ID type */		    sp_DirFileInfo->v_TypeOfObj = FS_OBJECT_FILE;  		    if ( vl_IDType & FM_MASK_OBJ_TYPE_DIR ) sp_DirFileInfo->v_TypeOfObj = FS_OBJECT_DIR;		    /* Updates ID of object */    	    	    sp_DirFileInfo->v_IdOfObj = vl_IDType & ~FM_MASK_OBJ_TYPE_DIR;		    /* Update entry lenght */                    sp_DirFileInfo->v_EntryLenght = FM_SIZE_OF_OBJ_ID + strlen(&vl_Buff[vl_Index]) + 1;		    /* Update object existence */	  	    sp_DirFileInfo->v_Exist = TRUE;		    /* Update position in file */	 	    sp_DirFileInfo->v_PositionInFile = vl_BeginPosOfRead + vl_Index 								- FM_SIZE_OF_OBJ_ID;		    return;		}		else  		{		    /* String in file is not finished, so searched string is less than 				string in file */		    vl_PosMax = vl_BeginPosOfRead + vl_Index - FM_SIZE_OF_OBJ_ID;		}	    }	    /* If string pointed less than string searched update min after current object in file */	    else if ( vl_StrCmp < 0 ) 		vl_PosMax = vl_BeginPosOfRead + vl_Index - FM_SIZE_OF_OBJ_ID;			    /* If string found greather than string found update max before current object in file */	    else vl_PosMin = vl_BeginPosOfRead + vl_Index + strlen (&vl_Buff[vl_Index]) + 1;           /* Until intervalle tend to a null lenght */           } while ( vl_PosMax > vl_PosMin );	}    /* Update output parameters */    sp_DirFileInfo->v_PositionInFile = vl_PosMin;    } #undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 4s32 mFm80_04ReadEntrysOfDirFile ( t_WhichType vp_Which, s32 vp_NbrElemToRead, t_OpenedDirCtx * pp_DirCtx,				 void * pp_DestBuff, u32 vp_SizeOfDestBuff, 				 char * pp_ReadBuff, u32 vp_SizeOfReadBuff, s32 * pp_Status ){    ascii 	vl_Buff[FM_BUFF_LENGHT];	/* Reserve buffer to load info */    u32 		vl_SizeToRead;    ascii *	pl_BeginningOfReadBuff;    ascii * 	pl_ReadBuffPtr;    ascii *	pl_DestBuffPtr = (ascii*) pp_DestBuff;    u32		vl_SizeOfReadBuff ; 		/* Size of buffer is at beginning of buffer */    s32 	vl_NbrElemRead = 0;    u8		vl_ExitReq = 0, vl_PointNextReq = 0;    /* Update size of read buffer */    if ( pp_ReadBuff != NIL )    {	/* If a Read buffer is indicated take it's address and size */	pl_BeginningOfReadBuff = pp_ReadBuff;	vl_SizeOfReadBuff = vp_SizeOfReadBuff;     }    else     {	/* If no read buffer given take the local reserved buffer's address and size */	pl_BeginningOfReadBuff = vl_Buff;	vl_SizeOfReadBuff = sizeof(vl_Buff)-1;     }    /* Is it the first of the list or the next */    if ( vp_Which.v_Position == FS_FIRST_DIR )    {	/* Set position to beginning of file */	pp_DirCtx->v_Position = 0;	/* If file not empty clear end-of-file flag else return 0  */	if ( pp_DirCtx->v_FileSize != 0 ) pp_DirCtx->v_EndOfFile = FALSE;	else return (0);    }    else /* FM_NEXT_DIR */    {    	/* If end of file reached return 0 elements found */    	if (pp_DirCtx->v_EndOfFile ) return (0);    }    /* Loop until destination buffer full or number max of elements araised or end-of-file reached */    do    {	/* Point at beginning of read buffer */    	pl_ReadBuffPtr = pl_BeginningOfReadBuff;    	/* Fill buffer or read until end-of-file */    	if ( pp_DirCtx->v_Position + vl_SizeOfReadBuff > pp_DirCtx->v_FileSize)			vl_SizeToRead = pp_DirCtx->v_FileSize - pp_DirCtx->v_Position;    	else  vl_SizeToRead = vl_SizeOfReadBuff;    	/* Read this data from file */    	MC_MFM_LL_READ( pp_DirCtx->v_DirId, pl_ReadBuffPtr, pp_DirCtx->v_Position, vl_SizeToRead,								 pp_Status );    	/* If status not OK return 0 elements read */    	if ( *pp_Status != FS_OK) return(0);	do 	{	  s32 vl_NameLength;	  u16 vl_IDType; 	  u8  vl_TypeOfObj;	    /* Too near of end of read buffer the exit to reload it */	    if ( pl_ReadBuffPtr + FM_ONE_ENTRY_LENGHT >= pl_BeginningOfReadBuff + vl_SizeOfReadBuff )				break;	    /* Calculate length of name */	    vl_NameLength = strlen (&pl_ReadBuffPtr[FM_SIZE_OF_OBJ_ID]);	    /* If end of string found at end of buffer than buffer has to be reloaded			exit this loop to reload read buffer */	    /* if ( pl_ReadBuffPtr + vl_NameLength + FM_SIZE_OF_OBJ_ID 					>=			 pl_BeginningOfReadBuff + vl_SizeToRead )  break;  */	    /* Load ID and type of object which is placed in front of the name */	    vl_IDType =  ((u8)(pl_ReadBuffPtr[0]) << 8 ) + (u8)(pl_ReadBuffPtr[1]);	    /* Decode this ID ( Made to avoid a byte equal to zero which can create				a mismatch with '\0' end of string character */	    vl_IDType = mFm80_02Decode(vl_IDType);	    /* Type of object is in the most significant bit of the ID type */	    vl_TypeOfObj = FS_OBJECT_FILE;  	    if ( vl_IDType & FM_MASK_OBJ_TYPE_DIR ) vl_TypeOfObj = FS_OBJECT_DIR;

⌨️ 快捷键说明

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