diff --git a/components/fs/littlefs/lfs_api.c b/components/fs/littlefs/lfs_api.c index 8596cb04..50da6e94 100644 --- a/components/fs/littlefs/lfs_api.c +++ b/components/fs/littlefs/lfs_api.c @@ -128,56 +128,30 @@ int LfsMount(const char * source, const char * target, const char * fileSystemTy { int ret; - pthread_mutex_lock(&g_FslocalMutex); g_fsOp.fsVops = &lfs_vops; ret = lfs_mount(&g_lfs, (struct lfs_config*)data); - pthread_mutex_unlock(&g_FslocalMutex); return ret; } int LfsUmount(const char * target) { - int ret; - - pthread_mutex_lock(&g_FslocalMutex); - ret = lfs_unmount(&g_lfs); - pthread_mutex_unlock(&g_FslocalMutex); - - return ret; + return lfs_unmount(&g_lfs); } int LfsUnlink(const char * fileName) { - int ret; - - pthread_mutex_lock(&g_FslocalMutex); - ret = lfs_remove(&g_lfs, fileName); - pthread_mutex_unlock(&g_FslocalMutex); - - return ret; + return lfs_remove(&g_lfs, fileName); } int LfsMkdir(const char * dirName, mode_t mode) { - int ret; - - pthread_mutex_lock(&g_FslocalMutex); - ret = lfs_mkdir(&g_lfs, dirName); - pthread_mutex_unlock(&g_FslocalMutex); - - return ret; + return lfs_mkdir(&g_lfs, dirName); } int LfsRmdir(const char * dirName) { - int ret; - - pthread_mutex_lock(&g_FslocalMutex); - ret = lfs_remove(&g_lfs, dirName); - pthread_mutex_unlock(&g_FslocalMutex); - - return ret; + return lfs_remove(&g_lfs, dirName); } DIR *LfsOpendir(const char * dirName) @@ -189,9 +163,7 @@ DIR *LfsOpendir(const char * dirName) return NULL; } - pthread_mutex_lock(&g_FslocalMutex); ret = lfs_dir_open(&g_lfs, dir, dirName); - pthread_mutex_unlock(&g_FslocalMutex); if (ret == 0) { return (DIR *)dir; @@ -205,7 +177,6 @@ struct dirent *LfsReaddir(DIR * dir) int ret; struct lfs_info lfsInfo; - pthread_mutex_lock(&g_FslocalMutex); ret = lfs_dir_read(&g_lfs, (lfs_dir_t *)dir, &lfsInfo); if (ret == 0) { (void)memcpy_s(g_nameValue.d_name, sizeof(g_nameValue.d_name), lfsInfo.name, strlen(lfsInfo.name) + 1); @@ -216,31 +187,22 @@ struct dirent *LfsReaddir(DIR * dir) } g_nameValue.d_reclen = lfsInfo.size; - pthread_mutex_unlock(&g_FslocalMutex); return &g_nameValue; } - pthread_mutex_unlock(&g_FslocalMutex); return NULL; } int LfsClosedir(DIR * dir) { - int ret; - - pthread_mutex_lock(&g_FslocalMutex); - ret = lfs_dir_close(&g_lfs, (lfs_dir_t *)dir); - pthread_mutex_unlock(&g_FslocalMutex); - - return ret; + return lfs_dir_close(&g_lfs, (lfs_dir_t *)dir); } int LfsOpen(const char * path, int openFlag, int mode) { int fd = INVALID_FD; - pthread_mutex_lock(&g_FslocalMutex); LittleFsHandleStruct *fsHandle = GetFreeFd(&fd); if (fd == INVALID_FD) { goto errout; @@ -251,56 +213,36 @@ int LfsOpen(const char * path, int openFlag, int mode) goto errout; } - pthread_mutex_unlock(&g_FslocalMutex); return fd; errout: - pthread_mutex_unlock(&g_FslocalMutex); return INVALID_FD; } int LfsRead(int fd, void * buf, unsigned int len) { - int ret = VFS_ERROR; - if (fd >= LITTLE_FS_MAX_OPEN_FILES && fd < 0) { - return ret; + return VFS_ERROR; } - pthread_mutex_lock(&g_FslocalMutex); - ret = lfs_file_read(&g_lfs, &(g_handle[fd].file), buf, len); - pthread_mutex_unlock(&g_FslocalMutex); - - return ret; + return lfs_file_read(&g_lfs, &(g_handle[fd].file), buf, len); } int LfsWrite(int fd, const void * buf, unsigned int len) { - int ret = VFS_ERROR; - if (fd >= LITTLE_FS_MAX_OPEN_FILES && fd < 0) { - return ret; + return VFS_ERROR; } - pthread_mutex_lock(&g_FslocalMutex); - ret = lfs_file_write(&g_lfs, &(g_handle[fd].file), buf, len); - pthread_mutex_unlock(&g_FslocalMutex); - - return ret; + return lfs_file_write(&g_lfs, &(g_handle[fd].file), buf, len); } int LfsSeek(int fd, off_t offset, int whence) { - int ret = VFS_ERROR; - if (fd >= LITTLE_FS_MAX_OPEN_FILES && fd < 0) { - return ret; + return VFS_ERROR; } - pthread_mutex_lock(&g_FslocalMutex); - ret = lfs_file_seek(&g_lfs, &(g_handle[fd].file), offset, whence); - pthread_mutex_unlock(&g_FslocalMutex); - - return ret; + return lfs_file_seek(&g_lfs, &(g_handle[fd].file), offset, whence); } int LfsClose(int fd) @@ -311,23 +253,15 @@ int LfsClose(int fd) return ret; } - pthread_mutex_lock(&g_FslocalMutex); ret = lfs_file_close(&g_lfs, &(g_handle[fd].file)); g_handle[fd].useFlag = 0; - pthread_mutex_unlock(&g_FslocalMutex); return ret; } int LfsRename(const char * oldName, const char * newName) { - int ret; - - pthread_mutex_lock(&g_FslocalMutex); - ret = lfs_rename(&g_lfs, oldName, newName); - pthread_mutex_unlock(&g_FslocalMutex); - - return ret; + return lfs_rename(&g_lfs, oldName, newName); } int LfsStat(const char * path, struct stat * buf) @@ -335,24 +269,16 @@ int LfsStat(const char * path, struct stat * buf) int ret; struct lfs_info info; - pthread_mutex_lock(&g_FslocalMutex); ret = lfs_stat(&g_lfs, path, &info); if (ret == 0) { buf->st_size = info.size; } - pthread_mutex_unlock(&g_FslocalMutex); return ret; } int LfsFsync(int fd) { - int ret; - - pthread_mutex_lock(&g_FslocalMutex); - ret = lfs_file_sync(&g_lfs, &(g_handle[fd].file)); - pthread_mutex_unlock(&g_FslocalMutex); - - return ret; + return lfs_file_sync(&g_lfs, &(g_handle[fd].file)); }