From 75f61870a002e238385bc9a7632d42b0b2488c9a Mon Sep 17 00:00:00 2001 From: Leon Chan Date: Mon, 28 Jun 2021 15:19:29 +0800 Subject: [PATCH] fix: compile warnings 1, function prototypes: LfsSeek, LfsCloseDir 2, fix some other minor warnings and remove some while spaces close: #I3Y57X Signed-off-by: Leon Chan Change-Id: Id8b77c8a6b2e8d2b9bc5f02e22bfc6a15d70f648 --- components/fs/littlefs/lfs_api.c | 25 +++++++++++++------------ components/fs/littlefs/lfs_api.h | 6 +++--- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/components/fs/littlefs/lfs_api.c b/components/fs/littlefs/lfs_api.c index b829d48f..a9346c3f 100644 --- a/components/fs/littlefs/lfs_api.c +++ b/components/fs/littlefs/lfs_api.c @@ -32,6 +32,7 @@ #define _GNU_SOURCE 1 #include "lfs_api.h" #include "los_config.h" +#include "securec.h" lfs_t g_lfs; FileDirInfo g_lfsDir[LFS_MAX_OPEN_DIRS] = {0}; @@ -64,7 +65,7 @@ static void LfsFreeFd(int fd) pthread_mutex_lock(&g_FslocalMutex); g_handle[fd].useFlag = 0; if (g_handle[fd].pathName != NULL) { - free(g_handle[fd].pathName); + free((void *)g_handle[fd].pathName); g_handle[fd].pathName = NULL; } @@ -104,7 +105,7 @@ FileDirInfo *GetFreeDir(const char *dirName) return NULL; } -void FreeDirInfo(const char *dirName) +void FreeDirInfo(const char *dirName) { pthread_mutex_lock(&g_FslocalMutex); for (int i = 0; i < LFS_MAX_OPEN_DIRS; i++) { @@ -168,7 +169,7 @@ BOOL CheckPathIsMounted(const char *pathName, struct FileOpInfo **fileOpInfo) return FALSE; } -struct FileOpInfo *AllocMountRes(const char* target, struct FileOps *fileOps) +struct FileOpInfo *AllocMountRes(const char* target, const struct FileOps *fileOps) { pthread_mutex_lock(&g_FslocalMutex); for (int i = 0; i < LOSCFG_LFS_MAX_MOUNT_SIZE; i++) { @@ -190,8 +191,8 @@ int SetDefaultMountPath(int pathNameIndex, const char* target) if (pathNameIndex >= LOSCFG_LFS_MAX_MOUNT_SIZE) { return VFS_ERROR; } - - pthread_mutex_lock(&g_FslocalMutex); + + pthread_mutex_lock(&g_FslocalMutex); g_littlefsMntName[pathNameIndex] = strdup(target); pthread_mutex_unlock(&g_FslocalMutex); return VFS_OK; @@ -381,7 +382,7 @@ int LfsMount(const char *source, const char *target, const char *fileSystemType, ret = VFS_ERROR; goto errout; } - + ret = lfs_mount(&(fileOpInfo->lfsInfo), (struct lfs_config*)data); if (ret != 0) { ret = lfs_format(&(fileOpInfo->lfsInfo), (struct lfs_config*)data); @@ -571,7 +572,7 @@ struct dirent *LfsReaddir(DIR *dir) return NULL; } -int LfsClosedir(const DIR *dir) +int LfsClosedir(DIR *dir) { int ret; FileDirInfo *dirInfo = (FileDirInfo *)dir; @@ -674,9 +675,9 @@ int LfsWrite(int fd, const void *buf, unsigned int len) return ret; } -int LfsSeek(int fd, off_t offset, int whence) +off_t LfsSeek(int fd, off_t offset, int whence) { - int ret; + off_t ret; if (fd >= LITTLE_FS_MAX_OPEN_FILES || fd < 0) { errno = EFAULT; return VFS_ERROR; @@ -687,7 +688,7 @@ int LfsSeek(int fd, off_t offset, int whence) return VFS_ERROR; } - ret = lfs_file_seek(g_handle[fd].lfsHandle, &(g_handle[fd].file), offset, whence); + ret = (off_t)lfs_file_seek(g_handle[fd].lfsHandle, &(g_handle[fd].file), offset, whence); if (ret != 0) { errno = LittlefsErrno(ret); } @@ -719,7 +720,7 @@ int LfsClose(int fd) errno = LittlefsErrno(ret); } - return ret; + return ret; } int LfsRename(const char *oldName, const char *newName) @@ -768,7 +769,7 @@ int LfsStat(const char *path, struct stat *buf) errno = LittlefsErrno(ret); } - return ret; + return ret; } int LfsFsync(int fd) diff --git a/components/fs/littlefs/lfs_api.h b/components/fs/littlefs/lfs_api.h index 8fbf87a9..9d0ccbf3 100644 --- a/components/fs/littlefs/lfs_api.h +++ b/components/fs/littlefs/lfs_api.h @@ -65,7 +65,7 @@ typedef struct { struct FileOpInfo { uint8_t useFlag; - struct FileOps *fsVops; + const struct FileOps *fsVops; char *dirName; lfs_t lfsInfo; }; @@ -103,11 +103,11 @@ int LfsMkdir(const char *dirName, mode_t mode); int LfsRmdir(const char *dirName); DIR *LfsOpendir(const char *dirName); struct dirent *LfsReaddir(DIR *dir); -int LfsClosedir(const DIR *dir); +int LfsClosedir(DIR *dir); int LfsOpen(const char *pathName, int openFlag, int mode); int LfsRead(int fd, void *buf, unsigned int len); int LfsWrite(int fd, const void *buf, unsigned int len); -int LfsSeek(int fd, off_t offset, int whence); +off_t LfsSeek(int fd, off_t offset, int whence); int LfsClose(int fd); int LfsRename(const char *oldName, const char *newName); int LfsStat(const char *path, struct stat *buf);