📄 jvm_file.c
字号:
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (handle < 0)
{
return -1;
}
h = file->h.handler;
if (file->file_tag == NORMAL_FILE_TAG || file->file_tag == ENCRYPTED_JAR_FILE)
{
if (FS_Close(h) == FS_NO_ERROR)
{
result = 0;
}
else
{
result = -1;
}
#ifdef __DRM_SUPPORT__
}
else if (file->file_tag == DRM_FILE_TAG)
{
if (DRM_close_file(h) == FS_NO_ERROR)
{
result = 0;
}
else
{
result = -1;
}
#endif /* __DRM_SUPPORT__ */
}
else if (file->file_tag == VIRTUAL_FILE_TAG)
{
result = 0;
}
else
{
result = -1;
}
if ((file->file_tag == NORMAL_FILE_TAG) ||
(file->file_tag == VIRTUAL_FILE_TAG) ||
(file->file_tag == ENCRYPTED_JAR_FILE) || (file->file_tag == DRM_FILE_TAG))
{
file->file_tag = 0;
/* Avoid duplicate close */
free_ctrl_buffer((unsigned char*)file);
}
return result;
}
/*****************************************************************************
* FUNCTION
* jvm_file_read
* DESCRIPTION
*
* PARAMETERS
* handle [IN]
* buf [?]
* count [IN]
* RETURNS
*
*****************************************************************************/
int jvm_file_read(int handle, void *buf, int count)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
pvfile file = (pvfile) handle;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (handle < 0)
{
return -1;
}
if (file->file_tag == NORMAL_FILE_TAG)
{
kal_uint32 real_count = 0;
#if DATACACHE_FBBR_ON
/* this function is only workable when DATACACHE_FBBR_ON is 1 */
buf = (char*)FBBR_invalid_l1_cache(buf, count);
#endif /* DATACACHE_FBBR_ON */
if (FS_Read(file->h.handler, buf, count, &real_count) == FS_NO_ERROR)
{
return real_count;
}
else
{
return -1;
}
#ifdef __DRM_SUPPORT__
}
else if (file->file_tag == DRM_FILE_TAG)
{
kal_uint32 real_count = 0;
#if DATACACHE_FBBR_ON
/* this function is only workable when DATACACHE_FBBR_ON is 1 */
buf = (char*)FBBR_invalid_l1_cache(buf, count);
#endif /* DATACACHE_FBBR_ON */
if (DRM_read_file(file->h.handler, buf, count, &real_count) == FS_NO_ERROR)
{
return real_count;
}
else
{
return -1;
}
#endif /* __DRM_SUPPORT__ */
#ifdef ENCRYPT_JAR_FILE
}
else if (file->file_tag == ENCRYPTED_JAR_FILE)
{
kal_uint32 real_count = 0;
kal_uint32 pos = FS_Seek(file->h.handler, 0, SEEK_CUR);
#if DATACACHE_FBBR_ON
/* this function is only workable when DATACACHE_FBBR_ON is 1 */
buf = (char*)FBBR_invalid_l1_cache(buf, count);
#endif /* DATACACHE_FBBR_ON */
if (FS_Read(file->h.handler, buf, count, &real_count) == FS_NO_ERROR)
{
decrypt_buffer(buf, file->f.encrypt_code, pos, real_count);
return real_count;
}
else
{
return -1;
}
#endif /* ENCRYPT_JAR_FILE */
}
else if (file->file_tag == VIRTUAL_FILE_TAG)
{
kal_int32 file_size = file->f.filesize;
kal_int32 position = file->h.position;
kal_uint8 *file_data = file->filedata + position;
if (file_size < position)
{
return -1;
}
if (file_size < position + count)
{
count = file_size - position;
}
file->h.position += count;
memcpy(buf, file_data, count);
return count;
}
else
{
return -1;
}
}
/*****************************************************************************
* FUNCTION
* jvm_file_write
* DESCRIPTION
*
* PARAMETERS
* handle [IN]
* buf [IN]
* count [IN]
* RETURNS
*
*****************************************************************************/
int jvm_file_write(int handle, const void *buf, int count)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_uint32 real_count = 0;
pvfile file = (pvfile) handle;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (handle < 0)
{
return -1;
}
if ((file->file_tag == NORMAL_FILE_TAG))
{
#if DATACACHE_FBBR_ON
/* this function is only workable when DATACACHE_FBBR_ON is 1 */
buf = (const void*)FBBR_invalid_l1_cache((void*)buf, count);
#endif /* DATACACHE_FBBR_ON */
if (FS_Write(file->h.handler, (void*)buf, count, &real_count) == FS_NO_ERROR)
{
return real_count;
}
else
{
return -1;
}
}
else
#ifdef ENCRYPT_JAR_FILE
if (file->file_tag == ENCRYPTED_JAR_FILE)
{
ASSERT(0);
}
#endif /* ENCRYPT_JAR_FILE */
return -1;
}
/*****************************************************************************
* FUNCTION
* jvm_file_lseek
* DESCRIPTION
*
* PARAMETERS
* handle [IN]
* offset [IN]
* whence [IN]
* RETURNS
*
*****************************************************************************/
int jvm_file_lseek(int handle, int offset, int whence)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
pvfile file = (pvfile) handle;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (handle < 0)
{
return -1;
}
if (file->file_tag == NORMAL_FILE_TAG || file->file_tag == ENCRYPTED_JAR_FILE)
{
int result = FS_Seek(file->h.handler, offset, whence);
if (result < 0)
{
return -1;
}
else
{
return result;
}
#ifdef __DRM_SUPPORT__
}
else if (file->file_tag == DRM_FILE_TAG)
{
int result = DRM_seek_file(file->h.handler, offset, (kal_uint8) whence);
if (result < 0)
{
return -1;
}
else
{
return result;
}
#endif /* __DRM_SUPPORT__ */
}
else if (file->file_tag == VIRTUAL_FILE_TAG)
{
int position = file->h.position;
switch (whence)
{
case SEEK_SET:
position = offset;
break;
case SEEK_CUR:
position += offset;
break;
case SEEK_END:
position = file->f.filesize + offset;
break;
default:
return -1;
break;
}
if (position < 0 || position > file->f.filesize)
{
return EOF;
}
file->h.position = position;
return position;
}
return -1;
}
/*****************************************************************************
* FUNCTION
* jvm_file_getc
* DESCRIPTION
*
* PARAMETERS
* handle [IN]
* RETURNS
*
*****************************************************************************/
int jvm_file_getc(int handle)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
unsigned char buffer;
int read_bytes = Kread(handle, (void*)&buffer, 1);
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (read_bytes != 1)
{
return (-1);
}
else
{
return ((int)buffer);
}
}
/*****************************************************************************
* FUNCTION
* jvm_file_truncate
* DESCRIPTION
*
* PARAMETERS
* handle [IN]
* length [IN]
* RETURNS
*
*****************************************************************************/
int jvm_file_truncate(int handle, int length)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
pvfile file = (pvfile) handle;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (handle < 0)
{
return -1;
}
if ((file->file_tag == NORMAL_FILE_TAG))
{
if (FS_Seek(file->h.handler, length, FS_FILE_BEGIN) >= 0)
{
if (FS_Truncate(file->h.handler) == FS_NO_ERROR)
{
return handle;
}
}
}
return -1;
}
/*****************************************************************************
* FUNCTION
* jvm_file_getsize
* DESCRIPTION
*
* PARAMETERS
* handle [IN]
* sz_ptr [?]
* RETURNS
*
*****************************************************************************/
int jvm_file_getsize(int handle, kal_uint32 *sz_ptr)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
pvfile file = (pvfile) handle;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (handle < 0)
{
return -1;
}
if (file->file_tag == NORMAL_FILE_TAG || file->file_tag == ENCRYPTED_JAR_FILE)
{
if (FS_GetFileSize(file->h.handler, sz_ptr) == FS_NO_ERROR)
{
return 1;
}
else
{
return 0;
}
#ifdef __DRM_SUPPORT__
}
else if (file->file_tag == DRM_FILE_TAG)
{
if (DRM_file_size(file->h.handler, sz_ptr) == FS_NO_ERROR || *sz_ptr != 0)
{
return 1;
}
else
{
return 0;
}
#endif /* __DRM_SUPPORT__ */
}
else if (file->file_tag == VIRTUAL_FILE_TAG)
{
*sz_ptr = (kal_uint32) file->f.filesize;
return 1;
}
return -1;
}
/*****************************************************************************
* FUNCTION
* jvm_file_findfirst
* DESCRIPTION
*
* PARAMETERS
* string [?]
* RETURNS
*
*****************************************************************************/
char *jvm_file_findfirst(char *string)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
FS_DOSDirEntry info;
WCHAR name_pattern[MAX_WCHAR_FILENAME_LEN];
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (string[0] == 0)
{
find_file_is_java_dir = KAL_TRUE;
}
else
{
find_file_is_java_dir = KAL_FALSE;
}
find_file_from_vitual_file = KAL_FALSE;
find_file_vitual_file_id = 0;
findString = string;
kal_wsprintf(name_pattern, "%s\\%s*", work_dir_path, string);
KVM_FindFilehandle = FS_FindFirst(name_pattern, 0, 0, &info, WCHARFilename, 2 * MAX_WCHAR_FILENAME_LEN);
if (KVM_FindFilehandle > 0)
{
kal_dchar2char(WCHARFilename, CHARFilename);
return CHARFilename;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -