ff.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------/
2 / FatFs - FAT file system module include file R0.09 (C)ChaN, 2011
3 /----------------------------------------------------------------------------/
4 / FatFs module is a generic FAT file system module for small embedded systems.
5 / This is a free software that opened for education, research and commercial
6 / developments under license policy of following trems.
7 /
8 / Copyright (C) 2011, ChaN, all right reserved.
9 /
10 / * The FatFs module is a free software and there is NO WARRANTY.
11 / * No restriction on use. You can use, modify and redistribute it for
12 / personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY.
13 / * Redistributions of source code must retain the above copyright notice.
14 /
15 /----------------------------------------------------------------------------*/
16 #include <stdarg.h>
17 
18 #ifndef _FATFS
19 #define _FATFS 6502 /* Revision ID */
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #include "integer.h" /* Basic integer types */
26 #include "ffconf.h" /* FatFs configuration options */
27 
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) (vol) /* Each logical drive is bound to the same physical drive number */
47 #define LD2PT(vol) 0 /* Always mounts the 1st 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 in 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  BYTE fs_type; /* FAT sub-type (0:Not mounted) */
80  BYTE drv; /* Physical drive number */
81  BYTE csize; /* Sectors per cluster (1,2,4...128) */
82  BYTE n_fats; /* Number of FAT copies (1,2) */
83  BYTE wflag; /* win[] dirty flag (1:must be written back) */
84  BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */
85  WORD id; /* File system mount ID */
86  WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
87 #if _MAX_SS != 512
88  WORD ssize; /* Bytes per sector (512, 1024, 2048 or 4096) */
89 #endif
90 #if _FS_REENTRANT
91  _SYNC_t sobj; /* Identifier of sync object */
92 #endif
93 #if !_FS_READONLY
94  DWORD last_clust; /* Last allocated cluster */
95  DWORD free_clust; /* Number of free clusters */
96  DWORD fsi_sector; /* fsinfo sector (FAT32) */
97 #endif
98 #if _FS_RPATH
99  DWORD cdir; /* Current directory start cluster (0:root) */
100 #endif
101  DWORD n_fatent; /* Number of FAT entries (= number of clusters + 2) */
102  DWORD fsize; /* Sectors per FAT */
103  DWORD fatbase; /* FAT start sector */
104  DWORD dirbase; /* Root directory start sector (FAT32:Cluster#) */
105  DWORD database; /* Data start sector */
106  DWORD winsect; /* Current sector appearing in the win[] */
107  BYTE win[_MAX_SS]; /* Disk access window for Directory, FAT (and Data on tiny cfg) */
108 } FATFS;
109 
110 
111 
112 /* File object structure (FIL) */
113 
114 typedef struct {
115  FATFS* fs; /* Pointer to the owner file system object */
116  WORD id; /* Owner file system mount ID */
117  BYTE flag; /* File status flags */
119  DWORD fptr; /* File read/write pointer (0 on file open) */
120  DWORD fsize; /* File size */
121  DWORD sclust; /* File start cluster (0 when fsize==0) */
122  DWORD clust; /* Current cluster */
123  DWORD dsect; /* Current data sector */
124 #if !_FS_READONLY
125  DWORD dir_sect; /* Sector containing the directory entry */
126  BYTE* dir_ptr; /* Ponter to the directory entry in the window */
127 #endif
128 #if _USE_FASTSEEK
129  DWORD* cltbl; /* Pointer to the cluster link map table (null on file open) */
130 #endif
131 #if _FS_SHARE
132  UINT lockid; /* File lock ID (index of file semaphore table) */
133 #endif
134 #if !_FS_TINY
135  BYTE buf[_MAX_SS]; /* File data read/write buffer */
136 #endif
137 } FIL;
138 
139 
140 
141 /* Directory object structure (DIR) */
142 
143 typedef struct {
144  FATFS* fs; /* Pointer to the owner file system object */
145  WORD id; /* Owner file system mount ID */
146  WORD index; /* Current read/write index number */
147  DWORD sclust; /* Table start cluster (0:Root dir) */
148  DWORD clust; /* Current cluster */
149  DWORD sect; /* Current sector */
150  BYTE* dir; /* Pointer to the current SFN entry in the win[] */
151  BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
152 #if _USE_LFN
153  WCHAR* lfn; /* Pointer to the LFN working buffer */
154  WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */
155 #endif
156 } DIR;
157 
158 
159 
160 /* File status structure (FILINFO) */
161 
162 typedef struct {
163  DWORD fsize; /* File size */
164  WORD fdate; /* Last modified date */
165  WORD ftime; /* Last modified time */
166  BYTE fattrib; /* Attribute */
167  TCHAR fname[13]; /* Short file name (8.3 format) */
168 #if _USE_LFN
169  TCHAR* lfname; /* Pointer to the LFN buffer */
170  UINT lfsize; /* Size of LFN buffer in TCHAR */
171 #endif
172 } FILINFO;
173 
174 
175 
176 /* File function return code (FRESULT) */
177 
178 typedef enum {
179  FR_OK = 0, /* (0) Succeeded */
180  FR_DISK_ERR, /* (1) A hard error occured in the low level disk I/O layer */
181  FR_INT_ERR, /* (2) Assertion failed */
182  FR_NOT_READY, /* (3) The physical drive cannot work */
183  FR_NO_FILE, /* (4) Could not find the file */
184  FR_NO_PATH, /* (5) Could not find the path */
185  FR_INVALID_NAME, /* (6) The path name format is invalid */
186  FR_DENIED, /* (7) Acces denied due to prohibited access or directory full */
187  FR_EXIST, /* (8) Acces denied due to prohibited access */
188  FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
189  FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
190  FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
191  FR_NOT_ENABLED, /* (12) The volume has no work area */
192  FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
193  FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any parameter error */
194  FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
195  FR_LOCKED, /* (16) The operation is rejected according to the file shareing policy */
196  FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
197  FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_SHARE */
198  FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
199 } FRESULT;
200 
201 
202 
203 /*--------------------------------------------------------------*/
204 /* FatFs module application interface */
205 
206 FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */
207 FRESULT f_open (FIL*, const TCHAR*, BYTE); /* Open or create a file */
208 FRESULT f_read (FIL*, void*, UINT, UINT*); /* Read data from a file */
209 FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */
210 FRESULT f_close (FIL*); /* Close an open file object */
211 FRESULT f_opendir (DIR*, const TCHAR*); /* Open an existing directory */
212 FRESULT f_readdir (DIR*, FILINFO*); /* Read a directory item */
213 FRESULT f_stat (const TCHAR*, FILINFO*); /* Get file status */
214 FRESULT f_write (FIL*, const void*, UINT, UINT*); /* Write data to a file */
215 FRESULT f_getfree (const TCHAR*, DWORD*, FATFS**); /* Get number of free clusters on the drive */
216 FRESULT f_truncate (FIL*); /* Truncate file */
217 FRESULT f_sync (FIL*); /* Flush cached data of a writing file */
218 FRESULT f_unlink (const TCHAR*); /* Delete an existing file or directory */
219 FRESULT f_mkdir (const TCHAR*); /* Create a new directory */
220 FRESULT f_chmod (const TCHAR*, BYTE, BYTE); /* Change attriburte of the file/dir */
221 FRESULT f_utime (const TCHAR*, const FILINFO*); /* Change timestamp of the file/dir */
222 FRESULT f_rename (const TCHAR*, const TCHAR*); /* Rename/Move a file or directory */
223 FRESULT f_chdrive (BYTE); /* Change current drive */
224 FRESULT f_chdir (const TCHAR*); /* Change current directory */
225 FRESULT f_getcwd (TCHAR*, UINT); /* Get current directory */
226 FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*); /* Forward data to the stream */
227 FRESULT f_mkfs (BYTE, BYTE, UINT); /* Create a file system on the drive */
228 FRESULT f_fdisk (BYTE, const DWORD[], void*); /* Divide a physical drive into some partitions */
229 int f_putc (TCHAR, FIL*); /* Put a character to the file */
230 int f_puts (const TCHAR*, FIL*); /* Put a string to the file */
231 int f_printf (FIL*, const TCHAR*, ...); /* Put a formatted string to the file */
232 int f_vprintf (FIL*, const TCHAR*, va_list arp); /* Put a formatted string to the file, passing a va_list (for var arg functions to forward their arguments. */
233 TCHAR* f_gets (TCHAR*, int, FIL*); /* Get a string from the file */
234 
235 #define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0)
236 #define f_error(fp) (((fp)->flag & FA__ERROR) ? 1 : 0)
237 #define f_tell(fp) ((fp)->fptr)
238 #define f_size(fp) ((fp)->fsize)
239 
240 #ifndef EOF
241 #define EOF (-1)
242 #endif
243 
244 
245 
246 
247 /*--------------------------------------------------------------*/
248 /* Additional user defined functions */
249 
250 /* RTC function */
251 #if !_FS_READONLY
252 DWORD get_fattime (void);
253 #endif
254 
255 /* Unicode support functions */
256 #if _USE_LFN /* Unicode - OEM code conversion */
257 WCHAR ff_convert (WCHAR, UINT); /* OEM-Unicode bidirectional conversion */
258 WCHAR ff_wtoupper (WCHAR); /* Unicode upper-case conversion */
259 #if _USE_LFN == 3 /* Memory functions */
260 void* ff_memalloc (UINT); /* Allocate memory block */
261 void ff_memfree (void*); /* Free memory block */
262 #endif
263 #endif
264 
265 /* Sync functions */
266 #if _FS_REENTRANT
267 int ff_cre_syncobj (BYTE, _SYNC_t*);/* Create a sync object */
268 int ff_req_grant (_SYNC_t); /* Lock sync object */
269 void ff_rel_grant (_SYNC_t); /* Unlock sync object */
270 int ff_del_syncobj (_SYNC_t); /* Delete a sync object */
271 #endif
272 
273 
274 
275 
276 /*--------------------------------------------------------------*/
277 /* Flags and offset address */
278 
279 
280 /* File access control and file status flags (FIL.flag) */
281 
282 #define FA_READ 0x01
283 #define FA_OPEN_EXISTING 0x00
284 #define FA__ERROR 0x80
285 
286 #if !_FS_READONLY
287 #define FA_WRITE 0x02
288 #define FA_CREATE_NEW 0x04
289 #define FA_CREATE_ALWAYS 0x08
290 #define FA_OPEN_ALWAYS 0x10
291 #define FA__WRITTEN 0x20
292 #define FA__DIRTY 0x40
293 #endif
294 
295 
296 /* FAT sub type (FATFS.fs_type) */
297 
298 #define FS_FAT12 1
299 #define FS_FAT16 2
300 #define FS_FAT32 3
301 
302 
303 /* File attribute bits for directory entry */
304 
305 #define AM_RDO 0x01 /* Read only */
306 #define AM_HID 0x02 /* Hidden */
307 #define AM_SYS 0x04 /* System */
308 #define AM_VOL 0x08 /* Volume label */
309 #define AM_LFN 0x0F /* LFN entry */
310 #define AM_DIR 0x10 /* Directory */
311 #define AM_ARC 0x20 /* Archive */
312 #define AM_MASK 0x3F /* Mask of defined bits */
313 
314 
315 /* Fast seek feature */
316 #define CREATE_LINKMAP 0xFFFFFFFF
317 
318 
319 
320 /*--------------------------------*/
321 /* Multi-byte word access macros */
322 
323 #if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
324 #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
325 #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
326 #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
327 #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
328 #else /* Use byte-by-byte access to the FAT structure */
329 #define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
330 #define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
331 #define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
332 #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)
333 #endif
334 
335 #ifdef __cplusplus
336 }
337 #endif
338 
339 #endif /* _FATFS */
FATFS * fs
Definition: ff.h:144
unsigned short WORD
Definition: integer.h:27
unsigned short WCHAR
Definition: integer.h:28
WORD index
Definition: ff.h:146
DWORD n_fatent
Definition: ff.h:101
DWORD sect
Definition: ff.h:149
FRESULT f_write(FIL *, const void *, UINT, UINT *)
Definition: ff.c:2482
FRESULT f_getcwd(TCHAR *, UINT)
DWORD database
Definition: ff.h:105
#define _MAX_SS
Definition: ffconf.h:134
unsigned char BYTE
FRESULT f_sync(FIL *)
Definition: ff.c:2601
WCHAR * lfn
Definition: ff.h:153
WORD fdate
Definition: ff.h:164
DWORD last_clust
Definition: ff.h:94
FRESULT f_mkfs(BYTE, BYTE, UINT)
DWORD fsi_sector
Definition: ff.h:96
Definition: ff.h:162
DWORD fsize
Definition: ff.h:120
Definition: ff.h:78
FRESULT f_forward(FIL *, UINT(*)(const BYTE *, UINT), UINT, UINT *)
int f_printf(FIL *, const TCHAR *,...)
FRESULT f_rename(const TCHAR *, const TCHAR *)
Definition: ff.c:3422
WORD ftime
Definition: ff.h:165
WORD id
Definition: ff.h:116
WORD id
Definition: ff.h:145
FRESULT f_truncate(FIL *)
Definition: ff.c:3150
BYTE flag
Definition: ff.h:117
char TCHAR
Definition: ff.h:67
Definition: ff.h:186
WORD lfn_idx
Definition: ff.h:154
FRESULT f_read(FIL *, void *, UINT, UINT *)
Definition: ff.c:2381
TCHAR * lfname
Definition: ff.h:169
BYTE * dir
Definition: ff.h:150
BYTE csize
Definition: ff.h:81
int f_putc(TCHAR, FIL *)
DWORD sclust
Definition: ff.h:147
BYTE fs_type
Definition: ff.h:79
WCHAR ff_wtoupper(WCHAR)
Definition: ccsbcs.c:528
Definition: ff.h:181
FRESULT f_chdir(const TCHAR *)
Definition: ff.h:143
unsigned long DWORD
Definition: integer.h:33
int f_vprintf(FIL *, const TCHAR *, va_list arp)
Definition: ff.h:187
FRESULT f_utime(const TCHAR *, const FILINFO *)
Definition: ff.c:3381
Definition: ff.h:183
BYTE n_fats
Definition: ff.h:82
UINT lfsize
Definition: ff.h:170
DWORD winsect
Definition: ff.h:106
DWORD fatbase
Definition: ff.h:103
Definition: ff.h:184
FRESULT f_lseek(FIL *, DWORD)
Definition: ff.c:2812
FRESULT f_chmod(const TCHAR *, BYTE, BYTE)
Definition: ff.c:3339
FRESULT
Definition: ff.h:178
WCHAR ff_convert(WCHAR, UINT)
Definition: ccsbcs.c:501
int f_puts(const TCHAR *, FIL *)
WORD id
Definition: ff.h:85
DWORD sclust
Definition: ff.h:121
BYTE drv
Definition: ff.h:80
Definition: ff.h:194
DWORD get_fattime(void)
Current time returned is packed into a DWORD value.
Definition: fattime_rtc.c:57
FRESULT f_unlink(const TCHAR *)
Definition: ff.c:3198
FRESULT f_getfree(const TCHAR *, DWORD *, FATFS **)
Definition: ff.c:3085
BYTE fsi_flag
Definition: ff.h:84
BYTE * dir_ptr
Definition: ff.h:126
FRESULT f_readdir(DIR *, FILINFO *)
Definition: ff.c:3010
BYTE fattrib
Definition: ff.h:166
DWORD dsect
Definition: ff.h:123
unsigned int UINT
Definition: integer.h:17
DWORD clust
Definition: ff.h:148
#define _SYNC_t
Definition: ffconf.h:177
Definition: ff.h:195
DWORD fsize
Definition: ff.h:163
FRESULT f_fdisk(BYTE, const DWORD[], void *)
FRESULT f_chdrive(BYTE)
FRESULT f_open(FIL *, const TCHAR *, BYTE)
Definition: ff.c:2251
WORD n_rootdir
Definition: ff.h:86
Definition: ff.h:114
TCHAR * f_gets(TCHAR *, int, FIL *)
FRESULT f_stat(const TCHAR *, FILINFO *)
Definition: ff.c:3052
DWORD free_clust
Definition: ff.h:95
Definition: ff.h:179
BYTE wflag
Definition: ff.h:83
DWORD fptr
Definition: ff.h:119
FRESULT f_mount(BYTE, FATFS *)
Definition: ff.c:2211
DWORD clust
Definition: ff.h:122
FATFS * fs
Definition: ff.h:115
DWORD dir_sect
Definition: ff.h:125
BYTE pad1
Definition: ff.h:118
FRESULT f_opendir(DIR *, const TCHAR *)
Definition: ff.c:2970
FRESULT f_mkdir(const TCHAR *)
Definition: ff.c:3266
BYTE * fn
Definition: ff.h:151
DWORD fsize
Definition: ff.h:102
DWORD dirbase
Definition: ff.h:104
FRESULT f_close(FIL *)
Definition: ff.c:2648


inertial_sense_ros
Author(s):
autogenerated on Sat Sep 19 2020 03:19:04