| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#ifndef FF_DEFINED |
| 23 |
#define FF_DEFINED 86631 |
| 24 |
|
| 25 |
#ifdef __cplusplus |
| 26 |
extern "C" { |
| 27 |
#endif |
| 28 |
|
| 29 |
#include "ffconf.h" |
| 30 |
|
| 31 |
#if FF_DEFINED != FFCONF_DEF |
| 32 |
#error Wrong configuration file (ffconf.h). |
| 33 |
#endif |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
#if defined(_WIN32) |
| 39 |
#define FF_INTDEF 2 |
| 40 |
#include <windows.h> |
| 41 |
typedef unsigned __int64 QWORD; |
| 42 |
#include <float.h> |
| 43 |
#define isnan(v) _isnan(v) |
| 44 |
#define isinf(v) (!_finite(v)) |
| 45 |
|
| 46 |
#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus) |
| 47 |
#define FF_INTDEF 2 |
| 48 |
#include <stdint.h> |
| 49 |
typedef unsigned int UINT; |
| 50 |
typedef unsigned char BYTE; |
| 51 |
typedef uint16_t WORD; |
| 52 |
typedef uint32_t DWORD; |
| 53 |
typedef uint64_t QWORD; |
| 54 |
typedef WORD WCHAR; |
| 55 |
|
| 56 |
#else |
| 57 |
#define FF_INTDEF 1 |
| 58 |
typedef unsigned int UINT; |
| 59 |
typedef unsigned char BYTE; |
| 60 |
typedef unsigned short WORD; |
| 61 |
typedef unsigned long DWORD; |
| 62 |
typedef WORD WCHAR; |
| 63 |
#endif |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
#if FF_FS_EXFAT |
| 69 |
#if FF_INTDEF != 2 |
| 70 |
#error exFAT feature wants C99 or later |
| 71 |
#endif |
| 72 |
typedef QWORD FSIZE_t; |
| 73 |
#if FF_LBA64 |
| 74 |
typedef QWORD LBA_t; |
| 75 |
#else |
| 76 |
typedef DWORD LBA_t; |
| 77 |
#endif |
| 78 |
#else |
| 79 |
#if FF_LBA64 |
| 80 |
#error exFAT needs to be enabled when enable 64-bit LBA |
| 81 |
#endif |
| 82 |
typedef DWORD FSIZE_t; |
| 83 |
typedef DWORD LBA_t; |
| 84 |
#endif |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
#if FF_USE_LFN && FF_LFN_UNICODE == 1 |
| 91 |
typedef WCHAR FATFS_TCHAR; |
| 92 |
#define FATFS__T(x) L ## x |
| 93 |
#define FATFS__TEXT(x) L ## x |
| 94 |
#elif FF_USE_LFN && FF_LFN_UNICODE == 2 |
| 95 |
typedef char FATFS_TCHAR; |
| 96 |
#define FATFS__T(x) u8 ## x |
| 97 |
#define FATFS__TEXT(x) u8 ## x |
| 98 |
#elif FF_USE_LFN && FF_LFN_UNICODE == 3 |
| 99 |
typedef DWORD FATFS_TCHAR; |
| 100 |
#define FATFS__T(x) U ## x |
| 101 |
#define FATFS__TEXT(x) U ## x |
| 102 |
#elif FF_USE_LFN && (FF_LFN_UNICODE < 0 || FF_LFN_UNICODE > 3) |
| 103 |
#error Wrong FF_LFN_UNICODE setting |
| 104 |
#else |
| 105 |
typedef char FATFS_TCHAR; |
| 106 |
#define FATFS__T(x) x |
| 107 |
#define FATFS__TEXT(x) x |
| 108 |
#endif |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
#if FF_MULTI_PARTITION |
| 115 |
typedef struct { |
| 116 |
BYTE pd; |
| 117 |
BYTE pt; |
| 118 |
} PARTITION; |
| 119 |
extern PARTITION VolToPart[]; |
| 120 |
#endif |
| 121 |
|
| 122 |
#if FF_STR_VOLUME_ID |
| 123 |
#ifndef FF_VOLUME_STRS |
| 124 |
extern const char* VolumeStr[FF_VOLUMES]; |
| 125 |
#endif |
| 126 |
#endif |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
typedef struct { |
| 133 |
BYTE fs_type; |
| 134 |
BYTE pdrv; |
| 135 |
BYTE n_fats; |
| 136 |
BYTE wflag; |
| 137 |
BYTE fsi_flag; |
| 138 |
WORD id; |
| 139 |
WORD n_rootdir; |
| 140 |
WORD csize; |
| 141 |
#if FF_MAX_SS != FF_MIN_SS |
| 142 |
WORD ssize; |
| 143 |
#endif |
| 144 |
#if FF_USE_LFN |
| 145 |
WCHAR* lfnbuf; |
| 146 |
#endif |
| 147 |
#if FF_FS_EXFAT |
| 148 |
BYTE* dirbuf; |
| 149 |
#endif |
| 150 |
#if FF_FS_REENTRANT |
| 151 |
FF_SYNC_t sobj; |
| 152 |
#endif |
| 153 |
#if !FF_FS_READONLY |
| 154 |
DWORD last_clst; |
| 155 |
DWORD free_clst; |
| 156 |
#endif |
| 157 |
#if FF_FS_RPATH |
| 158 |
DWORD cdir; |
| 159 |
#if FF_FS_EXFAT |
| 160 |
DWORD cdc_scl; |
| 161 |
DWORD cdc_size; |
| 162 |
DWORD cdc_ofs; |
| 163 |
#endif |
| 164 |
#endif |
| 165 |
DWORD n_fatent; |
| 166 |
DWORD fsize; |
| 167 |
LBA_t volbase; |
| 168 |
LBA_t fatbase; |
| 169 |
LBA_t dirbase; |
| 170 |
LBA_t database; |
| 171 |
#if FF_FS_EXFAT |
| 172 |
LBA_t bitbase; |
| 173 |
#endif |
| 174 |
LBA_t winsect; |
| 175 |
BYTE win[FF_MAX_SS]; |
| 176 |
} FATFS; |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
typedef struct { |
| 183 |
FATFS* fs; |
| 184 |
WORD id; |
| 185 |
BYTE attr; |
| 186 |
BYTE stat; |
| 187 |
DWORD sclust; |
| 188 |
FSIZE_t objsize; |
| 189 |
#if FF_FS_EXFAT |
| 190 |
DWORD n_cont; |
| 191 |
DWORD n_frag; |
| 192 |
DWORD c_scl; |
| 193 |
DWORD c_size; |
| 194 |
DWORD c_ofs; |
| 195 |
#endif |
| 196 |
#if FF_FS_LOCK |
| 197 |
UINT lockid; |
| 198 |
#endif |
| 199 |
} FFOBJID; |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
typedef struct { |
| 206 |
FFOBJID obj; |
| 207 |
BYTE flag; |
| 208 |
BYTE err; |
| 209 |
FSIZE_t fptr; |
| 210 |
DWORD clust; |
| 211 |
LBA_t sect; |
| 212 |
#if !FF_FS_READONLY |
| 213 |
LBA_t dir_sect; |
| 214 |
BYTE* dir_ptr; |
| 215 |
#endif |
| 216 |
#if FF_USE_FASTSEEK |
| 217 |
DWORD* cltbl; |
| 218 |
#endif |
| 219 |
#if !FF_FS_TINY |
| 220 |
BYTE buf[FF_MAX_SS]; |
| 221 |
#endif |
| 222 |
} FIL; |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
typedef struct { |
| 229 |
FFOBJID obj; |
| 230 |
DWORD dptr; |
| 231 |
DWORD clust; |
| 232 |
LBA_t sect; |
| 233 |
BYTE* dir; |
| 234 |
BYTE fn[12]; |
| 235 |
#if FF_USE_LFN |
| 236 |
DWORD blk_ofs; |
| 237 |
#endif |
| 238 |
#if FF_USE_FIND |
| 239 |
const FATFS_TCHAR* pat; |
| 240 |
#endif |
| 241 |
} DIR; |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
typedef struct { |
| 248 |
FSIZE_t fsize; |
| 249 |
WORD fdate; |
| 250 |
WORD ftime; |
| 251 |
BYTE fattrib; |
| 252 |
#if FF_USE_LFN |
| 253 |
FATFS_TCHAR altname[FF_SFN_BUF + 1]; |
| 254 |
FATFS_TCHAR fname[FF_LFN_BUF + 1]; |
| 255 |
#else |
| 256 |
FATFS_TCHAR fname[12 + 1]; |
| 257 |
#endif |
| 258 |
} FILINFO; |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
typedef struct { |
| 265 |
BYTE fmt; |
| 266 |
BYTE n_fat; |
| 267 |
UINT align; |
| 268 |
UINT n_root; |
| 269 |
DWORD au_size; |
| 270 |
} MKFS_PARM; |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
typedef enum { |
| 277 |
FR_OK = 0, |
| 278 |
FR_DISK_ERR, |
| 279 |
FR_INT_ERR, |
| 280 |
FR_NOT_READY, |
| 281 |
FR_NO_FILE, |
| 282 |
FR_NO_PATH, |
| 283 |
FR_INVALID_NAME, |
| 284 |
FR_DENIED, |
| 285 |
FR_EXIST, |
| 286 |
FR_INVALID_OBJECT, |
| 287 |
FR_WRITE_PROTECTED, |
| 288 |
FR_INVALID_DRIVE, |
| 289 |
FR_NOT_ENABLED, |
| 290 |
FR_NO_FILESYSTEM, |
| 291 |
FR_MKFS_ABORTED, |
| 292 |
FR_TIMEOUT, |
| 293 |
FR_LOCKED, |
| 294 |
FR_NOT_ENOUGH_CORE, |
| 295 |
FR_TOO_MANY_OPEN_FILES, |
| 296 |
FR_INVALID_PARAMETER |
| 297 |
} FRESULT; |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
FRESULT f_open (FIL* fp, const FATFS_TCHAR* path, BYTE mode); |
| 305 |
FRESULT f_close (FIL* fp); |
| 306 |
FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); |
| 307 |
FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); |
| 308 |
FRESULT f_lseek (FIL* fp, FSIZE_t ofs); |
| 309 |
FRESULT f_truncate (FIL* fp); |
| 310 |
FRESULT f_sync (FIL* fp); |
| 311 |
FRESULT f_opendir (DIR* dp, const FATFS_TCHAR* path); |
| 312 |
FRESULT f_closedir (DIR* dp); |
| 313 |
FRESULT f_readdir (DIR* dp, FILINFO* fno); |
| 314 |
FRESULT f_findfirst (DIR* dp, FILINFO* fno, const FATFS_TCHAR* path, const FATFS_TCHAR* pattern); |
| 315 |
FRESULT f_findnext (DIR* dp, FILINFO* fno); |
| 316 |
FRESULT f_mkdir (const FATFS_TCHAR* path); |
| 317 |
FRESULT f_unlink (const FATFS_TCHAR* path); |
| 318 |
FRESULT f_rename (const FATFS_TCHAR* path_old, const FATFS_TCHAR* path_new); |
| 319 |
FRESULT f_stat (const FATFS_TCHAR* path, FILINFO* fno); |
| 320 |
FRESULT f_chmod (const FATFS_TCHAR* path, BYTE attr, BYTE mask); |
| 321 |
FRESULT f_utime (const FATFS_TCHAR* path, const FILINFO* fno); |
| 322 |
FRESULT f_chdir (const FATFS_TCHAR* path); |
| 323 |
FRESULT f_chdrive (const FATFS_TCHAR* path); |
| 324 |
FRESULT f_getcwd (FATFS_TCHAR* buff, UINT len); |
| 325 |
FRESULT f_getfree (const FATFS_TCHAR* path, DWORD* nclst, FATFS** fatfs); |
| 326 |
FRESULT f_getlabel (const FATFS_TCHAR* path, FATFS_TCHAR* label, DWORD* vsn); |
| 327 |
FRESULT f_setlabel (const FATFS_TCHAR* label); |
| 328 |
FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); |
| 329 |
FRESULT f_expand (FIL* fp, FSIZE_t fsz, BYTE opt); |
| 330 |
FRESULT f_mount (FATFS* fs, const FATFS_TCHAR* path, BYTE opt); |
| 331 |
FRESULT f_mkfs (const FATFS_TCHAR* path, const MKFS_PARM* opt, void* work, UINT len); |
| 332 |
FRESULT f_fdisk (BYTE pdrv, const LBA_t ptbl[], void* work); |
| 333 |
FRESULT f_setcp (WORD cp); |
| 334 |
int f_putc (FATFS_TCHAR c, FIL* fp); |
| 335 |
int f_puts (const FATFS_TCHAR* str, FIL* cp); |
| 336 |
int f_printf (FIL* fp, const FATFS_TCHAR* str, ...); |
| 337 |
FATFS_TCHAR* f_gets (FATFS_TCHAR* buff, int len, FIL* fp); |
| 338 |
|
| 339 |
#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize)) |
| 340 |
#define f_error(fp) ((fp)->err) |
| 341 |
#define f_tell(fp) ((fp)->fptr) |
| 342 |
#define f_size(fp) ((fp)->obj.objsize) |
| 343 |
#define f_rewind(fp) f_lseek((fp), 0) |
| 344 |
#define f_rewinddir(dp) f_readdir((dp), 0) |
| 345 |
#define f_rmdir(path) f_unlink(path) |
| 346 |
#define f_unmount(path) f_mount(0, path, 0) |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
#if !FF_FS_READONLY && !FF_FS_NORTC |
| 356 |
DWORD get_fattime (void); |
| 357 |
#endif |
| 358 |
|
| 359 |
|
| 360 |
#if FF_USE_LFN >= 1 |
| 361 |
WCHAR ff_oem2uni (WCHAR oem, WORD cp); |
| 362 |
WCHAR ff_uni2oem (DWORD uni, WORD cp); |
| 363 |
DWORD ff_wtoupper (DWORD uni); |
| 364 |
#endif |
| 365 |
#if FF_USE_LFN == 3 |
| 366 |
void* ff_memalloc (UINT msize); |
| 367 |
void ff_memfree (void* mblock); |
| 368 |
#endif |
| 369 |
|
| 370 |
|
| 371 |
#if FF_FS_REENTRANT |
| 372 |
int ff_cre_syncobj (BYTE vol, FF_SYNC_t* sobj); |
| 373 |
int ff_req_grant (FF_SYNC_t sobj); |
| 374 |
void ff_rel_grant (FF_SYNC_t sobj); |
| 375 |
int ff_del_syncobj (FF_SYNC_t sobj); |
| 376 |
#endif |
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
#define FA_READ 0x01 |
| 387 |
#define FA_WRITE 0x02 |
| 388 |
#define FA_OPEN_EXISTING 0x00 |
| 389 |
#define FA_CREATE_NEW 0x04 |
| 390 |
#define FA_CREATE_ALWAYS 0x08 |
| 391 |
#define FA_OPEN_ALWAYS 0x10 |
| 392 |
#define FA_OPEN_APPEND 0x30 |
| 393 |
|
| 394 |
|
| 395 |
#define CREATE_LINKMAP ((FSIZE_t)0 - 1) |
| 396 |
|
| 397 |
|
| 398 |
#define FM_FAT 0x01 |
| 399 |
#define FM_FAT32 0x02 |
| 400 |
#define FM_EXFAT 0x04 |
| 401 |
#define FM_ANY 0x07 |
| 402 |
#define FM_SFD 0x08 |
| 403 |
|
| 404 |
|
| 405 |
#define FS_FAT12 1 |
| 406 |
#define FS_FAT16 2 |
| 407 |
#define FS_FAT32 3 |
| 408 |
#define FS_EXFAT 4 |
| 409 |
|
| 410 |
|
| 411 |
#define AM_RDO 0x01 |
| 412 |
#define AM_HID 0x02 |
| 413 |
#define AM_SYS 0x04 |
| 414 |
#define AM_DIR 0x10 |
| 415 |
#define AM_ARC 0x20 |
| 416 |
|
| 417 |
|
| 418 |
#ifdef __cplusplus |
| 419 |
} |
| 420 |
#endif |
| 421 |
|
| 422 |
#endif |