📄 fat.h
字号:
/* - data area) */
#define FAT_ET_DATA 0xc0 /* Data area */
#define FAT_ET_MASK_AR 0xc0 /* Area bit mask */
#define FAT_ET_SHF_AR 0x06 /* Area bit shift */
/* FAT file _flag definition from MS-C Ver6.0 */
#define _IOREAD 0x0001 /* Read mode */
#define _IOWRT 0x0002 /* Write mode */
#define _IOEOF 0x0010 /* End of file */
#define _IOERR 0x0020 /* Error */
#define _IORW 0x0080 /* Read/write mode */
/* Seek definition */
#define SEEK_SET 0 /* File start point */
#define SEEK_CUR 1 /* Read/write point */
#define SEEK_END 2 /* File end point */
/* Disk read/write */
#define FAT_DSKSEC_RD 0 /* Disk sector read */
#define FAT_DSKSEC_WR 1 /* Disk sector write */
/* Current drive number */
extern unsigned char fat_bCurDrv;
/* Current directory ASCIIZ is separated by 0x01 */
extern unsigned char fat_bCurDir[FAT_MAX_PATH];
/* Media chage flag is set by another media change function */
extern unsigned char fat_bMediaChgFlag;
/* Verify flag is set by another function */
extern unsigned char fat_bVerifyFlag;
/* Drive geometry structure */
extern DrvGeom_t fat_stDrvGeom[FAT_DRV_NUM];
/* FAT file system error information */
extern FatErr_t fat_stFatErr;
extern volatile unsigned char fat_bDriveHandle;
/* ATA driver prototype */
unsigned char fatAtaInit(unsigned char, unsigned long);
unsigned char fatAtaOpen(unsigned char);
unsigned char fatAtaClose(unsigned char);
unsigned char fatAtaRead(unsigned char, unsigned long, unsigned long, unsigned char *);
unsigned char fatAtaWrite(unsigned char, unsigned long, unsigned long, unsigned char *, unsigned char);
unsigned char fatAtaIdent(unsigned char, DrvGeom_t *);
unsigned char fatAtaCFCardChk(void);
void fatAtaISRHandler(void);
unsigned char fatAtaWriteRegister(AtaReg_t *);
unsigned char fatAtaSoftRest(void);
/* FAT filesystem driver prototype */
int fatFatInit(FatInitParams_t *);
FatFile_t *fatFopen(const char *, const char *);
int fatFclose(FatFile_t *);
size_t fatFread(void *, size_t, size_t, FatFile_t *);
size_t fatFwrite(const void *, size_t, size_t, FatFile_t *);
int fatFseek(FatFile_t *, long, int);
int fatRemove(const char *);
int fatRename(char *, char *);
int fatFeof(FatFile_t *);
int fatFerror(FatFile_t *);
void fatClearerr(FatFile_t *);
int fatChdir(const char *);
const char* fatCurDir(void);
int fatMkdir(const char *);
int fatRmdir(const char *);
unsigned fatDosGetFileAttr(const char *, unsigned *);
unsigned fatDosSetFileAttr(const char *, unsigned);
int fatDosFindNext(struct find_t *);
int fatDosFindFirst(const char *, unsigned, struct find_t *);
unsigned fatDosGetDiskFree(unsigned char, struct diskfree_t *);
int fatGetFn(char *, unsigned long *);
int fatGetVolume(unsigned char, unsigned long **, unsigned char **);
int fatSetVolume(unsigned char, unsigned long, unsigned char **);
int fatIs2ByteCode1(unsigned char);
int fatIs2ByteCode2(unsigned char);
int fatIsFnChr(unsigned char);
unsigned long fatReadDate(void);
int fatDiskRwSec(unsigned char, unsigned long, unsigned char *, unsigned long, unsigned char);
/* FAT format driver prototype */
int fatChkFatFmt(unsigned char);
int fatFatFormat(unsigned char, DrvGeom_t *, unsigned long, unsigned char **);
/*------------------------------------------------------------------------------*/
/* Partition type */
#define FAT_PAR_UNKNOWN 0x00 /* Unknown or deleted if iNumSec is zero */
#define FAT_PAR_FAT12 0x01 /* MS-DOS 12-bit BPB/FAT < 16MB */
#define FAT_PAR_FAT16_1 0x04 /* MS-DOS 16-bit BPB/FAT < 32MB */
#define FAT_PAR_EXT 0x05 /* Extended MS-DOS partition */
#define FAT_PAR_FAT16_2 0x06 /* MS-DOS 16-bit BPB/FAT >= 32MB */
#define FAT_PAR_FAT16_LBA 0x0e /* MS-DOS 16-bit BPB/FAT (LBA) */
/* MBR partition address */
#define FAT_MBR_PAR_ENT1 0x1be /* Partition entry1 address */
#define FAT_MBR_PAR_ENT2 0x1ce /* Partition entry2 address */
#define FAT_MBR_PAR_ENT3 0x1de /* Partition entry3 address */
#define FAT_MBR_PAR_ENT4 0x1ee /* Partition entry4 address */
/* Boot partition code */
#define FAT_BOOT_PAR 0x80 /* Default boot partition */
#define FAT_BOOT_NONE 0x00 /* Not default boot partition */
/* Signature word address */
#define FAT_SIG_ADDR 0x1fe /* Signature word address */
/* Signature word code */
#define FAT_SIG_WORD_CODE 0xaa55
/* Ext boot signature code */
#define FAT_EXT_BOOT_CODE 0x29
/* FAT entry code */
#define FAT_FAT12_BAD_ENT 0xff7
#define FAT_FAT12_LAST_ENT 0xfff
#define FAT_FAT16_BAD_ENT 0xfff7
#define FAT_FAT16_LAST_ENT 0xffff
/* Read/write maximum sector size of ATA disk */
#define FAT_RW_MAX_SEC 256
/* Read/write retry count */
#define FAT_RETRY_CNT 3
/* File ID max */
#define FAT_FILE_ID_MAX 0x7fffffff
/* Search directory definition */
#define FAT_SERDIR_ROL 1
#define FAT_SERDIR_DIR 2
/* HDD unit number base */
#define FAT_HD_UNIT 0x80
/* Current directory */
#define FAT_CHG_CUR_DIR 0xff
/* Flag to show first writting */
#define FAT_C_TOPSECT 0x7fffffff
/* Disk I/O structure */
typedef struct { /* [R] ... Read, [W] ... Write */
unsigned char bDrvNum; /* [R] Drive number (Free = 0xff) */
unsigned char bUnitNum; /* [W] Unit number HDD = 0x80, 0x81, ..., 0x97 */
unsigned char bHd; /* [R] Header number */
unsigned short wTrk; /* [R] Track number */
unsigned char bSec; /* [R] Sector number */
unsigned char bFlag; /* [R/W] Flag */
unsigned long ulSecLen; /* [R/W] Sector length */
unsigned long ulStartSecNum; /* [R] Start sector number (LSN) */
unsigned char bCmd; /* [R] FAT command */
unsigned char bErrCode; /* [W] Result error code */
unsigned char *pbTransAddr; /* [R] Transfer address */
unsigned char *pbBpb; /* [R] BPB structure address */
} DiskIO_t;
typedef DiskIO_t *DiskIOPtr_t;
/* DiskIO_t bFlag member bit definition */
#define FAT_DISK_IO_FL_FAT12 0x10 /* [W] 1 = FAT12, 0 = FAT16(BPB setting) */
#define FAT_DISK_IO_FL_VERIFY 0x80 /* [R] 1 = Enable on verify and disk write */
/* Partition entry structure */
typedef struct {
unsigned char bBoot; /* Default boot partion */
unsigned char bStartHd; /* Head number where partion starts on media */
unsigned char bStartSec; /* Bits 0..5 are one-based(1) sector number */
/* where partion start on media. */
/* Bits 6 and 7 are high bits of zero-based(0) */
/* cylinder number where partion starts on */
/* media. */
unsigned char bStartCyl; /* Least significant eight bits of */
/* zero-based(0) cylinder number where */
/* partion starts on media. */
/* Upper two bits of starting cylinder */
/* numberare in StartSector field. */
unsigned char bParType; /* Partition type */
unsigned char bEndHd; /* Zero-based(0) head number where partition */
/* ends on media. */
unsigned char bEndSec; /* Bits 0..5 are one-based(1) sector number */
/* where partition ends on media. */
/* Bits 6 and 7 are high bits of zero-based(0) */
/* cylinder number where partion ends on */
/* media. */
unsigned char bEndCyl; /* Least significant eight bits of */
/* zero-based(0) cylinder number where */
/* partion ends on media. */
/* Upper two bits of ending cylinder numberare */
/* in StartSector field. */
unsigned long ulRelStartSec; /* Start sector relative to beginning of media */
/* or Extended MS-DOS partition */
unsigned long ulNumSec; /* Number of sector */
} PartitionEntry_t;
/* BPB (bios parameter block) structure in boot sector(IPL sector) */
typedef struct {
unsigned short wBytesPerSector; /* Byte per sector */
unsigned char bSectorsPerCluster; /* Sector per cluster */
unsigned short wReservedSectors; /* Reserved sector number */
unsigned char bFATNum; /* FAT number */
unsigned short wRootEntries; /* Root directory entry number */
unsigned short wTotalSectors; /* Total sector */
unsigned char bMediaDescriptor; /* Media descriptor */
unsigned short wSectorsPerFAT; /* Sector per FAT */
unsigned short wSectorsPerTrack; /* Sector per track */
unsigned short wHeadNum; /* Header number */
unsigned long ulHiddenSectors; /* Hidden sector number */
unsigned long ulTotalSectors; /* Disk total sector number */
unsigned char bDrvNum; /* Drive number (Free = 0xff) */
unsigned char bExtendedBootSig; /* Extended boot signature code */
unsigned long ulVolumeSerialNumber; /* Volume serial number */
unsigned char bVolumeLabel[FAT_FILE_LEN]; /* Volume label */
} FatBpb_t;
/* FAT disk parameter structure */
typedef struct {
unsigned char bDrvNum; /* Drive number (Free = 0xff) */
unsigned char bAttributes; /* Attributes */
unsigned char bFlag; /* Flag */
unsigned char bOpenFileCnt; /* Open file number */
FatBpb_t stBpb; /* BPB */
struct { /* Sector number information */
unsigned long ulBoot; /* Boot sector number */
unsigned long ulFAT1; /* FAT1 start sector number */
unsigned long ulDir; /* Directory start sector number */
unsigned long ulData; /* Data start sector number */
unsigned long ulEos; /* Last sector number + 1 */
} stSn;
unsigned long ulFreeCluster; /* Free cluster number */
unsigned long ulDefscn; /* Default free cluster pointer */
unsigned long ulEoc; /* End of cluster number + 1 */
unsigned long ulCdCluNum; /* Cluster number which has first entry of */
/* current directory */
unsigned char bCurDir[FAT_MAX_PATH]; /* Current directory ASCIIZ is separated by */
/* 0x01 */
} FatDskPar_t;
typedef FatDskPar_t *FatDskParPtr_t;
/* Drive table structure */
typedef struct {
unsigned char bIF; /* Interface */
unsigned char bUnitNum; /* Unit number HDD = 0x80, 0x81, ..., 0x97 */
FatDskParPtr_t pstFdp; /* Drive parameter pointer */
} DrvTbl_t;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -