f_getfree fails on assertion if no volume is mounted

maierkomor
Posts: 18
Joined: Sun Jul 03, 2022 8:35 pm

f_getfree fails on assertion if no volume is mounted

Postby maierkomor » Sun May 19, 2024 2:12 pm

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.

pacucha42
Posts: 27
Joined: Fri Mar 29, 2019 12:56 pm

Re: f_getfree fails on assertion if no volume is mounted

Postby pacucha42 » Mon May 20, 2024 7:43 am

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!

maierkomor
Posts: 18
Joined: Sun Jul 03, 2022 8:35 pm

Re: f_getfree fails on assertion if no volume is mounted

Postby maierkomor » Mon May 20, 2024 8:28 am

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.

Who is online

Users browsing this forum: Cimby1, Google [Bot] and 129 guests