📄 fat.h
字号:
/************************************************************************
* *
* Copyright (C) SEIKO EPSON CORP. 1999-2001 *
* *
* File name: fat.h *
* This is FAT function header file. *
* *
* Revision history *
* 1999.09.28 T.Mineshima Start. *
* 1999.10.12 T.Mineshima Add remove file, remove directory *
* function. *
* 1999.10.15 T.Mineshima Comment, define, variable modify. *
* 1999.12.10 T.Mineshima Variable modify. *
* 2000.02.03 T.Mineshima Define clean up. *
* 2000.02.17 T.Mineshima Define clean up. *
* 2000.02.23 T.Mineshima Define clean up. *
* 2000.03.22 T.Mineshima Define modify. *
* 2000.03.29 T.Mineshima Function name modify. *
* 2000.04.03 T.Mineshima Variable name modify. *
* 2000.04.17 T.Mineshima Function modify. *
* 2000.04.28 T.Mineshima Define modify. *
* 2000.04.29 T.Mineshima Define modify. *
* 2000.05.08 T.Mineshima Variable name modify. *
* 2000.05.16 T.Mineshima Comment clean up. *
* 2001.03.15 T.Mineshima Modify comment. *
* 2001.03.21 T.Mineshima Add FAT low level function. *
* 2001.03.30 T.Mineshima Change some global value name. *
* Add file max variable. *
* 2001.05.23 H.Ogura FAT33 library is made. *
* 2001.07.03 A.Saito Append "fat_FwrtSize" *
* 2001.09.21 A.Saito Append "fat_bDriveHandle" *
* 2001.10.09 A.Saito Append "fat_bFatFlag" *
* 2001.10.10 A.Saito Append "FAT_C_TOPSECT" *
* 2002.01.18 A.Saito Append "fatFtell". *
* 2002.08.01 A.Saito Append fatEraseChk*() prototype *
* 2002.10.09 A.Saito Remove ATA_BASE and some parameters. *
* 2003.03.13 A.Saito Add structure FatInitParam_t *
* Add definition FAT_VERIFY_* *
* Modify prototype function fatFatInit *
* 2003.06.05 A.Saito Modify comment. *
* 2003.07.22 TaTeishi Add fatCurDir() *
* *
************************************************************************/
#ifndef FATSUB_H
#define FATSUB_H
#include <stdio.h>
/* ATA return code */
#define ATA_SUCCESS 0x00
#define ATA_BAD_SIZE 0x41
#define ATA_NO_CARD 0x42
#define ATA_BAD_HANDLE 0x43
#define ATA_TIMEOUT_ERR 0x44
#define ATA_COMMAND_ERR 0x45
#define ATA_RDY_BUSY_ERR 0x46
#define ATA_RESOURCE_ERR 0x47
#define ATA_DRIVE_BUSY 0x48
#define ATA_FAILURE -1
/* 1 sector size */
#define FAT_SECTOR_SIZE 512 // PC-AT is 512 byte only
/* Drive, file and buffer definition */
#define FAT_FIRST_DRV 0 /* First drive */
#define FAT_LAST_DRV 0 /* Last drive */
#define FAT_DRV_NUM 1 /* Drive total number */
#define FAT_MAX_FILES 2 /* Open file max */
#define FAT_MAX_BUFFERS 2 /* Open buffer max */
/* Media change flag definition */
#define FAT_MEDIA_NOCHG 0 /* Media no change */
#define FAT_MEDIA_UNKNOWN 1 /* Media change unknown */
#define FAT_MEDIA_CHG 2 /* Media change or remove */
/* Maximum path length */
#define FAT_MAX_PATH 64 /* Maximum path length */
/* Filename length */
#define FAT_FILE_LEN 11 /* Filename length */
/* Filename length of find function */
#define FAT_FIND_LEN 13 /* Filename length of find function */
/* Reserved area length of find_t structure */
#define FAT_FIND_REVLEN 21
/* File attributes form MS-C Ver6.0 */
#define _A_NORMAL 0x00 /* Normal file */
#define _A_RDONLY 0x01 /* Read only file */
#define _A_HIDDEN 0x02 /* Hidden file */
#define _A_SYSTEM 0x04 /* System file */
#define _A_VOLID 0x08 /* Volume label */
#define _A_SUBDIR 0x10 /* Sub directory */
#define _A_ARCH 0x20 /* Archives attribute */
/* Write verify check flag */
#define FAT_VERIFY_ENA 0x01
#define FAT_VERIFY_DIS 0x00
/* find_t structure from MS-C Ver6.0 */
struct find_t {
char reserved[FAT_FIND_REVLEN]; /* Area used by function */
char attrib; /* Attributes */
unsigned wr_time; /* Time */
unsigned wr_date; /* Date */
long size; /* File size */
char name[FAT_FIND_LEN]; /* Filename */
};
/* diskfree_t structure from MS-C V6.0 */
struct diskfree_t {
unsigned total_clusters; /* Total cluster number */
unsigned avail_clusters; /* Available cluster number */
unsigned sectors_per_cluster; /* Sector number per cluster */
unsigned bytes_per_sector; /* Byte number per sector */
};
/* ATA regiser structure */
typedef struct {
unsigned char bReserved; /* Reserve */
unsigned char bFeatures; /* Features register */
unsigned char bSectorCount; /* Sector Count register */
unsigned char bSectorNumber; /* Sector Number register */
unsigned char bCyln_Low; /* Cylinder Low register */
unsigned char bCyln_High; /* Cylinder High register */
unsigned char bDrv_Head; /* Drive Head register */
unsigned char bCommand; /* Command register */
unsigned char bError; /* Error register */
unsigned char bASRStat; /* Alternate Status register */
} AtaReg_t;
/* Drive geometry structure */
typedef struct {
unsigned short wBytesPerSector; /* Bytes per sector */
unsigned short wCylinders; /* Number of cylinder */
unsigned short wHeads; /* Number of head */
unsigned short wSectorsPerCylinder; /* Sectors per cylinder */
unsigned long ulTotalSectors; /* Total sectors */
} DrvGeom_t;
/* FAT file structure */
typedef struct {
int _flag; /* File mode flag */
int _file; /* File discreptor */
} FatFile_t;
/* FAT error information structure */
typedef struct {
unsigned char bErrCode; /* Error code */
unsigned char bType; /* Error type bit */
unsigned char bDrvNum; /* Drive number (Free = 0xff) */
unsigned long ulSecNum; /* Sector number */
} FatErr_t;
/* Directory entry structure */
typedef struct {
unsigned char bFileName[FAT_FILE_LEN]; /* Filename */
/* - (name 8 character + extension 3 character) */
unsigned char bAttributes; /* File attributes */
unsigned char bRev[10]; /* Reserved */
unsigned short wUpTime; /* Time */
unsigned short wUpDate; /* Date */
unsigned long ulFatEntry; /* FAT entry */
unsigned long ulFileSize; /* File size */
} FatDirEnt_t;
/* File control structure */
typedef struct {
unsigned char bDrvNum; /* Drive number (Free = 0xff) */
unsigned char bFlag; /* File mode flag */
unsigned char bDupCnt; /* File handle duplicate count */
FatDirEnt_t stDirEntry; /* Directory entry */
unsigned long ulRwPtr; /* Read/write pointer */
unsigned long ulDirFstCluNum; /* Cluster number which has first entry of */
/* - directory */
unsigned long ulDirSecNum; /* Sector number which has directory entry of */
/* - file */
unsigned long ulDirSbpos; /* Sector byte point of directory entry of file */
int iFileID; /* File ID number */
} FatFcs_t;
/* Sector buffer structure */
typedef struct FatSecBuf_t {
unsigned char bDrvNum; /* Drive number (Free = 0xff) */
unsigned char bRwArea; /* Read/write area flag */
unsigned long ulSecNum; /* Sector number */
unsigned char bBuf[FAT_SECTOR_SIZE]; /* Sector buffer */
struct FatSecBuf_t *pstNextSecBuf; /* Next sector buffer pointer */
} FatSecBuf_t;
/* Library initialize parameter structure */
typedef struct {
FatFcs_t *pstFcs; /* File control information */
FatFile_t *pstFile; /* File information */
FatFile_t **pstFp; /* File pointer array */
FatSecBuf_t *pstSecBuf; /* Sector buffer structure */
unsigned char bMaxFiles; /* Openable File number */
unsigned char bMaxBuffers; /* Sector buffer number */
unsigned char bVerify; /* Verify Enable/disable flag */
} FatInitParams_t;
/* FAT file system error code definition */
#define FAT_EOF -2 /* End of file */
#define FAT_ERR -1 /* Error */
#define FAT_OK 0x00 /* OK */
#define FAT_INVALID_FUNCTION 0x01 /* Invalid function code */
#define FAT_FILE_NOTFOUND 0x02 /* File not found */
#define FAT_PATH_NOTFOUND 0x03 /* Path not found */
#define FAT_TOO_MANYOPEN 0x04 /* File too many open */
#define FAT_ACCESS_DENIED 0x05 /* Access denied */
#define FAT_INVALID_HANDLE 0x06 /* Invalid handle */
#define FAT_INVALID_ACCESSCODE 0x0c /* Invalid access code */
#define FAT_INVALID_DATA 0x0d /* Invalid data */
#define FAT_INVALID_DRIVE 0x0f /* Invalid drive */
#define FAT_ATTEMPT_REMOVECD 0x10 /* Attempt to remove current dir */
#define FAT_NOT_SAMEDEVICE 0x11 /* Not same device */
#define FAT_NOMORE_FILES 0x12 /* No more files */
#define FAT_DSK_WP 0x13 /* Write protected disk */
#define FAT_UNKNOWN_DSU 0x14 /* Unknown disk unit */
#define FAT_DRV_NOTREADY 0x15 /* Drive not ready */
#define FAT_INVALID_CMD 0x16 /* Invalid command */
#define FAT_CRC_ERROR 0x17 /* CRC error */
#define FAT_INVALID_LENGTH 0x18 /* Invalid length */
#define FAT_SEEK_ERROR 0x19 /* Seek error */
#define FAT_NOT_DOSDISK 0x1a /* Not DOS disk */
#define FAT_SECTOR_NOTFOUND 0x1b /* Sector not found */
#define FAT_WRITE_FAULT 0x1d /* Write fault */
#define FAT_READ_FAULT 0x1e /* Read fault */
#define FAT_GENERAL_FAILURE 0x1f /* General failure */
#define FAT_SHARING_VIOLATION 0x20 /* Sharing violation */
#define FAT_LOCK_VIOLATION 0x21 /* Lock violation */
#define FAT_INVALID_DISKCHANGE 0x22 /* Invalid disk change */
#define FAT_EMPTY_CLUSTER 0x23 /* Empty cluster */
#define FAT_DRIVE_BUSY 0x24 /* Drive busy */
/* FatErr_t type bit definition */
/* Error(bit3..0) */
#define FAT_ET_GENE 0x00 /* General failure */
#define FAT_ET_CHRDEV 0x01 /* Open character device */
#define FAT_ET_NOFAT 0x02 /* Not FAT file system */
#define FAT_ET_BADFNAME 0x03 /* Bad file name */
#define FAT_ET_BADFAT 0x04 /* Invalid information FAT, cluster */
#define FAT_ET_PARA 0x05 /* Invalid parameter */
#define FAT_ET_BPB_RD 0x08 /* BPB disk read failure */
#define FAT_ET_DSK_RD 0x09 /* Disk read failure */
#define FAT_ET_DSK_WR 0x0a /* Disk write failure */
#define FAT_ET_MASK_RM 0x0f /* Error bit mask */
/* Program end request(bit4) */
#define FAT_ET_ABORT 0x10 /* Program end request */
/* Reserved(bit5) : set 0 */
/* Error(bit7,6) */
#define FAT_ET_SYS 0x00 /* System area (except of FAT, directory, data) */
#define FAT_ET_FAT 0x40 /* FAT area */
#define FAT_ET_RDIR 0x80 /* Directory area (contain of sub directory in */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -