00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _FATFS
00018 #define _FATFS 80376
00019
00020 #ifdef __cplusplus
00021 extern "C" {
00022 #endif
00023
00024 #include "integer.h"
00025 #include "ffconf.h"
00026 #if _FATFS != _FFCONF
00027 #error Wrong configuration file (ffconf.h).
00028 #endif
00029
00030
00031
00032
00033
00034 #if _MULTI_PARTITION
00035 typedef struct {
00036 BYTE pd;
00037 BYTE pt;
00038 } PARTITION;
00039 extern PARTITION VolToPart[];
00040 #define LD2PD(vol) (VolToPart[vol].pd)
00041 #define LD2PT(vol) (VolToPart[vol].pt)
00042
00043 #else
00044 #define LD2PD(vol) (BYTE)(vol)
00045 #define LD2PT(vol) 0
00046
00047 #endif
00048
00049
00050
00051
00052
00053 #if _LFN_UNICODE
00054 #if !_USE_LFN
00055 #error _LFN_UNICODE must be 0 at non-LFN cfg.
00056 #endif
00057 #ifndef _INC_TCHAR
00058 typedef WCHAR TCHAR;
00059 #define _T(x) L ## x
00060 #define _TEXT(x) L ## x
00061 #endif
00062
00063 #else
00064 #ifndef _INC_TCHAR
00065 typedef char TCHAR;
00066 #define _T(x) x
00067 #define _TEXT(x) x
00068 #endif
00069
00070 #endif
00071
00072
00073
00074
00075
00076 typedef struct {
00077 BYTE fs_type;
00078 BYTE drv;
00079 BYTE csize;
00080 BYTE n_fats;
00081 BYTE wflag;
00082 BYTE fsi_flag;
00083 WORD id;
00084 WORD n_rootdir;
00085 #if _MAX_SS != _MIN_SS
00086 WORD ssize;
00087 #endif
00088 #if _FS_REENTRANT
00089 _SYNC_t sobj;
00090 #endif
00091 #if !_FS_READONLY
00092 DWORD last_clust;
00093 DWORD free_clust;
00094 #endif
00095 #if _FS_RPATH
00096 DWORD cdir;
00097 #endif
00098 DWORD n_fatent;
00099 DWORD fsize;
00100 DWORD volbase;
00101 DWORD fatbase;
00102 DWORD dirbase;
00103 DWORD database;
00104 DWORD winsect;
00105 BYTE win[_MAX_SS];
00106 } FATFS;
00107
00108
00109
00110
00111
00112 typedef struct {
00113 FATFS* fs;
00114 WORD id;
00115 BYTE flag;
00116 BYTE err;
00117 DWORD fptr;
00118 DWORD fsize;
00119 DWORD sclust;
00120 DWORD clust;
00121 DWORD dsect;
00122 #if !_FS_READONLY
00123 DWORD dir_sect;
00124 BYTE* dir_ptr;
00125 #endif
00126 #if _USE_FASTSEEK
00127 DWORD* cltbl;
00128 #endif
00129 #if _FS_LOCK
00130 UINT lockid;
00131 #endif
00132 #if !_FS_TINY
00133 BYTE buf[_MAX_SS];
00134 #endif
00135 } FIL;
00136
00137
00138
00139
00140
00141 typedef struct {
00142 FATFS* fs;
00143 WORD id;
00144 WORD index;
00145 DWORD sclust;
00146 DWORD clust;
00147 DWORD sect;
00148 BYTE* dir;
00149 BYTE* fn;
00150 #if _FS_LOCK
00151 UINT lockid;
00152 #endif
00153 #if _USE_LFN
00154 WCHAR* lfn;
00155 WORD lfn_idx;
00156 #endif
00157 } DIR;
00158
00159
00160
00161
00162
00163 typedef struct {
00164 DWORD fsize;
00165 WORD fdate;
00166 WORD ftime;
00167 BYTE fattrib;
00168 TCHAR fname[13];
00169 #if _USE_LFN
00170 TCHAR* lfname;
00171 UINT lfsize;
00172 #endif
00173 } FILINFO;
00174
00175
00176
00177
00178
00179 typedef enum {
00180 FR_OK = 0,
00181 FR_DISK_ERR,
00182 FR_INT_ERR,
00183 FR_NOT_READY,
00184 FR_NO_FILE,
00185 FR_NO_PATH,
00186 FR_INVALID_NAME,
00187 FR_DENIED,
00188 FR_EXIST,
00189 FR_INVALID_OBJECT,
00190 FR_WRITE_PROTECTED,
00191 FR_INVALID_DRIVE,
00192 FR_NOT_ENABLED,
00193 FR_NO_FILESYSTEM,
00194 FR_MKFS_ABORTED,
00195 FR_TIMEOUT,
00196 FR_LOCKED,
00197 FR_NOT_ENOUGH_CORE,
00198 FR_TOO_MANY_OPEN_FILES,
00199 FR_INVALID_PARAMETER
00200 } FRESULT;
00201
00202
00203
00204
00205
00206
00207 FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode);
00208 FRESULT f_close (FIL* fp);
00209 FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br);
00210 FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw);
00211 FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf);
00212 FRESULT f_lseek (FIL* fp, DWORD ofs);
00213 FRESULT f_truncate (FIL* fp);
00214 FRESULT f_sync (FIL* fp);
00215 FRESULT f_opendir (DIR* dp, const TCHAR* path);
00216 FRESULT f_closedir (DIR* dp);
00217 FRESULT f_readdir (DIR* dp, FILINFO* fno);
00218 FRESULT f_mkdir (const TCHAR* path);
00219 FRESULT f_unlink (const TCHAR* path);
00220 FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new);
00221 FRESULT f_stat (const TCHAR* path, FILINFO* fno);
00222 FRESULT f_chmod (const TCHAR* path, BYTE value, BYTE mask);
00223 FRESULT f_utime (const TCHAR* path, const FILINFO* fno);
00224 FRESULT f_chdir (const TCHAR* path);
00225 FRESULT f_chdrive (const TCHAR* path);
00226 FRESULT f_getcwd (TCHAR* buff, UINT len);
00227 FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs);
00228 FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn);
00229 FRESULT f_setlabel (const TCHAR* label);
00230 FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt);
00231 FRESULT f_mkfs (const TCHAR* path, BYTE sfd, UINT au);
00232 FRESULT f_fdisk (BYTE pdrv, const DWORD szt[], void* work);
00233 int f_putc (TCHAR c, FIL* fp);
00234 int f_puts (const TCHAR* str, FIL* cp);
00235 int f_printf (FIL* fp, const TCHAR* str, ...);
00236 TCHAR* f_gets (TCHAR* buff, int len, FIL* fp);
00237
00238 #define f_eof(fp) ((int)((fp)->fptr == (fp)->fsize))
00239 #define f_error(fp) ((fp)->err)
00240 #define f_tell(fp) ((fp)->fptr)
00241 #define f_size(fp) ((fp)->fsize)
00242
00243 #ifndef EOF
00244 #define EOF (-1)
00245 #endif
00246
00247
00248
00249
00250
00251
00252
00253
00254 #if !_FS_READONLY && !_FS_NORTC
00255 DWORD get_fattime (void);
00256 #endif
00257
00258
00259 #if _USE_LFN
00260 WCHAR ff_convert (WCHAR chr, UINT dir);
00261 WCHAR ff_wtoupper (WCHAR chr);
00262 #if _USE_LFN == 3
00263 void* ff_memalloc (UINT msize);
00264 void ff_memfree (void* mblock);
00265 #endif
00266 #endif
00267
00268
00269 #if _FS_REENTRANT
00270 int ff_cre_syncobj (BYTE vol, _SYNC_t* sobj);
00271 int ff_req_grant (_SYNC_t sobj);
00272 void ff_rel_grant (_SYNC_t sobj);
00273 int ff_del_syncobj (_SYNC_t sobj);
00274 #endif
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285 #define FA_READ 0x01
00286 #define FA_OPEN_EXISTING 0x00
00287
00288 #if !_FS_READONLY
00289 #define FA_WRITE 0x02
00290 #define FA_CREATE_NEW 0x04
00291 #define FA_CREATE_ALWAYS 0x08
00292 #define FA_OPEN_ALWAYS 0x10
00293 #define FA__WRITTEN 0x20
00294 #define FA__DIRTY 0x40
00295 #endif
00296
00297
00298
00299
00300 #define FS_FAT12 1
00301 #define FS_FAT16 2
00302 #define FS_FAT32 3
00303
00304
00305
00306
00307 #define AM_RDO 0x01
00308 #define AM_HID 0x02
00309 #define AM_SYS 0x04
00310 #define AM_VOL 0x08
00311 #define AM_LFN 0x0F
00312 #define AM_DIR 0x10
00313 #define AM_ARC 0x20
00314 #define AM_MASK 0x3F
00315
00316
00317
00318 #define CREATE_LINKMAP 0xFFFFFFFF
00319
00320
00321
00322
00323
00324
00325 #if _WORD_ACCESS == 1
00326 #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
00327 #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
00328 #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
00329 #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
00330 #else
00331 #define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
00332 #define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
00333 #define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
00334 #define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8); *((BYTE*)(ptr)+2)=(BYTE)((DWORD)(val)>>16); *((BYTE*)(ptr)+3)=(BYTE)((DWORD)(val)>>24)
00335 #endif
00336
00337 #ifdef __cplusplus
00338 }
00339 #endif
00340
00341 #endif