|
文件操作
所谓文件系统,是指对一个存储设备上的数据和元数据组织机制,在MTK平台中简称FS ,它有以下特性:
1、支持FAT-16,FAT-32
2、支持FAT格式
3、长文件名-255字符
4、支持UNICODE
5,支持软盘、闪存、SRAM
6、支持缓存
7、支持多任务
8、支持安装设备驱动
注意:FAT在模拟器中,存放路径为:\plutommi\WIN32FS\
8.7.1、常用函数
下面介绍与常用函数相关的两个重要的文件:
1、fs_func.h
该文件主要用来声明函数,具体代码如下:
// General I/O
extern int FS_Open(const WCHAR * FileName, UINT Flag);
extern int FS_OpenHint(const WCHAR * FileName, UINT Flag, FS_FileLocationHint * DSR_Hint);
extern int FS_Close(FS_HANDLE FileHandle);
extern int FS_CloseAll(void);
extern int FS_Read(FS_HANDLE FileHandle, void * DataPtr, UINT Length, UINT * Read);
extern int FS_Write(FS_HANDLE FileHandle, void * DataPtr, UINT Length, UINT * Written);
extern int FS_SetSeekHint(FS_HANDLE FileHandle, UINT HintNum, FS_FileLocationHint * Hint);
extern int FS_Seek(FS_HANDLE FileHandle, int Offset, int Whence);
extern int FS_Commit(FS_HANDLE FileHandle);
extern int FS_ReleaseFH(void * TaskId);
extern int FS_Abort(UINT ActionHandle);
extern int FS_ParseFH(FS_HANDLE FileHandle);
extern int FS_GenVirtualFileName(FS_HANDLE FileHandle, WCHAR * VFileNameBuf, UINT BufLength, UINT VFBeginOffset, UINT VFValidLength);
//Information
extern int FS_GetFileInfo(FS_HANDLE FileHandle, FS_FileInfo * FileInfo);
extern int FS_GetFileSize(FS_HANDLE FileHandle, UINT * Size);
extern int FS_GetFilePosition(FS_HANDLE FileHandle, UINT * Position);
extern int FS_SetFileTime(FS_HANDLE FileHandle, const FS_DOSDateTime * Time);
extern int FS_GetAttributes(const WCHAR * FileName);
extern int FS_GetFirstCluster(FS_HANDLE FileHandle, UINT * Cluster);
2、FSSim_core.c
该文件主要功能为函数实现,代码如下:
int FS_Open(const WCHAR *FileName, UINT Flag)
{
int fh = -1, is_exist, i;
unsigned int j, is_virtual, map_fh;
TCHAR strbuf[MAX_PATH], *pch;
DWORD access, share, create, attribute, error;
ASSERT(FileName != NULL);
__try {
if (fssim_mutex == NULL) {
fssim_init();
}
/* Virtual File Name Compare Hook */
if (wcsncmp(FileName, fssim_vfname_prefix, wcslen(fssim_vfname_prefix)) == 0) {
is_virtual = 1;
} else {
is_virtual = 0;
/* Stop irregular path input */
if (wcslen(FileName) >= MAX_PATH) {
return FS_PATH_OVER_LEN_ERROR;
}
/* convert file name (i.e., X:\ ==> DRIVE_X\) */
fssim_conv_fn(strbuf, FileName);
}
/* varify flags */ |
|