From 7259289bd98a743f596060bc607f77ab8f149129 Mon Sep 17 00:00:00 2001 From: li_zan <371442490@qq.com> Date: Thu, 17 Jun 2021 11:34:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dlittlefs=E7=BC=96?= =?UTF-8?q?=E8=AF=91fs.c=E7=BC=BA=E5=B0=91=E5=A4=B4=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=BB=B6=E4=BE=9D=E8=B5=96=E9=85=8D=E7=BD=AE+=E8=8B=A5?= =?UTF-8?q?=E5=B9=B2musl=E5=BA=93=E7=9A=84=E7=BC=BA=E5=A4=B1=E9=97=AE?= =?UTF-8?q?=E9=A2=98+=E5=A4=9A=E5=88=86=E5=8C=BA=E8=A7=84=E6=A0=BC?= =?UTF-8?q?=E5=AE=8F=E9=85=8D=E7=BD=AE=E9=97=AE=E9=A2=98=20close=EF=BC=9A#?= =?UTF-8?q?I3VT11?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li_zan <371442490@qq.com> --- components/fs/BUILD.gn | 8 ++++++++ components/fs/fs.c | 5 +++-- components/fs/littlefs/BUILD.gn | 1 - components/fs/littlefs/lfs_api.c | 17 +++++++++-------- components/fs/littlefs/lfs_api.h | 5 ----- kernel/include/los_config.h | 6 ++++++ 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/components/fs/BUILD.gn b/components/fs/BUILD.gn index bbc9adee..bfdda657 100644 --- a/components/fs/BUILD.gn +++ b/components/fs/BUILD.gn @@ -32,6 +32,14 @@ static_library("fs_operations") { "./fs.c", ] + include_dirs = [ + "../../../kernel/arch/include", + "../../../kernel/include", + "../../../utils", + "../../../kal/posix/include", + "./", + ] + deps = [ "//kernel/liteos_m/kal/posix" ] } diff --git a/components/fs/fs.c b/components/fs/fs.c index e9a38e50..1bb0cbca 100644 --- a/components/fs/fs.c +++ b/components/fs/fs.c @@ -29,6 +29,7 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "fs_operations.h" +#include "los_config.h" #ifdef LOSCFG_SUPPORT_FATFS #include "fatfs.h" #endif @@ -426,11 +427,11 @@ int stat(const char *path, struct stat *buf) errno = ENODEV; return FS_FAILURE; } - if (g_fs->fsFops == NULL || g_fs->fsFops->Stat == NULL) { + if (g_fs->fsFops == NULL || g_fs->fsFops->Getattr == NULL) { errno = ENOSYS; return FS_FAILURE; } - return g_fs->fsFops->Stat(path, buf); + return g_fs->fsFops->Getattr(path, buf); } int fsync(int fd) diff --git a/components/fs/littlefs/BUILD.gn b/components/fs/littlefs/BUILD.gn index 067ec0d0..171650b9 100644 --- a/components/fs/littlefs/BUILD.gn +++ b/components/fs/littlefs/BUILD.gn @@ -39,7 +39,6 @@ static_library("littlefs") { "../../../kernel/include", "../../../utils", "../../../kal/cmsis", - "../../../kal", "../../../kal/posix/include", "./", "../", diff --git a/components/fs/littlefs/lfs_api.c b/components/fs/littlefs/lfs_api.c index a4c10e6d..780659f8 100644 --- a/components/fs/littlefs/lfs_api.c +++ b/components/fs/littlefs/lfs_api.c @@ -31,15 +31,16 @@ #define _GNU_SOURCE 1 #include "lfs_api.h" +#include "los_config.h" lfs_t g_lfs; FileDirInfo g_lfsDir[LFS_MAX_OPEN_DIRS] = {0}; -struct FileOpInfo g_fsOp[LFS_MAX_MOUNT_SIZE] = {0}; +struct FileOpInfo g_fsOp[LOSCFG_LFS_MAX_MOUNT_SIZE] = {0}; static LittleFsHandleStruct g_handle[LITTLE_FS_MAX_OPEN_FILES] = {0}; struct dirent g_nameValue; static pthread_mutex_t g_FslocalMutex = PTHREAD_MUTEX_INITIALIZER; -static const char *g_littlefsMntName[LFS_MAX_MOUNT_SIZE] = {"/a","/b","/c"}; +static const char *g_littlefsMntName[LOSCFG_LFS_MAX_MOUNT_SIZE] = {"/a","/b","/c"}; LittleFsHandleStruct *LfsAllocFd(const char *fileName, int *fd) { @@ -126,7 +127,7 @@ BOOL CheckPathIsMounted(const char *pathName, struct FileOpInfo **fileOpInfo) int len = strlen(pathName) + 1; pthread_mutex_lock(&g_FslocalMutex); - for (int i = 0; i < LFS_MAX_MOUNT_SIZE; i++) { + for (int i = 0; i < LOSCFG_LFS_MAX_MOUNT_SIZE; i++) { if (g_fsOp[i].useFlag == 1) { mountPathNameLen = strlen(g_fsOp[i].dirName); if (len < mountPathNameLen + 1) { @@ -151,7 +152,7 @@ BOOL CheckPathIsMounted(const char *pathName, struct FileOpInfo **fileOpInfo) struct FileOpInfo *AllocMountRes(const char* target, struct FileOps *fileOps) { pthread_mutex_lock(&g_FslocalMutex); - for (int i = 0; i < LFS_MAX_MOUNT_SIZE; i++) { + for (int i = 0; i < LOSCFG_LFS_MAX_MOUNT_SIZE; i++) { if (g_fsOp[i].useFlag == 0 && strcmp(target, g_littlefsMntName[i]) == 0) { g_fsOp[i].useFlag = 1; g_fsOp[i].fsVops = fileOps; @@ -167,7 +168,7 @@ struct FileOpInfo *AllocMountRes(const char* target, struct FileOps *fileOps) int SetDefaultMountPath(int pathNameIndex, const char* target) { - if (pathNameIndex >= LFS_MAX_MOUNT_SIZE) { + if (pathNameIndex >= LOSCFG_LFS_MAX_MOUNT_SIZE) { return VFS_ERROR; } @@ -180,7 +181,7 @@ int SetDefaultMountPath(int pathNameIndex, const char* target) struct FileOpInfo *GetMountRes(const char *target, int *mountIndex) { pthread_mutex_lock(&g_FslocalMutex); - for (int i = 0; i < LFS_MAX_MOUNT_SIZE; i++) { + for (int i = 0; i < LOSCFG_LFS_MAX_MOUNT_SIZE; i++) { if (g_fsOp[i].useFlag == 1) { if (g_fsOp[i].dirName && strcmp(target, g_fsOp[i].dirName) == 0) { *mountIndex = i; @@ -196,7 +197,7 @@ struct FileOpInfo *GetMountRes(const char *target, int *mountIndex) int FreeMountResByIndex(int mountIndex) { - if (mountIndex < 0 || mountIndex >= LFS_MAX_MOUNT_SIZE) { + if (mountIndex < 0 || mountIndex >= LOSCFG_LFS_MAX_MOUNT_SIZE) { return VFS_ERROR; } @@ -214,7 +215,7 @@ int FreeMountResByIndex(int mountIndex) int FreeMountRes(const char *target) { pthread_mutex_lock(&g_FslocalMutex); - for (int i = 0; i < LFS_MAX_MOUNT_SIZE; i++) { + for (int i = 0; i < LOSCFG_LFS_MAX_MOUNT_SIZE; i++) { if (g_fsOp[i].useFlag == 1) { if (g_fsOp[i].dirName && strcmp(target, g_fsOp[i].dirName) == 0) { g_fsOp[i].useFlag = 0; diff --git a/components/fs/littlefs/lfs_api.h b/components/fs/littlefs/lfs_api.h index 44af2f48..8fbf87a9 100644 --- a/components/fs/littlefs/lfs_api.h +++ b/components/fs/littlefs/lfs_api.h @@ -91,11 +91,6 @@ typedef struct { #define LFS_MAX_OPEN_DIRS 10 #endif -#ifndef LFS_MAX_MOUNT_SIZE -#define LFS_MAX_MOUNT_SIZE 3 -#endif - - LittleFsHandleStruct *GetFreeFd(int *fd); int InitMountInfo(const char *fileSystemType, const struct MountOps *fsMops); diff --git a/kernel/include/los_config.h b/kernel/include/los_config.h index 339dee19..6b1f6ed5 100644 --- a/kernel/include/los_config.h +++ b/kernel/include/los_config.h @@ -590,6 +590,12 @@ extern UINT8 *m_aucSysMem0; #ifndef LOSCFG_SUPPORT_LITTLEFS #define LOSCFG_SUPPORT_LITTLEFS 1 #endif + +#ifndef LOSCFG_LFS_MAX_MOUNT_SIZE +#define LOSCFG_LFS_MAX_MOUNT_SIZE 3 +#endif + + /** * @ingroup los_config * Configuration trace tool