The f_getfree function gets number of the free clusters.
FRESULT f_getfree ( const XCHAR* Path, /* Root directory of the drive */ DWORD* Clusters, /* Pointer to the variable to store number of free clusters */ FATFS** FileSystemObject /* Pointer to pointer to file system object */ );
The f_getfree function gets number of free clusters on the drive. The member csize in the file system object is refrecting number of sectors per cluster, so that the free space in unit of sector can be calcurated with this. When FSInfo structure on FAT32 volume is not in sync, this function can return an incorrect free cluster count.
Available when _FS_READONLY == 0 and _FS_MINIMIZE == 0.
FATFS *fs; DWORD fre_clust, fre_sect, tot_sect; // Get drive information and free clusters res = f_getfree("/", &fre_clust, &fs); if (res) die(res); // Get total sectors and free sectors tot_sect = (fs->max_clust - 2) * fs->csize; fre_sect = fre_clust * fs->csize; // Print free space in unit of KB (assuming 512B/sector) printf("%lu KB total drive space.\n" "%lu KB available.\n", fre_sect / 2, tot_sect / 2);