From 01819f39b9ad2afb8f24d92f4f6f1e7dd9c0f4a9 Mon Sep 17 00:00:00 2001 From: tbaust Date: Sun, 12 Dec 2021 14:05:03 +0100 Subject: [PATCH 01/10] multithreading problem in esp_littlefs_info fixed multithreading problem in requesting the FS info --- src/esp_littlefs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/esp_littlefs.c b/src/esp_littlefs.c index 2b0c2e4..4019ee3 100644 --- a/src/esp_littlefs.c +++ b/src/esp_littlefs.c @@ -185,8 +185,10 @@ esp_err_t esp_littlefs_info(const char* partition_label, size_t *total_bytes, si if(err != ESP_OK) return false; efs = _efs[index]; + sem_take(efs); if(total_bytes) *total_bytes = efs->cfg.block_size * efs->cfg.block_count; if(used_bytes) *used_bytes = efs->cfg.block_size * lfs_fs_size(efs->fs); + sem_give(efs); return ESP_OK; } From e25e5bf406251172fb6c7cedd9a86c372a1fa644 Mon Sep 17 00:00:00 2001 From: Tony <454794+tonyrewin@users.noreply.github.com> Date: Tue, 24 May 2022 07:34:38 +0300 Subject: [PATCH 02/10] fixed small bug --- src/LITTLEFS.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LITTLEFS.cpp b/src/LITTLEFS.cpp index d14f1ee..a0a6e1e 100644 --- a/src/LITTLEFS.cpp +++ b/src/LITTLEFS.cpp @@ -41,7 +41,7 @@ LITTLEFSImpl::LITTLEFSImpl() bool LITTLEFSImpl::exists(const char* path) { - File f = open(path, "r"); + File f = open(path, "r", false); return (f == true); } From 227964da8c02a87b19cfc059bc89534bcbd4e2e5 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Thu, 26 May 2022 14:16:50 +0200 Subject: [PATCH 03/10] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index f856f8a..d5554bc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # LittleFS_esp32 +This is a fork from lorel LittleFS, with a few additional fixes to improve thread-safety. + + #### ***Ths library is now part of [Arduino esp32 core v2](https://github.com/espressif/arduino-esp32/tree/master/libraries/LittleFS )*** Note, there it is renamed from LITTLEFS to LittleFS, ***Please post your issues there. This here is kept for Arduino esp32 core 1.x purposes*** From f92b84e0da1a38c10683357be0cbb337e1873ff9 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Thu, 26 May 2022 15:37:13 +0200 Subject: [PATCH 04/10] two more fixes from joltwallet/esp_littlefs back-ported two additional fixes from joltwallet/esp_littlefs: * do not allow esp_littlefs_info to report used_bytes > total_bytes * fix bug where esp_littlefs_info returns ESP_OK if it fails to get partition by label --- src/esp_littlefs.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/esp_littlefs.c b/src/esp_littlefs.c index 4019ee3..9bdff1e 100644 --- a/src/esp_littlefs.c +++ b/src/esp_littlefs.c @@ -182,12 +182,17 @@ esp_err_t esp_littlefs_info(const char* partition_label, size_t *total_bytes, si esp_littlefs_t *efs = NULL; err = esp_littlefs_by_label(partition_label, &index); - if(err != ESP_OK) return false; + if(err != ESP_OK) return err; efs = _efs[index]; sem_take(efs); - if(total_bytes) *total_bytes = efs->cfg.block_size * efs->cfg.block_count; - if(used_bytes) *used_bytes = efs->cfg.block_size * lfs_fs_size(efs->fs); + size_t total_bytes_local = efs->cfg.block_size * efs->cfg.block_count; + if(total_bytes) *total_bytes = total_bytes_local; + + /* lfs_fs_size may return a size larger than the actual filesystem size. + * https://github.com/littlefs-project/littlefs/blob/9c7e232086f865cff0bb96fe753deb66431d91fd/lfs.h#L658 + */ + if(used_bytes) *used_bytes = MIN(total_bytes_local, efs->cfg.block_size * lfs_fs_size(efs->fs)); sem_give(efs); return ESP_OK; From 4830f8bd2ed293349e90c2eb81b3c07dc4836149 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Thu, 26 May 2022 15:59:55 +0200 Subject: [PATCH 05/10] revert pull request #2 from tonyrewin/master seems that 2 arguments are needed, not 3 --- src/LITTLEFS.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LITTLEFS.cpp b/src/LITTLEFS.cpp index a0a6e1e..d14f1ee 100644 --- a/src/LITTLEFS.cpp +++ b/src/LITTLEFS.cpp @@ -41,7 +41,7 @@ LITTLEFSImpl::LITTLEFSImpl() bool LITTLEFSImpl::exists(const char* path) { - File f = open(path, "r", false); + File f = open(path, "r"); return (f == true); } From 87899779882c758725b7011333e8de08951d1627 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Thu, 26 May 2022 16:13:38 +0200 Subject: [PATCH 06/10] typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d5554bc..64b72fb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # LittleFS_esp32 -This is a fork from lorel LittleFS, with a few additional fixes to improve thread-safety. +This is a fork from lorol LittleFS, with a few additional fixes to improve thread-safety. #### ***Ths library is now part of [Arduino esp32 core v2](https://github.com/espressif/arduino-esp32/tree/master/libraries/LittleFS )*** From d7930d99708408593acfd712e557f9a774c74ed4 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Thu, 26 May 2022 19:51:05 +0200 Subject: [PATCH 07/10] Added define so WLED can recognise the patch --- src/LITTLEFS.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/LITTLEFS.h b/src/LITTLEFS.h index c76cc88..2c792af 100644 --- a/src/LITTLEFS.h +++ b/src/LITTLEFS.h @@ -16,6 +16,9 @@ #include "FS.h" +// just for WLED, so it can recognise my fork. +#define LITTLEFS_threadsafe_SOFTHACK007 + namespace fs { From 8c4bfacf37bd4921adb510ef65c919495c32ca2c Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Thu, 7 Jul 2022 21:07:38 +0200 Subject: [PATCH 08/10] support for newer IDF versions seems that arduino-esp32 has recently added a third parameter to open() --- src/LITTLEFS.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/LITTLEFS.cpp b/src/LITTLEFS.cpp index d14f1ee..6b4ab0b 100644 --- a/src/LITTLEFS.cpp +++ b/src/LITTLEFS.cpp @@ -41,7 +41,11 @@ LITTLEFSImpl::LITTLEFSImpl() bool LITTLEFSImpl::exists(const char* path) { +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0) + File f = open(path, "r", false); +#else File f = open(path, "r"); +#endif return (f == true); } From a9aa0d168416bd6925e98f752fce2a17db7302f8 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Thu, 7 Jul 2022 21:44:41 +0200 Subject: [PATCH 09/10] removed WLED-specific define not needed for the general case --- src/LITTLEFS.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/LITTLEFS.h b/src/LITTLEFS.h index 2c792af..c76cc88 100644 --- a/src/LITTLEFS.h +++ b/src/LITTLEFS.h @@ -16,9 +16,6 @@ #include "FS.h" -// just for WLED, so it can recognise my fork. -#define LITTLEFS_threadsafe_SOFTHACK007 - namespace fs { From 4f22112e11e35e75769d3f52794de0b6e7226aac Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Thu, 7 Jul 2022 21:47:21 +0200 Subject: [PATCH 10/10] removed a private comment --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 64b72fb..f856f8a 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,5 @@ # LittleFS_esp32 -This is a fork from lorol LittleFS, with a few additional fixes to improve thread-safety. - - #### ***Ths library is now part of [Arduino esp32 core v2](https://github.com/espressif/arduino-esp32/tree/master/libraries/LittleFS )*** Note, there it is renamed from LITTLEFS to LittleFS, ***Please post your issues there. This here is kept for Arduino esp32 core 1.x purposes***