From 0116449161591f332e4f15ad3ba0862911e059e5 Mon Sep 17 00:00:00 2001 From: Augusto Zanellato Date: Wed, 29 Oct 2025 20:13:30 +0100 Subject: [PATCH] fix(storage/spiffs): fix readdir setting errno on directory end spiffs_res_to_errno maps `SPIFFS_ERR_END_OF_OBJECT` to EIO which breaks the common contract where errno should be 0 if readdir iterated through all the entries in a directory. The fix is explicitly checking for `SPIFFS_ERR_END_OF_OBJECT` and in that case set errno to 0. --- components/spiffs/esp_spiffs.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/spiffs/esp_spiffs.c b/components/spiffs/esp_spiffs.c index 68e253db141a..10815c2748f2 100644 --- a/components/spiffs/esp_spiffs.c +++ b/components/spiffs/esp_spiffs.c @@ -746,7 +746,15 @@ static int vfs_spiffs_readdir_r(void* ctx, DIR* pdir, struct dirent* entry, char * item_name; do { if (SPIFFS_readdir(&dir->d, &out) == 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); + s32_t spiffs_res = SPIFFS_errno(efs->fs); + switch (spiffs_res) { + case SPIFFS_ERR_END_OF_OBJECT: + errno = 0; + break; + default: + errno = spiffs_res_to_errno(spiffs_res); + break; + } SPIFFS_clearerr(efs->fs); if (!errno) { *out_dirent = NULL;