6 years, 1 month ago.

How to get free space in LocalFileSystem

Is there any supported API to get free space in the `LocalFileSystem`? I tried `statvfs` but it doesn't seem to work... Any ideas?

I guess I could simply list all files and substract from the total size, but I was wondering if there's a better way.

Thanks in advance!

1 Answer

6 years, 1 month ago.

Unfortunately some of the filesystem API’s are not exported via mbed. For me the a stat/fstat is missing and the disk free is missing.

Here is how I did it, the FileSystem code is available in the mbed git repository.

file system snippet

FATFS *x;
DWORD fre_clust;
f_getfree("0:",&fre_clust,&x);

printf("FSClusterSize=%d, FreeClusters=%d, Total=%d\r\n", fs.FSClusterSize(), x->free_clust, fs.FSClusterSize() * x->free_clust);

PS: The Clustersize you need to figure out on your own.

I hope this helps, regards Helmut