From 552353d58f69435374c5b4fe5782c9c091522c1d Mon Sep 17 00:00:00 2001 From: Fabian Wolter Date: Thu, 5 May 2022 10:50:59 +0200 Subject: [PATCH 1/7] Fix propagation of error code in LITTLEFS_write() The bytes-written argument must be signed, otherwise the check "if (*bw < 0)" will always yield false and the error code isn't available with SYS_FS_FileError(..). --- system/fs/src/sys_fs_littlefs_interface.c.ftl | 2 +- system/fs/templates/sys_fs_littlefs_interface.h.ftl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/system/fs/src/sys_fs_littlefs_interface.c.ftl b/system/fs/src/sys_fs_littlefs_interface.c.ftl index 3e4d49b18..53fbe9ffb 100644 --- a/system/fs/src/sys_fs_littlefs_interface.c.ftl +++ b/system/fs/src/sys_fs_littlefs_interface.c.ftl @@ -573,7 +573,7 @@ int LITTLEFS_write ( uintptr_t handle, /* Pointer to the file object */ const void *buff, /* Pointer to the data to be written */ uint32_t btw, /* Number of bytes to write */ - uint32_t* bw /* Pointer to number of bytes written */ + int32_t* bw /* Pointer to number of bytes written */ ) { lfs_t *fs = NULL; diff --git a/system/fs/templates/sys_fs_littlefs_interface.h.ftl b/system/fs/templates/sys_fs_littlefs_interface.h.ftl index 45548e5c2..957121310 100644 --- a/system/fs/templates/sys_fs_littlefs_interface.h.ftl +++ b/system/fs/templates/sys_fs_littlefs_interface.h.ftl @@ -83,7 +83,7 @@ bool LITTLEFS_eof(uintptr_t handle); uint32_t LITTLEFS_size(uintptr_t handle); <#if SYS_FS_LFS_READONLY == false> -int LITTLEFS_write (uintptr_t handle, const void* buff, uint32_t btw, uint32_t* bw); +int LITTLEFS_write (uintptr_t handle, const void* buff, uint32_t btw, int32_t* bw); int LITTLEFS_mkdir (const char* path); From ededb98d3fad9ecb1b422a9c4bd8c7ea9ed02f6b Mon Sep 17 00:00:00 2001 From: Fabian Wolter Date: Thu, 5 May 2022 18:36:26 +0200 Subject: [PATCH 2/7] Fix compiler warning --- system/fs/templates/sys_fs.h.ftl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/fs/templates/sys_fs.h.ftl b/system/fs/templates/sys_fs.h.ftl index 90880fa4d..1f74e0e45 100644 --- a/system/fs/templates/sys_fs.h.ftl +++ b/system/fs/templates/sys_fs.h.ftl @@ -508,7 +508,7 @@ typedef struct /* Function pointer of native file system for reading a file */ int (*read) (uintptr_t fp, void* buff, uint32_t btr, uint32_t *br); /* Function pointer of native file system for writing to a file */ - int (*write) (uintptr_t fp, const void* buff, uint32_t btw, uint32_t* bw); + int (*write) (uintptr_t fp, const void* buff, uint32_t btw, int32_t* bw); /* Function pointer of native file system for closing a file */ int (*close) (uintptr_t fp); /* Function pointer of native file system for moving the file pointer by a From 27b1ee09984865a24f06c87ff2b229b2221c033d Mon Sep 17 00:00:00 2001 From: Fabian Wolter Date: Thu, 5 May 2022 18:45:59 +0200 Subject: [PATCH 3/7] Fix compiler warning --- system/fs/src/sys_fs.c.ftl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/fs/src/sys_fs.c.ftl b/system/fs/src/sys_fs.c.ftl index 5c414d60c..6945926c3 100644 --- a/system/fs/src/sys_fs.c.ftl +++ b/system/fs/src/sys_fs.c.ftl @@ -2420,7 +2420,7 @@ size_t SYS_FS_FileWrite { int fileStatus = -1; SYS_FS_OBJ *fileObj = (SYS_FS_OBJ *)handle; - uint32_t bytesWritten = -1; + int32_t bytesWritten = -1; OSAL_RESULT osalResult = OSAL_RESULT_FALSE; /* Check if the handle is valid. */ From 87c6688292191a09ba6fdb05294f3d99ab8d2fbf Mon Sep 17 00:00:00 2001 From: Fabian Wolter Date: Thu, 5 May 2022 20:17:48 +0200 Subject: [PATCH 4/7] Revert "Fix compiler warning" This reverts commit 27b1ee09984865a24f06c87ff2b229b2221c033d. --- system/fs/src/sys_fs.c.ftl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/fs/src/sys_fs.c.ftl b/system/fs/src/sys_fs.c.ftl index 6945926c3..5c414d60c 100644 --- a/system/fs/src/sys_fs.c.ftl +++ b/system/fs/src/sys_fs.c.ftl @@ -2420,7 +2420,7 @@ size_t SYS_FS_FileWrite { int fileStatus = -1; SYS_FS_OBJ *fileObj = (SYS_FS_OBJ *)handle; - int32_t bytesWritten = -1; + uint32_t bytesWritten = -1; OSAL_RESULT osalResult = OSAL_RESULT_FALSE; /* Check if the handle is valid. */ From c31622223b93136b01f34fee3322f24d8e342fe7 Mon Sep 17 00:00:00 2001 From: Fabian Wolter Date: Thu, 5 May 2022 20:18:07 +0200 Subject: [PATCH 5/7] Revert "Fix compiler warning" This reverts commit ededb98d3fad9ecb1b422a9c4bd8c7ea9ed02f6b. --- system/fs/templates/sys_fs.h.ftl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/fs/templates/sys_fs.h.ftl b/system/fs/templates/sys_fs.h.ftl index 1f74e0e45..90880fa4d 100644 --- a/system/fs/templates/sys_fs.h.ftl +++ b/system/fs/templates/sys_fs.h.ftl @@ -508,7 +508,7 @@ typedef struct /* Function pointer of native file system for reading a file */ int (*read) (uintptr_t fp, void* buff, uint32_t btr, uint32_t *br); /* Function pointer of native file system for writing to a file */ - int (*write) (uintptr_t fp, const void* buff, uint32_t btw, int32_t* bw); + int (*write) (uintptr_t fp, const void* buff, uint32_t btw, uint32_t* bw); /* Function pointer of native file system for closing a file */ int (*close) (uintptr_t fp); /* Function pointer of native file system for moving the file pointer by a From 40954daf9e8a24b678cb1bd5d14dcce3b57070f3 Mon Sep 17 00:00:00 2001 From: Fabian Wolter Date: Thu, 5 May 2022 20:18:13 +0200 Subject: [PATCH 6/7] Revert "Fix propagation of error code in LITTLEFS_write()" This reverts commit 552353d58f69435374c5b4fe5782c9c091522c1d. --- system/fs/src/sys_fs_littlefs_interface.c.ftl | 2 +- system/fs/templates/sys_fs_littlefs_interface.h.ftl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/system/fs/src/sys_fs_littlefs_interface.c.ftl b/system/fs/src/sys_fs_littlefs_interface.c.ftl index 53fbe9ffb..3e4d49b18 100644 --- a/system/fs/src/sys_fs_littlefs_interface.c.ftl +++ b/system/fs/src/sys_fs_littlefs_interface.c.ftl @@ -573,7 +573,7 @@ int LITTLEFS_write ( uintptr_t handle, /* Pointer to the file object */ const void *buff, /* Pointer to the data to be written */ uint32_t btw, /* Number of bytes to write */ - int32_t* bw /* Pointer to number of bytes written */ + uint32_t* bw /* Pointer to number of bytes written */ ) { lfs_t *fs = NULL; diff --git a/system/fs/templates/sys_fs_littlefs_interface.h.ftl b/system/fs/templates/sys_fs_littlefs_interface.h.ftl index 957121310..45548e5c2 100644 --- a/system/fs/templates/sys_fs_littlefs_interface.h.ftl +++ b/system/fs/templates/sys_fs_littlefs_interface.h.ftl @@ -83,7 +83,7 @@ bool LITTLEFS_eof(uintptr_t handle); uint32_t LITTLEFS_size(uintptr_t handle); <#if SYS_FS_LFS_READONLY == false> -int LITTLEFS_write (uintptr_t handle, const void* buff, uint32_t btw, int32_t* bw); +int LITTLEFS_write (uintptr_t handle, const void* buff, uint32_t btw, uint32_t* bw); int LITTLEFS_mkdir (const char* path); From df7b9d54d8650cfd66eef77f2bbedfd6ce15bfc2 Mon Sep 17 00:00:00 2001 From: Fabian Wolter Date: Thu, 5 May 2022 20:21:35 +0200 Subject: [PATCH 7/7] Fix signedness-error in LITTLEFW_write/read comparison --- system/fs/src/sys_fs_littlefs_interface.c.ftl | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/system/fs/src/sys_fs_littlefs_interface.c.ftl b/system/fs/src/sys_fs_littlefs_interface.c.ftl index 3e4d49b18..fe0159d71 100644 --- a/system/fs/src/sys_fs_littlefs_interface.c.ftl +++ b/system/fs/src/sys_fs_littlefs_interface.c.ftl @@ -321,15 +321,19 @@ int LITTLEFS_read ( fs = &LITTLEFSVolume[0].volObj; - *br = lfs_file_read(fs, fp, buff, btr); + int32_t lfs_ret = lfs_file_read(fs, fp, buff, btr); - if (*br < 0) + if (lfs_ret < 0) { - res = *br; + res = lfs_ret; *br = 0; } - - return ((int)res); + else + { + *br = lfs_ret; + } + + return (LFS_Err_To_SYSFS_Err(res)); } @@ -583,13 +587,17 @@ int LITTLEFS_write ( fs = &LITTLEFSVolume[0].volObj; - *bw = lfs_file_write(fs, fp, buff, btw); + int32_t lfs_ret = lfs_file_write(fs, fp, buff, btw); - if (*bw < 0) + if (lfs_ret < 0) { - res = *bw; + res = lfs_ret; *bw = 0; } + else + { + *bw = lfs_ret; + } return (LFS_Err_To_SYSFS_Err(res)); }