Skip to content

Commit 679d973

Browse files
committed
Merge branch 'feature/fatfs_15_update' into 'master'
fatfs: Update to version 0.15 Closes IDF-6391 See merge request espressif/esp-idf!21330
2 parents f6b0d04 + e6fcaa4 commit 679d973

File tree

9 files changed

+745
-457
lines changed

9 files changed

+745
-457
lines changed
Lines changed: 142 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/*------------------------------------------------------------------------*/
2-
/* Sample Code of OS Dependent Functions for FatFs */
3-
/* (C)ChaN, 2017 */
2+
/* A Sample Code of User Provided OS Dependent Functions for FatFs */
43
/*------------------------------------------------------------------------*/
54

65

@@ -12,7 +11,11 @@
1211
#include "esp_heap_caps.h"
1312
#endif
1413

15-
void* ff_memalloc ( /* Returns pointer to the allocated memory block (null on not enough core) */
14+
/*------------------------------------------------------------------------*/
15+
/* Allocate/Free a Memory Block */
16+
/*------------------------------------------------------------------------*/
17+
18+
void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */
1619
unsigned msize /* Number of bytes to allocate */
1720
)
1821
{
@@ -25,12 +28,8 @@ void* ff_memalloc ( /* Returns pointer to the allocated memory block (null on
2528
}
2629

2730

28-
/*------------------------------------------------------------------------*/
29-
/* Free a memory block */
30-
/*------------------------------------------------------------------------*/
31-
3231
void ff_memfree (
33-
void* mblock /* Pointer to the memory block to free (nothing to do for null) */
32+
void* mblock /* Pointer to the memory block to free (no effect if null) */
3433
)
3534
{
3635
free(mblock); /* Free the memory block with POSIX API */
@@ -39,70 +38,175 @@ void ff_memfree (
3938

4039

4140

42-
#if FF_FS_REENTRANT /* Mutal exclusion */
4341

42+
#if FF_FS_REENTRANT /* Mutal exclusion */
4443
/*------------------------------------------------------------------------*/
45-
/* Create a Synchronization Object */
44+
/* Definitions of Mutex */
4645
/*------------------------------------------------------------------------*/
47-
/* This function is called in f_mount() function to create a new
48-
/ synchronization object for the volume, such as semaphore and mutex.
49-
/ When a 0 is returned, the f_mount() function fails with FR_INT_ERR.
50-
*/
5146

47+
#define OS_TYPE 3 /* 0:Win32, 1:uITRON4.0, 2:uC/OS-II, 3:FreeRTOS, 4:CMSIS-RTOS */
48+
49+
50+
#if OS_TYPE == 0 /* Win32 */
51+
#include <windows.h>
52+
static HANDLE Mutex[FF_VOLUMES + 1]; /* Table of mutex handle */
53+
54+
#elif OS_TYPE == 1 /* uITRON */
55+
#include "itron.h"
56+
#include "kernel.h"
57+
static mtxid Mutex[FF_VOLUMES + 1]; /* Table of mutex ID */
58+
59+
#elif OS_TYPE == 2 /* uc/OS-II */
60+
#include "includes.h"
61+
static OS_EVENT *Mutex[FF_VOLUMES + 1]; /* Table of mutex pinter */
62+
63+
#elif OS_TYPE == 3 /* FreeRTOS */
64+
#include "freertos/FreeRTOS.h"
65+
#include "freertos/semphr.h"
66+
static SemaphoreHandle_t Mutex[FF_VOLUMES + 1]; /* Table of mutex handle */
67+
68+
#elif OS_TYPE == 4 /* CMSIS-RTOS */
69+
#include "cmsis_os.h"
70+
static osMutexId Mutex[FF_VOLUMES + 1]; /* Table of mutex ID */
5271

53-
int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */
54-
BYTE vol, /* Corresponding volume (logical drive number) */
55-
FF_SYNC_t *sobj /* Pointer to return the created sync object */
72+
#endif
73+
74+
75+
76+
/*------------------------------------------------------------------------*/
77+
/* Create a Mutex */
78+
/*------------------------------------------------------------------------*/
79+
/* This function is called in f_mount function to create a new mutex
80+
/ or semaphore for the volume. When a 0 is returned, the f_mount function
81+
/ fails with FR_INT_ERR.
82+
*/
83+
84+
int ff_mutex_create ( /* Returns 1:Function succeeded or 0:Could not create the mutex */
85+
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
5686
)
5787
{
58-
*sobj = xSemaphoreCreateMutex();
59-
return (*sobj != NULL) ? 1 : 0;
88+
#if OS_TYPE == 0 /* Win32 */
89+
Mutex[vol] = CreateMutex(NULL, FALSE, NULL);
90+
return (int)(Mutex[vol] != INVALID_HANDLE_VALUE);
91+
92+
#elif OS_TYPE == 1 /* uITRON */
93+
T_CMTX cmtx = {TA_TPRI,1};
94+
95+
Mutex[vol] = acre_mtx(&cmtx);
96+
return (int)(Mutex[vol] > 0);
97+
98+
#elif OS_TYPE == 2 /* uC/OS-II */
99+
OS_ERR err;
100+
101+
Mutex[vol] = OSMutexCreate(0, &err);
102+
return (int)(err == OS_NO_ERR);
103+
104+
#elif OS_TYPE == 3 /* FreeRTOS */
105+
Mutex[vol] = xSemaphoreCreateMutex();
106+
return (int)(Mutex[vol] != NULL);
107+
108+
#elif OS_TYPE == 4 /* CMSIS-RTOS */
109+
osMutexDef(cmsis_os_mutex);
110+
111+
Mutex[vol] = osMutexCreate(osMutex(cmsis_os_mutex));
112+
return (int)(Mutex[vol] != NULL);
113+
114+
#endif
60115
}
61116

62117

63118
/*------------------------------------------------------------------------*/
64-
/* Delete a Synchronization Object */
119+
/* Delete a Mutex */
65120
/*------------------------------------------------------------------------*/
66-
/* This function is called in f_mount() function to delete a synchronization
67-
/ object that created with ff_cre_syncobj() function. When a 0 is returned,
68-
/ the f_mount() function fails with FR_INT_ERR.
121+
/* This function is called in f_mount function to delete a mutex or
122+
/ semaphore of the volume created with ff_mutex_create function.
69123
*/
70124

71-
int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error */
72-
FF_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
125+
void ff_mutex_delete ( /* Returns 1:Function succeeded or 0:Could not delete due to an error */
126+
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
73127
)
74128
{
75-
vSemaphoreDelete(sobj);
76-
return 1;
129+
#if OS_TYPE == 0 /* Win32 */
130+
CloseHandle(Mutex[vol]);
131+
132+
#elif OS_TYPE == 1 /* uITRON */
133+
del_mtx(Mutex[vol]);
134+
135+
#elif OS_TYPE == 2 /* uC/OS-II */
136+
OS_ERR err;
137+
138+
OSMutexDel(Mutex[vol], OS_DEL_ALWAYS, &err);
139+
140+
#elif OS_TYPE == 3 /* FreeRTOS */
141+
vSemaphoreDelete(Mutex[vol]);
142+
143+
#elif OS_TYPE == 4 /* CMSIS-RTOS */
144+
osMutexDelete(Mutex[vol]);
145+
146+
#endif
77147
}
78148

79149

80150
/*------------------------------------------------------------------------*/
81-
/* Request Grant to Access the Volume */
151+
/* Request a Grant to Access the Volume */
82152
/*------------------------------------------------------------------------*/
83-
/* This function is called on entering file functions to lock the volume.
153+
/* This function is called on enter file functions to lock the volume.
84154
/ When a 0 is returned, the file function fails with FR_TIMEOUT.
85155
*/
86156

87-
int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */
88-
FF_SYNC_t sobj /* Sync object to wait */
157+
int ff_mutex_take ( /* Returns 1:Succeeded or 0:Timeout */
158+
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
89159
)
90160
{
91-
return (xSemaphoreTake(sobj, FF_FS_TIMEOUT) == pdTRUE) ? 1 : 0;
161+
#if OS_TYPE == 0 /* Win32 */
162+
return (int)(WaitForSingleObject(Mutex[vol], FF_FS_TIMEOUT) == WAIT_OBJECT_0);
163+
164+
#elif OS_TYPE == 1 /* uITRON */
165+
return (int)(tloc_mtx(Mutex[vol], FF_FS_TIMEOUT) == E_OK);
166+
167+
#elif OS_TYPE == 2 /* uC/OS-II */
168+
OS_ERR err;
169+
170+
OSMutexPend(Mutex[vol], FF_FS_TIMEOUT, &err));
171+
return (int)(err == OS_NO_ERR);
172+
173+
#elif OS_TYPE == 3 /* FreeRTOS */
174+
return (int)(xSemaphoreTake(Mutex[vol], FF_FS_TIMEOUT) == pdTRUE);
175+
176+
#elif OS_TYPE == 4 /* CMSIS-RTOS */
177+
return (int)(osMutexWait(Mutex[vol], FF_FS_TIMEOUT) == osOK);
178+
179+
#endif
92180
}
93181

94182

183+
95184
/*------------------------------------------------------------------------*/
96-
/* Release Grant to Access the Volume */
185+
/* Release a Grant to Access the Volume */
97186
/*------------------------------------------------------------------------*/
98-
/* This function is called on leaving file functions to unlock the volume.
187+
/* This function is called on leave file functions to unlock the volume.
99188
*/
100189

101-
void ff_rel_grant (
102-
FF_SYNC_t sobj /* Sync object to be signaled */
190+
void ff_mutex_give (
191+
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
103192
)
104193
{
105-
xSemaphoreGive(sobj);
194+
#if OS_TYPE == 0 /* Win32 */
195+
ReleaseMutex(Mutex[vol]);
196+
197+
#elif OS_TYPE == 1 /* uITRON */
198+
unl_mtx(Mutex[vol]);
199+
200+
#elif OS_TYPE == 2 /* uC/OS-II */
201+
OSMutexPost(Mutex[vol]);
202+
203+
#elif OS_TYPE == 3 /* FreeRTOS */
204+
xSemaphoreGive(Mutex[vol]);
205+
206+
#elif OS_TYPE == 4 /* CMSIS-RTOS */
207+
osMutexRelease(Mutex[vol]);
208+
209+
#endif
106210
}
107211

108-
#endif // FF_FS_REENTRANT
212+
#endif /* FF_FS_REENTRANT */

components/fatfs/port/linux/ffsystem.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@ void ff_memfree(void* mblock)
2121
free(mblock);
2222
}
2323

24-
/* 1:Function succeeded, 0:Could not create the sync object */
25-
int ff_cre_syncobj(BYTE vol, FF_SYNC_t* sobj)
24+
static int* Mutex[FF_VOLUMES + 1]; /* Table of mutex handle */
25+
26+
/* 1:Function succeeded, 0:Could not create the mutex */
27+
int ff_mutex_create(int vol)
2628
{
27-
*sobj = NULL;
29+
Mutex[vol] = NULL;
2830
return 1;
2931
}
3032

31-
/* 1:Function succeeded, 0:Could not delete due to an error */
32-
int ff_del_syncobj(FF_SYNC_t sobj)
33+
void ff_mutex_delete(int vol)
3334
{
34-
return 1;
3535
}
3636

3737
/* 1:Function succeeded, 0:Could not acquire lock */
38-
int ff_req_grant (FF_SYNC_t sobj)
38+
int ff_mutex_take(int vol)
3939
{
4040
return 1;
4141
}
4242

43-
void ff_rel_grant (FF_SYNC_t sobj)
43+
void ff_mutex_give(int vol)
4444
{
4545
}

components/fatfs/src/00history.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,42 @@ R0.13c (October 14, 2018)
327327
Fixed reading a directory gets infinite loop when the last directory entry is not empty. (appeared at R0.12)
328328
Fixed creating a sub-directory in the fragmented sub-directory on the exFAT volume collapses FAT chain of the parent directory. (appeared at R0.12)
329329
Fixed f_getcwd() cause output buffer overrun when the buffer has a valid drive number. (appeared at R0.13b)
330+
331+
332+
333+
R0.14 (October 14, 2019)
334+
Added support for 64-bit LBA and GUID partition table (FF_LBA64 = 1)
335+
Changed some API functions, f_mkfs() and f_fdisk().
336+
Fixed f_open() function cannot find the file with file name in length of FF_MAX_LFN characters.
337+
Fixed f_readdir() function cannot retrieve long file names in length of FF_MAX_LFN - 1 characters.
338+
Fixed f_readdir() function returns file names with wrong case conversion. (appeared at R0.12)
339+
Fixed f_mkfs() function can fail to create exFAT volume in the second partition. (appeared at R0.12)
340+
341+
342+
R0.14a (December 5, 2020)
343+
Limited number of recursive calls in f_findnext().
344+
Fixed old floppy disks formatted with MS-DOS 2.x and 3.x cannot be mounted.
345+
Fixed some compiler warnings.
346+
347+
348+
349+
R0.14b (April 17, 2021)
350+
Made FatFs uses standard library <string.h> for copy, compare and search instead of built-in string functions.
351+
Added support for long long integer and floating point to f_printf(). (FF_STRF_LLI and FF_STRF_FP)
352+
Made path name parser ignore the terminating separator to allow "dir/".
353+
Improved the compatibility in Unix style path name feature.
354+
Fixed the file gets dead-locked when f_open() failed with some conditions. (appeared at R0.12a)
355+
Fixed f_mkfs() can create wrong exFAT volume due to a timing dependent error. (appeared at R0.12)
356+
Fixed code page 855 cannot be set by f_setcp().
357+
Fixed some compiler warnings.
358+
359+
360+
361+
R0.15 (November 6, 2022)
362+
Changed user provided synchronization functions in order to completely eliminate the platform dependency from FatFs code.
363+
FF_SYNC_t is removed from the configuration options.
364+
Fixed a potential error in f_mount when FF_FS_REENTRANT.
365+
Fixed file lock control FF_FS_LOCK is not mutal excluded when FF_FS_REENTRANT && FF_VOLUMES > 1 is true.
366+
Fixed f_mkfs() creates broken exFAT volume when the size of volume is >= 2^32 sectors.
367+
Fixed string functions cannot write the unicode characters not in BMP when FF_LFN_UNICODE == 2 (UTF-8).
368+
Fixed a compatibility issue in identification of GPT header.

components/fatfs/src/00readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FatFs Module Source Files R0.13c
1+
FatFs Module Source Files R0.15
22

33

44
FILES

0 commit comments

Comments
 (0)