Skip to content

Commit

Permalink
Allow to config the maximum number of VFS entries.
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverschmidt committed Mar 14, 2023
1 parent 1559b63 commit 6beeecb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 8 additions & 0 deletions components/vfs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ menu "Virtual file system"
help
Disabling this option can save memory when the support for termios.h is not required.

config VFS_MAX_COUNT
int "Maximum Number of Virtual Filesystems"
default 8
range 1 20
depends on VFS_SUPPORT_IO
help
Define maximum number of virtual filesystems that can be registered.


menu "Host File System I/O (Semihosting)"
depends on VFS_SUPPORT_IO
Expand Down
11 changes: 5 additions & 6 deletions components/vfs/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@

static const char *TAG = "vfs";

#define VFS_MAX_COUNT 8 /* max number of VFS entries (registered filesystems) */
#define LEN_PATH_PREFIX_IGNORED SIZE_MAX /* special length value for VFS which is never recognised by open() */
#define FD_TABLE_ENTRY_UNUSED (fd_table_t) { .permanent = false, .has_pending_close = false, .has_pending_select = false, .vfs_index = -1, .local_fd = -1 }

typedef uint8_t local_fd_t;
_Static_assert((1 << (sizeof(local_fd_t)*8)) >= MAX_FDS, "file descriptor type too small");

typedef int8_t vfs_index_t;
_Static_assert((1 << (sizeof(vfs_index_t)*8)) >= VFS_MAX_COUNT, "VFS index type too small");
_Static_assert((1 << (sizeof(vfs_index_t)*8)) >= CONFIG_VFS_MAX_COUNT, "VFS index type too small");
_Static_assert(((vfs_index_t) -1) < 0, "vfs_index_t must be a signed type");

typedef struct {
Expand All @@ -60,7 +59,7 @@ typedef struct {
fd_set errorfds;
} fds_triple_t;

static vfs_entry_t* s_vfs[VFS_MAX_COUNT] = { 0 };
static vfs_entry_t* s_vfs[CONFIG_VFS_MAX_COUNT] = { 0 };
static size_t s_vfs_count = 0;

static fd_table_t s_fd_table[MAX_FDS] = { [0 ... MAX_FDS-1] = FD_TABLE_ENTRY_UNUSED };
Expand Down Expand Up @@ -89,7 +88,7 @@ esp_err_t esp_vfs_register_common(const char* base_path, size_t len, const esp_v
}
}
if (index == s_vfs_count) {
if (s_vfs_count >= VFS_MAX_COUNT) {
if (s_vfs_count >= CONFIG_VFS_MAX_COUNT) {
free(entry);
return ESP_ERR_NO_MEM;
}
Expand Down Expand Up @@ -167,7 +166,7 @@ esp_err_t esp_vfs_register_with_id(const esp_vfs_t *vfs, void *ctx, esp_vfs_id_t

esp_err_t esp_vfs_unregister_with_id(esp_vfs_id_t vfs_id)
{
if (vfs_id < 0 || vfs_id >= VFS_MAX_COUNT || s_vfs[vfs_id] == NULL) {
if (vfs_id < 0 || vfs_id >= CONFIG_VFS_MAX_COUNT || s_vfs[vfs_id] == NULL) {
return ESP_ERR_INVALID_ARG;
}
vfs_entry_t* vfs = s_vfs[vfs_id];
Expand All @@ -176,7 +175,7 @@ esp_err_t esp_vfs_unregister_with_id(esp_vfs_id_t vfs_id)

_lock_acquire(&s_fd_table_lock);
// Delete all references from the FD lookup-table
for (int j = 0; j < VFS_MAX_COUNT; ++j) {
for (int j = 0; j < CONFIG_VFS_MAX_COUNT; ++j) {
if (s_fd_table[j].vfs_index == vfs_id) {
s_fd_table[j] = FD_TABLE_ENTRY_UNUSED;
}
Expand Down

0 comments on commit 6beeecb

Please sign in to comment.