You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1502 lines
27 KiB
C++
1502 lines
27 KiB
C++
/*****************************************************************************
|
|
* FileName : DSFileSystem.c *
|
|
* Programmer : AAAwen *
|
|
* Writen at : 2005.05.10 *
|
|
* Version : 1.0 *
|
|
* Description: 定义文件系统用来管理存储在flash中的文件 *
|
|
* Last modify: 2005.05.10 *
|
|
*****************************************************************************/
|
|
#ifdef OS_WINDOWS
|
|
#include <direct.h>
|
|
#include <stdlib.h>
|
|
#endif
|
|
#include "DSFileSystem.h"
|
|
#include "basefunc.h"
|
|
#include "common.h"
|
|
#include "os_heap.h"
|
|
#include "basetype.h"
|
|
#include <string.h>
|
|
|
|
extern char IniFilePath[256];
|
|
|
|
long LoadFile(const char *szFileName, char **ppDestMem)
|
|
{
|
|
FILE *fp;
|
|
size_t uReadLen, uContentLen;
|
|
char szDbg[128];
|
|
long lContentLen;
|
|
|
|
*ppDestMem = NULL;
|
|
if(NULL == szFileName)
|
|
{
|
|
sprintf(szDbg, "szFileName is NULL.\n");
|
|
DebugPrint(szDbg);
|
|
return 0;
|
|
}
|
|
|
|
fp = fopen(szFileName, "rb");
|
|
if(NULL == fp)
|
|
{
|
|
sprintf(szDbg, "<%s>: open is Error.\n", szFileName);
|
|
DebugPrint(szDbg);
|
|
return 0;
|
|
}
|
|
|
|
if(fseek(fp, 0, SEEK_END) != 0)
|
|
{
|
|
fclose(fp);
|
|
sprintf(szDbg, "<%s>: SeekEnd is Error.\n", szFileName);
|
|
DebugPrint(szDbg);
|
|
return 0;
|
|
}
|
|
|
|
lContentLen = ftell(fp);
|
|
if(lContentLen <= 0)
|
|
{
|
|
fclose(fp);
|
|
sprintf(szDbg, "<%s>: Content is Error.\n", szFileName);
|
|
DebugPrint(szDbg);
|
|
return 0;
|
|
}
|
|
|
|
*ppDestMem = (char *)HEAP_MALLOC(lContentLen);
|
|
uContentLen = (size_t)lContentLen;
|
|
|
|
fseek(fp, 0, SEEK_SET);
|
|
uReadLen = fread(*ppDestMem, sizeof(char), uContentLen, fp);
|
|
fclose(fp);
|
|
if(uReadLen != uContentLen)
|
|
{
|
|
sprintf(szDbg, "<%s>: ReadLen=%d don't equal ContentLen=%d.\n",
|
|
szFileName, uReadLen, uContentLen);
|
|
DebugPrint(szDbg);
|
|
|
|
if(feof(fp) != 0)
|
|
{
|
|
HEAP_FREE(*ppDestMem);
|
|
*ppDestMem = NULL;
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
lContentLen = uReadLen;
|
|
}
|
|
}
|
|
|
|
return lContentLen;
|
|
}
|
|
|
|
long LoadFileInDSFS(const char *szFileName, char **ppDestMem, BYTE *pFSAddr)
|
|
{
|
|
int i;
|
|
char szDbg[128];
|
|
long lContentLen;
|
|
BYTE *pMoveBuf;
|
|
DSFILEHEAD *pFileHead;
|
|
DSFILESYSTEMHEAD *pFileSystemHead;
|
|
|
|
*ppDestMem = NULL;
|
|
pFileHead = NULL;
|
|
if(NULL == szFileName)
|
|
{
|
|
sprintf(szDbg, "szFileName is NULL.\n");
|
|
DebugPrint(szDbg);
|
|
return 0;
|
|
}
|
|
|
|
if(NULL == pFSAddr)
|
|
{
|
|
sprintf(szDbg, "FileSystem Addr is NULL.\n");
|
|
DebugPrint(szDbg);
|
|
return 0;
|
|
}
|
|
|
|
pFileSystemHead = (DSFILESYSTEMHEAD *)pFSAddr;
|
|
|
|
pMoveBuf = pFSAddr+pFileSystemHead->m_iOffset;
|
|
for(i=0; i<pFileSystemHead->m_iFiles; i++)
|
|
{
|
|
pFileHead = (DSFILEHEAD *)pMoveBuf;
|
|
|
|
if(CmpString2(&pFileHead->m_FileName[0], szFileName))
|
|
{
|
|
break;
|
|
}
|
|
|
|
pMoveBuf += pFileHead->m_iFileSize + sizeof(DSFILEHEAD) - 1;
|
|
}
|
|
|
|
if(i >= pFileSystemHead->m_iFiles)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
lContentLen = pFileHead->m_iFileSize-pFileHead->m_iFileNameLen;
|
|
if(lContentLen <= 0)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
*ppDestMem = (char *)HEAP_MALLOC(lContentLen);
|
|
if(*ppDestMem == NULL)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
memcpy(*ppDestMem, pMoveBuf+pFileHead->m_iOffset, lContentLen);
|
|
|
|
return lContentLen;
|
|
}
|
|
|
|
int DS_Seek(FILECONTENT *stream, long offset, int origin)
|
|
{
|
|
int iRetval;
|
|
|
|
iRetval = 0;
|
|
|
|
switch(origin)
|
|
{
|
|
case SEEK_CUR:
|
|
if((stream->m_lOffset + offset) < stream->m_lContentLen)
|
|
{
|
|
stream->m_lOffset += offset;
|
|
}
|
|
else
|
|
{
|
|
iRetval = -1;
|
|
}
|
|
break;
|
|
case SEEK_END:
|
|
if(stream->m_lContentLen > 0)
|
|
{
|
|
stream->m_lOffset = stream->m_lContentLen - 1;
|
|
}
|
|
else
|
|
{
|
|
iRetval = -1;
|
|
}
|
|
break;
|
|
case SEEK_SET:
|
|
if((offset < stream->m_lContentLen)
|
|
&& (offset >= 0))
|
|
{
|
|
stream->m_lOffset = offset;
|
|
}
|
|
else
|
|
{
|
|
iRetval = -1;
|
|
}
|
|
break;
|
|
default:
|
|
iRetval = -1;
|
|
break;
|
|
}
|
|
|
|
return iRetval;
|
|
}
|
|
|
|
char *DS_Gets(char *pDest, int iDestMax, FILECONTENT *stream)
|
|
{
|
|
int i, j;
|
|
BOOL bExit;
|
|
|
|
if(stream == NULL)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
bExit = FALSE;
|
|
pDest[0] = 0;
|
|
for(j=0, i=stream->m_lOffset; i<(stream->m_lContentLen-1); i++)
|
|
{
|
|
if(TRUE == bExit)
|
|
{
|
|
break;
|
|
}
|
|
|
|
if(stream->m_pContent[i] == 0)
|
|
{
|
|
bExit = TRUE;
|
|
continue;
|
|
}
|
|
|
|
if(stream->m_pContent[i] == '\r')
|
|
{
|
|
if(i < (stream->m_lContentLen-2))
|
|
{
|
|
if(stream->m_pContent[i+1] == '\n')
|
|
{
|
|
i++;
|
|
bExit = TRUE;
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(stream->m_pContent[i] == '\n')
|
|
{
|
|
bExit = TRUE;
|
|
continue;
|
|
}
|
|
|
|
pDest[j++] = stream->m_pContent[i];
|
|
if(j >= (iDestMax-1))
|
|
{
|
|
bExit = TRUE;
|
|
}
|
|
}
|
|
|
|
stream->m_lOffset = i;
|
|
|
|
if(j > 0)
|
|
{
|
|
pDest[j] = 0;
|
|
}
|
|
else
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
return pDest;
|
|
}
|
|
|
|
int GetFileLen(FILE *fp)
|
|
{
|
|
int iLen;
|
|
|
|
fseek(fp, 0, SEEK_END);
|
|
iLen = ftell(fp);
|
|
|
|
return iLen;
|
|
}
|
|
|
|
HDSFILE DSOpenFile(const char *szFileName)
|
|
{
|
|
HDSFILE hFile;
|
|
char szDbg[128];
|
|
BYTE *pFSAddr;
|
|
|
|
if(NULL == szFileName)
|
|
{
|
|
sprintf(szDbg, "szFileName is NULL.\n");
|
|
DebugPrint(szDbg);
|
|
return NULL;
|
|
}
|
|
|
|
hFile = (HDSFILE)HEAP_MALLOC(sizeof(DSFILE));
|
|
memset(hFile, 0, sizeof(DSFILE));
|
|
#ifdef OS_LINUX
|
|
// 首4个字节文文件系统的长度
|
|
pFSAddr = (BYTE *)(MCF5272_FRAMBAR + DS_FILESYSTEM_ADDR+4);
|
|
hFile->m_lContentLen = LoadFileInDSFS(szFileName, &hFile->m_pContent, pFSAddr);
|
|
#else
|
|
//hFile->m_lContentLen = LoadFile(szFileName, &hFile->m_pContent);
|
|
// wen 2005.06.15 test
|
|
pFSAddr = FsReadCombinFile("DSFileSystem.dfs");
|
|
if(NULL != pFSAddr)
|
|
{
|
|
//getcwd(szCurDir, sizeof(szCurDir));
|
|
const char *ptr = szFileName+strlen(IniFilePath)+1;
|
|
hFile->m_lContentLen = LoadFileInDSFS(ptr, &hFile->m_pContent, pFSAddr);
|
|
HEAP_FREE(pFSAddr);
|
|
}
|
|
#endif
|
|
if(hFile->m_lContentLen <= 0)
|
|
{
|
|
HEAP_FREE(hFile);
|
|
hFile = NULL;
|
|
}
|
|
|
|
return hFile;
|
|
}
|
|
|
|
HDSFILE DSOpenFileEx(const char *szFileName)
|
|
{
|
|
FILE *fp;
|
|
HDSFILE hFile;
|
|
//char szDbg[128];
|
|
|
|
hFile = (HDSFILE)HEAP_MALLOC(sizeof(DSFILE));
|
|
memset(hFile, 0, sizeof(DSFILE));
|
|
|
|
fp = fopen(szFileName, "rb");
|
|
if(!fp)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
fseek(fp, 0, SEEK_END);
|
|
hFile->m_lContentLen = ftell(fp);
|
|
hFile->m_pContent = (char *)HEAP_MALLOC(hFile->m_lContentLen);
|
|
fseek(fp, 0, SEEK_SET);
|
|
fread(hFile->m_pContent, 1, hFile->m_lContentLen, fp);
|
|
fclose(fp);
|
|
|
|
if(hFile->m_lContentLen <= 0)
|
|
{
|
|
HEAP_FREE(hFile);
|
|
hFile = NULL;
|
|
}
|
|
|
|
return hFile;
|
|
}
|
|
|
|
|
|
HDSFILE DSOpenFileEx3(const char *szRootDir, const char *szFileName)
|
|
{
|
|
HDSFILE hFile;
|
|
char szDbg[128];
|
|
BYTE *pFSAddr;
|
|
#ifndef OS_LINUX
|
|
char szFileSystem[512];
|
|
#endif
|
|
|
|
if(NULL == szFileName)
|
|
{
|
|
sprintf(szDbg, "szFileName is NULL.\n");
|
|
DebugPrint(szDbg);
|
|
return NULL;
|
|
}
|
|
|
|
hFile = (HDSFILE)HEAP_MALLOC(sizeof(DSFILE));
|
|
memset(hFile, 0, sizeof(DSFILE));
|
|
#ifdef OS_LINUX
|
|
// 首4个字节文文件系统的长度
|
|
pFSAddr = (BYTE *)(MCF5272_FRAMBAR + DS_FILESYSTEM_ADDR+4);
|
|
hFile->m_lContentLen = LoadFileInDSFS(szFileName, &hFile->m_pContent, pFSAddr);
|
|
#else
|
|
sprintf(szFileSystem, "%s/DSFileSystem.dfs", szRootDir);
|
|
pFSAddr = FsReadCombinFileEx(szFileSystem);
|
|
if(NULL != pFSAddr)
|
|
{
|
|
hFile->m_lContentLen = LoadFileInDSFS(szFileName, &hFile->m_pContent, pFSAddr);
|
|
HEAP_FREE(pFSAddr);
|
|
}
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
#endif
|
|
if(hFile->m_lContentLen <= 0)
|
|
{
|
|
HEAP_FREE(hFile);
|
|
hFile = NULL;
|
|
}
|
|
|
|
return hFile;
|
|
}
|
|
|
|
HDSFILE DSOpenFileEx2(const char *szRootDir, const char *szFSName, const char *szFileName)
|
|
{
|
|
HDSFILE hFile;
|
|
char szDbg[128];
|
|
BYTE *pFSAddr;
|
|
#ifndef OS_LINUX
|
|
char szFileSystem[512];
|
|
#endif
|
|
|
|
if(NULL == szFileName)
|
|
{
|
|
sprintf(szDbg, "szFileName is NULL.\n");
|
|
DebugPrint(szDbg);
|
|
return NULL;
|
|
}
|
|
|
|
hFile = (HDSFILE)HEAP_MALLOC(sizeof(DSFILE));
|
|
memset(hFile, 0, sizeof(DSFILE));
|
|
#ifdef OS_LINUX
|
|
// 首4个字节文文件系统的长度
|
|
pFSAddr = (BYTE *)(MCF5272_FRAMBAR + DS_FILESYSTEM_ADDR+4);
|
|
hFile->m_lContentLen = LoadFileInDSFS(szFileName, &hFile->m_pContent, pFSAddr);
|
|
#else
|
|
sprintf(szFileSystem, "%s/%s", szRootDir, szFSName);
|
|
pFSAddr = FsReadCombinFileEx(szFileSystem);
|
|
if(NULL != pFSAddr)
|
|
{
|
|
hFile->m_lContentLen = LoadFileInDSFS(szFileName, &hFile->m_pContent, pFSAddr);
|
|
HEAP_FREE(pFSAddr);
|
|
}
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
#endif
|
|
if(hFile->m_lContentLen <= 0)
|
|
{
|
|
HEAP_FREE(hFile);
|
|
hFile = NULL;
|
|
}
|
|
|
|
return hFile;
|
|
}
|
|
|
|
BOOL DSCloseFile(HDSFILE hFile)
|
|
{
|
|
if(hFile->m_pContent != NULL)
|
|
{
|
|
HEAP_FREE(hFile->m_pContent);
|
|
hFile->m_pContent = NULL;
|
|
}
|
|
|
|
HEAP_FREE(hFile);
|
|
return TRUE;
|
|
}
|
|
|
|
size_t DSfread(void *buffer, size_t size, size_t count, HDSFILE hFile)
|
|
{
|
|
size_t RealBytes, RemainLen;
|
|
|
|
if(hFile == NULL)
|
|
{
|
|
return 0;
|
|
}
|
|
if(hFile->m_lContentLen <= 0)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
RealBytes = size*count;
|
|
if(RealBytes <= 0)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
if(DSfeof(hFile) == 0)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
RemainLen = hFile->m_lContentLen - hFile->m_lOffset;
|
|
if(RealBytes > RemainLen)
|
|
{
|
|
RealBytes = RemainLen / size;
|
|
if(RealBytes <= 0)
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
memcpy(buffer, hFile->m_pContent+hFile->m_lOffset, RealBytes*size);
|
|
|
|
hFile->m_lOffset += RealBytes*size;
|
|
|
|
return RealBytes;
|
|
}
|
|
|
|
char *DSfgets(char *string, int iMaxSize, HDSFILE hFile)
|
|
{
|
|
int i, j;
|
|
BOOL bExit;
|
|
#if 0
|
|
FILE *fp;
|
|
char szfilename[128];
|
|
|
|
#ifdef OS_LINUX
|
|
strcpy(szfilename, "/log/dsdebug.txt");
|
|
#else
|
|
strcpy(szfilename, "dsdebug.txt");
|
|
#endif
|
|
#endif
|
|
|
|
if(hFile == NULL)
|
|
{
|
|
return NULL;
|
|
}
|
|
if(hFile->m_lContentLen <= 0)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
bExit = FALSE;
|
|
string[0] = 0;
|
|
for(j=0, i=hFile->m_lOffset; i<hFile->m_lContentLen; i++)
|
|
{
|
|
if(TRUE == bExit)
|
|
{
|
|
break;
|
|
}
|
|
|
|
if(hFile->m_pContent[i] == 0)
|
|
{
|
|
bExit = TRUE;
|
|
continue;
|
|
}
|
|
|
|
if(hFile->m_pContent[i] == '\r')
|
|
{
|
|
if(i < (hFile->m_lContentLen-2))
|
|
{
|
|
if(hFile->m_pContent[i+1] == '\n')
|
|
{
|
|
i++;
|
|
bExit = TRUE;
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(hFile->m_pContent[i] == '\n')
|
|
{
|
|
bExit = TRUE;
|
|
continue;
|
|
}
|
|
|
|
string[j++] = hFile->m_pContent[i];
|
|
if(j >= (iMaxSize-1))
|
|
{
|
|
bExit = TRUE;
|
|
}
|
|
}
|
|
|
|
hFile->m_lReadCount += i - hFile->m_lOffset;
|
|
hFile->m_lOffset = i;
|
|
|
|
if(j > 0)
|
|
{
|
|
string[j] = 0;
|
|
}
|
|
else
|
|
{
|
|
if(i >= hFile->m_lContentLen)
|
|
{
|
|
return NULL;
|
|
}
|
|
else
|
|
{
|
|
string[0] = 0;
|
|
}
|
|
}
|
|
|
|
#if 0
|
|
fp = fopen(szfilename, "ab");
|
|
fwrite(string, 1, strlen(string), fp);
|
|
fwrite("\r\n", 1, strlen("\r\n"), fp);
|
|
fclose(fp);
|
|
#endif
|
|
|
|
return string;
|
|
}
|
|
|
|
char *DSfgetsEx(char *string, int iMaxSize, HDSFILE hFile)
|
|
{
|
|
int i, j;
|
|
BOOL bExit;
|
|
#if 0
|
|
FILE *fp;
|
|
char szfilename[128];
|
|
|
|
#ifdef OS_LINUX
|
|
strcpy(szfilename, "/log/dsdebug.txt");
|
|
#else
|
|
strcpy(szfilename, "dsdebug.txt");
|
|
#endif
|
|
#endif
|
|
|
|
if(hFile == NULL)
|
|
{
|
|
return NULL;
|
|
}
|
|
if(hFile->m_lContentLen <= 0)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
bExit = FALSE;
|
|
string[0] = 0;
|
|
i=hFile->m_lOffset+hFile->m_lReadCount;
|
|
for(j=0; i<hFile->m_lContentLen; i++)
|
|
{
|
|
if(TRUE == bExit)
|
|
{
|
|
break;
|
|
}
|
|
|
|
if(hFile->m_pContent[i] == 0)
|
|
{
|
|
bExit = TRUE;
|
|
continue;
|
|
}
|
|
|
|
if(hFile->m_pContent[i] == '\r')
|
|
{
|
|
if(i < (hFile->m_lContentLen-2))
|
|
{
|
|
if(hFile->m_pContent[i+1] == '\n')
|
|
{
|
|
i++;
|
|
bExit = TRUE;
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(hFile->m_pContent[i] == '\n')
|
|
{
|
|
bExit = TRUE;
|
|
continue;
|
|
}
|
|
|
|
string[j++] = hFile->m_pContent[i];
|
|
if(j >= (iMaxSize-1))
|
|
{
|
|
bExit = TRUE;
|
|
}
|
|
}
|
|
|
|
hFile->m_lReadCount = i - hFile->m_lOffset;
|
|
|
|
if(j > 0)
|
|
{
|
|
string[j] = 0;
|
|
}
|
|
else
|
|
{
|
|
if(i >= hFile->m_lContentLen)
|
|
{
|
|
return NULL;
|
|
}
|
|
else
|
|
{
|
|
string[0] = 0;
|
|
}
|
|
}
|
|
|
|
#if 0
|
|
fp = fopen(szfilename, "ab");
|
|
fwrite(string, 1, strlen(string), fp);
|
|
fwrite("\r\n", 1, strlen("\r\n"), fp);
|
|
fclose(fp);
|
|
#endif
|
|
|
|
return string;
|
|
}
|
|
|
|
int DSfgetreadcount(HDSFILE hFile)
|
|
{
|
|
return hFile->m_lReadCount;
|
|
}
|
|
|
|
int DSfseek(HDSFILE hFile, long offset, int origin)
|
|
{
|
|
int iRetval;
|
|
|
|
iRetval = 0;
|
|
|
|
switch(origin)
|
|
{
|
|
case SEEK_CUR:
|
|
if((hFile->m_lOffset + offset) < 0)
|
|
{
|
|
iRetval = -1;
|
|
break;
|
|
}
|
|
|
|
hFile->m_lOffset += offset;
|
|
break;
|
|
case SEEK_CUR_EX:
|
|
if((hFile->m_lReadCount - offset) < 0)
|
|
{
|
|
iRetval = -1;
|
|
break;
|
|
}
|
|
|
|
if(offset != 0)
|
|
{
|
|
if((hFile->m_lOffset + offset) < 0)
|
|
{
|
|
iRetval = -1;
|
|
break;
|
|
}
|
|
|
|
hFile->m_lOffset += offset;
|
|
hFile->m_lReadCount -= offset;
|
|
}
|
|
else
|
|
{
|
|
hFile->m_lOffset += hFile->m_lReadCount;
|
|
hFile->m_lReadCount = 0;
|
|
}
|
|
break;
|
|
case SEEK_END:
|
|
if(hFile->m_lContentLen > 0)
|
|
{
|
|
hFile->m_lOffset = hFile->m_lContentLen;
|
|
}
|
|
else
|
|
{
|
|
iRetval = -1;
|
|
}
|
|
break;
|
|
case SEEK_SET:
|
|
if(offset < 0)
|
|
{
|
|
iRetval = -1;
|
|
break;
|
|
}
|
|
|
|
if(offset > hFile->m_lContentLen)
|
|
{
|
|
iRetval = -1;
|
|
}
|
|
else
|
|
{
|
|
hFile->m_lOffset = offset;
|
|
}
|
|
break;
|
|
case SEEK_CLR_RCNT:
|
|
hFile->m_lReadCount = 0;
|
|
break;
|
|
default:
|
|
iRetval = -1;
|
|
break;
|
|
}
|
|
|
|
return iRetval;
|
|
}
|
|
|
|
int DSfeof(HDSFILE hFile)
|
|
{
|
|
if(hFile->m_lOffset >= hFile->m_lContentLen)
|
|
{
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
int DSfeofEx(HDSFILE hFile)
|
|
{
|
|
if((hFile->m_lOffset+hFile->m_lReadCount) >= hFile->m_lContentLen)
|
|
{
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
int DSfeob(HDSFILE hFile)
|
|
{
|
|
if(hFile->m_lReadCount >= hFile->m_lContentLen)
|
|
{
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
return hFile->m_lReadCount;
|
|
}
|
|
}
|
|
|
|
int DSftell(HDSFILE hFile)
|
|
{
|
|
return hFile->m_lOffset;
|
|
}
|
|
|
|
int DSHaveSection(char *pSection, HDSFILE hFile)
|
|
{
|
|
int iSrcLen, iMaxLen;
|
|
|
|
if(strstr(hFile->m_szSection, pSection))
|
|
{
|
|
return hFile->m_lSectionOk;
|
|
}
|
|
else
|
|
{
|
|
iSrcLen = strlen(pSection);
|
|
iMaxLen = sizeof(hFile->m_szSection)-1;
|
|
if(iSrcLen > iMaxLen)
|
|
{
|
|
hFile->m_szSection[0] = 0;
|
|
hFile->m_lSectionOk = DS_SECTION_NOEXIST;
|
|
return DS_SECTION_OUT;
|
|
}
|
|
else
|
|
{
|
|
strcpy(hFile->m_szSection, pSection);
|
|
hFile->m_lSectionOk = DS_SECTION_NOEXIST;
|
|
hFile->m_lSectionOffset = hFile->m_lOffset;
|
|
hFile->m_lSectionLines = 0;
|
|
hFile->m_lSectionLinesAddFlag = 1;
|
|
}
|
|
}
|
|
|
|
return DS_SECTION_SEARCH;
|
|
}
|
|
|
|
int DSSaveSectionOffset(HDSFILE hFile)
|
|
{
|
|
hFile->m_lSectionOffset = hFile->m_lOffset;
|
|
hFile->m_lSectionLines = 0;
|
|
hFile->m_lSectionLinesAddFlag = 1;
|
|
hFile->m_lSectionOk = DS_SECTION_EXIST;
|
|
|
|
return 1;
|
|
}
|
|
|
|
int DSRestoreSectionOffset(HDSFILE hFile)
|
|
{
|
|
hFile->m_lOffset = hFile->m_lSectionOffset;
|
|
|
|
return hFile->m_lOffset;
|
|
}
|
|
|
|
int DSAddSectionLines(int iLines, HDSFILE hFile)
|
|
{
|
|
if(hFile->m_lSectionLinesAddFlag > 0)
|
|
{
|
|
hFile->m_lSectionLines += iLines;
|
|
}
|
|
|
|
return hFile->m_lSectionLines;
|
|
}
|
|
|
|
int DSSubSectionLines(int iLines, HDSFILE hFile)
|
|
{
|
|
if(hFile->m_lSectionLinesAddFlag > 0)
|
|
{
|
|
hFile->m_lSectionLines -= iLines;
|
|
if(hFile->m_lSectionLines < 0)
|
|
{
|
|
hFile->m_lSectionLines = 0;
|
|
}
|
|
}
|
|
|
|
return hFile->m_lSectionLines;
|
|
}
|
|
|
|
int DSSetSectionLinesAddFlag(int iFlag, HDSFILE hFile)
|
|
{
|
|
hFile->m_lSectionLinesAddFlag = iFlag;
|
|
return iFlag;
|
|
}
|
|
|
|
int DSSectionisOver(int iReadLines, HDSFILE hFile)
|
|
{
|
|
if(hFile->m_lSectionLinesAddFlag)
|
|
{
|
|
return 0;
|
|
}
|
|
else if(hFile->m_lSectionLines <= iReadLines)
|
|
{
|
|
//DSRestoreSectionOffset(hFile);
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
BOOL FsCombinAllFile(const char *szListFileName, const char *szDestFileName, const char *szDestDir)
|
|
{
|
|
BOOL bReturn, bNetSequence;
|
|
int iLen, iFileLen, iRealLen, iOffset;
|
|
int iWriteLen, iFileOffset, iBufLen;
|
|
FILE *fp, *fp_dest, *fp_file;
|
|
char szDbg[512], szFileName[256], szList[128], *ptr;
|
|
BYTE *pBuf;
|
|
DSFILEHEAD sFileHead;
|
|
DSFILESYSTEMHEAD sFileSystemHead;
|
|
|
|
if(NULL == szListFileName)
|
|
{
|
|
sprintf(szDbg, "szListFileName is NULL.\n");
|
|
DebugPrint(szDbg);
|
|
return FALSE;
|
|
}
|
|
|
|
sprintf(szFileName, "%s\\%s", szDestDir, szListFileName);
|
|
fp = fopen(szFileName, "rb");
|
|
if(NULL == fp)
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
#ifdef OS_WINDOWS
|
|
sprintf(szFileName, "%s\\%s", szDestDir, szDestFileName);
|
|
#else
|
|
strcpy(szFileName, szDestFileName);
|
|
#endif
|
|
fp_dest = fopen(szFileName, "wb");
|
|
if(NULL == fp_dest)
|
|
{
|
|
fclose(fp);
|
|
return FALSE;
|
|
}
|
|
|
|
bNetSequence = IsNetSequence();
|
|
|
|
sFileSystemHead.m_iFiles = 0;
|
|
sFileSystemHead.m_iOffset = sizeof(DSFILESYSTEMHEAD);
|
|
fseek(fp_dest, sFileSystemHead.m_iOffset, SEEK_SET);
|
|
|
|
bReturn = TRUE;
|
|
iBufLen = sizeof(szList)-1;
|
|
while(fgets(szList, iBufLen, fp) != NULL)
|
|
{
|
|
szList[iBufLen] = 0;
|
|
//ptr = strstr(szList, "\r");
|
|
ptr = strchr(szList, '\r');
|
|
if(ptr != NULL)
|
|
{
|
|
*ptr = 0;
|
|
}
|
|
//ptr = strstr(szList, "\n");
|
|
ptr = strchr(szList, '\n');
|
|
if(ptr != NULL)
|
|
{
|
|
*ptr = 0;
|
|
}
|
|
|
|
iLen = strlen(szDestDir)+strlen(szList)+2;
|
|
if(iLen > sizeof(szFileName))
|
|
{
|
|
sprintf(szDbg, "文件名称长度(%d > %d)过长", iLen, sizeof(szFileName));
|
|
DebugPrint(szDbg);
|
|
bReturn = FALSE;
|
|
continue;
|
|
}
|
|
|
|
sprintf(szFileName, "%s\\%s", szDestDir, szList);
|
|
fp_file = fopen(szFileName, "rb");
|
|
if(NULL == fp_file)
|
|
{
|
|
sprintf(szDbg, "文件<%s>不存在或者打开错误.", szFileName);
|
|
DebugPrint(szDbg);
|
|
bReturn = FALSE;
|
|
continue;
|
|
}
|
|
|
|
// 写文件出错后,恢复的位置
|
|
iFileOffset = ftell(fp_dest);
|
|
|
|
// 文件的头结构
|
|
iFileLen = GetFileLen(fp_file);
|
|
fseek(fp_file, 0, SEEK_SET);
|
|
pBuf = (BYTE *)HEAP_MALLOC(iFileLen);
|
|
iRealLen = fread(pBuf, sizeof(BYTE), iFileLen, fp_file);
|
|
sFileHead.m_iFileNameLen = strlen(szList)+1;
|
|
sFileHead.m_iFileSize = sFileHead.m_iFileNameLen+iRealLen;
|
|
sFileHead.m_iOffset = sizeof(DSFILEHEAD)-1+sFileHead.m_iFileNameLen;
|
|
|
|
if(bNetSequence == FALSE)
|
|
{
|
|
SequenceHostToNet((char *)&sFileHead.m_iFileNameLen, sizeof(int));
|
|
SequenceHostToNet((char *)&sFileHead.m_iFileSize, sizeof(int));
|
|
SequenceHostToNet((char *)&sFileHead.m_iOffset, sizeof(int));
|
|
}
|
|
|
|
iWriteLen = fwrite((void *)&sFileHead, sizeof(BYTE), sizeof(DSFILEHEAD)-1, fp_dest);
|
|
if(iWriteLen < sizeof(DSFILEHEAD)-1)
|
|
{
|
|
iWriteLen = 0;
|
|
}
|
|
if(iWriteLen > 0)
|
|
{
|
|
iWriteLen = fwrite(szList, sizeof(char), strlen(szList)+1, fp_dest);
|
|
if(iWriteLen < (int)(strlen(szList)+1))
|
|
{
|
|
iWriteLen = 0;
|
|
}
|
|
}
|
|
if(iWriteLen > 0)
|
|
{
|
|
iWriteLen = fwrite(pBuf, sizeof(BYTE), iRealLen, fp_dest);
|
|
if(iWriteLen < iRealLen)
|
|
{
|
|
iWriteLen = 0;
|
|
}
|
|
}
|
|
if(iWriteLen > 0)
|
|
{
|
|
sFileSystemHead.m_iFiles++;
|
|
}
|
|
else
|
|
{
|
|
fseek(fp_dest, iFileOffset, SEEK_SET);
|
|
}
|
|
|
|
HEAP_FREE(pBuf);
|
|
fclose(fp_file);
|
|
}
|
|
|
|
// 文件系统的头结构
|
|
fseek(fp_dest, 0, SEEK_SET);
|
|
iOffset = sFileSystemHead.m_iOffset;
|
|
if(bNetSequence == FALSE)
|
|
{
|
|
SequenceHostToNet((char *)&sFileSystemHead.m_iFiles, sizeof(int));
|
|
SequenceHostToNet((char *)&sFileSystemHead.m_iOffset, sizeof(int));
|
|
}
|
|
fwrite((void *)&sFileSystemHead, sizeof(BYTE), iOffset, fp_dest);
|
|
|
|
fclose(fp);
|
|
fclose(fp_dest);
|
|
|
|
return bReturn;
|
|
}
|
|
|
|
BOOL FsSplitAllFile(const char *szCombinFile, const char *szDestDir)
|
|
{
|
|
BOOL bReturn, bNetSequence;
|
|
int i, iLen, iFileLen, iRealLen;
|
|
FILE *fp, *fp_dest;
|
|
char szDbg[512], szFileName[256];
|
|
BYTE *pBuf, *pMoveBuf;
|
|
DSFILEHEAD *pFileHead;
|
|
DSFILESYSTEMHEAD *pFileSystemHead;
|
|
|
|
if(NULL == szCombinFile)
|
|
{
|
|
sprintf(szDbg, "szCombinFile is NULL.\n");
|
|
DebugPrint(szDbg);
|
|
return FALSE;
|
|
}
|
|
|
|
strcpy(szFileName, szCombinFile);
|
|
fp = fopen(szFileName, "rb");
|
|
if(NULL == fp)
|
|
{
|
|
return FALSE;
|
|
}
|
|
iFileLen = GetFileLen(fp);
|
|
pBuf = (BYTE *)HEAP_MALLOC(iFileLen);
|
|
if(NULL == pBuf)
|
|
{
|
|
sprintf(szDbg, "malloc(%d) Error", iFileLen);
|
|
DebugPrint(szDbg);
|
|
fclose(fp);
|
|
return FALSE;
|
|
}
|
|
memset(pBuf, 0, iFileLen);
|
|
|
|
fseek(fp, 0, SEEK_SET);
|
|
iRealLen = fread(pBuf, sizeof(BYTE), iFileLen, fp);
|
|
|
|
bReturn = TRUE;
|
|
pFileSystemHead = (DSFILESYSTEMHEAD *)pBuf;
|
|
|
|
bNetSequence = IsNetSequence();
|
|
if(bNetSequence == FALSE)
|
|
{
|
|
SequenceNetToHost((char *)&pFileSystemHead->m_iFiles, sizeof(int));
|
|
SequenceNetToHost((char *)&pFileSystemHead->m_iOffset, sizeof(int));
|
|
}
|
|
|
|
pMoveBuf = pBuf+pFileSystemHead->m_iOffset;
|
|
for(i=0; i<pFileSystemHead->m_iFiles; i++)
|
|
{
|
|
pFileHead = (DSFILEHEAD *)pMoveBuf;
|
|
|
|
if(bNetSequence == FALSE)
|
|
{
|
|
SequenceNetToHost((char *)&pFileHead->m_iFileNameLen, sizeof(int));
|
|
SequenceNetToHost((char *)&pFileHead->m_iFileSize, sizeof(int));
|
|
SequenceNetToHost((char *)&pFileHead->m_iOffset, sizeof(int));
|
|
}
|
|
|
|
iLen = pFileHead->m_iFileNameLen+strlen(szDestDir)+2;
|
|
if(iLen > sizeof(szFileName))
|
|
{
|
|
sprintf(szDbg, "文件名称长度(%d > %d)过长", iLen, sizeof(szFileName));
|
|
DebugPrint(szDbg);
|
|
bReturn = FALSE;
|
|
break;
|
|
}
|
|
sprintf(szFileName, "%s\\%s", szDestDir, pFileHead->m_FileName);
|
|
fp_dest = fopen(szFileName, "wb");
|
|
if(fp_dest == NULL)
|
|
{
|
|
sprintf(szDbg, "文件<%s>打开错误.", szFileName);
|
|
DebugPrint(szDbg);
|
|
bReturn = FALSE;
|
|
break;
|
|
}
|
|
|
|
iFileLen = pFileHead->m_iFileSize - pFileHead->m_iFileNameLen;
|
|
fwrite(pMoveBuf+pFileHead->m_iOffset, sizeof(BYTE), iFileLen, fp_dest);
|
|
pMoveBuf += pFileHead->m_iFileSize+sizeof(DSFILEHEAD)-1;
|
|
fclose(fp_dest);
|
|
}
|
|
HEAP_FREE(pBuf);
|
|
fclose(fp);
|
|
|
|
return bReturn;
|
|
}
|
|
|
|
BYTE *FsReadCombinFile(const char *szCombinFile)
|
|
{
|
|
int iFileLen, iRealLen;
|
|
FILE *fp;
|
|
char szDbg[512], szFileName[256], filename[256];
|
|
BYTE *pBuf;
|
|
|
|
if(NULL == szCombinFile)
|
|
{
|
|
sprintf(szDbg, "szCombinFile is NULL.\n");
|
|
DebugPrint(szDbg);
|
|
return NULL;
|
|
}
|
|
#ifdef OS_LINUX
|
|
getcwd(filename, sizeof(filename));
|
|
#else
|
|
strcpy(filename, IniFilePath);
|
|
#endif //OS_LINUX
|
|
|
|
sprintf(szFileName, "%s/%s", filename, szCombinFile);
|
|
fp = fopen(szFileName, "rb");
|
|
if(NULL == fp)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
iFileLen = GetFileLen(fp);
|
|
fseek(fp, 0, SEEK_SET);
|
|
pBuf = (BYTE *)HEAP_MALLOC(iFileLen);
|
|
if(NULL == pBuf)
|
|
{
|
|
sprintf(szDbg, "malloc(%d) Error", iFileLen);
|
|
DebugPrint(szDbg);
|
|
fclose(fp);
|
|
return NULL;
|
|
}
|
|
memset(pBuf, 0, iFileLen);
|
|
|
|
iRealLen = fread(pBuf, sizeof(BYTE), iFileLen, fp);
|
|
|
|
fclose(fp);
|
|
|
|
// 将文件系统转换为主机字节格式
|
|
FsNetToHost(pBuf);
|
|
|
|
return pBuf;
|
|
}
|
|
|
|
BYTE *FsReadCombinFileEx(const char *szCombinFile)
|
|
{
|
|
int iFileLen, iRealLen;
|
|
FILE *fp;
|
|
char szDbg[512];
|
|
BYTE *pBuf;
|
|
|
|
if(NULL == szCombinFile)
|
|
{
|
|
sprintf(szDbg, "szCombinFile is NULL.\n");
|
|
DebugPrint(szDbg);
|
|
return NULL;
|
|
}
|
|
|
|
fp = fopen(szCombinFile, "rb");
|
|
if(NULL == fp)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
iFileLen = GetFileLen(fp);
|
|
fseek(fp, 0, SEEK_SET);
|
|
pBuf = (BYTE *)HEAP_MALLOC(iFileLen);
|
|
if(NULL == pBuf)
|
|
{
|
|
sprintf(szDbg, "malloc(%d) Error", iFileLen);
|
|
DebugPrint(szDbg);
|
|
fclose(fp);
|
|
return NULL;
|
|
}
|
|
memset(pBuf, 0, iFileLen);
|
|
|
|
iRealLen = fread(pBuf, sizeof(BYTE), iFileLen, fp);
|
|
|
|
fclose(fp);
|
|
|
|
// 将文件系统转换为主机字节格式
|
|
FsNetToHost(pBuf);
|
|
|
|
return pBuf;
|
|
}
|
|
|
|
BOOL FsLoadFileSystem(const char *szFileSystem, BYTE **ppDestBuf)
|
|
{
|
|
FILE *fp;
|
|
int iFileLen;
|
|
|
|
//#ifdef OS_WINDOWS
|
|
if(NULL == szFileSystem)
|
|
{
|
|
return FALSE;
|
|
}
|
|
fp = fopen(szFileSystem, "rb");
|
|
if(NULL == fp)
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
iFileLen = GetFileLen(fp);
|
|
*ppDestBuf = (BYTE *)HEAP_MALLOC(iFileLen);
|
|
fseek(fp, 0, SEEK_SET);
|
|
if(*ppDestBuf != NULL)
|
|
{
|
|
fread(*ppDestBuf, sizeof(BYTE), iFileLen, fp);
|
|
}
|
|
fclose(fp);
|
|
if(*ppDestBuf == NULL)
|
|
{
|
|
return FALSE;
|
|
}
|
|
/*#else
|
|
*ppDestBuf = (BYTE *)(MCF5272_FRAMBAR + DS_FILESYSTEM_ADDR+4);
|
|
#endif*/
|
|
|
|
// 将文件系统转换为主机字节格式
|
|
FsNetToHost(*ppDestBuf);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL FsUnLoadFileSystem(BYTE **ppDestBuf)
|
|
{
|
|
#ifdef OS_WINDOWS
|
|
if(*ppDestBuf != NULL)
|
|
{
|
|
HEAP_FREE(*ppDestBuf);
|
|
}
|
|
#endif
|
|
*ppDestBuf = NULL;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL FsDirFileName(const char *szPath, const char *szFileSystem)
|
|
{
|
|
int i;
|
|
DSFILEHEAD *pFileHead=NULL;
|
|
DSFILESYSTEMHEAD *pFileSystemHead = NULL;
|
|
BYTE *pBuf = NULL, *pMoveBuf = NULL;
|
|
BOOL bDisAll;
|
|
|
|
pMoveBuf = NULL;
|
|
if(FsLoadFileSystem(szFileSystem, &pBuf) == FALSE)
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
pMoveBuf = pBuf;
|
|
|
|
if(strcmp(szPath, "/") == 0)
|
|
{
|
|
bDisAll = TRUE;
|
|
}
|
|
else
|
|
{
|
|
bDisAll = FALSE;
|
|
}
|
|
pFileSystemHead = (DSFILESYSTEMHEAD *)pMoveBuf;
|
|
|
|
#ifdef OS_LINUX
|
|
printf("DFS: Files=%d\n", pFileSystemHead->m_iFiles);
|
|
#endif
|
|
|
|
for(i=0; i<pFileSystemHead->m_iFiles; i++)
|
|
{
|
|
if(i == 0)
|
|
{
|
|
pMoveBuf += pFileSystemHead->m_iOffset;
|
|
}
|
|
else
|
|
{
|
|
pMoveBuf += pFileHead->m_iFileSize+sizeof(DSFILEHEAD)-1;
|
|
}
|
|
|
|
pFileHead = (DSFILEHEAD *)pMoveBuf;
|
|
|
|
if((strstr(pFileHead->m_FileName, szPath) != NULL)
|
|
|| (bDisAll == TRUE))
|
|
{
|
|
#ifdef OS_WINDOWS
|
|
OutputDebugString((LPCWSTR)&pFileHead->m_FileName[0]);
|
|
OutputDebugString((LPCWSTR)"\n");
|
|
#else
|
|
printf("[at: 0x%08x]\t%s\n", pMoveBuf, &pFileHead->m_FileName[0]);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
FsUnLoadFileSystem(&pBuf);
|
|
return TRUE;
|
|
}
|
|
|
|
void FsDispHead(const char *szName, const char *szFileSystem)
|
|
{
|
|
int i;
|
|
char szDisp[128];
|
|
DSFILEHEAD *pFileHead=NULL;
|
|
DSFILESYSTEMHEAD *pFileSystemHead;
|
|
BYTE *pBuf, *pMoveBuf;
|
|
BOOL bDispAll;
|
|
|
|
if(FsLoadFileSystem(szFileSystem, &pBuf) == FALSE)
|
|
{
|
|
return;
|
|
}
|
|
|
|
pMoveBuf = pBuf;
|
|
|
|
pFileSystemHead = (DSFILESYSTEMHEAD *)pMoveBuf;
|
|
if(strcmp(szName, "fs") == 0)
|
|
{
|
|
printf("ds\\/>fs\n Files=%d\n offset=%d\n\n",\
|
|
pFileSystemHead->m_iFiles,\
|
|
pFileSystemHead->m_iOffset);
|
|
return;
|
|
}
|
|
|
|
if(strcmp(szName, "allfile") == 0)
|
|
{
|
|
bDispAll = TRUE;
|
|
}
|
|
else
|
|
{
|
|
bDispAll = FALSE;
|
|
}
|
|
|
|
pFileHead = (DSFILEHEAD *)pMoveBuf;
|
|
for(i=0; i<pFileSystemHead->m_iFiles; i++)
|
|
{
|
|
if(i == 0)
|
|
{
|
|
pMoveBuf += pFileSystemHead->m_iOffset;
|
|
}
|
|
else
|
|
{
|
|
pMoveBuf += pFileHead->m_iFileSize+sizeof(DSFILEHEAD)-1;
|
|
}
|
|
|
|
pFileHead = (DSFILEHEAD *)pMoveBuf;
|
|
if(bDispAll == FALSE)
|
|
{
|
|
if(strcmp(&pFileHead->m_FileName[0], szName))
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
|
|
#ifdef OS_WINDOWS
|
|
sprintf(szDisp, "ds\\/>%s\n filenamelen=%d\n filesize=%d\n offset=%d\n\n",\
|
|
&pFileHead->m_FileName[0], \
|
|
pFileHead->m_iFileNameLen, \
|
|
pFileHead->m_iFileSize, \
|
|
pFileHead->m_iOffset);
|
|
OutputDebugString((LPCWSTR)szDisp);
|
|
#else
|
|
printf("ds\\/>%s\n filenamelen=%d\n filesize=%d\n offset=%d\n\n",\
|
|
&pFileHead->m_FileName[0], \
|
|
pFileHead->m_iFileNameLen, \
|
|
pFileHead->m_iFileSize, \
|
|
pFileHead->m_iOffset);
|
|
#endif
|
|
if(bDispAll == FALSE)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
FsUnLoadFileSystem(&pBuf);
|
|
return;
|
|
}
|
|
|
|
BOOL FsNetToHost(BYTE *pFSBuf)
|
|
{
|
|
int i;
|
|
BYTE *pMoveBuf;
|
|
DSFILEHEAD *pFileHead=NULL;
|
|
DSFILESYSTEMHEAD *pFileSystemHead;
|
|
|
|
if(IsNetSequence() == TRUE)
|
|
{
|
|
return TRUE;
|
|
}
|
|
|
|
pMoveBuf = pFSBuf;
|
|
pFileSystemHead = (DSFILESYSTEMHEAD *)pMoveBuf;
|
|
|
|
SequenceNetToHost((char *)&pFileSystemHead->m_iFiles, sizeof(int));
|
|
SequenceNetToHost((char *)&pFileSystemHead->m_iOffset, sizeof(int));
|
|
|
|
pFileHead = (DSFILEHEAD *)pMoveBuf;
|
|
for(i=0; i<pFileSystemHead->m_iFiles; i++)
|
|
{
|
|
if(i == 0)
|
|
{
|
|
pMoveBuf += pFileSystemHead->m_iOffset;
|
|
}
|
|
else
|
|
{
|
|
pMoveBuf += pFileHead->m_iFileSize+sizeof(DSFILEHEAD)-1;
|
|
}
|
|
|
|
pFileHead = (DSFILEHEAD *)pMoveBuf;
|
|
SequenceNetToHost((char *)&pFileHead->m_iFileNameLen, sizeof(int));
|
|
SequenceNetToHost((char *)&pFileHead->m_iFileSize, sizeof(int));
|
|
SequenceNetToHost((char *)&pFileHead->m_iOffset, sizeof(int));
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL FsHostToNet(BYTE *pFSBuf)
|
|
{
|
|
int i;
|
|
BYTE *pMoveBuf;
|
|
DSFILEHEAD *pFileHead=NULL;
|
|
DSFILESYSTEMHEAD *pFileSystemHead;
|
|
|
|
if(IsNetSequence() == TRUE)
|
|
{
|
|
return TRUE;
|
|
}
|
|
|
|
pMoveBuf = pFSBuf;
|
|
pFileSystemHead = (DSFILESYSTEMHEAD *)pMoveBuf;
|
|
|
|
SequenceHostToNet((char *)&pFileSystemHead->m_iFiles, sizeof(int));
|
|
SequenceHostToNet((char *)&pFileSystemHead->m_iOffset, sizeof(int));
|
|
|
|
pFileHead = (DSFILEHEAD *)pMoveBuf;
|
|
for(i=0; i<pFileSystemHead->m_iFiles; i++)
|
|
{
|
|
if(i == 0)
|
|
{
|
|
pMoveBuf += pFileSystemHead->m_iOffset;
|
|
}
|
|
else
|
|
{
|
|
pMoveBuf += pFileHead->m_iFileSize+sizeof(DSFILEHEAD)-1;
|
|
}
|
|
|
|
pFileHead = (DSFILEHEAD *)pMoveBuf;
|
|
SequenceHostToNet((char *)&pFileHead->m_iFileNameLen, sizeof(int));
|
|
SequenceHostToNet((char *)&pFileHead->m_iFileSize, sizeof(int));
|
|
SequenceHostToNet((char *)&pFileHead->m_iOffset, sizeof(int));
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void DispMemoryData(const BYTE *pu8Addr, int iLen, int iNumofLine)
|
|
{
|
|
int i, j, iDispLen;
|
|
BOOL bOver;
|
|
|
|
bOver = FALSE;
|
|
iDispLen = iNumofLine;
|
|
for(i=0; i<iLen; )
|
|
{
|
|
if((i+iDispLen) > iLen)
|
|
{
|
|
iDispLen = iLen - i;
|
|
}
|
|
|
|
printf("0x%08x:", pu8Addr+i);
|
|
for(j=0; j<iDispLen; j++)
|
|
{
|
|
printf("%02x ", pu8Addr[i+j]);
|
|
}
|
|
printf("\n");
|
|
|
|
i += iDispLen;
|
|
}
|
|
} |