cancel
Showing results for 
Search instead for 
Did you mean: 

FATFS chan library wrong free space

hitsumen
Associate II
Posted on October 16, 2014 at 18:46

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

1 REPLY 1
hitsumen
Associate II
Posted on October 17, 2014 at 08:28

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