mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Allow to config the maximum number of VFS entries.
This commit is contained in:
parent
1559b6309f
commit
6beeecbbcf
@ -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
|
||||
|
@ -33,7 +33,6 @@
|
||||
|
||||
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 }
|
||||
|
||||
@ -41,7 +40,7 @@ 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 {
|
||||
@ -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 };
|
||||
@ -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;
|
||||
}
|
||||
@ -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];
|
||||
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user