#ifndef _FATFS
#define _FATFS 68020
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
typedef uint8_t BYTE;
typedef int16_t SHORT;
typedef uint16_t WORD;
typedef uint16_t WCHAR;
typedef int INT;
typedef unsigned int UINT;
typedef int32_t LONG;
typedef uint32_t DWORD;
typedef uint64_t QWORD;
#include FFCONF_H
#if _FATFS != _FFCONF
#error Wrong configuration file (ffconf.h).
#endif
#if _MULTI_PARTITION
#define LD2PT(fs) (fs->part)
#else
#define LD2PT(fs) 0
#endif
#if _LFN_UNICODE
#if _USE_LFN == 0
#error _LFN_UNICODE must be 0 at non-LFN cfg.
#endif
#ifndef _INC_TCHAR
typedef WCHAR TCHAR;
#define _T(x) L ## x
#define _TEXT(x) L ## x
#endif
#else
#ifndef _INC_TCHAR
typedef char TCHAR;
#define _T(x) x
#define _TEXT(x) x
#endif
#endif
#if _FS_EXFAT
#if _USE_LFN == 0
#error LFN must be enabled when enable exFAT
#endif
typedef QWORD FSIZE_t;
#else
typedef DWORD FSIZE_t;
#endif
typedef struct {
void *drv; #if _MULTI_PARTITION
BYTE part; #endif
BYTE fs_type;
BYTE n_fats;
BYTE wflag;
BYTE fsi_flag;
WORD id;
WORD n_rootdir;
WORD csize;
#if _MAX_SS != _MIN_SS
WORD ssize;
#endif
#if _USE_LFN != 0
WCHAR* lfnbuf;
#endif
#if _FS_EXFAT
BYTE* dirbuf;
#endif
#if _FS_REENTRANT
_SYNC_t sobj;
#endif
#if !_FS_READONLY
DWORD last_clst;
DWORD free_clst;
#endif
#if _FS_RPATH != 0
DWORD cdir;
#if _FS_EXFAT
DWORD cdc_scl;
DWORD cdc_size;
DWORD cdc_ofs;
#endif
#endif
DWORD n_fatent;
DWORD fsize;
DWORD volbase;
DWORD fatbase;
DWORD dirbase;
DWORD database;
DWORD winsect;
BYTE win[_MAX_SS];
} FATFS;
typedef struct {
FATFS* fs;
WORD id;
BYTE attr;
BYTE stat;
DWORD sclust;
FSIZE_t objsize;
#if _FS_EXFAT
DWORD n_cont;
DWORD c_scl;
DWORD c_size;
DWORD c_ofs;
#endif
#if _FS_LOCK != 0
UINT lockid;
#endif
} _FDID;
typedef struct {
_FDID obj;
BYTE flag;
BYTE err;
FSIZE_t fptr;
DWORD clust;
DWORD sect;
#if !_FS_READONLY
DWORD dir_sect;
BYTE* dir_ptr;
#endif
#if _USE_FASTSEEK
DWORD* cltbl;
#endif
#if !_FS_TINY
BYTE buf[_MAX_SS];
#endif
} FIL;
typedef struct {
_FDID obj;
DWORD dptr;
DWORD clust;
DWORD sect;
BYTE* dir;
BYTE fn[12];
#if _USE_LFN != 0
DWORD blk_ofs;
#endif
#if _USE_FIND
const TCHAR* pat;
#endif
} FF_DIR;
typedef struct {
FSIZE_t fsize;
WORD fdate;
WORD ftime;
BYTE fattrib;
#if _USE_LFN != 0
TCHAR altname[13];
TCHAR fname[_MAX_LFN + 1];
#else
TCHAR fname[13];
#endif
} FILINFO;
typedef enum {
FR_OK = 0,
FR_DISK_ERR,
FR_INT_ERR,
FR_NOT_READY,
FR_NO_FILE,
FR_NO_PATH,
FR_INVALID_NAME,
FR_DENIED,
FR_EXIST,
FR_INVALID_OBJECT,
FR_WRITE_PROTECTED,
FR_INVALID_DRIVE,
FR_NOT_ENABLED,
FR_NO_FILESYSTEM,
FR_MKFS_ABORTED,
FR_TIMEOUT,
FR_LOCKED,
FR_NOT_ENOUGH_CORE,
FR_TOO_MANY_OPEN_FILES,
FR_INVALID_PARAMETER
} FRESULT;
FRESULT f_open (FATFS *fs, FIL* fp, const TCHAR* path, BYTE mode);
FRESULT f_close (FIL* fp);
FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br);
FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw);
FRESULT f_lseek (FIL* fp, FSIZE_t ofs);
FRESULT f_truncate (FIL* fp);
FRESULT f_sync (FIL* fp);
FRESULT f_opendir (FATFS *fs, FF_DIR* dp, const TCHAR* path);
FRESULT f_closedir (FF_DIR* dp);
FRESULT f_readdir (FF_DIR* dp, FILINFO* fno);
FRESULT f_findfirst (FF_DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern);
FRESULT f_findnext (FF_DIR* dp, FILINFO* fno);
FRESULT f_mkdir (FATFS *fs, const TCHAR* path);
FRESULT f_unlink (FATFS *fs, const TCHAR* path);
FRESULT f_rename (FATFS *fs, const TCHAR* path_old, const TCHAR* path_new);
FRESULT f_stat (FATFS *fs, const TCHAR* path, FILINFO* fno);
FRESULT f_chmod (FATFS *fs, const TCHAR* path, BYTE attr, BYTE mask);
FRESULT f_utime (FATFS *fs, const TCHAR* path, const FILINFO* fno);
FRESULT f_chdir (FATFS *fs, const TCHAR* path);
FRESULT f_getcwd (FATFS *fs, TCHAR* buff, UINT len);
FRESULT f_getfree (FATFS *fs, DWORD* nclst);
FRESULT f_getlabel (FATFS *fs, TCHAR* label, DWORD* vsn);
FRESULT f_setlabel (FATFS *fs, const TCHAR* label);
FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf);
FRESULT f_expand (FIL* fp, FSIZE_t szf, BYTE opt);
FRESULT f_mount (FATFS* fs);
FRESULT f_umount (FATFS* fs);
FRESULT f_mkfs (FATFS *fs, BYTE opt, DWORD au, void* work, UINT len);
FRESULT f_fdisk (void *pdrv, const DWORD* szt, void* work);
#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
#define f_error(fp) ((fp)->err)
#define f_tell(fp) ((fp)->fptr)
#define f_size(fp) ((fp)->obj.objsize)
#define f_rewind(fp) f_lseek((fp), 0)
#define f_rewinddir(dp) f_readdir((dp), 0)
#ifndef EOF
#define EOF (-1)
#endif
#if !_FS_READONLY && !_FS_NORTC
DWORD get_fattime (void);
#endif
#if _USE_LFN != 0
WCHAR ff_convert (WCHAR chr, UINT dir);
WCHAR ff_wtoupper (WCHAR chr);
#if _USE_LFN == 3
void* ff_memalloc (UINT msize);
void ff_memfree (void* mblock);
#endif
#endif
#if _FS_REENTRANT
int ff_cre_syncobj (FATFS *fatfs, _SYNC_t* sobj);
int ff_req_grant (_SYNC_t sobj);
void ff_rel_grant (_SYNC_t sobj);
int ff_del_syncobj (_SYNC_t sobj);
#endif
#define FA_READ 0x01
#define FA_WRITE 0x02
#define FA_OPEN_EXISTING 0x00
#define FA_CREATE_NEW 0x04
#define FA_CREATE_ALWAYS 0x08
#define FA_OPEN_ALWAYS 0x10
#define FA_OPEN_APPEND 0x30
#define CREATE_LINKMAP ((FSIZE_t)0 - 1)
#define FM_FAT 0x01
#define FM_FAT32 0x02
#define FM_EXFAT 0x04
#define FM_ANY 0x07
#define FM_SFD 0x08
#define FS_FAT12 1
#define FS_FAT16 2
#define FS_FAT32 3
#define FS_EXFAT 4
#define AM_RDO 0x01
#define AM_HID 0x02
#define AM_SYS 0x04
#define AM_DIR 0x10
#define AM_ARC 0x20
#ifdef __cplusplus
}
#endif
#endif