📄 fat.h
字号:
typedef DrvTbl_t *DrvTblPtr_t;
/* DrvTbl_t I/F bit definition */
#define FAT_IF_NO 0x00 /* No drive */
#define FAT_IF_FAT 0x10 /* FAT(ISO9293) file system */
#define FAT_IF_CDROM 0x80 /* ISO9660 file system */
#define FAT_IF_NET 0x90 /* Network file system */
#define FAT_IF_FS_MASK 0xf0 /* File system mask bit */
#define FAT_IF_IF_MASK 0x0f /* Interface mask bit */
/* Interface definition */
#define FAT_IF_FD (FAT_IF_FAT | 0x00) /* FAT floppy disk */
#define FAT_IF_HD (FAT_IF_FAT | 0x01) /* FAT hard disk */
#define FAT_IF_SCSIRD (FAT_IF_FAT | 0x02) /* FAT scsi removal disk */
#define FAT_IF_SCSIHD (FAT_IF_FAT | 0x03) /* FAT scsi hard disk */
/* FatDskPar_t bAttributes bit definition */
#define FAT_AT_EJ 0x01 /* Software eject (only removal) */
#define FAT_AT_RM 0x10 /* Removable disk */
#define FAT_AT_IOCTL 0x40 /* Support IOCTL */
/* FatDskPar_t bFlag bit definition */
/* Drive status(bit3..0) */
#define FAT_DF_NR 0x01 /* Not ready */
#define FAT_DF_WP 0x02 /* Write protect */
/* Reserved(bit4) : set 0 */
/* FAT type(bit7..5) */
#define FAT_FAT16 0x40 /* FAT16 */
#define FAT_FAT12 0x80 /* FAT12 */
#define FAT_MASK_FAT 0xe0 /* FAT type bit mask */
/* Directory entry definition */
#define FAT_DIRENT_SIZE 32 /* 1directory entry 32 byte fixed */
typedef FatDirEnt_t *FatDirEntPtr_t;
/* FatDirEnt_t bAttributes bit definition */
#define FAT_AT_NOR 0x00 /* Normal file (same as _A_NORMAL) */
#define FAT_AT_ROL 0x01 /* Read only file (same as _A_RDONLY) */
#define FAT_AT_HID 0x02 /* Hidden file (same as _A_HIDDEN) */
#define FAT_AT_SYS 0x04 /* System file (same as _A_SYSTEM) */
#define FAT_AT_VOL 0x08 /* Volume label (same as _A_VOLID) */
#define FAT_AT_SBD 0x10 /* Sub directory (same as _A_SUBDIR) */
#define FAT_AT_ARC 0x20 /* Archives attribute (same as _A_ARCH) */
typedef FatFcs_t *FatFcsPtr_t;
/* FatFcs_t bDrvNum empty definition */
#define FAT_FF_EMPTY 0xff
/* FatFcs_t bFlag bit definition */
/* Access code(bit3..0) */
#define FAT_FF_RDMD 0x01 /* Read mode */
#define FAT_FF_WRMD 0x02 /* Write mode */
#define FAT_FF_DEUPD 0x04 /* Update directory entry */
#define FAT_FF_DIRRDMD 0x09 /* Directory read mode */
#define FAT_FF_ALLDIR 0x04 /* All directory read */
#define FAT_FF_MASK_AC 0x0f /* Access code bit mask */
/* Reserved(bit7..4) : set 0 */
typedef FatSecBuf_t *FatSecBufPtr_t;
/* FatSecBuf_t bDrvNum empty definition */
#define FAT_BF_EMPTY 0xff
/* FatSecBuf_t bFlag bit definition */
/* R/W(bit3..0) */
#define FAT_BF_RD 0x01 /* Read */
#define FAT_BF_WR 0x02 /* Write */
#define FAT_BF_MASK_RM 0x0f /* R/W bit mask */
/* Reserved(bit5,4) : set 0 */
/* R/W(bit7,6) */
#define FAT_BF_SYS 0x00 /* System area (except of FAT, directory, data) */
#define FAT_BF_FAT 0x40 /* FAT area */
#define FAT_BF_DIR 0x80 /* Directory area (contain of sub directory in */
/* data area) */
#define FAT_BF_DATA 0xc0 /* Data area */
#define FAT_BF_MASK_AR 0xc0 /* Area bit mask */
#define FAT_BF_SHF_AR 0x06 /* Area bit shift */
/* FatErr_t type bit definition */
#define FAT_BT_MASK_AR FAT_ET_MASK_AR /* Area bit mask */
#define FAT_BT_SHF_AR FAT_ET_SHF_AR /* Area bit shift */
/* File open flag definition */
/* Access code(bit3..0) */
#define FAT_OPEN_RD 0x00 /* Read mode */
#define FAT_OPEN_WR 0x01 /* Write mode */
#define FAT_OPEN_RW 0x02 /* Read/write mode */
#define FAT_OPEN_DIR_RD 0x0c /* Directory mode */
#define FAT_OPEN_DIR_ALL_RD 0x0d /* All directory read mode */
/* Reserved(bit7..4) : set 0 */
/* CnvFrwp function structure */
typedef struct {
unsigned long ulCcn; /* File R/W pointer cluster number */
unsigned long ulCsnt; /* Header sector number of ulCcn */
unsigned long ulCsnr; /* Relative sector number from ulCsnt */
unsigned long ulCsbp; /* Byte position in sector number from ulCsnr */
} CnvFrwp_t;
typedef CnvFrwp_t *CnvFrwpPtr_t;
/* Fat_dos_findfirst function, Fat_dos_findnext function emulate DTA area definition */
#define FAT_FIND_DRVNUM 0 /* Offset 0, size 1 byte : dirve number */
#define FAT_FIND_FILENAME 1 /* Offset 1, size 11 byte : finename */
#define FAT_FIND_ATTR 12 /* Offset 12, size 1 byte, attribute */
#define FAT_FIND_ID 13 /* Offset 13, size 1 byte, ID 0x23 */
#define FAT_FIND_CLUNUM 14 /* Offset 14, size 4 byte, cluster number */
#define FAT_FIND_RDPTR 18 /* Offset 18, size 2 byte, read pointer */
#define FAT_FIND_CHKSUM 20 /* Offset 20, size 1 byte, check sum */
/* Maximum file value */
extern unsigned char fat_bMaxFile;
/* Maximum buffer value */
extern unsigned char fat_bMaxBuffer;
/* First drive */
extern unsigned char fat_bFirstDrv;
/* Last drive */
extern unsigned char fat_bLastDrv;
/* Open file (8..255) */
extern unsigned char fat_bOpenFiles;
/* Drive table */
extern DrvTbl_t fat_stDrvTbl[FAT_DRV_NUM];
/* File control structure table pointer */
extern FatFcsPtr_t fat_pstFcsTbl;
/* Sector buffer pointer */
extern FatSecBufPtr_t fat_pstSecBuf;
/* FAT disk parameter structure table */
extern FatDskPar_t fat_stDrvFdp[FAT_DRV_NUM];
/* Disk I/O structure */
extern DiskIO_t fat_stDiskIO;
/* Partition entry */
extern PartitionEntry_t fat_stParEnt;
/* File structure pointer */
extern FatFile_t *fat_pfpFile;
/* File structure pointer array pointer */
extern FatFile_t **fat_pfpFp;
/* File ID variable */
extern int fat_iNextFileIO; /* Next file ID number */
extern int fat_iFileIDMax; /* File ID number max */
/* SearchFnx0, SearchFnx function */
extern unsigned long fat_ulSubDirLastCluNum; /* Sub directory last cluster number */
extern unsigned long fat_ulFstDirEmpSecNum; /* Sector number of first empty directory entry */
extern unsigned long fat_ulFstDirEmpSecPtr; /* Sector byte point of first empty directory */
/* entry */
/* CutPath function wild card check flag */
extern unsigned char fat_bCutPathWcbFlag;
/* SearchDir function path check flag */
extern unsigned char fat_bDirEntExist;
/* AllocateClu function final cluster number */
extern unsigned long fat_ulEndCluNum;
/* Work buffer */
extern unsigned char fat_bWkFn[FAT_FILE_LEN + 1]; /* Filename 11 character(8 + 3) */
extern unsigned char fat_bWkDir[32]; /* Buffer for directory */
extern FatDskPar_t fat_stWkFdp; /* FAT disk parameter structure */
extern unsigned char fat_bWkArea[3 * FAT_SECTOR_SIZE]; /* Freee work area */
/* Directory separate characotr */
extern const unsigned char fat_bDirDlm;
/* No volume label string */
extern const unsigned char fat_bVolNoName[FAT_FILE_LEN];
/* Data size which fatFwrite receive */
extern unsigned long fat_FwrtSize;
extern FatDskPar_t *fat_Fdp;
extern CnvFrwp_t fat_Frwp;
/* A flag to bypass the fatAtaOpen(close) in fatDiskIORwDrv */
extern volatile unsigned char fat_bFatFlag;
/* A pointer to the FAT system area chache RAM area */
extern unsigned char *fat_CacheRAM;
/* Macro for FAT entry */
#define FAT_SET_HI28BIT(x) (0xfffffff0 | (x))
/* Macro for byte to word and double word */
#define FAT_WORD_PEEK(p) ((((unsigned short)*((unsigned char *)(p) + 1)) << 8) | (unsigned short)*((unsigned char *)(p)))
#define FAT_DWORD_PEEK(p) ((((unsigned long)*((unsigned char *)(p) + 3)) << 24) | (((unsigned long)*((unsigned char *)(p) + 2)) << 16) | (((unsigned long)*((unsigned char *)(p) + 1)) << 8) | (unsigned long)*((unsigned char *)(p)))
#define FAT_WORD_POKE(p, wData) { *(unsigned char *)(p) = (unsigned char)(wData & 0xff); *((unsigned char *)(p) + 1) = (unsigned char)((wData >> 8) & 0xff); }
#define FAT_DWORD_POKE(p, ulData) { *(unsigned char *)(p) = (unsigned char)(ulData & 0xff); *((unsigned char *)(p) + 1) = (unsigned char)((ulData >> 8) & 0xff); *((unsigned char *)(p) + 2) = (unsigned char)((ulData >> 16) & 0xff); *((unsigned char *)(p) + 3) = (unsigned char)((ulData >> 24) & 0xff); }
/* Prototype */
int fatCutPath(unsigned char *, unsigned char **, unsigned char);
int fatRebuildPath(unsigned char, unsigned char *, unsigned char **, unsigned char);
int fatAddAbsPath(unsigned char *, unsigned char *);
void fatCopyPath01(unsigned char *, unsigned char *);
int fatGetMaskShift(unsigned long, unsigned long *, unsigned short *);
unsigned char fatSetFatErr(unsigned char, unsigned char, unsigned char, unsigned long);
int fatFatRwSec(unsigned char, unsigned long, unsigned char, unsigned char *, unsigned long, unsigned char);
FatSecBufPtr_t fatSearchEmptySB(void);
void fatSetEmptySB(unsigned char);
void fatSetEmptySB2(unsigned char, unsigned long, unsigned long);
int fatWrSB(unsigned char);
int fatWrSB2(unsigned char, unsigned long, unsigned long);
int fatWrFatSB(unsigned char);
int fatRdSecBuf(unsigned char, unsigned long, unsigned long, unsigned char, unsigned char *, unsigned long);
int fatWrSecBuf(unsigned char, unsigned long, unsigned long, unsigned char, unsigned char *, unsigned long, int);
int fatResetFdp(FatDskParPtr_t, unsigned char);
FatFcsPtr_t fatGetEmptyFcs(void);
FatFcsPtr_t fatSearchFcsId(int, FatFcsPtr_t);
FatFcsPtr_t fatSearchPath(FatFcsPtr_t, FatFcsPtr_t);
int fatGetNewFileId(void);
unsigned long fatCluToSec(FatDskParPtr_t, unsigned long);
int fatRdFatEntry(FatDskParPtr_t, unsigned long, unsigned long *);
int fatWrFatEntry(FatDskParPtr_t, unsigned long, unsigned long, int);
int fatDrvRdyChk(unsigned char, unsigned char, FatDskParPtr_t *);
int fatCnvFrwp(FatDskParPtr_t, FatFcsPtr_t, CnvFrwpPtr_t);
void fatMkDirEntry(FatFcsPtr_t, unsigned char *);
int fatSearchFn(unsigned char *, unsigned long, FatDskParPtr_t, FatFcsPtr_t, unsigned char);
int fatSearchDir(unsigned char *, unsigned char *, unsigned char *, unsigned char, FatFcsPtr_t);
int fatChkCurDir(unsigned char);
int fatCntDirEntry(FatDskParPtr_t, unsigned long, unsigned short, unsigned long *);
int fatSearchFreeClu(unsigned long, unsigned long, unsigned long *, unsigned long *, FatDskParPtr_t);
int fatAllocateClu(unsigned long *, unsigned long, unsigned long, FatDskParPtr_t, int);
int fatReleaseClu(unsigned long, FatDskParPtr_t);
void fatReadEntry(int (*pFunc)(unsigned char, unsigned long, unsigned long, unsigned char *));
void fatWriteEntry(int (*pFunc)(unsigned char, unsigned long, unsigned long, unsigned char *, unsigned char));
unsigned long fatGetTotalSize(void);
int fatFindNextSector(unsigned long *);
long fatFtell(FatFile_t *);
void fatCacheRAMEntry(unsigned char *);
void fatCacheRAMclear(void);
unsigned char *fatGetCacheRAMAddr(void);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -