2014-10-16 09:46 AM
Good day everyone,
I tried to use Chan's FatFS library for a while, it works fine,
But I found some problems here.
If I read free space in my MicroSD card, it reads it wrong.
When I format it for a while it reads data normally, but later when I create, delete files, it shows it not correct.
Here is some debug information:
2058.049072 KB/s
done 4194304 bytes
7585 MiB total drive space.
7029 MiB available.
actual is:
7585 MiB total drive space.
7560 MiB available.
fat_res = f_getfree('''', &fre_clust, &fs);
tot_sect = (fs->n_fatent - 2) * fs->csize;
fre_sect = fre_clust * fs->csize;
printf(''\n%10lu MiB total drive space.\n%10lu MiB available.\n'', tot_sect / 2 / 1024, fre_sect / 2 / 1024);
Thank you,
//Nikolaj
2014-10-16 11:28 PM
Descriptions
The f_getfree() function gets number of free clusters on the volume. The member csize in the file system object indicates number of sectors per cluster, so that the free space in unit of sector can be calcurated with this information.When FSINFO structure on the FAT32 volume is not in sync, this function can return an incorrect free cluster count. To avoid this problem, FatFs can be forced full FAT scan by _FS_NOFSINFO option.
Defining _FS_NOFSINFO to 1 in ffconf.h, solved my problem:
#define _FS_NOFSINFO 1
Thank you,
//Nikolaj