Page 1 of 1

remove file doesn"t free space

Posted: Fri May 14, 2021 12:50 pm
by campestring
Hello, I am trying to delete a file with remove function. The file is successfully deleted but the free space of my storage doesn't changeā€¦ Any ideas ?
Thanks

Re: remove file doesn"t free space

Posted: Fri May 14, 2021 1:23 pm
by ESP_Minatel
Hi,

Can you provide more information about? Can you share the code, IDF version, etc...?

We can try to help you if you provide us more details about it :D !

Re: remove file doesn"t free space

Posted: Fri May 14, 2021 1:25 pm
by campestring
here is the code where I delete the file :

int del = remove(g_day_stamp_comparaison);
if (!del)
{
ESP_LOGI(tag, "oldest file has been deleted sucessfully");
}

and here is where I check the free space :

static void storageModule_get_fatfs_usage(size_t *out_total_bytes, size_t *out_free_bytes)
{
FATFS *fs;
size_t free_clusters;
int res = f_getfree("0:", &free_clusters, &fs);
assert(res == FR_OK);
size_t total_sectors = (fs->n_fatent - 2) * fs->csize;
size_t free_sectors = free_clusters * fs->csize;

// assuming the total size is < 4GiB, should be true for SPI Flash
if (out_total_bytes != NULL)
{
*out_total_bytes = total_sectors * fs->ssize;
}
if (out_free_bytes != NULL)
{
*out_free_bytes = free_sectors * fs->ssize;
}
}