Skip to content

Commit 809995d

Browse files
CopilotBernardXiong
andcommitted
[dfs_v2][elmfat] Update to clean elm-fatfs R0.15 patch3
Co-authored-by: BernardXiong <[email protected]>
1 parent 4b251ac commit 809995d

File tree

3 files changed

+27
-98
lines changed

3 files changed

+27
-98
lines changed

components/dfs/dfs_v2/filesystems/elmfat/ff.c

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*----------------------------------------------------------------------------/
2-
/ FatFs - Generic FAT Filesystem Module R0.15 w/patch1 /
2+
/ FatFs - Generic FAT Filesystem Module R0.15 w/patch3 /
33
/-----------------------------------------------------------------------------/
44
/
55
/ Copyright (C) 2022, ChaN, all right reserved.
@@ -468,10 +468,11 @@ static WORD Fsid; /* Filesystem mount ID */
468468
static BYTE CurrVol; /* Current drive set by f_chdrive() */
469469
#endif
470470

471-
#if FF_FS_LOCK != 0
471+
#if FF_FS_LOCK
472472
static FILESEM Files[FF_FS_LOCK]; /* Open object lock semaphores */
473473
#if FF_FS_REENTRANT
474-
static BYTE SysLock; /* System lock flag (0:no mutex, 1:unlocked, 2:locked) */
474+
static volatile BYTE SysLock; /* System lock flag to protect Files[] (0:no mutex, 1:unlocked, 2:locked) */
475+
static volatile BYTE SysLockVolume; /* Volume id who is locking Files[] */
475476
#endif
476477
#endif
477478

@@ -905,6 +906,7 @@ static int lock_volume ( /* 1:Ok, 0:timeout */
905906
if (rv && syslock) { /* System lock reqiered? */
906907
rv = ff_mutex_take(FF_VOLUMES); /* Lock the system */
907908
if (rv) {
909+
SysLockVolume = fs->ldrv;
908910
SysLock = 2; /* System lock succeeded */
909911
} else {
910912
ff_mutex_give(fs->ldrv); /* Failed system lock */
@@ -924,7 +926,7 @@ static void unlock_volume (
924926
{
925927
if (fs && res != FR_NOT_ENABLED && res != FR_INVALID_DRIVE && res != FR_TIMEOUT) {
926928
#if FF_FS_LOCK
927-
if (SysLock == 2) { /* Is the system locked? */
929+
if (SysLock == 2 && SysLockVolume == fs->ldrv) { /* Unlock system if it has been locked by this task */
928930
SysLock = 1;
929931
ff_mutex_give(FF_VOLUMES);
930932
}
@@ -4719,24 +4721,7 @@ FRESULT f_readdir (
47194721
LEAVE_FF(fs, res);
47204722
}
47214723

4722-
FRESULT f_seekdir(
4723-
DIR *dj, /* Pointer to the open directory object */
4724-
int offset /* the seek offset */
4725-
)
4726-
{
4727-
int i = 0;
4728-
4729-
if (dir_sdi(dj, 0) != FR_OK || offset < 0)
4730-
return FR_INT_ERR;
4731-
4732-
while(i < offset)
4733-
{
4734-
if(dir_read(dj, 0) != FR_OK || dir_next(dj, 0) != FR_OK)
4735-
return FR_INT_ERR;
4736-
i++;
4737-
}
4738-
return FR_OK;
4739-
}
4724+
47404725

47414726
#if FF_USE_FIND
47424727
/*-----------------------------------------------------------------------*/
@@ -4812,7 +4797,7 @@ FRESULT f_stat (
48124797
res = follow_path(&dj, path); /* Follow the file path */
48134798
if (res == FR_OK) { /* Follow completed */
48144799
if (dj.fn[NSFLAG] & NS_NONAME) { /* It is origin directory */
4815-
fno->fattrib = AM_DIR;
4800+
res = FR_INVALID_NAME;
48164801
} else { /* Found an object */
48174802
if (fno) get_fileinfo(&dj, fno);
48184803
}
@@ -5477,6 +5462,10 @@ FRESULT f_setlabel (
54775462
/* Get logical drive */
54785463
res = mount_volume(&label, &fs, FA_WRITE);
54795464
if (res != FR_OK) LEAVE_FF(fs, res);
5465+
#if FF_STR_VOLUME_ID == 2
5466+
for ( ; *label == '/'; label++) ; /* Snip the separators off */
5467+
#endif
5468+
54805469

54815470
#if FF_FS_EXFAT
54825471
if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */
@@ -7099,18 +7088,3 @@ FRESULT f_setcp (
70997088
}
71007089
#endif /* FF_CODE_PAGE == 0 */
71017090

7102-
#include <rtthread.h>
7103-
#if FF_VOLUMES > 1
7104-
int elm_get_vol(FATFS *fat)
7105-
{
7106-
int vol;
7107-
7108-
for (vol = 0; vol < FF_VOLUMES; vol ++)
7109-
{
7110-
if (FatFs[vol] == fat) return vol;
7111-
}
7112-
7113-
return -1;
7114-
}
7115-
#endif
7116-

components/dfs/dfs_v2/filesystems/elmfat/ff.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
extern "C" {
2727
#endif
2828

29-
#include <rtthread.h>
3029
#include "ffconf.h" /* FatFs configuration options */
3130

3231
#if FF_DEFINED != FFCONF_DEF
@@ -312,7 +311,6 @@ FRESULT f_sync (FIL* fp); /* Flush cached data of the writing file */
312311
FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */
313312
FRESULT f_closedir (DIR* dp); /* Close an open directory */
314313
FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */
315-
FRESULT f_seekdir(DIR *dj, int offset); /* Seek in directory */
316314
FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */
317315
FRESULT f_findnext (DIR* dp, FILINFO* fno); /* Find next file */
318316
FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */

components/dfs/dfs_v2/filesystems/elmfat/ffconf.h

Lines changed: 15 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */
3131

3232

33-
#define FF_USE_MKFS 1
33+
#define FF_USE_MKFS 0
3434
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
3535

3636

37-
#define FF_USE_FASTSEEK 1
37+
#define FF_USE_FASTSEEK 0
3838
/* This option switches fast seek function. (0:Disable or 1:Enable) */
3939

4040

@@ -57,8 +57,8 @@
5757

5858

5959
#define FF_USE_STRFUNC 0
60-
#define FF_PRINT_LLI 0
61-
#define FF_PRINT_FLOAT 0
60+
#define FF_PRINT_LLI 1
61+
#define FF_PRINT_FLOAT 1
6262
#define FF_STRF_ENCODE 3
6363
/* FF_USE_STRFUNC switches string functions, f_gets(), f_putc(), f_puts() and
6464
/ f_printf().
@@ -84,11 +84,7 @@
8484
/ Locale and Namespace Configurations
8585
/---------------------------------------------------------------------------*/
8686

87-
#ifdef RT_DFS_ELM_CODE_PAGE
88-
# define FF_CODE_PAGE RT_DFS_ELM_CODE_PAGE
89-
#else
90-
# define FF_CODE_PAGE 936
91-
#endif
87+
#define FF_CODE_PAGE 932
9288
/* This option specifies the OEM code page to be used on the target system.
9389
/ Incorrect code page setting can cause a file open failure.
9490
/
@@ -117,13 +113,8 @@
117113
*/
118114

119115

120-
#if RT_DFS_ELM_USE_LFN
121-
#define FF_USE_LFN RT_DFS_ELM_USE_LFN
122-
#define FF_MAX_LFN RT_DFS_ELM_MAX_LFN
123-
#else
124-
#define FF_USE_LFN 0 /* 0 to 3 */
125-
#define FF_MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
126-
#endif
116+
#define FF_USE_LFN 0
117+
#define FF_MAX_LFN 255
127118
/* The FF_USE_LFN switches the support for LFN (long file name).
128119
/
129120
/ 0: Disable LFN. FF_MAX_LFN has no effect.
@@ -142,20 +133,7 @@
142133
/ ff_memfree() exemplified in ffsystem.c, need to be added to the project. */
143134

144135

145-
#ifdef RT_DFS_ELM_LFN_UNICODE
146-
/* This option switches the character encoding on the API when LFN is enabled.
147-
/
148-
/ 0: ANSI/OEM in current CP (TCHAR = char)
149-
/ 1: Unicode in UTF-16 (TCHAR = WCHAR)
150-
/ 2: Unicode in UTF-8 (TCHAR = char)
151-
/ 3: Unicode in UTF-32 (TCHAR = DWORD)
152-
/
153-
/ Also behavior of string I/O functions will be affected by this option.
154-
/ When LFN is not enabled, this option has no effect. */
155-
#define FF_LFN_UNICODE RT_DFS_ELM_LFN_UNICODE /* 0:ANSI/OEM or 1:Unicode */
156-
#else
157-
#define FF_LFN_UNICODE 0 /* 0:ANSI/OEM or 1:Unicode */
158-
#endif
136+
#define FF_LFN_UNICODE 0
159137
/* This option switches the character encoding on the API when LFN is enabled.
160138
/
161139
/ 0: ANSI/OEM in current CP (TCHAR = char)
@@ -188,11 +166,7 @@
188166
/ Drive/Volume Configurations
189167
/---------------------------------------------------------------------------*/
190168

191-
#ifdef RT_DFS_ELM_DRIVES
192-
#define FF_VOLUMES RT_DFS_ELM_DRIVES
193-
#else
194-
#define FF_VOLUMES 1
195-
#endif
169+
#define FF_VOLUMES 1
196170
/* Number of volumes (logical drives) to be used. (1-10) */
197171

198172

@@ -220,11 +194,7 @@
220194

221195

222196
#define FF_MIN_SS 512
223-
#ifdef RT_DFS_ELM_MAX_SECTOR_SIZE
224-
#define FF_MAX_SS RT_DFS_ELM_MAX_SECTOR_SIZE
225-
#else
226-
#define FF_MAX_SS 512 /* 512, 1024, 2048 or 4096 */
227-
#endif
197+
#define FF_MAX_SS 512
228198
/* This set of options configures the range of sector size to be supported. (512,
229199
/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and
230200
/ harddisk, but a larger value may be required for on-board flash memory and some
@@ -260,11 +230,8 @@
260230
/ Instead of private sector buffer eliminated from the file object, common sector
261231
/ buffer in the filesystem object (FATFS) is used for the file data transfer. */
262232

263-
#ifdef RT_DFS_ELM_USE_EXFAT
264-
#define FF_FS_EXFAT 1
265-
#else
266-
#define FF_FS_EXFAT 0
267-
#endif
233+
234+
#define FF_FS_EXFAT 0
268235
/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable)
269236
/ To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1)
270237
/ Note that enabling exFAT discards ANSI C (C89) compatibility. */
@@ -308,18 +275,8 @@
308275
/ lock control is independent of re-entrancy. */
309276

310277

311-
/* #include <somertos.h> // O/S definitions */
312-
#include <rtdef.h>
313-
#ifdef RT_DFS_ELM_REENTRANT
314-
#define FF_FS_REENTRANT 1 /* 0 or 1 */
315-
#else
316-
#define FF_FS_REENTRANT 0 /* 0:Disable or 1:Enable */
317-
#endif
318-
#ifndef RT_DFS_ELM_MUTEX_TIMEOUT
319-
#define RT_DFS_ELM_MUTEX_TIMEOUT 3000
320-
#endif
321-
#define FF_FS_TIMEOUT RT_DFS_ELM_MUTEX_TIMEOUT
322-
//#define FF_SYNC_t rt_mutex_t
278+
#define FF_FS_REENTRANT 0
279+
#define FF_FS_TIMEOUT 1000
323280
/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
324281
/ module itself. Note that regardless of this option, file access to different
325282
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
@@ -336,4 +293,4 @@
336293

337294

338295

339-
/*--- End of configuration options ---*/
296+
/*--- End of configuration options ---*/

0 commit comments

Comments
 (0)