فهرست منبع

[dfs_v2][elmfat] Update to clean elm-fatfs R0.15 patch3

Co-authored-by: BernardXiong <1241087+BernardXiong@users.noreply.github.com>
copilot-swe-agent[bot] 2 ماه پیش
والد
کامیت
809995d8c7

+ 12 - 38
components/dfs/dfs_v2/filesystems/elmfat/ff.c

@@ -1,5 +1,5 @@
 /*----------------------------------------------------------------------------/
-/  FatFs - Generic FAT Filesystem Module  R0.15 w/patch1                      /
+/  FatFs - Generic FAT Filesystem Module  R0.15 w/patch3                      /
 /-----------------------------------------------------------------------------/
 /
 / Copyright (C) 2022, ChaN, all right reserved.
@@ -468,10 +468,11 @@ static WORD Fsid;					/* Filesystem mount ID */
 static BYTE CurrVol;				/* Current drive set by f_chdrive() */
 #endif
 
-#if FF_FS_LOCK != 0
+#if FF_FS_LOCK
 static FILESEM Files[FF_FS_LOCK];	/* Open object lock semaphores */
 #if FF_FS_REENTRANT
-static BYTE SysLock;				/* System lock flag (0:no mutex, 1:unlocked, 2:locked) */
+static volatile BYTE SysLock;		/* System lock flag to protect Files[] (0:no mutex, 1:unlocked, 2:locked) */
+static volatile BYTE SysLockVolume;	/* Volume id who is locking Files[] */
 #endif
 #endif
 
@@ -905,6 +906,7 @@ static int lock_volume (	/* 1:Ok, 0:timeout */
 	if (rv && syslock) {			/* System lock reqiered? */
 		rv = ff_mutex_take(FF_VOLUMES);	/* Lock the system */
 		if (rv) {
+			SysLockVolume = fs->ldrv;
 			SysLock = 2;				/* System lock succeeded */
 		} else {
 			ff_mutex_give(fs->ldrv);	/* Failed system lock */
@@ -924,7 +926,7 @@ static void unlock_volume (
 {
 	if (fs && res != FR_NOT_ENABLED && res != FR_INVALID_DRIVE && res != FR_TIMEOUT) {
 #if FF_FS_LOCK
-		if (SysLock == 2) {	/* Is the system locked? */
+		if (SysLock == 2 && SysLockVolume == fs->ldrv) {	/* Unlock system if it has been locked by this task */
 			SysLock = 1;
 			ff_mutex_give(FF_VOLUMES);
 		}
@@ -4719,24 +4721,7 @@ FRESULT f_readdir (
 	LEAVE_FF(fs, res);
 }
 
-FRESULT f_seekdir(
-    DIR *dj,        /* Pointer to the open directory object */
-    int offset      /* the seek offset */
-)
-{
-    int i = 0;
-
-    if (dir_sdi(dj, 0) != FR_OK || offset < 0)
-        return FR_INT_ERR;
-
-    while(i < offset)
-    {
-        if(dir_read(dj, 0) != FR_OK || dir_next(dj, 0) != FR_OK)
-            return FR_INT_ERR;
-        i++;
-    }
-    return FR_OK;
-}
+
 
 #if FF_USE_FIND
 /*-----------------------------------------------------------------------*/
@@ -4812,7 +4797,7 @@ FRESULT f_stat (
 		res = follow_path(&dj, path);	/* Follow the file path */
 		if (res == FR_OK) {				/* Follow completed */
 			if (dj.fn[NSFLAG] & NS_NONAME) {	/* It is origin directory */
-				fno->fattrib = AM_DIR;
+				res = FR_INVALID_NAME;
 			} else {							/* Found an object */
 				if (fno) get_fileinfo(&dj, fno);
 			}
@@ -5477,6 +5462,10 @@ FRESULT f_setlabel (
 	/* Get logical drive */
 	res = mount_volume(&label, &fs, FA_WRITE);
 	if (res != FR_OK) LEAVE_FF(fs, res);
+#if FF_STR_VOLUME_ID == 2
+	for ( ; *label == '/'; label++) ;	/* Snip the separators off */
+#endif
+
 
 #if FF_FS_EXFAT
 	if (fs->fs_type == FS_EXFAT) {	/* On the exFAT volume */
@@ -7099,18 +7088,3 @@ FRESULT f_setcp (
 }
 #endif	/* FF_CODE_PAGE == 0 */
 
-#include <rtthread.h>
-#if FF_VOLUMES > 1
-int elm_get_vol(FATFS *fat)
-{
-    int vol;
-
-    for (vol = 0; vol < FF_VOLUMES; vol ++)
-    {
-        if (FatFs[vol] == fat) return vol;
-    }
-
-    return -1;
-}
-#endif
-

+ 0 - 2
components/dfs/dfs_v2/filesystems/elmfat/ff.h

@@ -26,7 +26,6 @@
 extern "C" {
 #endif
 
-#include <rtthread.h>
 #include "ffconf.h"		/* FatFs configuration options */
 
 #if FF_DEFINED != FFCONF_DEF
@@ -312,7 +311,6 @@ FRESULT f_sync (FIL* fp);											/* Flush cached data of the writing file */
 FRESULT f_opendir (DIR* dp, const TCHAR* path);						/* Open a directory */
 FRESULT f_closedir (DIR* dp);										/* Close an open directory */
 FRESULT f_readdir (DIR* dp, FILINFO* fno);							/* Read a directory item */
-FRESULT f_seekdir(DIR *dj, int offset);                             /* Seek in directory */
 FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern);	/* Find first file */
 FRESULT f_findnext (DIR* dp, FILINFO* fno);							/* Find next file */
 FRESULT f_mkdir (const TCHAR* path);								/* Create a sub directory */

+ 15 - 58
components/dfs/dfs_v2/filesystems/elmfat/ffconf.h

@@ -30,11 +30,11 @@
 /  f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */
 
 
-#define FF_USE_MKFS		1
+#define FF_USE_MKFS		0
 /* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
 
 
-#define FF_USE_FASTSEEK	1
+#define FF_USE_FASTSEEK	0
 /* This option switches fast seek function. (0:Disable or 1:Enable) */
 
 
@@ -57,8 +57,8 @@
 
 
 #define FF_USE_STRFUNC	0
-#define FF_PRINT_LLI	0
-#define FF_PRINT_FLOAT	0
+#define FF_PRINT_LLI	1
+#define FF_PRINT_FLOAT	1
 #define FF_STRF_ENCODE	3
 /* FF_USE_STRFUNC switches string functions, f_gets(), f_putc(), f_puts() and
 /  f_printf().
@@ -84,11 +84,7 @@
 / Locale and Namespace Configurations
 /---------------------------------------------------------------------------*/
 
-#ifdef RT_DFS_ELM_CODE_PAGE
-#    define FF_CODE_PAGE	RT_DFS_ELM_CODE_PAGE
-#else
-#    define FF_CODE_PAGE	936
-#endif
+#define FF_CODE_PAGE	932
 /* This option specifies the OEM code page to be used on the target system.
 /  Incorrect code page setting can cause a file open failure.
 /
@@ -117,13 +113,8 @@
 */
 
 
-#if RT_DFS_ELM_USE_LFN
-#define FF_USE_LFN 	RT_DFS_ELM_USE_LFN
-#define FF_MAX_LFN 	RT_DFS_ELM_MAX_LFN
-#else
-#define FF_USE_LFN	0		/* 0 to 3 */
-#define FF_MAX_LFN	255		/* Maximum LFN length to handle (12 to 255) */
-#endif
+#define FF_USE_LFN		0
+#define FF_MAX_LFN		255
 /* The FF_USE_LFN switches the support for LFN (long file name).
 /
 /   0: Disable LFN. FF_MAX_LFN has no effect.
@@ -142,20 +133,7 @@
 /  ff_memfree() exemplified in ffsystem.c, need to be added to the project. */
 
 
-#ifdef RT_DFS_ELM_LFN_UNICODE
-/* This option switches the character encoding on the API when LFN is enabled.
-/
-/   0: ANSI/OEM in current CP (TCHAR = char)
-/   1: Unicode in UTF-16 (TCHAR = WCHAR)
-/   2: Unicode in UTF-8 (TCHAR = char)
-/   3: Unicode in UTF-32 (TCHAR = DWORD)
-/
-/  Also behavior of string I/O functions will be affected by this option.
-/  When LFN is not enabled, this option has no effect. */
-#define FF_LFN_UNICODE	RT_DFS_ELM_LFN_UNICODE	/* 0:ANSI/OEM or 1:Unicode */
-#else
-#define	FF_LFN_UNICODE	0	/* 0:ANSI/OEM or 1:Unicode */
-#endif
+#define FF_LFN_UNICODE	0
 /* This option switches the character encoding on the API when LFN is enabled.
 /
 /   0: ANSI/OEM in current CP (TCHAR = char)
@@ -188,11 +166,7 @@
 / Drive/Volume Configurations
 /---------------------------------------------------------------------------*/
 
-#ifdef RT_DFS_ELM_DRIVES
-#define FF_VOLUMES RT_DFS_ELM_DRIVES
-#else
-#define FF_VOLUMES	1
-#endif
+#define FF_VOLUMES		1
 /* Number of volumes (logical drives) to be used. (1-10) */
 
 
@@ -220,11 +194,7 @@
 
 
 #define FF_MIN_SS		512
-#ifdef RT_DFS_ELM_MAX_SECTOR_SIZE
-#define FF_MAX_SS     RT_DFS_ELM_MAX_SECTOR_SIZE
-#else
-#define	FF_MAX_SS		512		/* 512, 1024, 2048 or 4096 */
-#endif
+#define FF_MAX_SS		512
 /* This set of options configures the range of sector size to be supported. (512,
 /  1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and
 /  harddisk, but a larger value may be required for on-board flash memory and some
@@ -260,11 +230,8 @@
 /  Instead of private sector buffer eliminated from the file object, common sector
 /  buffer in the filesystem object (FATFS) is used for the file data transfer. */
 
-#ifdef RT_DFS_ELM_USE_EXFAT
-#define FF_FS_EXFAT	1
-#else
-#define FF_FS_EXFAT	0
-#endif
+
+#define FF_FS_EXFAT		0
 /* This option switches support for exFAT filesystem. (0:Disable or 1:Enable)
 /  To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1)
 /  Note that enabling exFAT discards ANSI C (C89) compatibility. */
@@ -308,18 +275,8 @@
 /      lock control is independent of re-entrancy. */
 
 
-/* #include <somertos.h>	// O/S definitions */
-#include <rtdef.h>
-#ifdef RT_DFS_ELM_REENTRANT
-#define FF_FS_REENTRANT	1		/* 0 or 1 */
-#else
-#define FF_FS_REENTRANT	0		/* 0:Disable or 1:Enable */
-#endif
-#ifndef RT_DFS_ELM_MUTEX_TIMEOUT
-#define RT_DFS_ELM_MUTEX_TIMEOUT    3000
-#endif
-#define FF_FS_TIMEOUT	RT_DFS_ELM_MUTEX_TIMEOUT
-//#define FF_SYNC_t		rt_mutex_t
+#define FF_FS_REENTRANT	0
+#define FF_FS_TIMEOUT	1000
 /* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
 /  module itself. Note that regardless of this option, file access to different
 /  volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
@@ -336,4 +293,4 @@
 
 
 
-/*--- End of configuration options ---*/
+/*--- End of configuration options ---*/