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