Code: Untitled.c Select all
bool SD_getFreeSpace(uint32_t *tot, uint32_t *free)
{
FATFS *fs;
DWORD fre_clust, fre_sect, tot_sect;
/* Get volume information and free clusters of drive 0 */
if(f_getfree("0:", &fre_clust, &fs) == FR_OK)
{
/* Get total sectors and free sectors */
tot_sect = (fs->n_fatent - 2) * fs->csize;
fre_sect = fre_clust * fs->csize;
*tot = tot_sect / 2;
*free = fre_sect / 2;
/* Print the free space (assuming 512 bytes/sector) */
ESP_LOGD(TAG, "%10lu KiB total drive space. %10lu KiB available.", *tot, *free);
return true;
}
return false;
}
Currently I am opening and closing an empty file to do this.