From 9bc9f3aa53be7bf392d3da09adcb184dec8e3da2 Mon Sep 17 00:00:00 2001 From: fangye Date: Fri, 11 Feb 2022 14:52:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20littlefs=E6=9C=80=E5=A4=A7=E6=89=93?= =?UTF-8?q?=E5=BC=80=E6=96=87=E4=BB=B6=E4=B8=AA=E6=95=B0=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E5=8F=AF=E9=80=9A=E8=BF=87menuconfig=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fangye Change-Id: Iba141821200b6044d89ec50b7ddb1047490f5229 --- components/fs/littlefs/Kconfig | 5 +++++ components/fs/littlefs/lfs_api.c | 8 ++++---- components/fs/littlefs/lfs_conf.h | 1 - components/fs/vfs/vfs_config.h | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/components/fs/littlefs/Kconfig b/components/fs/littlefs/Kconfig index c08c7915..cd29283e 100644 --- a/components/fs/littlefs/Kconfig +++ b/components/fs/littlefs/Kconfig @@ -42,4 +42,9 @@ config LFS_MAX_MOUNT_SIZE help This is a global maximum number of mount points. +config LFS_MAX_OPEN_FILES + int "Maximum number of open files" + default 100 + help + This is a global maximum number of open files. endif # FS_LITTLEFS diff --git a/components/fs/littlefs/lfs_api.c b/components/fs/littlefs/lfs_api.c index 30a1610a..bc11c6d2 100644 --- a/components/fs/littlefs/lfs_api.c +++ b/components/fs/littlefs/lfs_api.c @@ -38,7 +38,7 @@ lfs_t g_lfs; FileDirInfo g_lfsDir[LFS_MAX_OPEN_DIRS] = {0}; struct FileOpInfo g_fsOp[LOSCFG_LFS_MAX_MOUNT_SIZE] = {0}; -static LittleFsHandleStruct g_handle[LITTLE_FS_MAX_OPEN_FILES] = {0}; +static LittleFsHandleStruct g_handle[LOSCFG_LFS_MAX_OPEN_FILES] = {0}; struct dirent g_nameValue; static pthread_mutex_t g_FslocalMutex = PTHREAD_MUTEX_INITIALIZER; static const char *g_littlefsMntName[LOSCFG_LFS_MAX_MOUNT_SIZE] = {"/a"}; @@ -46,7 +46,7 @@ static const char *g_littlefsMntName[LOSCFG_LFS_MAX_MOUNT_SIZE] = {"/a"}; LittleFsHandleStruct *LfsAllocFd(const char *fileName, int *fd) { pthread_mutex_lock(&g_FslocalMutex); - for (int i = 0; i < LITTLE_FS_MAX_OPEN_FILES; i++) { + for (int i = 0; i < LOSCFG_LFS_MAX_OPEN_FILES; i++) { if (g_handle[i].useFlag == 0) { *fd = i; g_handle[i].useFlag = 1; @@ -78,7 +78,7 @@ static void LfsFreeFd(int fd) BOOL CheckFileIsOpen(const char *fileName) { pthread_mutex_lock(&g_FslocalMutex); - for (int i = 0; i < LITTLE_FS_MAX_OPEN_FILES; i++) { + for (int i = 0; i < LOSCFG_LFS_MAX_OPEN_FILES; i++) { if (g_handle[i].useFlag == 1) { if (strcmp(g_handle[i].pathName, fileName) == 0) { pthread_mutex_unlock(&g_FslocalMutex); @@ -92,7 +92,7 @@ BOOL CheckFileIsOpen(const char *fileName) static BOOL LfsFdIsValid(int fd) { - if (fd >= LITTLE_FS_MAX_OPEN_FILES || fd < 0) { + if (fd >= LOSCFG_LFS_MAX_OPEN_FILES || fd < 0) { return FALSE; } if (g_handle[fd].lfsHandle == NULL) { diff --git a/components/fs/littlefs/lfs_conf.h b/components/fs/littlefs/lfs_conf.h index f0f785bb..4aa8174c 100644 --- a/components/fs/littlefs/lfs_conf.h +++ b/components/fs/littlefs/lfs_conf.h @@ -31,7 +31,6 @@ #ifndef _LFS_CONF_H #define _LFS_CONF_H -#define LITTLE_FS_MAX_OPEN_FILES 100 #define LITTLE_FS_STANDARD_NAME_LENGTH 50 #define LITTLE_FS_MAX_NAME_LEN 255 diff --git a/components/fs/vfs/vfs_config.h b/components/fs/vfs/vfs_config.h index f0ad857d..a3538a34 100644 --- a/components/fs/vfs/vfs_config.h +++ b/components/fs/vfs/vfs_config.h @@ -106,7 +106,7 @@ #ifdef LOSCFG_FS_LITTLEFS #include "lfs_conf.h" -#define __LFS_NFILE LITTLE_FS_MAX_OPEN_FILES +#define __LFS_NFILE LOSCFG_LFS_MAX_OPEN_FILES #else #define __LFS_NFILE 0 #endif