Page 1 of 1

f_getfree fails on assertion if no volume is mounted

Posted: Sun May 19, 2024 2:12 pm
by maierkomor
f_getfree calls mount_volume, which calls get_ldnumber, which crashes in lock_volume, if no volume is mounted. The crash is due to an assertion failure of an uninitialized Mutex in xQueueSemaphoreTake, called by ff_mutex_take. Both Mutex[0] and FatFs[0] seem to have an invalid pointer at that time.

Re: f_getfree fails on assertion if no volume is mounted

Posted: Mon May 20, 2024 7:43 am
by pacucha42
Hi @maierkomor,
I assume your code looks similar to the FatFS example on the elm-chan.org site:

FATFS *fs;
DWORD fre_clust, fre_sect, tot_sect;


/* Get volume information and free clusters of drive 1 */
res = f_getfree("1:", &fre_clust, &fs);
if (res) die(res);

/* Get total sectors and free sectors */
tot_sect = (fs->n_fatent - 2) * fs->csize;
fre_sect = fre_clust * fs->csize;

/* Print the free space (assuming 512 bytes/sector) */
printf("%10lu KiB total drive space.\n%10lu KiB available.\n", tot_sect / 2, fre_sect / 2);

We have to check the f_getfree() behaviour to confirm whether the issue comes from the IDF locks incorporation to the FatFS, or from the FatFS itself. Will keep you posted, thanks for the report!

Re: f_getfree fails on assertion if no volume is mounted

Posted: Mon May 20, 2024 8:28 am
by maierkomor
Another hint for tracking the issue down. It might be the case that a mount attempt failed before calling the f_getfree. So it might be a case, of incomplete cleanup of the relevant data-structures after a failed mount attempt.