CARME-M4 BSP  V1.5
ff.h
Go to the documentation of this file.
1 #ifndef _FATFS
2 #define _FATFS 80960 /* Revision ID */
3 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif /* __cplusplus */
37 
38 #include "integer.h" /* Basic integer types */
39 #include "ffconf.h" /* FatFs configuration options */
40 
41 #if _FATFS != _FFCONF
42 #error Wrong configuration file (ffconf.h).
43 #endif
44 
45 /* Definitions of volume management */
46 #if _MULTI_PARTITION /* Multiple partition configuration */
47 
51 typedef struct {
52  BYTE pd;
53  BYTE pt;
54 } PARTITION;
55 extern PARTITION VolToPart[];
56 #define LD2PD(vol) (VolToPart[vol].pd)
57 #define LD2PT(vol) (VolToPart[vol].pt)
58 #else /* Single partition configuration */
59 #define LD2PD(vol) (BYTE)(vol)
61 #define LD2PT(vol) 0
62 #endif
63 
64 
65 /* Type of path name strings on FatFs API */
66 #if _LFN_UNICODE /* Unicode string */
67 #if !_USE_LFN
68 #error _LFN_UNICODE must be 0 in non-LFN cfg.
69 #endif
70 #ifndef _INC_TCHAR
71 typedef WCHAR TCHAR;
72 #define _T(x) L ## x
73 #define _TEXT(x) L ## x
74 #endif
75 #else /* ANSI/OEM string */
76 #ifndef _INC_TCHAR
77 typedef char TCHAR;
78 #define _T(x) x
79 #define _TEXT(x) x
80 #endif
81 #endif /* _LFN_UNICODE */
82 
86 typedef struct {
87  BYTE fs_type;
88  BYTE drv;
89  BYTE csize;
90  BYTE n_fats;
91  BYTE wflag;
92  BYTE fsi_flag;
93  WORD id;
94  WORD n_rootdir;
96 #if _MAX_SS != 512
97  WORD ssize;
98 #endif
99 #if _FS_REENTRANT
100  _SYNC_t sobj;
101 #endif
102 #if !_FS_READONLY
103  DWORD last_clust;
104  DWORD free_clust;
105 #endif
106 #if _FS_RPATH
107  DWORD cdir;
108 #endif
109  DWORD n_fatent;
111  DWORD fsize;
112  DWORD volbase;
113  DWORD fatbase;
114  DWORD dirbase;
116  DWORD database;
117  DWORD winsect;
118  BYTE win[_MAX_SS];
121 
125 typedef struct {
126  FATFS* fs;
128  WORD id;
130  BYTE flag;
131  BYTE err;
132  DWORD fptr;
134  DWORD fsize;
135  DWORD sclust;
137  DWORD clust;
138  DWORD dsect;
139 #if !_FS_READONLY
140  DWORD dir_sect;
141  BYTE* dir_ptr;
143 #endif
144 #if _USE_FASTSEEK
145  DWORD* cltbl;
147 #endif
148 #if _FS_LOCK
149  UINT lockid;
151 #endif
152 #if !_FS_TINY
153  BYTE buf[_MAX_SS];
154 #endif
155 } FIL;
156 
160 typedef struct {
161  FATFS* fs;
163  WORD id;
165  WORD index;
166  DWORD sclust;
167  DWORD clust;
168  DWORD sect;
169  BYTE* dir;
171  BYTE* fn;
173 #if _FS_LOCK
174  UINT lockid;
176 #endif
177 #if _USE_LFN
178 WCHAR* lfn;
179 WORD lfn_idx;
181 #endif
182 } DIR;
183 
187 typedef struct {
188  DWORD fsize;
189  WORD fdate;
190  WORD ftime;
191  BYTE fattrib;
192  TCHAR fname[13];
193 #if _USE_LFN
194  TCHAR* lfname;
195  UINT lfsize;
196 #endif
197 } FILINFO;
198 
202 typedef enum {
203  FR_OK = 0,
207  FR_NOT_READY,
231 FRESULT f_open(FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
232 FRESULT f_close(FIL* fp); /* Close an open file object */
233 FRESULT f_read(FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from a file */
234 #if !_FS_READONLY
235 FRESULT f_write(FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to a file */
236 #endif
237 #if _USE_FORWARD && _FS_TINY
238 FRESULT f_forward(FIL* fp, UINT (*func)(const BYTE*, UINT), UINT btf,
239  UINT* bf); /* Forward data to the stream */
240 #endif
241 #if _FS_MINIMIZE <= 2
242 FRESULT f_lseek(FIL* fp, DWORD ofs); /* Move file pointer of a file object */
243 #endif
244 #if _FS_MINIMIZE == 0 && !_FS_READONLY
245 FRESULT f_truncate(FIL* fp); /* Truncate file */
246 #endif
247 #if !_FS_READONLY
248 FRESULT f_sync(FIL* fp); /* Flush cached data of a writing file */
249 #endif
250 #if _FS_MINIMIZE <= 1
251 FRESULT f_opendir(DIR* dp, const TCHAR* path); /* Open a directory */
252 #endif
253 #if _FS_MINIMIZE <= 1
254 FRESULT f_closedir(DIR* dp); /* Close an open directory */
255 #endif
256 #if _FS_MINIMIZE <= 1
257 FRESULT f_readdir(DIR* dp, FILINFO* fno); /* Read a directory item */
258 #endif
259 #if _FS_MINIMIZE == 0 && !_FS_READONLY
260 FRESULT f_mkdir(const TCHAR* path); /* Create a sub directory */
261 #endif
262 #if _FS_MINIMIZE == 0 && !_FS_READONLY
263 FRESULT f_unlink(const TCHAR* path); /* Delete an existing file or directory */
264 #endif
265 #if _FS_MINIMIZE == 0 && !_FS_READONLY
266 FRESULT f_rename(const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
267 #endif
268 #if _FS_MINIMIZE == 0
269 FRESULT f_stat(const TCHAR* path, FILINFO* fno); /* Get file status */
270 #endif
271 #if _FS_MINIMIZE == 0 && !_FS_READONLY
272 FRESULT f_chmod(const TCHAR* path, BYTE value, BYTE mask); /* Change attribute of the file/dir */
273 #endif
274 #if _FS_MINIMIZE == 0 && !_FS_READONLY
275 FRESULT f_utime(const TCHAR* path, const FILINFO* fno); /* Change times-tamp of the file/dir */
276 #endif
277 #if _FS_RPATH >= 1
278 FRESULT f_chdir(const TCHAR* path); /* Change current directory */
279 #endif
280 #if _FS_RPATH >= 1 && _VOLUMES >= 2
281 FRESULT f_chdrive(const TCHAR* path); /* Change current drive */
282 #endif
283 #if _FS_RPATH >= 2
284 FRESULT f_getcwd(TCHAR* buff, UINT len); /* Get current directory */
285 #endif
286 #if _FS_MINIMIZE == 0 && !_FS_READONLY
287 FRESULT f_getfree(const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */
288 #endif
289 #if _USE_LABEL
290 FRESULT f_getlabel(const TCHAR* path, TCHAR* label, DWORD* sn); /* Get volume label */
291 #endif
292 #if _USE_LABEL && !_FS_READONLY
293 FRESULT f_setlabel(const TCHAR* label); /* Set volume label */
294 #endif
295 FRESULT f_mount(FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
296 #if _USE_MKFS && !_FS_READONLY
297 FRESULT f_mkfs(const TCHAR* path, BYTE sfd, UINT au); /* Create a file system on the volume */
298 #endif
299 #if _USE_MKFS && !_FS_READONLY && _MULTI_PARTITION
300 FRESULT f_fdisk(BYTE pdrv, const DWORD szt[], void* work); /* Divide a physical drive into some partitions */
301 #endif
302 #if _USE_STRFUNC && !_FS_READONLY
303 int f_putc(TCHAR c, FIL* fp); /* Put a character to the file */
304 #endif
305 #if _USE_STRFUNC && !_FS_READONLY
306 int f_puts(const TCHAR* str, FIL* cp); /* Put a string to the file */
307 #endif
308 #if _USE_STRFUNC && !_FS_READONLY
309 int f_printf(FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
310 #endif
311 #if _USE_STRFUNC
312 TCHAR* f_gets(TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
313 #endif
314 
318 #define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0)
319 #define f_error(fp) ((fp)->err)
320 #define f_tell(fp) ((fp)->fptr)
321 #define f_size(fp) ((fp)->fsize)
323 #ifndef EOF
324 #define EOF (-1)
325 #endif
335 /* RTC function */
336 #if !_FS_READONLY
337 DWORD get_fattime (void);
338 #endif
339 
340 /* Unicode support functions */
341 #if _USE_LFN /* Unicode - OEM code conversion */
342 WCHAR ff_convert (WCHAR chr, UINT dir);
344 WCHAR ff_wtoupper (WCHAR chr);
345 #if _USE_LFN == 3 /* Memory functions */
346 void* ff_memalloc (UINT msize);
347 void ff_memfree (void* mblock);
348 #endif
349 #endif
350 
351 /* Sync functions */
352 #if _FS_REENTRANT
353 int ff_cre_syncobj(BYTE vol, _SYNC_t* sobj);
354 int ff_req_grant(_SYNC_t sobj);
355 void ff_rel_grant(_SYNC_t sobj);
356 int ff_del_syncobj(_SYNC_t sobj);
357 #endif
358 
369 #define FA_READ 0x01
373 #define FA_OPEN_EXISTING 0x00
377 #if !_FS_READONLY
378 #define FA_WRITE 0x02
382 #define FA_CREATE_NEW 0x04
385 #define FA_CREATE_ALWAYS 0x08
388 #define FA_OPEN_ALWAYS 0x10
393 #define FA__WRITTEN 0x20
394 #define FA__DIRTY 0x40
395 #endif
396 
407 #define FS_FAT12 1
408 #define FS_FAT16 2
409 #define FS_FAT32 3
410 
420 /* File attribute bits for directory entry */
421 
422 #define AM_RDO 0x01
423 #define AM_HID 0x02
424 #define AM_SYS 0x04
425 #define AM_VOL 0x08
426 #define AM_LFN 0x0F
427 #define AM_DIR 0x10
428 #define AM_ARC 0x20
429 #define AM_MASK 0x3F
431 /* Fast seek feature */
432 #define CREATE_LINKMAP 0xFFFFFFFF
433 
444 #if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
445 #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
446 #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
447 #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
448 #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
449 #else /* Use byte-by-byte access to the FAT structure */
450 #define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
451 #define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
452 #define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
453 #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)
454 #endif
455 
456 #ifdef __cplusplus
457 }
458 #endif
459 
468 #endif /* _FATFS */
FRESULT f_opendir(DIR *dp, const TCHAR *path)
Create a Directory Object.
Definition: ff.c:3160
Definition: ff.h:208
FRESULT f_chmod(const TCHAR *path, BYTE value, BYTE mask)
Change Attribute.
Definition: ff.c:3566
FRESULT f_lseek(FIL *fp, DWORD ofs)
Seek File R/W Pointer.
Definition: ff.c:3005
FRESULT
File function return code.
Definition: ff.h:204
Definition: ff.h:223
Definition: ff.h:215
File object structure.
Definition: ff.h:127
int ff_del_syncobj(_SYNC_t sobj)
Directory object structure.
Definition: ff.h:162
File system object structure.
Definition: ff.h:88
Definition: ff.h:213
Definition: ff.h:210
Definition: ff.h:225
FRESULT f_mkdir(const TCHAR *path)
Create a Directory.
Definition: ff.c:3493
FRESULT f_rename(const TCHAR *path_old, const TCHAR *path_new)
Rename File/Directory.
Definition: ff.c:3644
FRESULT f_close(FIL *fp)
Close File.
Definition: ff.c:2822
FRESULT f_getfree(const TCHAR *path, DWORD *nclst, FATFS **fatfs)
Get Number of Free Clusters.
Definition: ff.c:3311
#define _SYNC_t
O/S dependent type of sync object. e.g. HANDLE, OS_EVENT*, ID and etc..
Definition: ffconf.h:379
FRESULT f_utime(const TCHAR *path, const FILINFO *fno)
Change Timestamp.
Definition: ff.c:3605
FRESULT f_write(FIL *fp, const void *buff, UINT btw, UINT *bw)
Write File.
Definition: ff.c:2664
FRESULT f_read(FIL *fp, void *buff, UINT btr, UINT *br)
Read File.
Definition: ff.c:2565
FRESULT f_mount(FATFS *fs, const TCHAR *path, BYTE opt)
Mount/Unmount a Logical Drive.
Definition: ff.c:2392
FRESULT f_stat(const TCHAR *path, FILINFO *fno)
Get File Status.
Definition: ff.c:3277
Definition: ff.h:205
FRESULT f_truncate(FIL *fp)
Truncate File.
Definition: ff.c:3373
FRESULT f_unlink(const TCHAR *path)
Delete a File or Directory.
Definition: ff.c:3426
DWORD get_fattime(void)
Get the time from the RTC. This function is used from the FatFs and the function prototype is given ...
Definition: rtc.c:326
FRESULT f_open(FIL *fp, const TCHAR *path, BYTE mode)
Open or Create a File.
Definition: ff.c:2434
#define _MAX_SS
Maximum sector size to be handled. Always set 512 for memory card and hard disk but a larger value ma...
Definition: ffconf.h:298
FRESULT f_readdir(DIR *dp, FILINFO *fno)
Read Directory Entries in Sequence.
Definition: ff.c:3238
FRESULT f_closedir(DIR *dp)
Close Directory.
Definition: ff.c:3212
int ff_cre_syncobj(BYTE vol, _SYNC_t *sobj)
File status structure.
Definition: ff.h:189
void ff_rel_grant(_SYNC_t sobj)
Definition: ff.h:211
int ff_req_grant(_SYNC_t sobj)
FRESULT f_sync(FIL *fp)
Synchronize the File.
Definition: ff.c:2779