STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
ff.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------/
2 / FatFs - FAT file system module include R0.11 (C)ChaN, 2015
3 /----------------------------------------------------------------------------/
4 / FatFs module is a free software that opened under license policy of
5 / following conditions.
6 /
7 / Copyright (C) 2015, ChaN, all right reserved.
8 /
9 / 1. Redistributions of source code must retain the above copyright notice,
10 / this condition and the following disclaimer.
11 /
12 / This software is provided by the copyright holder and contributors "AS IS"
13 / and any warranties related to this software are DISCLAIMED.
14 / The copyright owner or contributors be NOT LIABLE for any damages caused
15 / by use of this software.
16 /---------------------------------------------------------------------------*/
17 
18 
19 #ifndef _FATFS
20 #define _FATFS 32020 /* Revision ID */
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #include "integer.h" /* Basic integer types */
27 #include "ffconf.h" /* FatFs configuration options */
28 #if _FATFS != _FFCONF
29 #error Wrong configuration file (ffconf.h).
30 #endif
31 
32 
33 
34 /* Definitions of volume management */
35 
36 #if _MULTI_PARTITION /* Multiple partition configuration */
37 typedef struct {
38  BYTE pd; /* Physical drive number */
39  BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
40 } PARTITION;
41 extern PARTITION VolToPart[]; /* Volume - Partition resolution table */
42 #define LD2PD(vol) (VolToPart[vol].pd) /* Get physical drive number */
43 #define LD2PT(vol) (VolToPart[vol].pt) /* Get partition index */
44 
45 #else /* Single partition configuration */
46 #define LD2PD(vol) (BYTE)(vol) /* Each logical drive is bound to the same physical drive number */
47 #define LD2PT(vol) 0 /* Find first valid partition or in SFD */
48 
49 #endif
50 
51 
52 
53 /* Type of path name strings on FatFs API */
54 
55 #if _LFN_UNICODE /* Unicode string */
56 #if !_USE_LFN
57 #error _LFN_UNICODE must be 0 at non-LFN cfg.
58 #endif
59 #ifndef _INC_TCHAR
60 typedef WCHAR TCHAR;
61 #define _T(x) L ## x
62 #define _TEXT(x) L ## x
63 #endif
64 
65 #else /* ANSI/OEM string */
66 #ifndef _INC_TCHAR
67 typedef char TCHAR;
68 #define _T(x) x
69 #define _TEXT(x) x
70 #endif
71 
72 #endif
73 
74 
75 
76 /* File system object structure (FATFS) */
77 
78 typedef struct {
79  union{
80  UINT d32[_MAX_SS/4]; /* Force 32bits alignement */
81  BYTE d8[_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
82  }win;
83  BYTE fs_type; /* FAT sub-type (0:Not mounted) */
84  BYTE drv; /* Physical drive number */
85  BYTE csize; /* Sectors per cluster (1,2,4...128) */
86  BYTE n_fats; /* Number of FAT copies (1 or 2) */
87  BYTE wflag; /* win[] flag (b0:dirty) */
88  BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
89  WORD id; /* File system mount ID */
90  WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
91 #if _MAX_SS != _MIN_SS
92  WORD ssize; /* Bytes per sector (512, 1024, 2048 or 4096) */
93 #endif
94 #if _FS_REENTRANT
95  _SYNC_t sobj; /* Identifier of sync object */
96 #endif
97 #if !_FS_READONLY
98  DWORD last_clust; /* Last allocated cluster */
99  DWORD free_clust; /* Number of free clusters */
100 #endif
101 #if _FS_RPATH
102  DWORD cdir; /* Current directory start cluster (0:root) */
103 #endif
104  DWORD n_fatent; /* Number of FAT entries, = number of clusters + 2 */
105  DWORD fsize; /* Sectors per FAT */
106  DWORD volbase; /* Volume start sector */
107  DWORD fatbase; /* FAT start sector */
108  DWORD dirbase; /* Root directory start sector (FAT32:Cluster#) */
109  DWORD database; /* Data start sector */
110  DWORD winsect; /* Current sector appearing in the win[] */
111 
112 } FATFS;
113 
114 
115 
116 /* File object structure (FIL) */
117 
118 typedef struct {
119 #if !_FS_TINY
120  union{
121  UINT d32[_MAX_SS/4]; /* Force 32bits alignement */
122  BYTE d8[_MAX_SS]; /* File data read/write buffer */
123  }buf;
124 #endif
125  FATFS* fs; /* Pointer to the related file system object (**do not change order**) */
126  WORD id; /* Owner file system mount ID (**do not change order**) */
127  BYTE flag; /* Status flags */
128  BYTE err; /* Abort flag (error code) */
129  DWORD fptr; /* File read/write pointer (Zeroed on file open) */
130  DWORD fsize; /* File size */
131  DWORD sclust; /* File start cluster (0:no cluster chain, always 0 when fsize is 0) */
132  DWORD clust; /* Current cluster of fpter (not valid when fprt is 0) */
133  DWORD dsect; /* Sector number appearing in buf[] (0:invalid) */
134 #if !_FS_READONLY
135  DWORD dir_sect; /* Sector number containing the directory entry */
136  BYTE* dir_ptr; /* Pointer to the directory entry in the win[] */
137 #endif
138 #if _USE_FASTSEEK
139  DWORD* cltbl; /* Pointer to the cluster link map table (Nulled on file open) */
140 #endif
141 #if _FS_LOCK
142  UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */
143 #endif
144 
145 } FIL;
146 
147 
148 
149 /* Directory object structure (DIR) */
150 
151 typedef struct {
152 #if !_FS_TINY
153  union{
154  UINT d32[_MAX_SS/4]; /* Force 32bits alignement */
155  BYTE d8[_MAX_SS]; /* File data read/write buffer */
156  }buf;
157 #endif
158  FATFS* fs; /* Pointer to the owner file system object (**do not change order**) */
159  WORD id; /* Owner file system mount ID (**do not change order**) */
160  WORD index; /* Current read/write index number */
161  DWORD sclust; /* Table start cluster (0:Root dir) */
162  DWORD clust; /* Current cluster */
163  DWORD sect; /* Current sector */
164  BYTE* dir; /* Pointer to the current SFN entry in the win[] */
165  BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
166 #if _FS_LOCK
167  UINT lockid; /* File lock ID (index of file semaphore table Files[]) */
168 #endif
169 #if _USE_LFN
170  WCHAR* lfn; /* Pointer to the LFN working buffer */
171  WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */
172 #endif
173 #if _USE_FIND
174  const TCHAR* pat; /* Pointer to the name matching pattern */
175 #endif
176 } DIR;
177 
178 
179 
180 /* File information structure (FILINFO) */
181 
182 typedef struct {
183  DWORD fsize; /* File size */
184  WORD fdate; /* Last modified date */
185  WORD ftime; /* Last modified time */
186  BYTE fattrib; /* Attribute */
187  TCHAR fname[13]; /* Short file name (8.3 format) */
188 #if _USE_LFN
189  TCHAR* lfname; /* Pointer to the LFN buffer */
190  UINT lfsize; /* Size of LFN buffer in TCHAR */
191 #endif
192 } FILINFO;
193 
194 
195 
196 /* File function return code (FRESULT) */
197 
198 typedef enum {
199  FR_OK = 0, /* (0) Succeeded */
200  FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
201  FR_INT_ERR, /* (2) Assertion failed */
202  FR_NOT_READY, /* (3) The physical drive cannot work */
203  FR_NO_FILE, /* (4) Could not find the file */
204  FR_NO_PATH, /* (5) Could not find the path */
205  FR_INVALID_NAME, /* (6) The path name format is invalid */
206  FR_DENIED, /* (7) Access denied due to prohibited access or directory full */
207  FR_EXIST, /* (8) Access denied due to prohibited access */
208  FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
209  FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
210  FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
211  FR_NOT_ENABLED, /* (12) The volume has no work area */
212  FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
213  FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any parameter error */
214  FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
215  FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
216  FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
217  FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_SHARE */
218  FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
219 } FRESULT;
220 
221 
222 
223 /*--------------------------------------------------------------*/
224 /* FatFs module application interface */
225 
226 FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
227 FRESULT f_close (FIL* fp); /* Close an open file object */
228 FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from a file */
229 FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to a file */
230 FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */
231 FRESULT f_lseek (FIL* fp, DWORD ofs); /* Move file pointer of a file object */
232 FRESULT f_truncate (FIL* fp); /* Truncate file */
233 FRESULT f_sync (FIL* fp); /* Flush cached data of a writing file */
234 FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */
235 FRESULT f_closedir (DIR* dp); /* Close an open directory */
236 FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */
237 FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */
238 FRESULT f_findnext (DIR* dp, FILINFO* fno); /* Find next file */
239 FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */
240 FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */
241 FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
242 FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */
243 FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of the file/dir */
244 FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change times-tamp of the file/dir */
245 FRESULT f_chdir (const TCHAR* path); /* Change current directory */
246 FRESULT f_chdrive (const TCHAR* path); /* Change current drive */
247 FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */
248 FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */
249 FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */
250 FRESULT f_setlabel (const TCHAR* label); /* Set volume label */
251 FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
252 FRESULT f_mkfs (const TCHAR* path, BYTE sfd, UINT au); /* Create a file system on the volume */
253 FRESULT f_fdisk (BYTE pdrv, const DWORD szt[], void* work); /* Divide a physical drive into some partitions */
254 int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */
255 int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
256 int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
257 TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
258 
259 #define f_eof(fp) ((int)((fp)->fptr == (fp)->fsize))
260 #define f_error(fp) ((fp)->err)
261 #define f_tell(fp) ((fp)->fptr)
262 #define f_size(fp) ((fp)->fsize)
263 #define f_rewind(fp) f_lseek((fp), 0)
264 #define f_rewinddir(dp) f_readdir((dp), 0)
265 
266 #ifndef EOF
267 #define EOF (-1)
268 #endif
269 
270 
271 
272 
273 /*--------------------------------------------------------------*/
274 /* Additional user defined functions */
275 
276 /* RTC function */
277 #if !_FS_READONLY && !_FS_NORTC
278 DWORD get_fattime (void);
279 #endif
280 
281 /* Unicode support functions */
282 #if _USE_LFN /* Unicode - OEM code conversion */
283 WCHAR ff_convert (WCHAR chr, UINT dir); /* OEM-Unicode bidirectional conversion */
284 WCHAR ff_wtoupper (WCHAR chr); /* Unicode upper-case conversion */
285 #if _USE_LFN == 3 /* Memory functions */
286 void* ff_memalloc (UINT msize); /* Allocate memory block */
287 void ff_memfree (void* mblock); /* Free memory block */
288 #endif
289 #endif
290 
291 /* Sync functions */
292 #if _FS_REENTRANT
293 int ff_cre_syncobj (BYTE vol, _SYNC_t* sobj); /* Create a sync object */
294 int ff_req_grant (_SYNC_t sobj); /* Lock sync object */
295 void ff_rel_grant (_SYNC_t sobj); /* Unlock sync object */
296 int ff_del_syncobj (_SYNC_t sobj); /* Delete a sync object */
297 #endif
298 
299 
300 
301 
302 /*--------------------------------------------------------------*/
303 /* Flags and offset address */
304 
305 
306 /* File access control and file status flags (FIL.flag) */
307 
308 #define FA_READ 0x01
309 #define FA_OPEN_EXISTING 0x00
310 
311 #if !_FS_READONLY
312 #define FA_WRITE 0x02
313 #define FA_CREATE_NEW 0x04
314 #define FA_CREATE_ALWAYS 0x08
315 #define FA_OPEN_ALWAYS 0x10
316 #define FA__WRITTEN 0x20
317 #define FA__DIRTY 0x40
318 #endif
319 
320 
321 /* FAT sub type (FATFS.fs_type) */
322 
323 #define FS_FAT12 1
324 #define FS_FAT16 2
325 #define FS_FAT32 3
326 
327 
328 /* File attribute bits for directory entry */
329 
330 #define AM_RDO 0x01 /* Read only */
331 #define AM_HID 0x02 /* Hidden */
332 #define AM_SYS 0x04 /* System */
333 #define AM_VOL 0x08 /* Volume label */
334 #define AM_LFN 0x0F /* LFN entry */
335 #define AM_DIR 0x10 /* Directory */
336 #define AM_ARC 0x20 /* Archive */
337 #define AM_MASK 0x3F /* Mask of defined bits */
338 
339 
340 /* Fast seek feature */
341 #define CREATE_LINKMAP 0xFFFFFFFF
342 
343 
344 
345 /*--------------------------------*/
346 /* Multi-byte word access macros */
347 
348 #if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
349 #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
350 #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
351 #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
352 #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
353 #else /* Use byte-by-byte access to the FAT structure */
354 #define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
355 #define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
356 #define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
357 #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)
358 #endif
359 
360 #ifdef __cplusplus
361 }
362 #endif
363 
364 #endif /* _FATFS */
WORD id
Definition: ff.h:126
FRESULT f_chdrive(const TCHAR *path)
int f_puts(const TCHAR *str, FIL *cp)
WCHAR ff_wtoupper(WCHAR chr)
Definition: cc932.c:3786
BYTE * dir_ptr
Definition: ff.h:136
unsigned short WORD
Definition: integer.h:20
unsigned short WCHAR
Definition: integer.h:21
int f_putc(TCHAR c, FIL *fp)
DWORD sclust
Definition: ff.h:161
FATFS * fs
Definition: ff.h:158
#define _MAX_SS
Definition: ffconf.h:226
DWORD free_clust
Definition: ff.h:99
DWORD dsect
Definition: ff.h:133
DWORD volbase
Definition: ff.h:106
WORD ftime
Definition: ff.h:185
DWORD dir_sect
Definition: ff.h:135
Definition: ff.h:118
DWORD n_fatent
Definition: ff.h:104
BYTE * fn
Definition: ff.h:165
FRESULT f_fdisk(BYTE pdrv, const DWORD szt[], void *work)
DWORD fatbase
Definition: ff.h:107
DWORD winsect
Definition: ff.h:110
FRESULT f_mount(FATFS *fs, const TCHAR *path, BYTE opt)
Definition: ff.c:2475
Definition: ff.h:151
Definition: ff.h:78
BYTE err
Definition: ff.h:128
FRESULT f_getlabel(const TCHAR *path, TCHAR *label, DWORD *vsn)
char TCHAR
Definition: ff.h:67
Definition: ff.h:206
FRESULT f_chdir(const TCHAR *path)
DWORD fsize
Definition: ff.h:130
FRESULT f_chmod(const TCHAR *path, BYTE attr, BYTE mask)
Definition: ff.c:3743
DWORD sect
Definition: ff.h:163
DWORD database
Definition: ff.h:109
BYTE fs_type
Definition: ff.h:83
FRESULT f_readdir(DIR *dp, FILINFO *fno)
Definition: ff.c:3348
FRESULT f_read(FIL *fp, void *buff, UINT btr, UINT *br)
Definition: ff.c:2658
DWORD fsize
Definition: ff.h:183
FRESULT f_getfree(const TCHAR *path, DWORD *nclst, FATFS **fatfs)
Definition: ff.c:3477
DWORD fsize
Definition: ff.h:105
BYTE csize
Definition: ff.h:85
WCHAR ff_convert(WCHAR chr, UINT dir)
Definition: cc932.c:3726
FRESULT f_mkdir(const TCHAR *path)
Definition: ff.c:3669
DWORD clust
Definition: ff.h:132
WORD index
Definition: ff.h:160
Definition: ff.h:201
FRESULT f_close(FIL *fp)
Definition: ff.c:2930
unsigned long DWORD
Definition: integer.h:29
FRESULT f_lseek(FIL *fp, DWORD ofs)
Definition: ff.c:3102
Definition: ff.h:207
FRESULT f_truncate(FIL *fp)
Definition: ff.c:3544
WORD id
Definition: ff.h:89
FRESULT f_forward(FIL *fp, UINT(*func)(const BYTE *, UINT), UINT btf, UINT *bf)
Definition: ff.h:203
unsigned char BYTE
Definition: integer.h:16
FRESULT f_closedir(DIR *dp)
Definition: ff.c:3316
Definition: ff.h:204
FRESULT f_stat(const TCHAR *path, FILINFO *fno)
Definition: ff.c:3442
FRESULT f_rename(const TCHAR *path_old, const TCHAR *path_new)
Definition: ff.c:3786
BYTE flag
Definition: ff.h:127
FRESULT f_write(FIL *fp, const void *buff, UINT btw, UINT *bw)
Definition: ff.c:2759
DWORD sclust
Definition: ff.h:131
FRESULT
Definition: ff.h:198
FRESULT f_sync(FIL *fp)
Definition: ff.c:2881
FRESULT f_open(FIL *fp, const TCHAR *path, BYTE mode)
Definition: ff.c:2522
BYTE n_fats
Definition: ff.h:86
FRESULT f_mkfs(const TCHAR *path, BYTE sfd, UINT au)
Definition: ff.h:214
WORD id
Definition: ff.h:159
DWORD get_fattime(void)
Gets Time from RTC.
Definition: diskio.c:154
WORD fdate
Definition: ff.h:184
DWORD fptr
Definition: ff.h:129
unsigned int UINT
Definition: integer.h:25
FRESULT f_setlabel(const TCHAR *label)
BYTE wflag
Definition: ff.h:87
BYTE fsi_flag
Definition: ff.h:88
Definition: ff.h:215
BYTE drv
Definition: ff.h:84
FRESULT f_findfirst(DIR *dp, FILINFO *fno, const TCHAR *path, const TCHAR *pattern)
WORD n_rootdir
Definition: ff.h:90
FRESULT f_utime(const TCHAR *path, const FILINFO *fno)
Definition: ff.c:3864
BYTE * dir
Definition: ff.h:164
TCHAR * f_gets(TCHAR *buff, int len, FIL *fp)
int f_printf(FIL *fp, const TCHAR *str,...)
DWORD clust
Definition: ff.h:162
Definition: ff.h:199
FATFS * fs
Definition: ff.h:125
Definition: ff.h:182
DWORD last_clust
Definition: ff.h:98
FRESULT f_findnext(DIR *dp, FILINFO *fno)
FRESULT f_opendir(DIR *dp, const TCHAR *path)
Definition: ff.c:3260
FRESULT f_unlink(const TCHAR *path)
Definition: ff.c:3600
DWORD dirbase
Definition: ff.h:108
BYTE fattrib
Definition: ff.h:186
FRESULT f_getcwd(TCHAR *buff, UINT len)