From b55cfc1ba7fc470b876c555ac7d3be0aa1d3d363 Mon Sep 17 00:00:00 2001 From: li_zan <371442490@qq.com> Date: Tue, 22 Jun 2021 11:45:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dlittlefs=E7=9A=84?= =?UTF-8?q?=E5=A4=9A=E5=88=86=E5=8C=BA=E6=8C=82=E8=BD=BD=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=AF=B9pathname=E7=9A=84=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=20close=EF=BC=9A#I3WWFA?= 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/littlefs/lfs_api.c | 30 +++++++++++++++++------------- kal/posix/BUILD.gn | 2 +- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/components/fs/littlefs/lfs_api.c b/components/fs/littlefs/lfs_api.c index 780659f8..ba83114b 100644 --- a/components/fs/littlefs/lfs_api.c +++ b/components/fs/littlefs/lfs_api.c @@ -120,24 +120,28 @@ BOOL CheckDirIsOpen(const char *dirName) return FALSE; } +int GetFirstLevelPathLen(const char *pathName) +{ + int len = 1; + for (int i = 1; i < strlen(pathName) + 1; i++) { + if (pathName[i] == '/') { + break; + } + len++; + } + + return len; +} + BOOL CheckPathIsMounted(const char *pathName, struct FileOpInfo **fileOpInfo) { char tmpName[LITTLEFS_MAX_LFN_LEN] = {0}; - int mountPathNameLen; - int len = strlen(pathName) + 1; + int len = GetFirstLevelPathLen(pathName); pthread_mutex_lock(&g_FslocalMutex); 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) { - pthread_mutex_unlock(&g_FslocalMutex); - return FALSE; - } - - (void)strncpy_s(tmpName, LITTLEFS_MAX_LFN_LEN, pathName, mountPathNameLen); - tmpName[mountPathNameLen] = '\0'; - + (void)strncpy_s(tmpName, LITTLEFS_MAX_LFN_LEN, pathName, len); if (strcmp(tmpName, g_fsOp[i].dirName) == 0) { *fileOpInfo = &(g_fsOp[i]); pthread_mutex_unlock(&g_FslocalMutex); @@ -156,7 +160,7 @@ struct FileOpInfo *AllocMountRes(const char* target, struct FileOps *fileOps) if (g_fsOp[i].useFlag == 0 && strcmp(target, g_littlefsMntName[i]) == 0) { g_fsOp[i].useFlag = 1; g_fsOp[i].fsVops = fileOps; - g_fsOp[i].dirName == strdup(target); + g_fsOp[i].dirName = strdup(target); pthread_mutex_unlock(&g_FslocalMutex); return &(g_fsOp[i]); } @@ -530,7 +534,7 @@ struct dirent *LfsReaddir(DIR *dir) } ret = lfs_dir_read(dirInfo->lfsHandle, (lfs_dir_t *)(&(dirInfo->dir)), &lfsInfo); - if (ret == 0) { + if (ret == TRUE) { pthread_mutex_lock(&g_FslocalMutex); (void)strncpy_s(g_nameValue.d_name, sizeof(g_nameValue.d_name), lfsInfo.name, strlen(lfsInfo.name) + 1); if (lfsInfo.type == LFS_TYPE_DIR) { diff --git a/kal/posix/BUILD.gn b/kal/posix/BUILD.gn index 1df98fe8..192e1f2e 100644 --- a/kal/posix/BUILD.gn +++ b/kal/posix/BUILD.gn @@ -38,7 +38,7 @@ static_library("posix") { "src/pthread_mutex.c", "src/semaphore.c", "src/time.c", - "//third_party/musl/src/string/strdup.c", + "//third_party/musl/porting/liteos_m/kernel/src/string/strdup.c", ] include_dirs = [