Go to the documentation of this file.
37 #define FATFS_R(major, minor, patch) ((major << 16) | (minor << 8) | (0x ## patch))
41 #define FATFS_REVISON FATFS_R(0, 7, c)
43 #define FATFS_REVISON FATFS_R(0, 7, e)
44 #elif (_FATFS == 8085)
45 #define FATFS_REVISON FATFS_R(0, 8, 0)
46 #elif (_FATFS == 8255)
47 #define FATFS_REVISON FATFS_R(0, 8, a)
48 #elif (_FATFS == 8237)
49 #define FATFS_REVISON FATFS_R(0, 8, b)
50 #elif (_FATFS == 6502)
51 #define FATFS_REVISON FATFS_R(0, 9, 0)
52 #elif (_FATFS == 4004)
53 #define FATFS_REVISON FATFS_R(0, 9, a)
54 #elif (_FATFS == 82786)
55 #define FATFS_REVISON FATFS_R(0, 9, b)
56 #elif (_FATFS == 80960)
57 #define FATFS_REVISON FATFS_R(0, 10, 0)
58 #elif (_FATFS == 29000)
59 #define FATFS_REVISON FATFS_R(0, 10, a)
60 #elif (_FATFS == 8051)
61 #define FATFS_REVISON FATFS_R(0, 10, b)
62 #elif (_FATFS == 80376)
63 #define FATFS_REVISON FATFS_R(0, 10, c)
64 #elif (_FATFS == 32020)
65 #define FATFS_REVISON FATFS_R(0, 11, 0)
66 #elif (_FATFS == 64180)
67 #define FATFS_REVISON FATFS_R(0, 11, a)
68 #elif (_FATFS == 88100)
69 #define FATFS_REVISON FATFS_R(0, 12, 0)
70 #elif (_FATFS == 80186)
71 #define FATFS_REVISON FATFS_R(0, 12, a)
72 #elif (_FATFS == 68020)
73 #define FATFS_REVISON FATFS_R(0, 12, b)
74 #elif (_FATFS == 68300)
75 #define FATFS_REVISON FATFS_R(0, 12, c)
76 #elif (FF_DEFINED == 87030)
77 #define FATFS_REVISON FATFS_R(0, 13, 0)
78 #elif (FF_DEFINED == 89352)
79 #define FATFS_REVISON FATFS_R(0, 13, a)
80 #elif (FF_DEFINED == 63463)
81 #define FATFS_REVISON FATFS_R(0, 13, b)
82 #elif (FF_DEFINED == 86604)
83 #define FATFS_REVISON FATFS_R(0, 13, c)
84 #elif (FF_DEFINED == 86606)
85 #define FATFS_REVISON FATFS_R(0, 14, 0)
86 #elif (FF_DEFINED == 80196)
87 #define FATFS_REVISON FATFS_R(0, 14, a)
88 #elif (FF_DEFINED == 86631)
89 #define FATFS_REVISON FATFS_R(0, 14, b)
90 #elif (FF_DEFINED == 80286)
91 #define FATFS_REVISON FATFS_R(0, 15, 0)
93 #define FATFS_REVISON FATFS_R(0, 0, 0)
115 osMemset(fileTable, 0,
sizeof(fileTable));
116 osMemset(dirTable, 0,
sizeof(dirTable));
126 #if (FATFS_REVISON <= FATFS_R(0, 9, b))
127 res = f_mount(0, &fs);
129 res = f_mount(&fs,
"", 1);
157 #if (FATFS_REVISON <= FATFS_R(0, 11, a) && _USE_LFN != 0)
166 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
167 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
173 res = f_stat(path, &fno);
175 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
176 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
186 if(fno.fattrib & AM_DIR)
209 #if (FATFS_REVISON <= FATFS_R(0, 11, a) && _USE_LFN != 0)
215 if(path == NULL || size == NULL)
218 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
219 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
225 res = f_stat(path, &fno);
227 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
228 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
238 if(fno.fattrib & AM_DIR)
261 #if (FATFS_REVISON <= FATFS_R(0, 11, a) && _USE_LFN != 0)
267 if(path == NULL || fileStat == NULL)
270 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
271 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
277 res = f_stat(path, &fno);
279 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
280 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
295 fileStat->
size = fno.fsize;
298 fileStat->
modified.
year = 1980 + ((fno.fdate >> 9) & 0x7F);
327 #if (_FS_READONLY == 1 || FF_FS_READONLY == 1)
334 if(oldPath == NULL || newPath == NULL)
337 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
338 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
344 res = f_rename(oldPath, newPath);
346 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
347 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
370 #if (_FS_READONLY == 1 || FF_FS_READONLY == 1)
380 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
381 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
387 res = f_unlink(path);
389 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
390 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
433 #if (FATFS_REVISON <= FATFS_R(0, 11, a))
434 if(fileTable[i].fs == NULL)
436 if(fileTable[i].obj.fs == NULL)
450 flags |= FA_OPEN_ALWAYS;
453 flags |= FA_CREATE_ALWAYS;
456 res = f_open(&fileTable[i], path,
flags);
460 file = &fileTable[i];
491 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
492 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
501 offset += f_tell((FIL *)
file);
506 offset += f_size((FIL *)
file);
514 res = f_lseek((FIL *)
file, offset);
516 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
517 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
541 #if (_FS_READONLY == 1 || FF_FS_READONLY == 1)
552 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
553 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
561 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
562 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
602 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
603 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
611 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
612 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
646 f_close((FIL *)
file);
649 #if (FATFS_REVISON <= FATFS_R(0, 11, a))
650 ((FIL *)
file)->fs = NULL;
652 ((FIL *)
file)->obj.fs = NULL;
672 #if (FATFS_REVISON <= FATFS_R(0, 11, a) && _USE_LFN != 0)
685 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
686 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
692 res = f_stat(path, &fno);
694 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
695 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
705 if(fno.fattrib & AM_DIR)
724 #if (_FS_READONLY == 1 || FF_FS_READONLY == 1)
734 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
735 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
743 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
744 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
767 #if (_FS_READONLY == 1 || FF_FS_READONLY == 1)
777 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
778 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
784 res = f_unlink(path);
786 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
787 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
827 #if (FATFS_REVISON <= FATFS_R(0, 11, a))
828 if(dirTable[i].fs == NULL)
830 if(dirTable[i].obj.fs == NULL)
834 res = f_opendir(&dirTable[i], path);
866 #if (FATFS_REVISON <= FATFS_R(0, 11, a) && _USE_LFN != 0)
869 fno.lfsize =
sizeof(lfn);
876 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
877 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
883 res = f_readdir((DIR *) dir, &fno);
885 #if ((FATFS_REVISON <= FATFS_R(0, 12, c) && _FS_REENTRANT == 0) || \
886 (FATFS_REVISON >= FATFS_R(0, 13, 0) && FF_FS_REENTRANT == 0))
896 if(fno.fname[0] ==
'\0')
900 #if (FATFS_REVISON <= FATFS_R(0, 11, a) && _USE_LFN != 0)
901 fn = (*fno.lfname !=
'\0') ? fno.lfname : fno.fname;
909 dirEntry->
size = fno.fsize;
912 dirEntry->
modified.
year = 1980 + ((fno.fdate >> 9) & 0x7F);
935 dirEntry->
name[
n] =
'\0';
955 #if (FATFS_REVISON >= FATFS_R(0, 10, 0))
957 f_closedir((DIR *) dir);
961 #if (FATFS_REVISON <= FATFS_R(0, 11, a))
962 ((DIR *) dir)->fs = NULL;
964 ((DIR *) dir)->obj.fs = NULL;
error_t fsSeekFile(FsFile *file, int_t offset, uint_t origin)
Move to specified position in file.
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
error_t fsGetFileSize(const char_t *path, uint32_t *size)
Retrieve the size of the specified file.
error_t fsRemoveDir(const char_t *path)
Remove a directory.
error_t fsCreateDir(const char_t *path)
Create a directory.
error_t fsReadFile(FsFile *file, void *data, size_t size, size_t *length)
Read data from the specified file.
FsDir * fsOpenDir(const char_t *path)
Open a directory stream.
@ ERROR_INVALID_PARAMETER
Invalid parameter.
void fsCloseFile(FsFile *file)
Close a file.
error_t fsRenameFile(const char_t *oldPath, const char_t *newPath)
Rename the specified file.
bool_t fsFileExists(const char_t *path)
Check whether a file exists.
@ ERROR_FAILURE
Generic error code.
error_t fsReadDir(FsDir *dir, FsDirEntry *dirEntry)
Read an entry from the specified directory stream.
FsFile * fsOpenFile(const char_t *path, uint_t mode)
Open the specified file for reading or writing.
File system abstraction layer.
char_t name[FS_MAX_NAME_LEN+1]
error_t fsInit(void)
File system initialization.
void osDeleteMutex(OsMutex *mutex)
Delete a mutex object.
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
bool_t fsDirExists(const char_t *path)
Check whether a directory exists.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
error_t fsWriteFile(FsFile *file, void *data, size_t length)
Write data to the specified file.
#define osStrncpy(s1, s2, length)
error_t fsGetFileStat(const char_t *path, FsFileStat *fileStat)
Retrieve the attributes of the specified file.
void fsCloseDir(FsDir *dir)
Close a directory stream.
File system abstraction layer (FatFs)
#define osMemset(p, value, length)
error_t fsDeleteFile(const char_t *path)
Delete a file.
void FsFile
File descriptor.