From fe0fc40049e4b8cd516905f7c130c911df1608a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Rohl=C3=ADnek?= Date: Tue, 6 Aug 2024 10:56:30 +0200 Subject: [PATCH] fix(storage/vfs): incorrect registration checks --- components/vfs/include/esp_vfs.h | 2 ++ components/vfs/vfs.c | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/components/vfs/include/esp_vfs.h b/components/vfs/include/esp_vfs.h index 42c6a1199a..5a664475aa 100644 --- a/components/vfs/include/esp_vfs.h +++ b/components/vfs/include/esp_vfs.h @@ -486,6 +486,8 @@ ssize_t esp_vfs_pwrite(int fd, const void *src, size_t size, off_t offset); */ void esp_vfs_dump_fds(FILE *fp); +void esp_vfs_dump_registered_paths(FILE *fp); + #ifdef __cplusplus } // extern "C" #endif diff --git a/components/vfs/vfs.c b/components/vfs/vfs.c index 7e494b90ef..6a88a96d2e 100644 --- a/components/vfs/vfs.c +++ b/components/vfs/vfs.c @@ -77,7 +77,7 @@ static fd_table_t s_fd_table[MAX_FDS] = { [0 ... MAX_FDS-1] = FD_TABLE_ENTRY_UNU static _lock_t s_fd_table_lock; static ssize_t esp_get_free_index(void) { - for (ssize_t i = 0; i < MAX_FDS; i++) { + for (ssize_t i = 0; i < VFS_MAX_COUNT; i++) { if (s_vfs[i] == NULL) { return i; } @@ -294,7 +294,7 @@ static esp_err_t esp_vfs_register_minified_common(const char* base_path, size_t } else { bzero(entry->path_prefix, sizeof(entry->path_prefix)); } - entry->path_prefix_len = strlen(base_path); + entry->path_prefix_len = len; entry->vfs = vfs; entry->ctx = ctx; entry->offset = index; @@ -326,6 +326,7 @@ esp_err_t esp_vfs_register_minified(const char* base_path, const esp_vfs_minifie esp_err_t ret = esp_vfs_register_minified_common(base_path, strlen(base_path), _vfs, flags, ctx, NULL); if (ret != ESP_OK) { esp_free_minified_vfs(_vfs); + return ret; } return ESP_OK; @@ -354,6 +355,7 @@ esp_err_t esp_vfs_register_common(const char* base_path, size_t len, const esp_v esp_err_t ret = esp_vfs_register_minified_common(base_path, len, _vfs, vfs->flags, ctx, vfs_index); if (ret != ESP_OK) { esp_free_minified_vfs(_vfs); + return ret; } return ESP_OK; @@ -542,6 +544,16 @@ void esp_vfs_dump_fds(FILE *fp) _lock_release(&s_fd_table_lock); } +void esp_vfs_dump_registered_paths(FILE *fp) +{ + fprintf(fp, "------------------------------------------------------\n"); + fprintf(fp, ": -> \n"); + fprintf(fp, "------------------------------------------------------\n"); + for (size_t i = 0; i < VFS_MAX_COUNT; ++i) { + fprintf(fp, "%d:%s -> %p\n", i, s_vfs[i] ? s_vfs[i]->path_prefix : "NULL", s_vfs[i]); + } +} + /* * Set ESP_VFS_FLAG_READONLY_FS read-only flag for a registered virtual filesystem * for given path prefix. Should be only called from the esp_vfs_*filesystem* register