[En-Nut-Discussion] How to get free memory space on SD

PragmaLab info at pragmalab.nl
Fri May 2 22:19:41 CEST 2008


Hi Helmut,

> Is there any better way to obtain free space?

why not use the FAT-table itself? It contains the exact administration of
your volume. Like Eric suggested, the function 'PhatCountFreeClusters()'
will report the number of free clusters. The clustersize is known after
mounting the volume, so you now the number of bytes that can be used for new
files or extending existing ones. FAT32 normally uses a clustersize of 4K,
FAT16 takes normally 16K per cluster, but the 'SectorsPerCluster' will tell
you the exact size (a sector is always 512 bytes).

Please note that adding files will also demand some additional bytes for the
creation of a directory entry (32 bytes per entry for short 8.3 filenames,
long filename entries take up several 8.3 entries, depending on the length
of the filename). Extending existing files just demand more clusters, you
don't need additinal space for the dir-entry (the entry was already there).

By the way, I optimised the 'PhatCountFreeClusters()' function for FAT16 and
FAT32 (not for FAT12 since clusterentries are not alligned with sectors and
counting free clusters for FAT12 does not take a long time anyway). It
speeds up the counting of the free clusters by 4 (we need it for SD cards >
1GB). If you're interested I'll send you the modified 'pahtvol.c'.

Regards,

Rob van Lieshout

 




More information about the En-Nut-Discussion mailing list