From 24031dd89a2055619b7c9360ce6f3148e1eb36e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Procha=CC=81zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 21 Mar 2022 13:57:20 +0100 Subject: [PATCH 1/2] Edited VFSFileImpl::read to use both read/fread --- libraries/FS/src/vfs_api.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/libraries/FS/src/vfs_api.cpp b/libraries/FS/src/vfs_api.cpp index e43b4397452..ce36fe449b1 100644 --- a/libraries/FS/src/vfs_api.cpp +++ b/libraries/FS/src/vfs_api.cpp @@ -16,6 +16,8 @@ using namespace fs; +#define READ_SIZE_SWITCH 128 //swithc to read func when read size > 128bytes + FileImplPtr VFSImpl::open(const char* fpath, const char* mode, const bool create) { if(!_mountpoint) { @@ -374,7 +376,28 @@ size_t VFSFileImpl::read(uint8_t* buf, size_t size) return 0; } - return fread(buf, 1, size, _f); + //ERASE BYTEBUFFER and use read when size > READ_SIZE_SWITCH always + if(size > READ_SIZE_SWITCH) + { + //check some data in buffer exists –> clear buffer and move pointer to deleted data + size_t bytesinbuf = __fpending(_f); + if (bytesinbuf && (bytesinbuf != 128)) //buffer lenght is 128 bytes + { + fpurge(_f); + lseek(fileno(_f),(-128+bytesinbuf),SEEK_CUR); + } + + int res = ::read(fileno(_f), buf, size); + if (res < 0) { + // an error occurred + return 0; + } + return res; + } + else + { + return fread(buf, 1, size, _f); + } } void VFSFileImpl::flush() From df8ad1646df03505afd2227ab199b3c18d83a77d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Procha=CC=81zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 21 Mar 2022 14:08:29 +0100 Subject: [PATCH 2/2] Added missing include --- libraries/FS/src/vfs_api.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/FS/src/vfs_api.cpp b/libraries/FS/src/vfs_api.cpp index ce36fe449b1..9e200a1500b 100644 --- a/libraries/FS/src/vfs_api.cpp +++ b/libraries/FS/src/vfs_api.cpp @@ -13,6 +13,7 @@ // limitations under the License. #include "vfs_api.h" +#include using namespace fs;