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