Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to config the maximum number of VFS entries. (IDFGH-9641) #10987

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) */
Copy link
Member

@igrr igrr Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One note, here I had to re-introduce VFS_MAX_COUNT macro so it's still defined even if CONFIG_VFS_SUPPORT_IO is not set. Otherwise the build would fail when CONFIG_VFS_SUPPORT_IO is disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your time and sorry for wasting it on this not fully functional pull request!

I'm now instead following a pattern I find all over the place in the ESP-IDF code base.

#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