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

📄 fs20fopen.c

📁 我今天开始上传5份TI、NXP、MTK的手机开发全套资料。希望对大家有很大的帮助
💻 C
字号:
#ifdef FSS_FTR#define ACCESS_RIGHTS_INTERNAL_FS#define FS20FOPEN_C#undef  FILE_NUMBER#define FILE_NUMBER 20 #include "Fs.h"/* Fopen of C */#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 1void Fs20_01FOpen ( void * pp_Param ){   t_FsCmdFOpen * pl_Param = (t_FsCmdFOpen *) pp_Param;   t_fsFILE *	pl_FilePtr;   t_FileMode	s_Mode;   u8		vl_StreamState;   t_ObjectInfo sl_Info;   t_fsVolStruct * pl_Volume;   fsPath * pl_RestOfPath;   /* Point in the path after the volume name or if the current path is				available pointer on it */   s32 vl_FilePosition ;   t_fsEntityStruct * pl_FsEntityPtr;	/* Pointer on entity's CB */     /* Verify if max file size input parameter >= 0 */     if ( pl_Param->v_MaxFileSize < 0 )     {	/* MaxFileSize < 0 -> invalid argument */	MC_FS_STATUS(pl_Param) = FS_EINVAL;	return;     }  /* Update mode */  /*-------------*/    /* Initialize mode */     * (u32 * ) &s_Mode = 0;    /* Treatement of first character */    if ( *(pl_Param->p_Mode) == 'r')     {	s_Mode.v_ReadEnabled = TRUE;	vl_StreamState = FS_SSTATE_IN_READ;    }    else if ( *(pl_Param->p_Mode) == 'w')     {	s_Mode.v_WriteEnabled = TRUE;	s_Mode.v_EmptyedOnOpen = TRUE;	s_Mode.v_CreationEnabled = TRUE;	vl_StreamState = FS_SSTATE_IN_WRITE;    }    else if ( *(pl_Param->p_Mode) == 'a')    { 	s_Mode.v_OpenAppend = TRUE;	s_Mode.v_WriteEnabled = TRUE;	s_Mode.v_CreationEnabled = TRUE;	vl_StreamState = FS_SSTATE_IN_WRITE;    }    else    {	/* Bad character in open mode -> error invalid argument */	MC_FS_STATUS(pl_Param) = FS_EINVAL;	return;    }    /* treatement of second character */    if ( *(pl_Param->p_Mode+1) == '+' )    {	s_Mode.v_WriteEnabled = TRUE;	s_Mode.v_ReadEnabled = TRUE;	/* If file state in read then read or write is possible */	if ( vl_StreamState == FS_SSTATE_IN_READ ) vl_StreamState = FS_SSTATE_READ_OR_WRITE;	/* If 'b' character present as third character */  	if ( *(pl_Param->p_Mode+2) == 'b')	{	    /* It must be followed by '\0 */	    if ( *(pl_Param->p_Mode+3) != '\0')	    {	    	/* Bad character in open mode -> error invalid argument */	    	MC_FS_STATUS(pl_Param) = FS_EINVAL;	    	return;	    }	}	else if ( *(pl_Param->p_Mode+2) != '\0')	{	    	/* Bad character in open mode -> error invalid argument */	    	MC_FS_STATUS(pl_Param) = FS_EINVAL;	    	return;	}	    }    else if ( *(pl_Param->p_Mode+1) == 'b')    {	if ( *(pl_Param->p_Mode+2) == '+' )   	{	    s_Mode.v_WriteEnabled = TRUE;	    s_Mode.v_ReadEnabled = TRUE;	    /* If file state in read then read or write is possible */	    if ( vl_StreamState == FS_SSTATE_IN_READ ) vl_StreamState = FS_SSTATE_READ_OR_WRITE;	}	else if ( *(pl_Param->p_Mode+2) != '\0' )    	{	    /* Bad character in open mode -> error invalid argument */	    MC_FS_STATUS(pl_Param) = FS_EINVAL;	    return;    	}    }    else if ( *(pl_Param->p_Mode+1) != '\0')    {	/* Bad character in open mode -> error invalid argument */	MC_FS_STATUS(pl_Param) = FS_EINVAL;	return;    }     /* Get entity's context pointer */    pl_FsEntityPtr = MC_FS_ED_GET_ENTITY_PTR( MC_FS_KERNEL_ID(pl_Param) );    /* Get volume of object */    pl_Volume =  MC_FS_CO_GIVE_VOLUME_FROM_PATH( pl_FsEntityPtr, (ascii*)pl_Param->p_FileName, 						&pl_RestOfPath, &sl_Info, 						&MC_FS_STATUS(pl_Param));    /* If no volume return ( status was update by function ) */    if ( pl_Volume == NIL ) return;    /* If rest of path empty  no file name can be present -> err no entry */     if ( pl_RestOfPath == NIL )    { 	MC_FS_STATUS(pl_Param) = FS_ENOENT;	return;    }    /* Set the interlayer table pointer */    MC_FS_LL_SET_NEW_VOL(pl_Volume);        /* Gives the rest of path to analyze to lower layer to have  ( dir exist, object exist, ...)  */    MC_FS_LL_GET_OBJECT_INFO (&sl_Info, pl_RestOfPath, &MC_FS_STATUS(pl_Param));    /* If an error in info get return */    if ( MC_FS_STATUS(pl_Param) != FS_OK ) return;    /* This file exist ? */    if ( sl_Info.s_FileStatus.v_ObjExist )    {	/* Verify if object is a file  */        if (  sl_Info.s_FileStatus.v_ObjIsFile == FALSE )	{	    /* Object is not a file but a directory error */	    MC_FS_STATUS(pl_Param) = FS_EISDIR;	    return;	}	else	{ 	  t_FileMode sl_AlreadyOpenMode;	     *((u32*)&sl_AlreadyOpenMode) = 0;	    /* The file exist this file can already been open.	   		if is is already open in write mode no other open is possible			if it has been open in read mode no other open in write mode is possible	       than no other open is possible	    */	    Fs05_03CheckFileAlreadyOpenMode ( pl_Volume, &sl_Info , &sl_AlreadyOpenMode); 	    if (  ( sl_AlreadyOpenMode.v_WriteEnabled )				||	   	  ( ( s_Mode.v_WriteEnabled ) && ( sl_AlreadyOpenMode.v_ReadEnabled ) ) )	    {		/* File is already open return error */	    	MC_FS_STATUS(pl_Param) = FS_EBUSY;	    	return;	    }	}	/* If file to empty on open and file size not null made it */	if ( ( s_Mode.v_EmptyedOnOpen == TRUE ) && ( sl_Info.v_FileSize != 0 ))	{	    /* Empty the file and update info structure */	    MC_FS_BF_RESIZE_FILE(sl_Info.v_ObjID, 0, &MC_FS_STATUS(pl_Param));	    /* If resize not OK return */	    if ( MC_FS_STATUS(pl_Param) != FS_OK ) return;    	    /* Else updates file size in info structure */    	    sl_Info.v_FileSize = 0;	}        /* If file was open we must place file position at end of file */	if ( s_Mode.v_OpenAppend == TRUE )	{	   vl_FilePosition = sl_Info.v_FileSize;	}	else vl_FilePosition = 0;    }    else /* File do not exist we must see to create it */    {	if ( s_Mode.v_CreationEnabled == FALSE )    	{ 	    MC_FS_STATUS(pl_Param) = FS_ENOENT;	    return;    	}	else	{	    /* Creates file through lower layers */            MC_FS_LL_CREATE_OBJ(&sl_Info, pl_Param->v_MaxFileSize, FS_OBJECT_FILE, 								&MC_FS_STATUS(pl_Param) );	    /* If creation not possible return */	    if ( MC_FS_STATUS(pl_Param) != FS_OK ) return;		    vl_FilePosition = 0;	}    }    /* Open the file for lower layers */    MC_FS_LL_OPEN_FILE( &sl_Info, &MC_FS_STATUS(pl_Param) );    /* If not possible to open file return */    if ( MC_FS_STATUS(pl_Param) != FS_OK ) return;    /* Reserve file structure  */    pl_FilePtr = ( t_fsFILE *) MC_FS_GET_MEMORY( sizeof ( t_fsFILE ) );    /* Insert file in entity's list */    MC_FS_ED_INSERT_FILE_IN_ENTITY( pl_FsEntityPtr, pl_FilePtr );    /* Insert file in the volume list */    MC_FS_VD_INSERT_FILE_IN_VOL( pl_Volume, pl_FilePtr );    /* File is open or created we must update internal FILE structure data */    pl_FilePtr->s_OpenMode = s_Mode;    pl_FilePtr->v_StreamState = vl_StreamState;    pl_FilePtr->v_FileSize = sl_Info.v_FileSize;    pl_FilePtr->v_FileID = sl_Info.v_ObjID;    pl_FilePtr->v_FilePosition = vl_FilePosition;    pl_FilePtr->v_OperationExecuted = FALSE;    pl_FilePtr->v_Pattern = FS_FILE_PATTERN;    /* If volume configuration enable it allocate an IO buffer to the file 		and update it */    MC_FS_BF_ALLOCATE_INTERNAL_BUFF(pl_FilePtr, vl_FilePosition);    /* Update file pointer in interface data structure */    pl_Param->p_Stream = pl_FilePtr;}#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 2u32 Fs20_02ProcessFOpen(const fsPath * pp_FileName, const ascii * pp_Mode ){   /* Reserve message space */   t_FsCmdFOpen * pl_Fopen = ( t_FsCmdFOpen * ) MC_FS_GET_MEMORY(sizeof(t_FsCmdFOpen));    /* Fill message with input parameters */    pl_Fopen->p_FileName = pp_FileName;    pl_Fopen->p_Mode = pp_Mode;    pl_Fopen->v_MaxFileSize = 0;    /* Send message by setting operation and return command identifier */    return( MC_FS_MA_SEND_CMD_MSG_TO_FS(FS_WITH_ACK, (void*)pl_Fopen,FS_CMD_FOPEN_REQ));}#undef PROCEDURE_NUMBER #define PROCEDURE_NUMBER 3u32 Fs20_03ProcessFOpenSized(const fsPath * pp_FileName, const ascii * pp_Mode, s32 vp_MaxFileSize ){   /* Reserve message space */   t_FsCmdFOpen * pl_Fopen = ( t_FsCmdFOpen * ) MC_FS_GET_MEMORY(sizeof(t_FsCmdFOpen));    /* Fill message with input parameters */    pl_Fopen->p_FileName = pp_FileName;    pl_Fopen->p_Mode = pp_Mode;    pl_Fopen->v_MaxFileSize = vp_MaxFileSize;    /* Send message by setting operation and return command identifier */    return( MC_FS_MA_SEND_CMD_MSG_TO_FS(FS_WITH_ACK, (void*)pl_Fopen,FS_CMD_FOPEN_REQ));}#endif /* FSS_FTR */

⌨️ 快捷键说明

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