FAT FS Maximum number of files
Posted: Sat Sep 19, 2020 7:08 am
Hi everyone I am pretty new to the ESP32 and I have been experimenting with a persistent storage mechanism.
Because I intend to use flash encryption eventually, I have been testing a FAT file system although at this stage I have not actually turned it on in the compile options. While using the example for wear leveling in ESP IDF, I tried to create 600 files and met an issue where I cant seem to create more than 512 files. Does anyone know what is the cause for this? When I return the errno value I get an error of -2 and I cant tell what exactly it means. When I check the space left in the FAT using f_getfree I find that I still have space remaining so it is not because I have run out of space s I have set the partition as 1MB.
Any help to point me in the right direction would be appreciated.
Thanks in advance!
I set my in the wear leveling options of idf menu
Code snippet:
Partition:
Because I intend to use flash encryption eventually, I have been testing a FAT file system although at this stage I have not actually turned it on in the compile options. While using the example for wear leveling in ESP IDF, I tried to create 600 files and met an issue where I cant seem to create more than 512 files. Does anyone know what is the cause for this? When I return the errno value I get an error of -2 and I cant tell what exactly it means. When I check the space left in the FAT using f_getfree I find that I still have space remaining so it is not because I have run out of space s I have set the partition as 1MB.
Any help to point me in the right direction would be appreciated.
Thanks in advance!
I set my
Code: Select all
CONFIG_WL_SECTOR_SIZE = 512
Code snippet:
Code: Select all
static wl_handle_t s_wl_handle = WL_INVALID_HANDLE;
esp_err_t err;
char *basePath = "/spiflash";
char *logFilePath = "/spiflash/";
FILE *f;
const esp_vfs_fat_mount_config_t mount_config = {
.max_files = 4,
.format_if_mount_failed = true,
.allocation_unit_size = CONFIG_WL_SECTOR_SIZE};
err = esp_vfs_fat_spiflash_mount(basePath, "storage", &mount_config, &s_wl_handle);
char filepath[27] = "";
char str[12]; // Index
for (int k = 0; k < 600; k++)
{
filepath[0] = '\0';
sprintf(str, "%d", k); // convert int to char
strncat(filepath, logFilePath, 14); // Put Base path
strncat(filepath, str, 12); // Add index
ESP_LOGI(TAG, "Get Entry FilePath: %s", filepath);
f = fopen(filepath, "w");
if (f == NULL)
{
ESP_LOGE(TAG, "Failed to open file for writing error: %d", errno);
return;
}
else
{
if (fprintf(f, "%s", "helloWorld") == EOF)
{
ESP_LOGE(TAG, "ERROR RETURNED, Memory Might be full");
}
fclose(f);
}
fclose(f);
}
esp_vfs_fat_spiflash_unmount(basePath, s_wl_handle);
Partition:
Code: Select all
# Name, Type, SubType, Offset, Size, Flags
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 1M,
storage, data, fat, , 1M, encrypted