📄 fat.h
字号:
//****************************************************************
// FileName: fat.h
// Description: fat16/fat12/fat32 define
// Version: 1.0
// Histrory:
// 1.0 chanjl 2003.11.10 create the module
//****************************************************************
#ifndef _FAT_H_
#define _FAT_H_
#include "type.h"
//---------------------------------------------------------------------------
//Fat Config
#define COMPILE_FAT_12 0
#define COMPILE_FAT_16 1
#define COMPILE_FAT_32 0
#define COMPILE_FAT_WRITE 0
//---------------------------------------------------------------------------
#define FAT_PARTITIONNED TRUE /* TRUE: format with 1 partition,
FALSE: without partition */
#define FILE_READ ((byte)0)
#define FILE_WRITE ((byte)1)
#define FAT_IS_12 ((byte)0)
#define FAT_IS_16 ((byte)1)
#define FAT_IS_32 ((byte)2)
#define FREE_CLUSTER ((Uint16)0x0000) /* free cluster value in FAT */
#define LAST_CLUSTER12 ((Uint16)0x0FFF) /* last file cluster in FAT 12 */
#define BAD_CLUSTER12 ((Uint16)0x0FF7) /* bad cluster value in FAT 12 */
#define LAST_CLUSTER16 ((Uint16)0xFFFF) /* last file cluster in FAT 16 */
#define BAD_CLUSTER16 ((Uint16)0xFFF7) /* bad cluster value in FAT 16 */
#define LAST_CLUSTER32 ((Uint32)0x0FFFFFFF)
#define MBR_ADDRESS ((Uint32)0) /* Master Boot Record address */
#define ATTR_READ_ONLY ((Byte)0x01) /* only read file attribute*/
#define ATTR_HIDDEN ((Byte)0x02) /* Hidden File Attribute */
#define ATTR_SYSTEM ((Byte)0x04) /* System File Attribute */
#define ATTR_VOLUME_ID ((Byte)0x08) /* on the volume file Attribute*/
#define ATTR_DIRECTORY ((Byte)0x10) /* Directory Attribute */
#define ATTR_ARCHIVE ((Byte)0x20) /* Archive Attribute */
#define ATTR_LFN_ENTRY ((Byte)0x0F) /* LFN entry attribute */
#define ATTR_ROOT_DIR ((Byte)0x90) /* internal use only */
#define PARTITION_ACTIVE ((Byte)0x80) /* the active partition state */
#define FILE_NOT_EXIST ((char)0x00) /* current file does not exist */
//#define FILE_DATA_AREA ((char)0xFF) /* file does not exist in data area*/
#define FILE_DELETED ((char)0xE5) /* current file is deleted */
#define LFN_SEQ_MASK ((Byte)0x3F) /* LFN sequence number mask */
#define FAT12 ((Byte)0x01) /* FAT12 type */
#define FAT16_INF32M ((Byte)0x04) /* FAT16 type < 32 Mbytes */
#define FAT16_SUP32M ((Byte)0x06) /* FAT16 type > 32 Mbytes */
#define FAT32 ((Byte)0x0B) /* FAT32 type not supported */
#define MAX_CLUSTERS12 ((Uint16)4084) /* FAT12 if < FAT16 else */
#define MAX_CLUSTERS16 ((Uint16)65524) /* FAT16 if < FAT32 else */
/* Format Info */
#define DIR_SIZE ((Byte)32) /* directory entry size */
#define NB_ROOT_ENTRY ((Uint16)512)
//#define NB_RESERVED ((Byte)1) /* number of reserved sectors */
#define NB_FATS ((Byte)2)
#define HARD_DISK ((Byte)0xF8) /* hard disk device */
#define FAT_DRIVE_NUMBER ((Byte)0x81)
#define FAT_EXT_SIGN ((Byte)0x29)
#define BR_SIGNATURE ((Uint16)0xAA55) /* boot record signature */
#define MBR_ADDRESS ((Uint32)0) /* master boot record address */
#define HEAD_NUMBER ((word)0x10)
/* maximum number of LFN entries */
#define MAX_LFN_ENTRIES ((Byte)8)
/* maximum file name length + 18 */
#define MAX_FILENAME_LEN 130 - 1//((Byte)(103 * 2 + 18 ))
#define MAX_FILE_FRAGMENT_NUMBER ((Byte)150)/* maximum number of authorized */
/* fragment for a file */
#define MAX_DIR_FRAGMENT_NUMBER ((Byte)10) /* maximum number of authorized */
/* fragment for a directory */
/* a directory */
#define MAX_DIR_CLUST_NUMBER ((Byte)5) /*maximum number of a directory's cluster number */
/*******************************************************************************
* PURPOSE:
* FAT Directory Entry structure
*******************************************************************************/
typedef struct
{
Byte extName[3];
Byte attributes; /* Attributes bits */
Union32 start_cluster; /* Starting cluster number */
Union32 size; /* File size in bytes */
} fat_st_dir_entry;
/*******************************************************************************
* PURPOSE:
* FAT cache of parent directory and current file or directory
*******************************************************************************/
typedef struct
{
fat_st_dir_entry parent; /* parent directory */
fat_st_dir_entry current; /* current file/directory info */
} fat_st_cache;
/* FAT cluster chain structure (each index is a fragment of the file)*/
typedef struct
{
Union32 cluster; /* starting cluster of fragment */
Byte number; /* number of subsequent clusters in fragment */
} fat_st_clust_chain;
#define MAX_CL_PER_FRAG 255
#define MAX_SUBDIR_DEPTH ((Byte)10)
/* fat search file in extern memory */
typedef struct
{
Uint16 index;
Byte file;
}fat_st_info;
#define SCAN_DIR ((Byte)0)
#define SCAN_FILE ((Byte)1)
#define SCAN_XXX ((Byte)0xFF)
#define DIR_ROOT ((Uint16)0xffff)
#define DIR_XXX ((Uint16)0xeeee)
enum
{
SEARCH_DIR = 0,
SEARCH_FILE,
GOTO_PARENT,
GOTO_CHILD
};
/* File Type */
#define FILE_XXX ((INT32U)0)
#define FILE_DIR ((INT32U)1)
#define FILE_LRC ((INT32U)2)
#define FILE_MP3 ((INT32U)4)
#define FILE_WAV ((INT32U)8)
#define FILE_WMA ((INT32U)16)
#define FILE_MID ((INT32U)32)
#define FILE_AV6 ((INT32U)64)
#define FILE_BMP ((INT32U)128)
#define FILE_JPG ((INT32U)256)
#define FILE_TXT ((INT32U)512)
#define FILE_AAC ((INT32U)1024)
#define FILE_OGG ((INT32U)2048)
#define FILE_IMA ((INT32U)4096)
#endif /* _FAT_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -