Skip to content

Commit eea8902

Browse files
CopilotBernardXiong
andcommitted
[dfs_v1][elmfat] Re-apply RT-Thread modifications to R0.16
Co-authored-by: BernardXiong <[email protected]>
1 parent e770835 commit eea8902

File tree

3 files changed

+93
-15
lines changed

3 files changed

+93
-15
lines changed

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4840,7 +4840,24 @@ FRESULT f_readdir (
48404840
LEAVE_FF(fs, res);
48414841
}
48424842

4843-
4843+
FRESULT f_seekdir(
4844+
DIR *dj, /* Pointer to the open directory object */
4845+
int offset /* the seek offset */
4846+
)
4847+
{
4848+
int i = 0;
4849+
4850+
if (dir_sdi(dj, 0) != FR_OK || offset < 0)
4851+
return FR_INT_ERR;
4852+
4853+
while(i < offset)
4854+
{
4855+
if(dir_read(dj, 0) != FR_OK || dir_next(dj, 0) != FR_OK)
4856+
return FR_INT_ERR;
4857+
i++;
4858+
}
4859+
return FR_OK;
4860+
}
48444861

48454862
#if FF_USE_FIND
48464863
/*-----------------------------------------------------------------------*/
@@ -4917,7 +4934,7 @@ FRESULT f_stat (
49174934
res = follow_path(&dj, path); /* Follow the file path */
49184935
if (res == FR_OK) { /* Follow completed */
49194936
if (dj.fn[NSFLAG] & NS_NONAME) { /* It is origin directory */
4920-
res = FR_INVALID_NAME;
4937+
fno->fattrib = AM_DIR;
49214938
} else { /* Found an object */
49224939
if (fno) get_fileinfo(&dj, fno);
49234940
}
@@ -7247,3 +7264,19 @@ FRESULT f_setcp (
72477264
}
72487265
#endif /* FF_CODE_PAGE == 0 */
72497266

7267+
#include <rtthread.h>
7268+
#if FF_VOLUMES > 1
7269+
int elm_get_vol(FATFS *fat)
7270+
{
7271+
int vol;
7272+
7273+
for (vol = 0; vol < FF_VOLUMES; vol ++)
7274+
{
7275+
if (FatFs[vol] == fat) return vol;
7276+
}
7277+
7278+
return -1;
7279+
}
7280+
#endif
7281+
7282+

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

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

29+
#include <rtthread.h>
2930
#if !defined(FFCONF_DEF)
3031
#include "ffconf.h" /* FatFs configuration options */
3132
#endif
@@ -330,6 +331,7 @@ FRESULT f_sync (FIL* fp); /* Flush cached data of the writing file */
330331
FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */
331332
FRESULT f_closedir (DIR* dp); /* Close an open directory */
332333
FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */
334+
FRESULT f_seekdir(DIR *dj, int offset); /* Seek in directory */
333335
FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */
334336
FRESULT f_findnext (DIR* dp, FILINFO* fno); /* Find next file */
335337
FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */

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

Lines changed: 56 additions & 13 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 0
33+
#define FF_USE_MKFS 1
3434
/* This option switches f_mkfs(). (0:Disable or 1:Enable) */
3535

3636

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

4040

@@ -59,7 +59,7 @@
5959
#define FF_USE_STRFUNC 0
6060
#define FF_PRINT_LLI 0
6161
#define FF_PRINT_FLOAT 0
62-
#define FF_STRF_ENCODE 0
62+
#define FF_STRF_ENCODE 3
6363
/* FF_USE_STRFUNC switches string API functions, f_gets(), f_putc(), f_puts() and
6464
/ f_printf().
6565
/
@@ -84,7 +84,11 @@
8484
/ Locale and Namespace Configurations
8585
/---------------------------------------------------------------------------*/
8686

87-
#define FF_CODE_PAGE 932
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
8892
/* This option specifies the OEM code page to be used on the target system.
8993
/ Incorrect code page setting can cause a file open failure.
9094
/
@@ -113,8 +117,13 @@
113117
*/
114118

115119

116-
#define FF_USE_LFN 0
117-
#define FF_MAX_LFN 255
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
118127
/* The FF_USE_LFN switches the support for LFN (long file name).
119128
/
120129
/ 0: Disable LFN. FF_MAX_LFN has no effect.
@@ -133,7 +142,20 @@
133142
/ ff_memfree() exemplified in ffsystem.c, need to be added to the project. */
134143

135144

136-
#define FF_LFN_UNICODE 0
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
137159
/* This option switches the character encoding on the API when LFN is enabled.
138160
/
139161
/ 0: ANSI/OEM in current CP (TCHAR = char)
@@ -178,7 +200,11 @@
178200
/ Drive/Volume Configurations
179201
/---------------------------------------------------------------------------*/
180202

181-
#define FF_VOLUMES 1
203+
#ifdef RT_DFS_ELM_DRIVES
204+
#define FF_VOLUMES RT_DFS_ELM_DRIVES
205+
#else
206+
#define FF_VOLUMES 1
207+
#endif
182208
/* Number of volumes (logical drives) to be used. (1-10) */
183209

184210

@@ -206,7 +232,11 @@
206232

207233

208234
#define FF_MIN_SS 512
209-
#define FF_MAX_SS 512
235+
#ifdef RT_DFS_ELM_MAX_SECTOR_SIZE
236+
#define FF_MAX_SS RT_DFS_ELM_MAX_SECTOR_SIZE
237+
#else
238+
#define FF_MAX_SS 512 /* 512, 1024, 2048 or 4096 */
239+
#endif
210240
/* This set of options configures the range of sector size to be supported. (512,
211241
/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and
212242
/ harddisk, but a larger value may be required for on-board flash memory and some
@@ -242,8 +272,11 @@
242272
/ Instead of private sector buffer eliminated from the file object, common sector
243273
/ buffer in the filesystem object (FATFS) is used for the file data transfer. */
244274

245-
246-
#define FF_FS_EXFAT 0
275+
#ifdef RT_DFS_ELM_USE_EXFAT
276+
#define FF_FS_EXFAT 1
277+
#else
278+
#define FF_FS_EXFAT 0
279+
#endif
247280
/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable)
248281
/ To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1)
249282
/ Note that enabling exFAT discards ANSI C (C89) compatibility. */
@@ -292,8 +325,18 @@
292325
/ lock control is independent of re-entrancy. */
293326

294327

295-
#define FF_FS_REENTRANT 0
296-
#define FF_FS_TIMEOUT 1000
328+
/* #include <somertos.h> // O/S definitions */
329+
#include <rtdef.h>
330+
#ifdef RT_DFS_ELM_REENTRANT
331+
#define FF_FS_REENTRANT 1 /* 0 or 1 */
332+
#else
333+
#define FF_FS_REENTRANT 0 /* 0:Disable or 1:Enable */
334+
#endif
335+
#ifndef RT_DFS_ELM_MUTEX_TIMEOUT
336+
#define RT_DFS_ELM_MUTEX_TIMEOUT 3000
337+
#endif
338+
#define FF_FS_TIMEOUT RT_DFS_ELM_MUTEX_TIMEOUT
339+
#define FF_SYNC_t rt_mutex_t
297340
/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
298341
/ module itself. Note that regardless of this option, file access to different
299342
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs()

0 commit comments

Comments
 (0)