From 9a1f8b2fd3a7c3233ffef95f557c3138d2259d63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Rohl=C3=ADnek?= Date: Fri, 15 Nov 2024 12:32:53 +0100 Subject: [PATCH 1/3] Update to new version of VFS API --- src/esp_littlefs.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/esp_littlefs.c b/src/esp_littlefs.c index 17a7d0a..14c9ce8 100644 --- a/src/esp_littlefs.c +++ b/src/esp_littlefs.c @@ -88,7 +88,9 @@ static ssize_t vfs_littlefs_pread(void *ctx, int fd, void *dst, size_t size, o static int vfs_littlefs_close(void* ctx, int fd); static off_t vfs_littlefs_lseek(void* ctx, int fd, off_t offset, int mode); static int vfs_littlefs_fsync(void* ctx, int fd); +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 4, 0) static esp_vfs_t vfs_littlefs_create_struct(bool writeable); +#endif // ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 4, 0) #ifdef CONFIG_VFS_SUPPORT_DIR static int vfs_littlefs_stat(void* ctx, const char * path, struct stat * st); @@ -364,10 +366,58 @@ esp_err_t esp_littlefs_sdmmc_info(sdmmc_card_t *sdcard, size_t *total_bytes, siz } #endif +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0) + +#ifdef CONFIG_VFS_SUPPORT_DIR +static esp_vfs_dir_ops_t s_vfs_littlefs_dir = { + .stat_p = &vfs_littlefs_stat, + .link_p = NULL, /* Not Supported */ + .unlink_p = &vfs_littlefs_unlink, + .rename_p = &vfs_littlefs_rename, + .opendir_p = &vfs_littlefs_opendir, + .readdir_p = &vfs_littlefs_readdir, + .readdir_r_p = &vfs_littlefs_readdir_r, + .telldir_p = &vfs_littlefs_telldir, + .seekdir_p = &vfs_littlefs_seekdir, + .closedir_p = &vfs_littlefs_closedir, + .mkdir_p = &vfs_littlefs_mkdir, + .rmdir_p = &vfs_littlefs_rmdir, + // access_p + .truncate_p = &vfs_littlefs_truncate, +#ifdef ESP_LITTLEFS_ENABLE_FTRUNCATE + .ftruncate_p = &vfs_littlefs_ftruncate, +#endif // ESP_LITTLEFS_ENABLE_FTRUNCATE +#if CONFIG_LITTLEFS_USE_MTIME + .utime_p = &vfs_littlefs_utime, +#endif // CONFIG_LITTLEFS_USE_MTIME +}; +#endif // CONFIG_VFS_SUPPORT_DIR + +static esp_vfs_fs_ops_t s_vfs_littlefs = { + .write_p = &vfs_littlefs_write, + .pwrite_p = &vfs_littlefs_pwrite, + .lseek_p = &vfs_littlefs_lseek, + .read_p = &vfs_littlefs_read, + .pread_p = &vfs_littlefs_pread, + .open_p = &vfs_littlefs_open, + .close_p = &vfs_littlefs_close, + .fsync_p = &vfs_littlefs_fsync, + .fcntl_p = &vfs_littlefs_fcntl, +#ifndef CONFIG_LITTLEFS_USE_ONLY_HASH + .fstat_p = &vfs_littlefs_fstat, +#endif +#ifdef CONFIG_VFS_SUPPORT_DIR + .dir = &s_vfs_littlefs_dir, +#endif // CONFIG_VFS_SUPPORT_DIR +}; + +#endif // ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0) esp_err_t esp_vfs_littlefs_register(const esp_vfs_littlefs_conf_t * conf) { assert(conf->base_path); +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 4, 0) const esp_vfs_t vfs = vfs_littlefs_create_struct(!conf->read_only); +#endif // ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 4, 0) esp_err_t err = esp_littlefs_init(conf); if (err != ESP_OK) { @@ -399,7 +449,15 @@ esp_err_t esp_vfs_littlefs_register(const esp_vfs_littlefs_conf_t * conf) } strlcat(_efs[index]->base_path, conf->base_path, ESP_VFS_PATH_MAX + 1); +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0) + int flags = ESP_VFS_FLAG_CONTEXT_PTR | ESP_VFS_FLAG_STATIC; + if (conf->read_only) { + flags |= ESP_VFS_FLAG_READONLY_FS; + } + err = esp_vfs_register_fs(conf->base_path, &s_vfs_littlefs, flags, _efs[index]); +#else err = esp_vfs_register(conf->base_path, &vfs, _efs[index]); +#endif // ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0) if (err != ESP_OK) { esp_littlefs_free(&_efs[index]); ESP_LOGE(ESP_LITTLEFS_TAG, "Failed to register Littlefs to \"%s\"", conf->base_path); @@ -636,6 +694,7 @@ static const char * esp_littlefs_errno(enum lfs_error lfs_errno) { #define esp_littlefs_errno(x) "" #endif +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 4, 0) static esp_vfs_t vfs_littlefs_create_struct(bool writeable) { esp_vfs_t vfs = { .flags = ESP_VFS_FLAG_CONTEXT_PTR, @@ -675,6 +734,9 @@ static esp_vfs_t vfs_littlefs_create_struct(bool writeable) { #endif // CONFIG_VFS_SUPPORT_DIR }; if(!writeable) { +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0) + vfs.flags |= ESP_VFS_FLAG_READONLY_FS; +#endif // ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0) vfs.write_p = NULL; vfs.pwrite_p = NULL; vfs.fsync_p = NULL; @@ -686,6 +748,7 @@ static esp_vfs_t vfs_littlefs_create_struct(bool writeable) { } return vfs; } +#endif // ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 4, 0) /** * @brief Free and clear a littlefs definition structure. From 548e35d8c0930850cae12210a4fadb8f4c8e3428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Rohl=C3=ADnek?= Date: Thu, 21 Nov 2024 08:39:48 +0100 Subject: [PATCH 2/3] Fix size data type in tests --- test/test_littlefs_static_partition.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_littlefs_static_partition.c b/test/test_littlefs_static_partition.c index 5d550a0..b9927e8 100644 --- a/test/test_littlefs_static_partition.c +++ b/test/test_littlefs_static_partition.c @@ -137,7 +137,7 @@ TEST_CASE("grow filesystem", "[littlefs]") .partition = (const esp_partition_t *) &partition, }; - uint32_t shrink_bytes; + size_t shrink_bytes; /* Format a smaller partition */ { @@ -158,7 +158,7 @@ TEST_CASE("grow filesystem", "[littlefs]") /* Mount, ensure that it DOES grow */ { - uint32_t grow_bytes; + size_t grow_bytes; conf.grow_on_mount = true; TEST_ESP_OK(esp_vfs_littlefs_register(&conf)); TEST_ESP_OK(esp_littlefs_partition_info(&partition, &grow_bytes, NULL)); From 1e3b3bd9c56e17186799ab29cec53e6934db1506 Mon Sep 17 00:00:00 2001 From: Brian Pugh Date: Fri, 22 Nov 2024 10:24:58 -0500 Subject: [PATCH 3/3] fix open-maximum-number-of-files test. --- test/test_littlefs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_littlefs.c b/test/test_littlefs.c index 1c1418d..82337e4 100644 --- a/test/test_littlefs.c +++ b/test/test_littlefs.c @@ -156,7 +156,8 @@ TEST_CASE("w+ mode read and write file", "[littlefs]") TEST_CASE("can open maximum number of files", "[littlefs]") { - size_t max_files = 61; /* account for stdin, stdout, stderr, esp-idf defaults to maximum 64 file descriptors */ + size_t max_files = FOPEN_MAX - 3; /* account for stdin, stdout, stderr, esp-idf defaults to maximum 64 file descriptors */ + test_setup(); test_littlefs_open_max_files("/littlefs/f", max_files); test_teardown();