From 74a7a4b1053f089939e4469b1a45007e74d578f6 Mon Sep 17 00:00:00 2001 From: "sonika.rathi" Date: Mon, 14 Sep 2026 10:17:53 +0200 Subject: [PATCH] fix(fatfs): restore FF_USE_EXPAND for contiguous file API Closes https://github.com/espressif/esp-idf/issues/19067 --- .../fatfs/host_test/main/test_fatfs_vfs.cpp | 26 +++++++++++++++++++ components/fatfs/src/ffconf.h | 2 +- .../flash_wl/main/test_fatfs_flash_wl.c | 2 -- .../test_apps/sdcard/main/test_fatfs_sdmmc.c | 2 -- .../test_fatfs_common/test_fatfs_common.c | 2 -- .../test_fatfs_common/test_fatfs_common.h | 2 -- 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/components/fatfs/host_test/main/test_fatfs_vfs.cpp b/components/fatfs/host_test/main/test_fatfs_vfs.cpp index e2779dc9891..298ab2b25d1 100644 --- a/components/fatfs/host_test/main/test_fatfs_vfs.cpp +++ b/components/fatfs/host_test/main/test_fatfs_vfs.cpp @@ -611,3 +611,29 @@ TEST_CASE("can create and remove directories", "[fatfs]") test_mkdir_rmdir(); test_teardown(); } + +TEST_CASE("esp_vfs_fat_create_contiguous_file works (requires FF_USE_EXPAND)", "[fatfs]") +{ + /* Do not gate this case on FF_USE_EXPAND: with expand disabled the test app + * fails to link (undefined reference to f_expand), catching ffconf regressions. */ + STATIC_REQUIRE(FF_USE_EXPAND == 1); + + test_setup(); + + const char *base_path = "/linux"; + const char *full_path = "/linux/expand.txt"; + constexpr uint64_t desired_size = 64; + + remove(full_path); + REQUIRE(esp_vfs_fat_create_contiguous_file(base_path, full_path, desired_size, true) == ESP_OK); + + struct stat st; + REQUIRE(stat(full_path, &st) == 0); + REQUIRE(st.st_size == (off_t)desired_size); + + bool is_contiguous = false; + REQUIRE(esp_vfs_fat_test_contiguous_file(base_path, full_path, &is_contiguous) == ESP_OK); + REQUIRE(is_contiguous); + + test_teardown(); +} diff --git a/components/fatfs/src/ffconf.h b/components/fatfs/src/ffconf.h index b8ae97bb63b..a996344bb37 100644 --- a/components/fatfs/src/ffconf.h +++ b/components/fatfs/src/ffconf.h @@ -43,7 +43,7 @@ /* This option switches fast seek feature. (0:Disable or 1:Enable) */ -#define FF_USE_EXPAND 0 +#define FF_USE_EXPAND 1 /* This option switches f_expand(). (0:Disable or 1:Enable) */ diff --git a/components/fatfs/test_apps/flash_wl/main/test_fatfs_flash_wl.c b/components/fatfs/test_apps/flash_wl/main/test_fatfs_flash_wl.c index ca9aa172076..d5ac955fd81 100644 --- a/components/fatfs/test_apps/flash_wl/main/test_fatfs_flash_wl.c +++ b/components/fatfs/test_apps/flash_wl/main/test_fatfs_flash_wl.c @@ -223,14 +223,12 @@ TEST_CASE("(WL) can ftruncate", "[fatfs][wear_levelling]") test_teardown(); } -#if FF_USE_EXPAND TEST_CASE("(WL) can esp_vfs_fat_create_contiguous_file", "[fatfs][wear_levelling]") { test_setup(); test_fatfs_create_contiguous_file("/spiflash", "/spiflash/expand.txt"); test_teardown(); } -#endif TEST_CASE("(WL) stat returns correct values", "[fatfs][wear_levelling]") { diff --git a/components/fatfs/test_apps/sdcard/main/test_fatfs_sdmmc.c b/components/fatfs/test_apps/sdcard/main/test_fatfs_sdmmc.c index e6478ad9030..abc2858c71c 100644 --- a/components/fatfs/test_apps/sdcard/main/test_fatfs_sdmmc.c +++ b/components/fatfs/test_apps/sdcard/main/test_fatfs_sdmmc.c @@ -200,7 +200,6 @@ TEST_CASE("(SD) can ftruncate", "[fatfs][sdmmc]") test_teardown_sdmmc(card); } -#if FF_USE_EXPAND TEST_CASE("(SD) can esp_vfs_fat_create_contiguous_file", "[fatfs][sdmmc]") { sdmmc_card_t *card = NULL; @@ -208,7 +207,6 @@ TEST_CASE("(SD) can esp_vfs_fat_create_contiguous_file", "[fatfs][sdmmc]") test_fatfs_create_contiguous_file("/sdcard", "/sdcard/expand.txt"); test_teardown_sdmmc(card); } -#endif TEST_CASE("(SD) stat returns correct values", "[fatfs][sdmmc]") { diff --git a/components/fatfs/test_apps/test_fatfs_common/test_fatfs_common.c b/components/fatfs/test_apps/test_fatfs_common/test_fatfs_common.c index f24e5acddd7..21585507846 100644 --- a/components/fatfs/test_apps/test_fatfs_common/test_fatfs_common.c +++ b/components/fatfs/test_apps/test_fatfs_common/test_fatfs_common.c @@ -1436,7 +1436,6 @@ void test_fatfs_info(const char* base_path, const char* filepath) TEST_ASSERT_EQUAL(free_bytes, free_bytes_new); } -#if FF_USE_EXPAND void test_fatfs_create_contiguous_file(const char* base_path, const char* full_path) { size_t desired_file_size = 64; @@ -1459,4 +1458,3 @@ void test_fatfs_create_contiguous_file(const char* base_path, const char* full_p TEST_ASSERT_EQUAL(ESP_OK, err); TEST_ASSERT_TRUE(is_contiguous); } -#endif diff --git a/components/fatfs/test_apps/test_fatfs_common/test_fatfs_common.h b/components/fatfs/test_apps/test_fatfs_common/test_fatfs_common.h index 1253ec338be..32119cdf5c3 100644 --- a/components/fatfs/test_apps/test_fatfs_common/test_fatfs_common.h +++ b/components/fatfs/test_apps/test_fatfs_common/test_fatfs_common.h @@ -79,9 +79,7 @@ void test_fatfs_rw_speed(const char* filename, void* buf, size_t buf_size, size_ void test_fatfs_info(const char* base_path, const char* filepath); -#if FF_USE_EXPAND void test_fatfs_create_contiguous_file(const char* base_path, const char* full_path); -#endif void test_fatfs_readdir_stat(const char* path);