/***************************************************************************** * FUNCTION * PmgCheckImyMidFileSize * DESCRIPTION * * PARAMETERS * path [?] * RETURNS * *****************************************************************************/ PMG_ADDFILE_ERRNO PmgCheckImyMidFileSize(S8 *path) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ S8 *file_ext_p; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ file_ext_p = PmgGetFileExt(path); if (mmi_ucs2ncmp(file_ext_p, (S8*) L"mid", 3) == 0 || mmi_ucs2ncmp(file_ext_p, (S8*) L"MID", 3) == 0 || mmi_ucs2ncmp(file_ext_p, (S8*) L"imy", 3) == 0 || mmi_ucs2ncmp(file_ext_p, (S8*) L"IMY", 3) == 0) { FS_HANDLE h; kal_uint32 file_size = 0; /* U32 file_size=0; */ h = FS_Open((U16*) path, FS_READ_ONLY); if (h) { FS_GetFileSize(h, &file_size); FS_Close(h); } else { return PMG_ADDFILE_ERR_UNKNOWN; } if (file_size > mdi_audio_get_midi_size_limit() ) { return PMG_ADDFILE_ERR_FILE_TOO_LARGE; } } return PMG_ADDFILE_ERR_SUCCESS; }
/***************************************************************************** * FUNCTION * applib_get_file_size * DESCRIPTION * This function is used to get the size of one file. * PARAMETERS * filename [IN] The filename * RETURNS * file size. *****************************************************************************/ kal_uint32 applib_get_file_size(kal_wchar *filename) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ kal_int32 fileHandle; kal_uint32 fileSize = 0; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ if (filename == NULL) { return 0; } fileHandle = FS_Open(filename, APPLIB_ASYNC_FILE_READ | FS_NONBLOCK_MODE | FS_OPEN_SHARED); if (fileHandle < 0) { return 0; } FS_GetFileSize(fileHandle, &fileSize); FS_Close(fileHandle); return fileSize; }
kal_int32 SDS_ReadNvramFileInRecord_sim(const kal_uint16 *pFilename, kal_uint8* pBuf, kal_uint32 bufLen) { kal_int32 status; kal_uint32 readLen, fileLen; kal_int32 fd = FS_Open(pFilename, FS_OPEN_NO_DIR | FS_READ_ONLY); ASSERT(fd >= 0); status = FS_GetFileSize(fd, &fileLen); ASSERT(status >= 0); if(pBuf == NULL && bufLen == 0) { return fileLen; } if(bufLen < fileLen) { return SDS_BUF_TOO_SMALL; } status = FS_Read(fd, pBuf, fileLen, &readLen); ASSERT(status >= 0 && readLen == fileLen); FS_Close(fd); return readLen; }
/* ----------------------------------------------------------------------------- Function: Cmd_Exec_f -Execute script file. Parameters: Nothing. Returns: Nothing. Notes: Console function, exec <filename> ----------------------------------------------------------------------------- */ PRIVATE void Cmd_Exec_f( void ) { filehandle_t *hfile; char *f2; int len; if( Cmd_Argc () != 2 ) { Com_Printf( "exec <filename> : execute a script file\n" ); return; } hfile = FS_OpenFile( Cmd_Argv( 1 ), FA_FILE_IPHONE_DOC_DIR ); if( ! hfile ) { Com_Printf( "couldn't exec %s\n", Cmd_Argv( 1 ) ); return; } len = FS_GetFileSize( hfile ); Com_Printf( "execing %s\n", Cmd_Argv( 1 ) ); // the file doesn't have a trailing 0, so we need to copy it off f2 = Z_Malloc( len + 1 ); memcpy( f2, hfile->filedata, len ); f2[ len ] = 0; printf( "%s", f2 ); // !@# Cbuf_InsertText( f2 ); Z_Free( f2 ); FS_CloseFile( hfile ); }
/** * \brief Load the file into memory. * \param[out] Pointer to a valid filehandle_t structure. * \return true on success, otherwise false. */ PRIVATE _boolean LoadFile( filehandle_t *hFile ) { W32 read; hFile->filesize = FS_GetFileSize( hFile ); hFile->filedata = Z_Malloc( hFile->filesize ); read = fread( hFile->filedata, 1, hFile->filesize, hFile->hFile ); if( read != hFile->filesize ) { fclose( hFile->hFile ); return false; } fclose( hFile->hFile ); hFile->hFile = NULL; // align our file data pointers hFile->ptrStart = hFile->ptrCurrent = (PW8)hFile->filedata; hFile->ptrEnd = (PW8)hFile->filedata + hFile->filesize; hFile->bLoaded = true; return true; }
/***************************************************************************** * FUNCTION * jma_audio_recorder_timer_expired * DESCRIPTION * This function handles if audio recorder timer is expired * PARAMETERS * mma_type [IN] * java_recorder [IN] * int reocrder(?) * RETURNS * void *****************************************************************************/ void jma_audio_recorder_timer_expired(kal_int32 vm_id) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ kal_uint32 record_size = 0; kal_int32 ticks = kal_milli_secs_to_ticks(200); /* 200 ms */ FS_HANDLE file_handle; kal_int32 result; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ kal_trace(TRACE_GROUP_4, FUNC_J2ME_JMA_AUDIO_RECORDER_TIMER_EXPIRED, vm_id, audio_recorder[vm_id].id, audio_recorder[vm_id].state); JMA_CS_ENTER(vm_id, JMA_VOID); if (audio_recorder[vm_id].state != JAVA_MEDIA_STATE_RECORDING) { JMA_CS_LEAVE(JMA_VOID); } EXT_ASSERT(audio_recorder[vm_id].state == JAVA_MEDIA_STATE_RECORDING, 0, 0, 0); /* Get file size */ file_handle = FS_Open(audio_recorder[vm_id].filename, FS_READ_ONLY | FS_OPEN_SHARED); if (file_handle <= 0) { kal_trace(TRACE_GROUP_4, INFO_J2ME_MMA_MARKER_FAIL); kal_trace(TRACE_GROUP_4, INFO_J2ME_MMA_D, file_handle); JMA_CS_LEAVE(JMA_VOID); } result = FS_GetFileSize(file_handle, &record_size); result = FS_Close(file_handle); if(1 == result) { kal_trace(TRACE_GROUP_4, INFO_J2ME_MMA_D, record_size+1); } kal_trace(TRACE_GROUP_4, INFO_J2ME_MMA_D, record_size); /* Reach record size limit */ if (record_size >= audio_recorder[vm_id].record_size_limit) { /* State will be changed */ jma_mvm_audio_recorder_commit(vm_id, audio_recorder[vm_id].id); jvm_post_mma_event(MMA_EVENT_RECORD_STOPPED, audio_recorder[vm_id].id, audio_recorder[vm_id].current_time); } else /* re-start timer */ { kal_trace(TRACE_GROUP_4, INFO_J2ME_MMA_STACK_START_TIMER); stack_start_timer(&java_media_timer, JAVA_MEDIA_TIMER_AUDIO_RECORDER + vm_id, ticks); } JMA_CS_LEAVE(JMA_VOID); }
/***************************************************************************** * FUNCTION * xml_generate_inline_element * DESCRIPTION * This function is for application to generate a whole element without child element * and attribute, only content. just as following: <a> test </a>. * PARAMETERS * hd [IN] handle of generator * el [IN] element name * data [IN] Filename or buffer with data. * datalen [IN] if with buffer, datalen is the length of buffer, * if with file, datalen should be 0 * RETURNS * <0: means failed, returns error code; * 0 : means succeed; *****************************************************************************/ kal_int32 xml_generate_inline_element(XG_HANDLE hd, const kal_char* el, kal_char* data, kal_uint32 datalen) { kal_int32 ret; kal_uint32 len_read, len; FS_HANDLE fhandle = -1; kal_char tempbuf[TEMP_BUF_LEN]; if ((ret = xml_generate_stag(hd, el, NULL, 0)) < 0) { return ret; } if (datalen == 0) { fhandle = FS_Open((WCHAR*)data, FS_READ_ONLY); if (fhandle < 0) { return XG_E_FAIL; } ret = FS_GetFileSize(fhandle, &len); if (ret < 0) { FS_Close(fhandle); return XG_E_FAIL; } while ((ret = FS_Read(fhandle, tempbuf, TEMP_BUF_LEN-1, &len_read)) >= FS_NO_ERROR) { if (len_read == 0) { break; } if ((ret=xml_generate_converted_data(hd, tempbuf, len_read)) < 0) { return ret; } } FS_Close(fhandle); } else { if ((ret = xml_generate_converted_data(hd, data, datalen)) < 0) { return ret; } } /* if ((ret = xml_generate_data(hd, data, datalen)) < 0) { return ret; } */ return xml_generate_etag(hd, el); }
void VERIFY_DATA_TO_DSP_RESUME( void ) { kal_uint32 uFileSize; kal_int32 ret; fs_handle = FS_Open( (const kal_wchar*)fname, FS_READ_WRITE|FS_CREATE ); ASSERT( fs_handle > 0 ); if(FS_GetFileSize(fs_handle, &uFileSize) < 0) ASSERT(0); if(FS_Seek(fs_handle, uFileSize, FS_FILE_BEGIN) < 0) ASSERT(0); uDSPBufferSize = 8192; }
SFBool SFFS_GetSize(SFFS_HANDLE hHandle,SFSize_T*pSz) { #ifdef WIN32 long fsz=_filelength(g_kernal.fpFile->_file); if(fsz>=0) { *pSz=fsz; return SFTrue; } return SFFalse; #else UINT sz=0; FS_GetFileSize(g_kernal.hFile,&sz); *pSz=sz; return SFTrue; #endif }
kal_int32 cached_io_get_state(FS_HANDLE fh, cached_io_file_state_t* state) { FS_FileInfo fi; kal_int32 ret; ASSERT(fh >= 0); ret = FS_GetFileInfo(fh, &fi); if (ret >= 0) { state->filename = mtv_filename_dup((kal_wchar*)fi.FullName); ASSERT(state->filename); ret = FS_GetFileSize(fh, &state->size); ASSERT(ret >= 0); } return ret; }
static kal_int32 SDS_GetFileSize(const kal_uint16 *pFn) { kal_int32 fd = FS_Open(pFn, FS_OPEN_NO_DIR | FS_READ_ONLY); kal_uint32 fileSize = 0; if(fd < 0) { return SDS_FILE_SYSTEM_ERROR; } if(FS_GetFileSize(fd, &fileSize) < 0) { FS_Close(fd); return SDS_FILE_SYSTEM_ERROR; } FS_Close(fd); return fileSize; }
image_t * IMG_readfileTGA (const char *fullpath, image_t *img) { //FILE *fp; byte tga_header_buf[18]; int sz; // int i,j; filehandle_t fh; if ( ! FS_FOpenReadOnly( fullpath, &fh ) ) Com_Error ( ERR_FATAL, "couldn't open file: %s\n", fullpath); if ( ! FS_Read( (void *)tga_header_buf, 18, fh ) ) Com_Error ( ERR_FATAL, "couldn't read file: %s\n", fullpath); IMG_copyHeaderTGA (&img->header.tga, tga_header_buf); sz = FS_GetFileSize( fh ); if ( sz < 0 ) Com_Error( ERR_FATAL, "returned bad size, file not found?\n" ); img->data = (byte *)V_Malloc( sz - 18 ); img->numbytes = FS_ReadAll( img->data, fh ); if ( !img->numbytes ) Com_Error ( ERR_FATAL, "error reading rest of file: %s\n", fullpath); if ( img->numbytes != sz-18 ) Com_Error ( ERR_WARNING, "sizes don't match %i %i\n", img->numbytes, sz ); img->type = IMG_TGA; img->h = img->header.tga.height; img->w = img->header.tga.width; img->bpp = img->header.tga.pixel_size / 8; FS_FClose( fh ); return img; }
/***************************************************************************** * FUNCTION * btmtk_fs_get_filesize * DESCRIPTION * * PARAMETERS * fileName [IN] * RETURNS * *****************************************************************************/ S32 btmtk_fs_get_filesize(const U8 *fileName) { #ifdef BTMTK_ON_WISE /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ int err, handle; U32 size; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ bt_asc_str_n_to_ucs2_str((S8 *)pathBuf, (S8 *)fileName, FS_MAX_PATH_LEN * sizeof(U16)); handle = FS_Open(pathBuf, FS_READ_ONLY | FS_OPEN_SHARED); if (handle < 0) { return translateFileError(handle); } err = FS_GetFileSize(handle, &size); FS_Close(handle); return translateFileError(err); #else /* BTMTK_ON_WISE */ FILE *fp; int size; translateFilePath(fileName, (U8 *)pathBuf); fp = fopen((char *)pathBuf, translateFileModeC(BTMTK_FS_READ_ONLY)); if (fp == NULL) { return BTMTK_FS_ERR; } fseek(fp, 0, SEEK_END); size = ftell(fp); fclose(fp); return size; #endif /* BTMTK_ON_WISE */ }
Media_Status wavRecordAppendable( Media_Format format, FS_HANDLE fs, Media_Record_File_Info *info ) { uint8 *pBuf; Media_Status status; uint32 len; // To initialize info memset(info, 0, sizeof(Media_Record_File_Info)); // Get the file size if (FS_NO_ERROR != FS_GetFileSize(fs, &info->fileSize) ) return MEDIA_READ_FAIL; // To get the enough wav header which is supported by MediaTek pBuf = (uint8*)get_ctrl_buffer( 60*sizeof(uint8) ); memset(pBuf, 0, 60*sizeof(uint8)); if ( FS_NO_ERROR != FS_Read(fs, pBuf, 60, &len) ) { status = MEDIA_READ_FAIL; } else { // Parse the wav header status = wavParseRecordFile(pBuf, len, info); } free_ctrl_buffer( pBuf ); // Compare the file information and wav format if (status == MEDIA_SUCCESS) { // Type mismatch if (format != info->format) return MEDIA_FAIL; } return status; }
/***************************************************************************** * FUNCTION * mmi_syncml_get_record_res_req * DESCRIPTION * Protocol event sender * PARAMETERS * void * RETURNS * void *****************************************************************************/ void mmi_syncml_get_record_res_req(void) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ MYQUEUE Message; mmi_syncml_get_record_res_req_struct *dataPtr; FS_HANDLE fs_handle; U32 read_length, fs_size; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ if (g_syncml_sync_context.operation != SYNCML_RECORD_GET_DEL_NOTIFY) { if (g_syncml_sync_context.result == SYNCML_OK) { fs_handle = FS_Open(SYNCML_VOBJ_PATH, FS_READ_ONLY); FS_GetFileSize(fs_handle, &fs_size); mmi_syncml_free_vobj_buffer(); g_syncml_sync_context.vobj_ptr = OslMalloc(fs_size); FS_Read(fs_handle, (void*) g_syncml_sync_context.vobj_ptr, fs_size, &read_length); FS_Close(fs_handle); FS_Delete(SYNCML_VOBJ_PATH); } else { mmi_syncml_free_vobj_buffer(); fs_size = 0; g_syncml_sync_context.result = SYNCML_FAIL; PRINT_INFORMATION_2(MMI_TRACE_G7_MISC, "[SyncML] Get record fail"); } } Message.oslSrcId = MOD_MMI; Message.oslDestId = MOD_SYNCML; Message.oslMsgId = MSG_ID_MMI_SYNCML_GET_RECORD_RES_REQ; dataPtr = (mmi_syncml_get_record_res_req_struct*) OslConstructDataPtr(sizeof(mmi_syncml_get_record_res_req_struct)); dataPtr->result = g_syncml_sync_context.result; if (g_syncml_sync_context.operation != SYNCML_RECORD_GET_DEL_NOTIFY) { dataPtr->data_length = fs_size; dataPtr->data = g_syncml_sync_context.vobj_ptr; dataPtr->more_data = 0; } Message.oslDataPtr = (oslParaType*) dataPtr; Message.oslPeerBuffPtr = NULL; OslMsgSendExtQueue(&Message); /* update to show the current progress */ if (g_syncml_sync_context.database == SYNCML_DB_PHONEBOOK) { g_syncml_context.contact_send_current++; mmi_syncml_update_progress_string(PROGRESS_CONTACT_DATASTORE_SENDING); } else if (g_syncml_sync_context.database == SYNCML_DB_TODOLIST) { g_syncml_context.calendar_send_current++; mmi_syncml_update_progress_string(PROGRESS_TASK_DATASTORE_SENDING); } }
static BOOL mmi_da_wps_send_http_req(U8 request_id, U8 http_method, S8 * url, S8 * post_data, PU16 file_path) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ wps_http_req_struct *http_req; wps_http_req_var_struct http_req_var; peer_buff_struct *peer_buff_ptr = NULL; U16 pdu_length; U16 len; FS_HANDLE hd; static S8 range_header[30]; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ DA_WPS_TRACE(MMI_DA_WPS_TRACE_GROUP, MMI_DA_OMA_SEND_HTTP_REQ, request_id); ASSERT(_da_wps_is_ready()); ASSERT(request_id < MMI_DA_WPS_REQUEST_ID_RANGE); http_req = (wps_http_req_struct *) construct_local_para(sizeof(wps_http_req_struct), TD_CTRL); http_req->channel_id = da_wps_context.channel_id; http_req->request_id = request_id + MMI_DA_WPS_REQUEST_ID_BASE; http_req->method = http_method; http_req->option = WPS_HTTP_OPTION_NO_CACHE; http_req_var.request_url_len = (kal_uint32) strlen(url); http_req_var.request_url = (kal_uint8 *) url; http_req_var.request_header_len = 0; http_req_var.request_header = NULL; if (http_method == WPS_HTTP_METHOD_POST) { ASSERT(post_data != NULL); http_req->reply_type = WPS_DATA_TYPE_BUFFER; http_req->reply_segment_len = 0; /* no use here */ http_req->post_type = WPS_DATA_TYPE_BUFFER; http_req->post_path[0] = '\0'; http_req->post_path[1] = '\0'; http_req->post_total_len = strlen(post_data); http_req->more_post = MMI_FALSE; http_req_var.post_segment_len = strlen(post_data); http_req_var.post_segment = (kal_uint8 *) post_data; http_req_var.request_header_len = strlen("Content-Type: text/plain; charset=UTF-8\r\n"); http_req_var.request_header = (kal_uint8 *)"Content-Type: text/plain; charset=UTF-8\r\n"; } else { ASSERT(file_path != NULL && mmi_ucs2strlen((S8 *) file_path) < 256); http_req->reply_type = WPS_DATA_TYPE_FILE; mmi_ucs2cpy((S8 *) http_req->reply_path, (S8 *) file_path); http_req->reply_segment_len = 0; /* no use here */ http_req->post_type = WPS_DATA_TYPE_BUFFER; http_req->post_path[0] = '\0'; http_req->post_path[1] = '\0'; http_req->post_total_len = 0; http_req->more_post = MMI_FALSE; http_req_var.post_segment_len = 0; http_req_var.post_segment = NULL; // If the target file exist, it means RESUME if ((hd = FS_Open((PU16)file_path, FS_READ_ONLY)) >= 0) { UINT file_size; FS_GetFileSize(hd, &file_size); sprintf(range_header, "Range:bytes=%d-", file_size); FS_Close(hd); http_req_var.request_header_len = strlen(range_header); http_req_var.request_header = (kal_uint8 *)range_header; } } pdu_length = wps_pun_var_part(WPS_PUN_SIZE, MSG_ID_WPS_HTTP_REQ, &http_req_var, NULL); if (pdu_length > 0) { peer_buff_ptr = construct_peer_buff(pdu_length, 0, 0, TD_RESET); if (wps_pun_var_part(WPS_PUN_PACK, MSG_ID_WPS_HTTP_REQ, &http_req_var, get_pdu_ptr(peer_buff_ptr, &len)) != pdu_length) { free_peer_buff(peer_buff_ptr); peer_buff_ptr = NULL; } } mmi_da_send_ilm(http_req, peer_buff_ptr, MSG_ID_WPS_HTTP_REQ, MOD_WPS); SetProtocolEventHandler((PsFuncPtr) mmi_da_wps_recv_http_rsp, MSG_ID_WPS_HTTP_RSP); SetProtocolEventHandler((PsFuncPtr) mmi_da_wps_recv_dl_progress_ind, MSG_ID_WPS_DL_PROGRESS_IND); SetProtocolEventHandler((PsFuncPtr) mmi_da_wps_recv_http_auth_ind, MSG_ID_WPS_HTTP_AUTH_IND); return MMI_TRUE; }
/** * \brief Load font details from file * \param[in] filename File name to load details * \return Valid pointer to font_t */ PUBLIC font_t *createFont( const char *filename ) { font_t *temp_font; char *datname; filehandle_t *fp; W32 size; W32 i; if( num_fonts == (MAX_FONTS - 1) ) { Com_Printf( "[createFont]: No more font slots open\n" ); return NULL; } temp_font = (font_t *)Z_Malloc( sizeof( font_t ) ); temp_font->texfont = TM_FindTexture( filename, TT_Pic ); if( NULL == temp_font->texfont ) { Com_Printf( "[createFont]: unable to open file (%s)\n", filename ); Z_Free( temp_font ); return NULL; } memset( temp_font->nCharWidth, 0, sizeof( temp_font->nCharWidth ) ); datname = (char *)MM_MALLOC( strlen( filename ) + 1 ); FS_RemoveExtension( filename, datname ); com_strlcat( datname, ".dat", strlen( filename ) + 1 ); fp = FS_OpenFile( datname, 0 ); if( NULL == fp ) { Com_Printf( "[createFont]: unable to open file (%s)\n", datname ); MM_FREE( datname ); Z_Free( temp_font ); return NULL; } size = FS_GetFileSize( fp ); // check header size if( size < 10 ) { Com_Printf( "[createFont]: File (%s) has incorrect file length\n", datname ); MM_FREE( datname ); Z_Free( temp_font ); FS_CloseFile( fp ); return NULL; } // Check sig of font dat file FS_ReadFile( &size, 1, 4, fp ); FS_ReadFile( &temp_font->nMaxWidth, 1, 1, fp ); FS_ReadFile( &temp_font->nMaxHeight, 1, 1, fp ); FS_ReadFile( &size, 1, 4, fp ); size = LittleLong( size ); if( size > 127 ) { Com_Printf( "[createFont]: File (%s) has incorrect Character Width array\n", datname ); MM_FREE( datname ); Z_Free( temp_font ); FS_CloseFile( fp ); return NULL; } FS_ReadFile( &temp_font->nCharWidth, 1, size, fp ); FS_CloseFile( fp ); temp_font->nSize = 2; temp_font->colour[ 3 ] = 255; temp_font->hFrac = (float)(temp_font->nMaxHeight / (float)temp_font->texfont->height); temp_font->wFrac = (float)(temp_font->nMaxWidth / (float)temp_font->texfont->width); for( i = 0 ; i < MAX_FONTS ; ++i ) { if( ! myfonts[ i ] ) { break; } } if( i == (MAX_FONTS - 1) ) { Com_Printf( "[createFont]: No more font slots open\n" ); MM_FREE( datname ); Z_Free( temp_font ); return NULL; } myfonts[ i ] = temp_font; MM_FREE( datname ); return temp_font; }
/****************************************************************************** * Function: * GPSLocateNvramInitDataFile * * Usage: * Initialize data file * If the file doesn't exist, create it and write the default data to the file. Otherwise, load the * content of the file to the cache. * * Parameters: * None * * Return: * KAL_TRUE - successfully * KAL_FALSE - failed ******************************************************************************/ kal_bool GPSLocateNvramInitDataFile(void) { FS_HANDLE file_handle; int result; kal_uint16 folderName[GPSLOCATE_NVRAMDATA_FULLPATHNAME_LEN_MAX]; char tmpBuffer[GPSLOCATE_NVRAMDATA_FULLPATHNAME_LEN_MAX]; kal_bool bRet = KAL_TRUE, bNeedCreate = KAL_FALSE; unsigned int Size; unsigned char Ver; if (gGPSLocateNvramSem != NULL) { //has been initialized //do nothing, return error directly return KAL_FALSE; } //create semaphore gGPSLocateNvramSem = kal_create_sem("GPSNVRAM SEM", 1); ASSERT((gGPSLocateNvramSem!=NULL)); /* * Taking the semaphore here will make the handset not able to power up. * Maybe, semaphore is not ready now. */ //take the semaphore //kal_take_sem(gGPSLocateNvramSem, KAL_INFINITE_WAIT); //initialize global data gGPSLocateNvramFullPathFileName[0] = 0x0000; gGPSLocateNvramDataCache.Valid = KAL_FALSE; //construct folder name sprintf(tmpBuffer, "%c:\\%s", GPSLOCATE_NVRAMDATA_DRV, GPSLOCATE_NVRAMDATA_FOLDER_NAME); app_ansii_to_unicodestring((kal_int8*)folderName, (kal_int8*)tmpBuffer); //check the folder exists or not file_handle = FS_Open(folderName, FS_OPEN_DIR | FS_READ_ONLY ); if (file_handle < FS_NO_ERROR) { //the folder doesn't exist, create it. result = FS_CreateDir(folderName); if (result < FS_NO_ERROR) { //fail to create bRet = KAL_FALSE; //return KAL_FALSE; goto _RelSem_Return_; } } else { FS_Close(file_handle); } /* 1. construct full path file name 2. check file exist or not 3. check file valid or not (by file size) 4. if file doesn't exist or it is invalid, re-create and restore default data for it */ //construct full path file name sprintf(tmpBuffer, "%c:\\%s%s", GPSLOCATE_NVRAMDATA_DRV, GPSLOCATE_NVRAMDATA_FOLDER_NAME, GPSLOCATE_NVRAMDATA_FILE_NAME); app_ansii_to_unicodestring((kal_int8*)gGPSLocateNvramFullPathFileName, (kal_int8*)tmpBuffer); //check files exist or not file_handle = FS_Open(gGPSLocateNvramFullPathFileName, FS_READ_ONLY); if (file_handle < FS_NO_ERROR) { //this file doesn't exist, need create it bNeedCreate = KAL_TRUE; } else { if (FS_GetFileSize(file_handle, &Size) < FS_NO_ERROR) { //fail to get file size, consider the file invalid, need create it bNeedCreate = KAL_TRUE; } else if (Size != sizeof(GPSLocateNvramDataStruct_t)) { //invalid size, need re-create it bNeedCreate = KAL_TRUE; } else { //check version number result = FS_Read(file_handle, &Ver, sizeof(unsigned char), &Size); if (result == FS_NO_ERROR && Size == sizeof(unsigned char)) { //Got version number if (Ver != GPSLOCATE_NVRAM_VER_NO) { //old version, should be re-created bNeedCreate = KAL_TRUE; } } } //close the file FS_Close(file_handle); if (bNeedCreate == KAL_TRUE) { //delete the bad file FS_Delete(gGPSLocateNvramFullPathFileName); } } if (bNeedCreate == KAL_FALSE) { #if 0//defined(M100) if (gGPSLocateRestoreFlag == 1 && BMT.PWRon == PWRKEYPWRON) { //should restore the default value file_handle = FS_Open(gGPSLocateNvramFullPathFileName, FS_READ_WRITE); if (file_handle < FS_NO_ERROR) { //fail to open bRet = KAL_FALSE; goto _RelSem_Return_; } else { //load default bRet = GPSLocateNvramLoadDefault(file_handle, KAL_FALSE); FS_Close(file_handle); goto _RelSem_Return_; } } else #endif // M100 { //valid file, load the content to the cache bRet = GPSLocateNvramLoadData(); goto _RelSem_Return_; } } else { //create the file if (GPSLocateNvramCreateDataFile() != KAL_TRUE) { //fail to create, set the full path name empty gGPSLocateNvramFullPathFileName[0] = 0x0000; bRet = KAL_FALSE; //return KAL_FALSE; goto _RelSem_Return_; } } _RelSem_Return_: //release the semaphore //kal_give_sem(gGPSLocateNvramSem); return bRet; }
void SpiFlashDownFromSD(bool ForceDownload,const u8 *CfgPath,u8 *FileBuf,u8 *PageBuf) { u8 Buffer2[16]; u8 *pTmp; u8 *pSecStart[MaxSecItem]; u8 *pSecEnd[MaxSecItem]; u8 *pAddr[MaxDownItem]; u8 *pBinPath[MaxDownItem]; u8 EarseSecFlag; //存储每个文件的匹配结果 u8 CurSecItem=0;//当前解析的扇区配置项 u8 CurDownItemNum=0;//当前扇区项下面的下载项个数 u8 *pCfg; int i,j; UINT ReadByte; u32 SecStart,SecEnd; FS_FILE *pFileObj; //打开配置文件 if((CfgPath[0]==0)||(CfgPath==NULL)) return; if ((pFileObj=FS_FOpen((void *)CfgPath, FA_OPEN_EXISTING | FA_READ)) == 0 ) { Debug("Cannot open file \"%s\"\n\r",CfgPath); return; } //读取配置文件 if((ReadByte=FS_FRead((void *)FileBuf, CfgFileSize,1,pFileObj ))==0) { Debug("Read cfg file error!\n\r"); FS_FClose(pFileObj); return; } //Debug("Cfg content:\n\r%s\n\r",Cfg); //关闭配置文件 if( FS_FClose(pFileObj) == -1 ) { Debug("Close file error\n"); return; } pCfg=FileBuf; //检查配置文件版本 if((pTmp=(void *)strstr((void *)pCfg,"#"))==NULL) return; if((pCfg=(void *)strstr((void *)pTmp,";"))==NULL) return; pTmp++; *pCfg++=0; if(strcmp((void *)pTmp,"m25p16 1.0")) { Debug("Cfg file %s version is error!(%s!=%s)\n\r",CfgPath,"m25p16 1.0",pTmp); return; } //检查配置项完整性 if((pTmp=(void *)strstr((void *)pCfg,"$"))==NULL) return; *pTmp++=0; //开始提取配置文件内容 while(1) { *pTmp='%';//恢复上一个扇区项 //先获取扇区项 if((pSecStart[CurSecItem]=(void *)strstr((void *)pCfg,"%"))==NULL) return; if((pSecEnd[CurSecItem]=(void *)strstr((void *)pSecStart[CurSecItem],"-"))==NULL) return; if((pCfg=(void *)strstr((void *)pSecEnd[CurSecItem],";"))==NULL) return; *pSecStart[CurSecItem]++=0; *pSecEnd[CurSecItem]++=0; *pCfg++=0; Debug("Current SectorItem:%d,SecStart:%s,SecEnd:%s\n\r",CurSecItem,pSecStart[CurSecItem],pSecEnd[CurSecItem]); SecStart=StrToUint((void *)pSecStart[CurSecItem]); SecEnd=StrToUint((void *)pSecEnd[CurSecItem]); if(SecStart>SecEnd) return;//扇区错误 if(SecEnd>31) return;//扇区错误 EarseSecFlag=0;//置0擦除标志 if((pTmp=(void *)strstr((void *)pCfg,"%"))!=NULL) *pTmp=0;//先屏蔽下一个扇区项 else pTmp=FileBuf; //再获取下载项 for(i=0; i<MaxDownItem; i++) { if((pBinPath[i]=(void *)strstr((void *)pCfg,"="))==NULL) return;//找到文件路径 if((pAddr[i]=(void *)strstr((void *)pBinPath[i],"@"))==NULL) return;//找到起始页数 if((pCfg=(void *)strstr((void *)pAddr[i],";"))==NULL) return;//找到本条结尾位置 *pBinPath[i]++=0; *pAddr[i]++=0; *pCfg++=0; Debug("=%s download to page %s\n\r",pBinPath[i],pAddr[i]); if(strstr((void *)pCfg,"=")==NULL) //也没有下一个下载项了 { i++; break; } } CurDownItemNum=i; Debug("Current DownItem Max Num:%d\n\r",CurDownItemNum); if(!ForceDownload) { for(i=0; i<CurDownItemNum; i++) { //打开bin文件 if ((pFileObj=FS_FOpen((void *)pBinPath[i], FA_OPEN_EXISTING | FA_READ)) ==0 ) { Debug("Cannot open file %s,Cancle download\n\r",pBinPath[i]); return; } //对比每个下载项文件和flash page的头16字节内容 if((ReadByte=FS_FRead((void *)PageBuf, sizeof(Buffer2), 1,pFileObj)) != 0) { if(ReadByte) { //读取spi flash内容进行匹配 Q_SpiFlashSync(FlashRead,SPI_FLASH_PAGE_SIZE*StrToUint((void *)pAddr[i]),sizeof(Buffer2),Buffer2); for(j=0; j<sizeof(Buffer2); j++) { //Debug("%x?=%x\n\r",Buffer2[j],Buffer[j]); if(Buffer2[j]!=PageBuf[j]) { EarseSecFlag=1; Debug("We need erase sectors becase of file %s first %d bytes.\n\r",pBinPath[i],sizeof(Buffer2)); if( FS_FClose(pFileObj) == -1 ) Debug("Close file %s error\n",pBinPath[i]); goto Erase; } } //if(j==sizeof(Buffer2)) //{ // Debug("We needn't download file %s to spi flash\n\r",pBinPath[i]); //} } else //没有读到内容 { Debug("File %s is NULL,cancle download\n\r",pBinPath[i]); return; } } //对比每个下载项文件和flash page的尾16字节内容 FS_FSeek(pFileObj,-sizeof(Buffer2),FS_SEEK_END); if((ReadByte=FS_FRead((void *)PageBuf, sizeof(Buffer2), 1,pFileObj)) != 0) { if(ReadByte) { //读取spi flash内容进行匹配 Q_SpiFlashSync(FlashRead, SPI_FLASH_PAGE_SIZE*StrToUint((void *)pAddr[i])+FS_GetFileSize(pFileObj)-sizeof(Buffer2), sizeof(Buffer2),Buffer2); for(j=0; j<sizeof(Buffer2); j++) { //Debug("%x?=%x\n\r",Buffer2[j],Buffer[j]); if(Buffer2[j]!=PageBuf[j]) { EarseSecFlag=1; Debug("We need erase sectors becase of file %s last %d byte.\n\r",pBinPath[i],sizeof(Buffer2)); if( FS_FClose(pFileObj) == -1 ) Debug("Close file %s error\n",pBinPath[i]); goto Erase; } } if(j==sizeof(Buffer2)) { Debug("We needn't download file %s to spi flash\n\r",pBinPath[i]); } } else //没有读到内容 { Debug("File %s is NULL,cancle download\n\r",pBinPath[i]); return; } } if( FS_FClose(pFileObj) == -1 ) Debug("Close file %s error\n",pBinPath[i]); } } Erase: //擦除扇区 if(EarseSecFlag||ForceDownload) { for(i=SecStart; i<=SecEnd; i++) { Debug("Erase sector %d(page %d to %d)\n\r",i,i<<8,(i<<8)+256); Q_SpiFlashSync(FlashSectorEarse,i<<16,0,NULL); } //烧录文件 for(i=0; i<CurDownItemNum; i++) { Debug("#Download %s ",pBinPath[i]); if ((pFileObj=FS_FOpen((void *)pBinPath[i], FA_OPEN_EXISTING | FA_READ)) == 0 ) { Debug("Cannot open file %s\n\r",pBinPath[i]); return; } for(ReadByte=0,j=StrToUint((void *)pAddr[i]);; j++) { if((ReadByte=FS_FRead((void *)PageBuf, SPI_FLASH_PAGE_SIZE, 1,pFileObj)) != 0) { //读到非0个数据 Q_SpiFlashSync(FlashWrite,j*SPI_FLASH_PAGE_SIZE,ReadByte,PageBuf); Debug("."); //显示进度条 } else //读到0个数据,说明读到文件末了 { break; } } Debug("\n\rHave Download \"%s\" to spi flash,from page %d to page %d\n\r",pBinPath[i],StrToUint((void *)pAddr[i]),j-1); if( FS_FClose(pFileObj) == -1 ) Debug("Close file %s error\n",pBinPath[i]); } } if(++CurSecItem==MaxSecItem) return;//下一个扇区项 } }
/** * \brief Load wav file. * \param[in] filename Name of wav file to load. * \param[in] wav wav data. * \param[in] info wav sound info. * \return True if file loaded, otherwise false. * \note Caller is responsible for freeing wav data by calling Z_Free. */ PUBLIC _boolean LoadWavInfo( const char *filename, W8 **wav, soundInfo_t *info ) { filehandle_t *hFile; W8 *data; W32 wavlength; hFile = FS_OpenFile( filename, FA_FILE_FLAG_LOAD ); if( ! hFile ) { return false; } data = (PW8)FS_GetLoadedFilePointer( hFile, SEEK_SET ); wavlength = FS_GetFileSize( hFile ); iff_data = data; iff_end = data + wavlength; // look for RIFF signature Wav_FindChunk( "RIFF" ); if( ! (iff_pdata && ! com_strnicmp( iff_pdata + 8, "WAVE", 4 ) ) ) { Com_DPrintf( "[LoadWavInfo]: Missing RIFF/WAVE chunks (%s)\n", filename ); FS_CloseFile( hFile ); return false; } // Get "fmt " chunk iff_data = iff_pdata + 12; Wav_FindChunk( "fmt " ); if( ! iff_pdata ) { Com_DPrintf( "[LoadWavInfo]: Missing fmt chunk (%s)\n", filename ); FS_CloseFile( hFile ); return false; } iff_pdata += 8; if( Wav_GetLittleShort() != 1 ) { Com_DPrintf( "[LoadWavInfo]: Microsoft PCM format only (%s)\n", filename ); FS_CloseFile( hFile ); return false; } info->channels = Wav_GetLittleShort(); info->sample_rate = Wav_GetLittleLong(); iff_pdata += 4; info->sample_size = Wav_GetLittleShort(); // Bytes Per Sample if (info->sample_size != 1 && info->sample_size != 2) { Com_DPrintf( "[LoadWavInfo]: only 8 and 16 bit WAV files supported (%s)\n", filename ); FS_CloseFile( hFile ); return false; } iff_pdata += 2; // Find data chunk Wav_FindChunk( "data" ); if( ! iff_pdata ) { Com_DPrintf( "[LoadWavInfo]: missing 'data' chunk (%s)\n", filename ); FS_CloseFile( hFile ); return false; } iff_pdata += 4; info->samples = Wav_GetLittleLong() / info->sample_size; if( info->samples <= 0 ) { Com_DPrintf( "[LoadWavInfo]: file with 0 samples (%s)\n", filename ); FS_CloseFile( hFile ); return false; } // Load the data *wav = Z_Malloc( info->samples * info->sample_size ); memcpy( *wav, data + (iff_pdata - data), info->samples * info->sample_size ); FS_CloseFile( hFile ); return true; }
UINT DevAssetManager::GetFileSize( PakFileHandle file ) { const FileHandle fileHandle = Pak_To_OS_File_Handle( file ); return FS_GetFileSize( fileHandle ); }
kal_int32 SDS_RestoreNvramFilesFromRecord_Sim(kal_uint32* pBuf) { kal_uint8 *p = (kal_uint8*)pBuf; kal_int32 fd; kal_uint32 len; kal_uint32 fileCount = 0; PackedDataHeadStruct *pHead; FileInfoStruct *pFileInfo = NULL; kal_uint16 buf[FS_MAX_PATH]; ASSERT( ((kal_uint32)p)%4 == 0); pHead = (PackedDataHeadStruct*)p; p += pHead->headDataLen; while(fileCount < pHead->fileCount) { pFileInfo = (FileInfoStruct*)p; p += sizeof(FileInfoStruct); memcpy(buf, p, pFileInfo->fnLen); p += pFileInfo->fnLen; fd = FS_Open(buf, FS_OPEN_NO_DIR | FS_READ_ONLY); ASSERT(fd>=0); FS_GetFileSize(fd, &len); ASSERT(len == pFileInfo->contentLen); while(len) { kal_uint32 readLen = 0; kal_uint32 n = len; kal_int32 fsRet; if(n > sizeof(buf)) { n = sizeof(buf); } memset(buf, 0xcd, sizeof(buf)); fsRet = FS_Read(fd, buf, n, &readLen); ASSERT(fsRet >=0 && readLen == n); ASSERT(memcmp(p, buf, n) == 0); p += n; len -= n; } FS_Close(fd); p += (4-(pFileInfo->fnLen + pFileInfo->contentLen) % 4) % 4; fileCount++; } return fileCount; }
/***************************************************************************** * FUNCTION * aud_trim_open_req_hdlr * DESCRIPTION * This function is used to open a trimming handler. * PARAMETERS * * RETURNS * void *****************************************************************************/ void aud_trim_open_req_hdlr(ilm_struct *ilm_ptr) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ kal_uint32 file_len = 0; FSAL_Status fsal_result; kal_uint8* fsal_buf_p = NULL; media_open_func_ptr open_fct = NULL; kal_int32 result = MED_RES_FAIL; l4aud_trim_open_req_struct* msg_p = (l4aud_trim_open_req_struct*) ilm_ptr->local_para_ptr; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ ASSERT(msg_p->file_name_in && msg_p->file_name_out && msg_p->handle_p); /* Check if trimming handler is already opened. Currently, we only support one instance. */ if (g_is_trim_opened) { result = MED_RES_BUSY; goto aud_trim_open_failed; } /* Initialize context */ g_is_trim_opened = KAL_TRUE; memset(&g_trim_ctx, 0, sizeof(aud_trim_context_t)); g_trim_ctx.file_output = -1; g_trim_ctx.src_mod_id = ilm_ptr->src_mod_id; /* Select a MHdl open function per media format */ g_trim_ctx.format = med_get_media_type(msg_p->file_name_in); switch (g_trim_ctx.format) { #ifdef DAF_DECODE case MED_TYPE_DAF: #endif /* DAF_DECODE */ open_fct = DAF_Open; break; default: /* Unsupport format */ ASSERT(0); } if (open_fct) { /* Create a FSAL handler */ if ((fsal_result = FSAL_Open(&g_trim_ctx.fsal_handle, msg_p->file_name_in, FSAL_READ_SHARED)) != FSAL_OK) { result = MED_RES_OPEN_FILE_FAIL; goto aud_trim_open_failed; } g_trim_ctx.is_fsal_opened = KAL_TRUE; fsal_buf_p = (kal_uint8*) get_ctrl_buffer(sizeof(kal_uint8) * AUD_PROC_BUF_SIZE); FSAL_SetBuffer(&g_trim_ctx.fsal_handle, AUD_PROC_BUF_SIZE, fsal_buf_p); /* Open a MHdl handler */ g_trim_ctx.mhdl_handle_p = open_fct(_aud_trim_event_callback_fct, &g_trim_ctx.fsal_handle, NULL); _AUD_TRIM_TRACE(g_trim_ctx.mhdl_handle_p, g_trim_ctx.format, fsal_buf_p); if (g_trim_ctx.mhdl_handle_p == NULL) { result = MED_RES_BAD_FORMAT; goto aud_trim_open_failed; } /* Create output file handle */ g_trim_ctx.file_output = FS_Open(msg_p->file_name_out, FS_READ_WRITE | FS_OPEN_SHARED | FS_NOBUSY_CHECK_MODE); if (g_trim_ctx.file_output >= 0) /* File already exists */ { /* Check if the size of file is 0 because MMI may create the file to be trimmed to in advance */ FS_GetFileSize(g_trim_ctx.file_output, &file_len); if (file_len != 0) { /* Seek to the beginning of the file to overwrite all the data */ FS_Seek(g_trim_ctx.file_output, 0, FS_FILE_BEGIN); } } else /* File does not exist */ { /* Create a new file */ g_trim_ctx.file_output = FS_Open(msg_p->file_name_out, FS_CREATE | FS_READ_WRITE | FS_OPEN_SHARED | FS_NOBUSY_CHECK_MODE); } _AUD_TRIM_TRACE(g_trim_ctx.file_output, file_len, -1); if (g_trim_ctx.file_output < 0) { result = MED_RES_OPEN_FILE_FAIL; goto aud_trim_open_failed; } } /* Open successful */ *msg_p->handle_p = (kal_uint32)g_trim_ctx.mhdl_handle_p; AUD_TRIM_RETURN(MED_RES_OK); return; aud_trim_open_failed: /* Open failed */ _aud_trim_close(); *msg_p->handle_p = (kal_uint32)0; AUD_TRIM_RETURN(result); }
/********************************************************************* * * _GetLen */ static long _GetLen(void * hFile) { _InitIfRequired(); // Perform automatic initialisation so that explicit call to FS_Init is not required return FS_GetFileSize((FS_FILE*) hFile); }
static kal_int32 xml_generate_flash_text(kal_int8 hd, kal_char *text, kal_uint32 textlen) { kal_uint32 length, len; kal_int32 ret; FS_HANDLE fhandle = -1; xml_generator_struct *p = NULL; /* first to get xml text length */ if(textlen == 0)/* text is in file */ { fhandle = FS_Open((WCHAR*)text, FS_READ_ONLY); if (fhandle < 0) { return XG_E_FAIL; } ret = FS_GetFileSize(fhandle, &length); if (ret == FS_FILE_NOT_FOUND) { return XG_E_FILE_NOT_FOUND; } if (ret < 0) { FS_Close(fhandle); return XG_E_FAIL; } } else /* text is in buffer */ { length = textlen; } p = &(xg_array[hd]); /* then write xml text to dest */ if(p->buf != NULL) /* write xml text to buffer */ { /* verify if over-buffer */ if(p->curlen+length > p->buflen) { if(fhandle != -1) { FS_Close(fhandle); } ASSERT(0); kal_printf("buffer to save will be overflow!!!!\r\n"); return XG_E_OVER_BUFFER; } if (textlen != 0) /* text is in buffer, write xml text from buffer to buffer */ { memcpy(p->buf+p->curlen, text, textlen); len = textlen; ret = 0; } else /* text is in file, write xml text from file to buffer */ { ret = xml_generate_write_filetobuf(p->buf+p->curlen, fhandle, &len); FS_Close(fhandle); } } else /* write xml text to file */ { if (textlen != 0) /* text is in buffer, write xml text from buffer to file */ { ret = FS_Write(p->file, text, textlen, &len); if(ret == FS_DISK_FULL) { return XG_E_LACK_DISK; } } else /* text is in file, write xml text from file to file */ { ret = xml_generate_write_filetofile(p->file, fhandle, &len); FS_Close(fhandle); } } if (ret < 0) { return ret; } else { p->curlen += len; return len; } }