Skip to content

Commit bb86d19

Browse files
committed
[fatfs] Move all the modifications made on original FatFs code to a separate file
- The propose is to make maintenance easier - The file is "dfs_patch_content.h" - "ff.c" and "ff.h" now have additional 1-line code comparing to original - All changes in "ffconf.h" with comment - "diskio.c" is removed
1 parent ff5177f commit bb86d19

File tree

6 files changed

+65
-45
lines changed

6 files changed

+65
-45
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=RT-Thread
2-
version=0.3.1
2+
version=0.4.0
33
author=Bernard Xiong <[email protected]>, onelife <[email protected]>
44
maintainer=onelife <[email protected]>
55
sentence=Real Time Operating System porting for Arduino SAM and SAMD boards
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/***************************************************************************//**
2+
* @file dfs_patch.h
3+
* @brief Arduino RT-Thread library ChaN's FatFs patch header
4+
* @note This file includes modifications made on original FatFs code to make
5+
* maintenance easier
6+
* @author onelife <onelife.real[at]gmail.com>
7+
******************************************************************************/
8+
#include "include/rtthread.h"
9+
#include "dfs_patch_header.h"
10+
11+
FRESULT f_seekdir(
12+
DIR *dj, /* Pointer to the open directory object */
13+
int offset /* the seek offset */
14+
) {
15+
int i = 0;
16+
17+
if (dir_sdi(dj, 0) != FR_OK || offset < 0)
18+
return FR_INT_ERR;
19+
20+
while (i < offset) {
21+
if (dir_read(dj, 0) != FR_OK || dir_next(dj, 0) != FR_OK)
22+
return FR_INT_ERR;
23+
i++;
24+
}
25+
return FR_OK;
26+
}
27+
28+
29+
#if FF_VOLUMES > 1
30+
31+
int elm_get_vol(FATFS *fat) {
32+
unsigned int vol;
33+
34+
for (vol = 0; vol < FF_VOLUMES; vol ++)
35+
if (FatFs[vol] == fat) return vol;
36+
37+
return -1;
38+
}
39+
40+
#endif /* FF_VOLUMES > 1 */
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/***************************************************************************//**
2+
* @file dfs_patch.h
3+
* @brief Arduino RT-Thread library ChaN's FatFs patch header
4+
* @author onelife <onelife.real[at]gmail.com>
5+
******************************************************************************/
6+
#ifndef __DFS_PATCH_H__
7+
#define __DFS_PATCH_H__
8+
9+
FRESULT f_seekdir(DIR *dj, int offset); /* Seek in directory */
10+
11+
#endif /* __DFS_PATCH_H__ */

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

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4537,24 +4537,7 @@ FRESULT f_readdir (
45374537
LEAVE_FF(fs, res);
45384538
}
45394539

4540-
FRESULT f_seekdir(
4541-
DIR *dj, /* Pointer to the open directory object */
4542-
int offset /* the seek offset */
4543-
)
4544-
{
4545-
int i = 0;
4546-
4547-
if (dir_sdi(dj, 0) != FR_OK || offset < 0)
4548-
return FR_INT_ERR;
45494540

4550-
while(i < offset)
4551-
{
4552-
if(dir_read(dj, 0) != FR_OK || dir_next(dj, 0) != FR_OK)
4553-
return FR_INT_ERR;
4554-
i++;
4555-
}
4556-
return FR_OK;
4557-
}
45584541

45594542
#if FF_USE_FIND
45604543
/*-----------------------------------------------------------------------*/
@@ -6571,18 +6554,4 @@ FRESULT f_setcp (
65716554
}
65726555
#endif /* FF_CODE_PAGE == 0 */
65736556

6574-
#include "include/rtthread.h"
6575-
#if FF_VOLUMES > 1
6576-
int elm_get_vol(FATFS *fat)
6577-
{
6578-
int vol;
6579-
6580-
for (vol = 0; vol < FF_VOLUMES; vol ++)
6581-
{
6582-
if (FatFs[vol] == fat) return vol;
6583-
}
6584-
6585-
return -1;
6586-
}
6587-
#endif
6588-
6557+
#include "dfs_patch_content.h"

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

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

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

3231
#if FF_DEFINED != FFCONF_DEF
@@ -291,7 +290,6 @@ FRESULT f_sync (FIL* fp); /* Flush cached data of the writing file */
291290
FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */
292291
FRESULT f_closedir (DIR* dp); /* Close an open directory */
293292
FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */
294-
FRESULT f_seekdir(DIR *dj, int offset); /* Seek in directory */
295293
FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */
296294
FRESULT f_findnext (DIR* dp, FILINFO* fno); /* Find next file */
297295
FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */
@@ -400,6 +398,8 @@ int ff_del_syncobj (FF_SYNC_t sobj); /* Delete a sync object */
400398
#define AM_ARC 0x20 /* Archive */
401399

402400

401+
#include "dfs_patch_header.h"
402+
403403
#ifdef __cplusplus
404404
}
405405
#endif

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@
3838
/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */
3939

4040

41-
#define FF_USE_MKFS 1
41+
#define FF_USE_MKFS 1 /* RTT config */
4242
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
4343

4444

45-
#define FF_USE_FASTSEEK 1
45+
#define FF_USE_FASTSEEK 1 /* RTT config */
4646
/* This option switches fast seek function. (0:Disable or 1:Enable) */
4747

4848

@@ -68,7 +68,7 @@
6868
/ Locale and Namespace Configurations
6969
/---------------------------------------------------------------------------*/
7070

71-
#ifdef RT_DFS_ELM_CODE_PAGE
71+
#ifdef RT_DFS_ELM_CODE_PAGE /* RTT config */
7272
#define FF_CODE_PAGE RT_DFS_ELM_CODE_PAGE
7373
#else
7474
#define FF_CODE_PAGE 932
@@ -101,7 +101,7 @@
101101
*/
102102

103103

104-
#if RT_DFS_ELM_USE_LFN
104+
#if RT_DFS_ELM_USE_LFN /* RTT config */
105105
#define FF_USE_LFN RT_DFS_ELM_USE_LFN
106106
#define FF_MAX_LFN RT_DFS_ELM_MAX_LFN
107107
#else
@@ -126,7 +126,7 @@
126126
/ ff_memfree() in ffsystem.c, need to be added to the project. */
127127

128128

129-
#ifdef RT_DFS_ELM_LFN_UNICODE
129+
#ifdef RT_DFS_ELM_LFN_UNICODE /* RTT config */
130130
#define FF_LFN_UNICODE 1
131131
#else
132132
#define FF_LFN_UNICODE 0
@@ -176,7 +176,7 @@
176176
/ Drive/Volume Configurations
177177
/---------------------------------------------------------------------------*/
178178

179-
#ifdef RT_DFS_ELM_DRIVES
179+
#ifdef RT_DFS_ELM_DRIVES /* RTT config */
180180
#define FF_VOLUMES RT_DFS_ELM_DRIVES
181181
#else
182182
#define FF_VOLUMES 1
@@ -208,7 +208,7 @@
208208

209209

210210
#define FF_MIN_SS 512
211-
#ifdef RT_DFS_ELM_MAX_SECTOR_SIZE
211+
#ifdef RT_DFS_ELM_MAX_SECTOR_SIZE /* RTT config */
212212
#define FF_MAX_SS RT_DFS_ELM_MAX_SECTOR_SIZE
213213
#else
214214
#define FF_MAX_SS 512
@@ -250,7 +250,7 @@
250250
/ Instead of private sector buffer eliminated from the file object, common sector
251251
/ buffer in the filesystem object (FATFS) is used for the file data transfer. */
252252

253-
#ifdef RT_DFS_ELM_USE_EXFAT
253+
#ifdef RT_DFS_ELM_USE_EXFAT /* RTT config */
254254
#define FF_FS_EXFAT 1
255255
#else
256256
#define FF_FS_EXFAT 0
@@ -287,13 +287,13 @@
287287

288288

289289
/* #include <somertos.h> // O/S definitions */
290-
#ifdef RT_DFS_ELM_REENTRANT
290+
#ifdef RT_DFS_ELM_REENTRANT /* RTT config */
291291
#define FF_FS_REENTRANT 1
292292
#else
293293
#define FF_FS_REENTRANT 0
294294
#endif
295295
#define FF_FS_TIMEOUT 1000
296-
#define FF_SYNC_t rt_mutex_t
296+
#define FF_SYNC_t rt_mutex_t /* RTT config */
297297
/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
298298
/ module itself. Note that regardless of this option, file access to different
299299
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs()

0 commit comments

Comments
 (0)