From 7d9976cd90cac52d4b4eb91e771e681d26e703e0 Mon Sep 17 00:00:00 2001 From: li_zan <371442490@qq.com> Date: Tue, 11 May 2021 20:30:31 +0800 Subject: [PATCH] Add already opened file logic --- components/fs/littlefs/lfs_api.c | 11 +++++------ components/fs/littlefs/lfs_api.h | 1 + 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/fs/littlefs/lfs_api.c b/components/fs/littlefs/lfs_api.c index eb2b527f..e30b3946 100644 --- a/components/fs/littlefs/lfs_api.c +++ b/components/fs/littlefs/lfs_api.c @@ -30,7 +30,6 @@ */ #include "lfs_api.h" -#include "iCunit.h" lfs_t g_lfs; FileDirInfo g_lfsDir[LFS_MAX_OPEN_DIRS] = {0}; @@ -57,7 +56,7 @@ LittleFsHandleStruct *LfsAllocFd(const char *fileName, int *fd) g_handle[i].useFlag = 1; g_handle[i].pathName = (char *)malloc(len); if (g_handle[i].pathName) { - memcpy_s(g_handle[i].pathName, len, fileName, len); + memcpy_s(g_handle[i].pathName, LITTLE_FS_MAX_NAME_LEN, fileName, len); } pthread_mutex_unlock(&g_FslocalMutex); return &(g_handle[i]); @@ -68,17 +67,17 @@ LittleFsHandleStruct *LfsAllocFd(const char *fileName, int *fd) return NULL; } -bool CheckFileIsOpen(const char *fileName) +BOOL CheckFileIsOpen(const char *fileName) { for (int i = 0; i < LITTLE_FS_MAX_OPEN_FILES; i++) { if (g_handle[i].useFlag == 1) { if (strcmp(g_handle[i].pathName, fileName) == 0) { - return true; + return TRUE; } } } - return false; + return FALSE; } lfs_dir_t *GetFreeDir() @@ -101,7 +100,7 @@ int InitMountInfo(const char *fileSystemType, const struct MountOps *fsMops) for (int i = 0; i < MAX_FILE_SYSTEM_LEN; i++) { if (g_fsmap[i].fileSystemtype == NULL) { g_fsmap[i].fileSystemtype = (char*)malloc(len); - memcpy_s(g_fsmap[i].fileSystemtype, len, fileSystemType, len); + memcpy_s(g_fsmap[i].fileSystemtype, LITTLE_FS_MAX_NAME_LEN, fileSystemType, len); g_fsmap[i].fsMops = fsMops; return VFS_OK; } diff --git a/components/fs/littlefs/lfs_api.h b/components/fs/littlefs/lfs_api.h index 0f1a9c39..8f87d108 100644 --- a/components/fs/littlefs/lfs_api.h +++ b/components/fs/littlefs/lfs_api.h @@ -98,6 +98,7 @@ typedef struct { #define LITTLE_FS_MAX_OPEN_FILES 100 #define LITTLE_FS_STANDARD_NAME_LENGTH 50 +#define LITTLE_FS_MAX_NAME_LEN 255 #define MAX_DEF_BUF_NUM 21 #define MAX_BUFFER_LEN 100