25 #include "driver/IO.h"
39 void setDriver(
IO& io) {
p_io = &io; }
44 FRESULT
f_open(
FIL* fp,
const TCHAR* path,
47 FRESULT
f_read(
FIL* fp,
void* buff, UINT btr,
49 FRESULT
f_write(
FIL* fp,
const void* buff, UINT btw,
59 const TCHAR* pattern);
61 FRESULT
f_mkdir(
const TCHAR* path);
64 FRESULT
f_rename(
const TCHAR* path_old,
65 const TCHAR* path_new);
67 FRESULT
f_chmod(
const TCHAR* path, BYTE attr,
69 FRESULT
f_utime(
const TCHAR* path,
73 FRESULT
f_getcwd(TCHAR* buff, UINT len);
75 const TCHAR* path, DWORD* nclst,
77 FRESULT
f_getlabel(
const TCHAR* path, TCHAR* label,
80 FRESULT
f_forward(
FIL* fp, UINT (*func)(
const BYTE*, UINT), UINT btf,
89 BYTE pdrv,
const LBA_t ptbl[],
96 TCHAR*
f_gets(TCHAR* buff,
int len,
FIL* fp);
98 inline bool f_eof(
FIL* fp) {
99 return ((
int)((fp)->fptr == (fp)->obj.objsize));
101 inline BYTE f_error(
FIL* fp) {
return ((fp)->err); }
102 inline FSIZE_t f_tell(FIL* fp) {
return ((fp)->fptr); }
103 inline FSIZE_t f_size(FIL* fp) {
return ((fp)->obj.objsize); }
104 inline FRESULT f_rewind(FIL* fp) {
return f_lseek((fp), 0); }
105 inline FRESULT f_rewinddir(DIR* dp) {
return f_readdir((dp), 0); }
106 inline FRESULT f_rmdir(
const TCHAR* path) {
return f_unlink(path); }
107 inline FRESULT f_unmount(
const TCHAR* path) {
return f_mount(0, path, 0); }
113 #if !FF_FS_READONLY && !FF_FS_NORTC
114 DWORD get_fattime(
void);
119 int ff_cre_syncobj(BYTE vol, FF_SYNC_t* sobj);
120 int ff_req_grant(FF_SYNC_t sobj);
121 void ff_rel_grant(FF_SYNC_t sobj);
122 int ff_del_syncobj(FF_SYNC_t sobj);
141 #if FF_VOLUMES < 1 || FF_VOLUMES > 10
142 #error Wrong FF_VOLUMES setting
153 FILESEM Files[FF_FS_LOCK];
157 #ifdef FF_VOLUME_STRS
158 const char*
const VolumeStr[FF_VOLUMES] = {
164 #if FF_MIN_GPT > 0x100000000
165 #error Wrong FF_MIN_GPT setting
167 const BYTE GUID_MS_Basic[16] = {0xA2, 0xA0, 0xD0, 0xEB, 0xE5, 0xB9,
168 0x33, 0x44, 0x87, 0xC0, 0x68, 0xB6,
169 0xB7, 0x26, 0x99, 0xC7};
178 #error LFN must be enabled when enable exFAT
181 #define INIT_NAMBUF(fs)
182 #define FREE_NAMBUF()
183 #define LEAVE_MKFS(res) return res
186 #if FF_MAX_LFN < 12 || FF_MAX_LFN > 255
187 #error Wrong setting of FF_MAX_LFN
189 #if FF_LFN_BUF < FF_SFN_BUF || FF_SFN_BUF < 12
190 #error Wrong setting of FF_LFN_BUF or FF_SFN_BUF
192 #if FF_LFN_UNICODE < 0 || FF_LFN_UNICODE > 3
193 #error Wrong setting of FF_LFN_UNICODE
196 1, 3, 5, 7, 9, 14, 16,
197 18, 20, 22, 24, 28, 30};
199 #define MAXDIRB(nc) \
207 DirBuf[MAXDIRB(FF_MAX_LFN)];
209 WCHAR
LfnBuf[FF_MAX_LFN + 1];
211 #define INIT_NAMBUF(fs)
212 #define FREE_NAMBUF()
213 #define LEAVE_MKFS(res) return res
215 #elif FF_USE_LFN == 2
219 WCHAR lbuf[FF_MAX_LFN + 1]; \
220 BYTE dbuf[MAXDIRB(FF_MAX_LFN)];
222 #define INIT_NAMBUF(fs) \
224 (fs)->lfnbuf = lbuf; \
225 (fs)->dirbuf = dbuf; \
227 #define FREE_NAMBUF()
229 #define DEF_NAMBUF WCHAR lbuf[FF_MAX_LFN + 1];
230 #define INIT_NAMBUF(fs) \
231 { (fs)->lfnbuf = lbuf; }
232 #define FREE_NAMBUF()
235 #define LEAVE_MKFS(res) return res
237 #elif FF_USE_LFN == 3
243 #define INIT_NAMBUF(fs) \
245 lfn = ff_memalloc((FF_MAX_LFN + 1) * 2 + MAXDIRB(FF_MAX_LFN)); \
246 if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); \
247 (fs)->lfnbuf = lfn; \
248 (fs)->dirbuf = (BYTE*)(lfn + FF_MAX_LFN + 1); \
250 #define FREE_NAMBUF() ff_memfree(lfn)
252 #define DEF_NAMBUF WCHAR* lfn;
253 #define INIT_NAMBUF(fs) \
255 lfn = ff_memalloc((FF_MAX_LFN + 1) * 2); \
256 if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); \
257 (fs)->lfnbuf = lfn; \
259 #define FREE_NAMBUF() ff_memfree(lfn)
261 #define LEAVE_MKFS(res) \
263 if (!work) ff_memfree(buf); \
266 #define MAX_MALLOC 0x8000
269 #error Wrong setting of FF_USE_LFN
274 void putc_bfd(
putbuff* pb, TCHAR c);
277 FRESULT sync_window(
FATFS* fs);
278 FRESULT move_window(
FATFS* fs, LBA_t sect);
279 FRESULT sync_fs(
FATFS* fs);
280 DWORD get_fat(
FFOBJID* obj, DWORD clst);
281 FRESULT put_fat(
FATFS* fs, DWORD clst, DWORD val);
282 DWORD find_bitmap(
FATFS* fs, DWORD clst, DWORD ncl);
283 FRESULT remove_chain(
FFOBJID* obj, DWORD clst, DWORD pclst);
284 DWORD create_chain(
FFOBJID* obj, DWORD clst);
285 FRESULT dir_clear(
FATFS* fs, DWORD clst);
286 FRESULT dir_sdi(
DIR* dp, DWORD ofs);
287 FRESULT dir_next(
DIR* dp,
int stretch);
288 FRESULT dir_alloc(
DIR* dp, UINT nent);
289 FRESULT dir_read(
DIR* dp,
int vol);
290 FRESULT dir_find(
DIR* dp);
291 FRESULT dir_register(
DIR* dp);
292 FRESULT dir_remove(
DIR* dp);
293 FRESULT follow_path(
DIR* dp,
const TCHAR* path);
294 UINT check_fs(
FATFS* fs, LBA_t sect);
295 UINT find_volume(
FATFS* fs, UINT part);
296 FRESULT mount_volume(
const TCHAR** path,
FATFS** rfs, BYTE mode);
297 int cmp_lfn(
const WCHAR* lfnbuf, BYTE* dir);
298 int pick_lfn(WCHAR* lfnbuf, BYTE* dir);
299 void put_lfn(
const WCHAR* lfn, BYTE* dir, BYTE ord, BYTE sum);
300 FRESULT create_partition(BYTE drv,
const LBA_t plst[], UINT sys, BYTE* buf);
301 FRESULT change_bitmap(
FATFS* fs, DWORD clst, DWORD ncl,
int bv);
302 FRESULT fill_first_frag(
FFOBJID* obj);
303 FRESULT fill_last_frag(
FFOBJID* obj, DWORD lcl, DWORD term);
304 FRESULT load_xdir(
DIR* dp);
305 FRESULT load_obj_xdir(
DIR* dp,
const FFOBJID* obj);
306 FRESULT store_xdir(
DIR*);
307 FRESULT chk_lock(
DIR* dp,
int acc);
309 UINT inc_lock(
DIR* dp,
int acc);
310 FRESULT dec_lock(UINT i);
323 return malloc(msize);
330 void ff_memfree(
void* mblock
341 WCHAR ff_oem2uni(WCHAR oem, WORD cp);
342 WCHAR ff_uni2oem(DWORD uni, WORD cp);
343 DWORD ff_wtoupper(DWORD uni);
API for FatFS See http://elm-chan.org/fsw/ff/00index_e.html.
Definition: ff.h:34
FRESULT f_readdir(DIR *dp, FILINFO *fno)
Definition: ff.cpp:4537
FRESULT f_close(FIL *fp)
Definition: ff.cpp:4065
FRESULT f_getcwd(TCHAR *buff, UINT len)
FRESULT f_expand(FIL *fp, FSIZE_t fsz, BYTE opt)
FRESULT f_utime(const TCHAR *path, const FILINFO *fno)
Definition: ff.cpp:5135
FRESULT f_mount(FATFS *fs, const TCHAR *path, BYTE opt)
Definition: ff.cpp:3521
FRESULT f_findnext(DIR *dp, FILINFO *fno)
FRESULT f_stat(const TCHAR *path, FILINFO *fno)
Definition: ff.cpp:4625
TCHAR * f_gets(TCHAR *buff, int len, FIL *fp)
Definition: ff.cpp:6244
WORD Fsid
Definition: ff.h:145
IO * p_io
Definition: ff.h:125
int f_puts(const TCHAR *str, FIL *cp)
Definition: ff.cpp:6550
FRESULT f_forward(FIL *fp, UINT(*func)(const BYTE *, UINT), UINT btf, UINT *bf)
FRESULT f_opendir(DIR *dp, const TCHAR *path)
Definition: ff.cpp:4443
FRESULT f_chdrive(const TCHAR *path)
FRESULT f_getlabel(const TCHAR *path, TCHAR *label, DWORD *vsn)
int f_printf(FIL *fp, const TCHAR *str,...)
Definition: ff.cpp:6570
FRESULT f_chmod(const TCHAR *path, BYTE attr, BYTE mask)
Definition: ff.cpp:5088
FRESULT f_unlink(const TCHAR *path)
Definition: ff.cpp:4800
FRESULT f_fdisk(BYTE pdrv, const LBA_t ptbl[], void *work)
FatFs(IO &io)
Constructor which is providing the io driver.
Definition: ff.h:38
IO * getDriver()
Definition: ff.h:40
FRESULT f_setlabel(const TCHAR *label)
FRESULT f_rename(const TCHAR *path_old, const TCHAR *path_new)
Definition: ff.cpp:4978
FRESULT f_getfree(const TCHAR *path, DWORD *nclst, FATFS **fatfs)
Definition: ff.cpp:4660
WCHAR LfnBuf[FF_MAX_LFN+1]
Definition: ff.h:210
FRESULT f_sync(FIL *fp)
Definition: ff.cpp:3984
FRESULT f_mkfs(const TCHAR *path, const MKFS_PARM *opt, void *work, UINT len)
Definition: ff.cpp:5708
FATFS * FatFsDir[FF_VOLUMES]
Definition: ff.h:143
FRESULT f_lseek(FIL *fp, FSIZE_t ofs)
Definition: ff.cpp:4280
FRESULT f_write(FIL *fp, const void *buff, UINT btw, UINT *bw)
Definition: ff.cpp:3862
FRESULT f_read(FIL *fp, void *buff, UINT btr, UINT *br)
Definition: ff.cpp:3761
FRESULT f_findfirst(DIR *dp, FILINFO *fno, const TCHAR *path, const TCHAR *pattern)
FRESULT f_chdir(const TCHAR *path)
FRESULT f_mkdir(const TCHAR *path)
Definition: ff.cpp:4894
FRESULT f_closedir(DIR *dp)
Definition: ff.cpp:4509
const BYTE LfnOfs[13]
Definition: ff.h:194
int f_putc(TCHAR c, FIL *fp)
Definition: ff.cpp:6530
void clear_lock(FATFS *fs)
FRESULT f_open(FIL *fp, const TCHAR *path, BYTE mode)
Definition: ff.cpp:3569
FRESULT f_truncate(FIL *fp)
Definition: ff.cpp:4750
FatFS interface definition.
Definition: IO.h:74