SD Card available free space

27 Mar 2012

Hi,

Does anyone know the command to find the available space on an SD Card? That's not the capacity but the remaining space.

Cheers,

Zera

05 Sep 2013

This was surprisingly difficult to figure out, so just in case someone else runs into this question, the following seems to work.

Note that the variables in the FATFS struct of the SDFileSystem (sd->_fs), such as free_clust and csize, have default values before f_getfree is called.

#include "SDFileSystem.h"
#include "FATDirHandle.h"

    // later...

    FATFS* fs;
    DWORD fre_clust;
    f_getfree("0:",&fre_clust,&fs);
    const float frs = float(fs->csize)*float(fs->free_clust)
#if _MAX_SS != 512
        *(fs->ssize);
#else
        *512;
#endif
    printf("free space = %g b (%g GB, %g MB, %g KB)\r\n",
        frs, frs/1073741824.0, frs/1048576.0, frs/1024.0);