📄 fsmdfs.h
字号:
/*****************************************************************************
FILE NAME: FsmDFs.h
DESCRIPTION:
Definitions for data file system.
Copyright (c) 2002, VIA Technologies, Inc.
*****************************************************************************/
#ifndef __FSM_DFS_H__
#define __FSM_DFS_H__
#include "fsmdefs.h"
#include "FsmFs.h"
#include "FsmVfs.h"
#include "ostype.h"
/* #define FSM_TAG "FSM@" */
/* For little-endian CPU */
#define FSM_TAG 0x404D5346 /* "FSM@" */
/* For big-endian CPU */
/*#define FSM_TAG 0x46534D40 */ /* "FSM@" */
#define INVALID_PSN 0xffffffff
#define PENDING_PSN 0xfffffffe
typedef /*PACKED*/ struct
{
uint16 FreeSectors;
uint16 UsedSectors;
uint16 DirtySectors;
uint32 EraseCount;
} FsmBlockStatisticT;
/* block status definitions. */
/* for little-endian CPU. */
#define BLOCK_ERASED 0xFFFF
#define BLOCK_WRITING 0xFFFC
#define BLOCK_ERASING 0xFFCC
#define BLOCK_VALID 0xFCCC
#define BLOCK_INVALID 0x0000
typedef /*PACKED*/ struct
{
uint32 BackupEraseCount;
uint32 EraseCount;
uint16 Pbn;
uint16 Status;
uint32 Tag;
} FsmBlockInfoT;
/* sector status definitions. */
/* for little-endian CPU. */
#define SECTOR_EMPTY 0xFFFF
#define SECTOR_WRITING 0xFFFC
#define SECTOR_APPENDING 0xCFCC
#define SECTOR_ALLOCATED 0xCCFC
#define SECTOR_UPDATING 0xFCCC
#define SECTOR_VALID 0xCCCC
#define SECTOR_DELETING 0xC0CC
#define SECTOR_INVALID 0x0000
/*==== sector type definitions ====*/
/*
* Defines what is contained in the
* sector.
*/
#define SECTOR_TYPE_SID 0x0000 /* single-instance data */
#define SECTOR_TYPE_MID 0x0100 /* multiple-instance data */
#define SECTOR_TYPE_FDE 0x0001 /* file directory entry */
#define SECTOR_TYPE_IDE 0x0002 /* (data) item directory entry */
typedef /*PACKED*/ struct
{
uint16 Status;
uint16 Type;
uint32 Lsn;
uint32 NextLsn;
} FsmFlashSectorHdrT;
/* directory status definitions. */
/* for little-endian CPU. */
#define ENTRY_EMPTY 0xFFFF
#define ENTRY_WRITING 0xFFFC
#define ENTRY_ALLOCATED 0xFFCC
#define ENTRY_UPDATING 0xFCFC
#define ENTRY_VALID 0xFCCC
#define ENTRY_DELETING 0xF0CC
#define ENTRY_INVALID 0x0000 /* 0xC000 */
/* directory entry type definitions. */
/*
* It defines what the entry is for.
*/
#define ENTRY_TYPE_SUBDIR 0x00
#define ENTRY_TYPE_FILE 0x01
#define ENTRY_TYPE_ITEM 0x02
#define DFS_MAX_FILE_NAME_LEN 16
typedef /*PACKED*/ struct
{
uint16 Status;
uint8 Type;
uint8 Rfu;
uint16 Date;
uint16 Time;
uint32 Length;
uint32 FirstLsn;
uint8 FileName[DFS_MAX_FILE_NAME_LEN];
} FsmFileDirEntryT;
/* Data item directory entry Method definitions. */
#define METHOD_SINGLE 0x00
#define METHOD_MULTI 0x01
typedef /*PACKED*/ struct
{
uint16 Status;
uint8 Type;
uint8 Method;
uint16 ItemType;
uint16 ItemId;
uint32 Length;
uint32 FirstLsn;
} FsmItemDirEntryT;
/* status definitions for Multi-Instance item. */
#define INSTANCE_EMPTY 0xFF
#define INSTANCE_WRITING 0xFC
#define INSTANCE_VALID 0xCC
#define INSTANCE_INVALID 0x00
typedef /*PACKED*/ struct
{
uint16 Length;
uint8 Status[1];
} FsmMultiInstanceT;
/*
* Defines the minimum number of instances
* that must fit into a sector.
*/
#define MIN_INSTANCES 3
/*
* To make these MACROs work,
* every nibble must transit from 0xF to 0xC then to 0x0.
*
* 0xF -> 0xC -> 0x0
*
*/
/* 16-bit block status. */
#define BLOCK_INTERMEDIATE_MASK 0xAAAA
#define VALID_BLOCK_STATE(status) (((status) ^ ((status) << 1)) & BLOCK_INTERMEDIATE_MASK)
#define FIX_BLOCK_STATE(inter, status) ((~((inter) | ((inter) >> 1))) & (status))
/* 8-bit item status. */
#define ITEM_INTERMEDIATE_MASK 0xAA
#define VALID_ITEM_STATE(status) (((status) ^ ((status) << 1)) & ITEM_INTERMEDIATE_MASK)
#define FIX_ITEM_STATE(inter, status) ((~((inter) | ((inter) >> 1))) & (status))
/* 16-bit sector status. */
#define SECTOR_INTERMEDIATE_MASK 0xAAAA
#define VALID_SECTOR_STATE(status) (((status) ^ ((status) << 1)) & SECTOR_INTERMEDIATE_MASK)
#define FIX_SECTOR_STATE(inter, status) ((~((inter) | ((inter) >> 1))) & (status))
/* 16-bit entry status. */
#define ENTRY_INTERMEDIATE_MASK 0xAAAA
#define VALID_ENTRY_STATE(status) (((status) ^ ((status) << 1)) & ENTRY_INTERMEDIATE_MASK)
#define FIX_ENTRY_STATE(inter, status) ((~((inter) | ((inter) >> 1))) & (status))
/* Wearing level threshold. */
#define WEARING_LEVEL_THRESHOLD 1000
#define WEARING_LEVEL_INCREMENT 5
/* Write task priority */
#define FSM_WRITE_TASK_PRIORITY 100
/* write task stack size */
#define FSM_WRITE_TASK_STACK_SIZE 3000
/*******************************************
*
* The following structures are used for
* DATA file system.
*
*******************************************/
typedef /*PACKED*/ struct
{
FsmMediaObjHdrT MediaObjHdr;
uint32 SectorSize;
uint16 SectorsPerBlock;
uint32 BlockSize;
uint32 MaxPsn;
uint16 SpareBlk;
HMSEM MapTblLock;
uint32 * Lsn2PsnP;
HMSEM InfoLock;
FsmBlockStatisticT* BlockInfoP;
} FsmFlashMediaT;
/* Flags for Data fs File descriptor. */
#define DFD_FLAG_FREE 0x00
#define DFD_FLAG_IN_USE 0x01
#define DFD_FLAG_PENDING 0x02
/*#define DFD_FLAG_CLOSED 0x04 */
#define DFS_MAX_PATH_LEN 128
typedef /*PACKED*/ struct
{
FsmFileDescriptorHdrT FdHdr;
uint32 FilePointer;
uint32 AccessMode;
uint16 CreateDate;
uint16 CreateTime;
uint32 FileLength;
uint32 FirstLsn;
uint32 ParentDirFirstLsn;
uint16 Attrib;
HMSEM MutexSem;
char PathName[DFS_MAX_PATH_LEN + 1];
uint8 Flag;
} FsmDfsFileDescriptorT;
/* Data filesystem API */
uint32 FsmDfsCreate(FsmDevObjHdrT * DevObjP, char * path, uint32 CreateFlag, uint32 * ErrorCodeP);
uint32 FsmDfsOpen(FsmDevObjHdrT * DevObjP, char * path, uint32 OpenMode, uint32 * ErrorCodeP);
uint32 FsmDfsDelete(FsmDevObjHdrT * DevObjP, char * path);
uint32 FsmDfsClose(uint32 fd);
uint32 FsmDfsRead(uint32 fd, uint8 * buffer, uint32 size, uint32 *ErrorCodeP);
uint32 FsmDfsWrite(uint32 fd, uint8 * buffer, uint32 size, uint32 *ErrorCodeP);
uint32 FsmDfsIoCtrl(uint32 fd, uint32 cmd, void * arg);
uint32 FsmDfsInit(FsmDevObjHdrT * DevObjP, uint32 SectorSize);
uint32 FsmDfsTerminate(FsmDevObjHdrT * DevObjP);
/* Data filesystem IO ctl functions. */
uint32 DfsFileEof(uint32 fd, uint32 * eof);
uint32 DfsFileSeek(uint32 fd, FsmIoctlSeekT * arg);
uint32 DfsFileGetAttrib(uint32 fd, FsmFileAttribT * arg);
uint32 DfsFileTruncate(uint32 fd, uint32 newsize);
uint32 DfsFileRename(FsmIoctlRenameT * arg);
uint32 DfsFileFlush(uint32 fd);
uint32 DfsGetVolumeFreeSpace(FsmIoctlGetFreeSpaceT * arg);
uint32 DfsFormat(FsmDevObjHdrT *DevP);
/* Data filesystem reclamation API */
uint32 DfsReclaimProcess(FsmDevObjHdrT * DevObjP);
#if (OS_TYPE == OS_WINDOWS)
uint32 BkgdWriteTask(void * argv);
#else
void BkgdWriteTask(uint32 argc, void * argv);
#endif
uint32 FsmPlrDfsCheck(FsmDevObjHdrT * pDev, uint32 BlockSize, uint32 Blocks);
/* help functions used internally. */
uint32
DfsReadData(
FsmDevObjHdrT * DevP,
uint8 * buf,
uint32 FirstLsn,
uint32 offset,
uint32 size,
uint32 * read_size
);
uint32 DfsLsn2Psn(FsmFlashMediaT * MediaObjP, uint32 Lsn);
uint32 DfsPsn2Addr(FsmFlashMediaT * MediaObjP, uint32 Psn);
uint32 DfsAvailSpaceCalc(FsmFlashMediaT * MediaP);
/* functions from the fileutil.c */
uint32 GetFirstPath(const char * path, uint32 * start, uint32 * length);
char * ExtractFilename(const char * path);
uint32 ExtractDir(const char * path, uint32 * end);
uint32 FsmStringMatched(char * wildcard, char * target);
#endif /* __FSM_DFS_H__ */
/*****************************************************************************
* $Log: FsmDfs.h $
* Revision 1.4 2004/03/17 12:57:24 zgy
* Revision 1.32 2004/03/16 15:54:26 jjs
* Revision 1.31 2004/03/11 14:37:23 jjs
* moved some macros.
* Revision 1.30 2004/02/20 17:26:03 jjs
* added a PENDING_PSN flag to reserve LSN.
* Revision 1.29 2003/11/25 16:01:54 wsm
* 1.format (use extern dfsformat to use it)
* 2.get blockinfo
* 3.attrib define change
* Revision 1.28 2003/11/25 14:03:23 wangli
* Add Macro WEARING_LEVEL_DIFFERENTIAL for Reclaimation
* Revision 1.27 2003/11/11 11:29:38 jjs
* added function declaration for DfsFilenameValid.
* Revision 1.26 2003/11/05 11:37:15 jjs
* Revision 1.25 2003/11/05 11:19:58 jjs
* replace //
* Revision 1.23 2003/10/24 17:07:58 jjs
* Added Format function declaration.
* Revision 1.22 2003/10/16 10:35:15 jjs
* Revision 1.21 2003/10/14 14:43:21 jjs
* Revision 1.20 2003/10/08 21:09:29 jjs
* Revision 1.19 2003/10/08 20:04:36 jjs
* Revision 1.18 2003/10/08 12:41:31 jjs
* Revision 1.17 2003/09/19 09:50:14 jjs
* Revision 1.16 2003/09/16 17:10:43 wsm
* Revision 1.15 2003/09/16 13:58:12 wsm
* Revision 1.14 2003/09/15 09:51:32 wsm
* Revision 1.13 2003/09/14 16:57:15 jjs
* Revision 1.12 2003/09/13 19:40:20 jjs
* Revision 1.11 2003/09/12 17:26:15 jjs
* Revision 1.10 2003/09/12 17:13:52 jjs
* Revision 1.9 2003/09/12 16:27:01 jjs
* Revision 1.8 2003/09/12 14:55:24 jjs
* Move DfsPlrQueueT structure to FsmPlr.c
* Revision 1.7 2003/09/12 14:54:15 wsm
* Revision 1.6 2003/09/12 14:51:42 jjs
* Revision 1.5 2003/09/12 10:23:32 wsm
* Macro update :
* File_Dir to ENTRY_TYPE_FILE
* Revision 1.4 2003/09/12 10:19:50 wsm
* add Macro for entry type check
* Revision 1.3 2003/09/11 09:53:43 wsm
* update the Macro name
* Revision 1.2 2003/09/11 09:03:53 wsm
* update funtion name
* Revision 1.1 2003/09/09 15:06:58 jjs
* Initial revision
*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -