Welcome! Log In Create A New Profile

Advanced

How do I know the free space of SD card?

Posted by pcfree 
How do I know the free space of SD card?
June 03, 2009 06:01PM
Is there any function that could easily get free space information of an FAT device such as SD card? Or should I do low level sector read to retrieve boot sector and FAT table to analyze them by myself?
Re: How do I know the free space of SD card?
June 03, 2009 10:10PM
statvfs may be what you need.

#include sys/statvfs.h
void UpdateFreeSpace()
{
	struct statvfs fiData;
	if(statvfs("/",&fiData) < 0)
	{
		snprintf(diskinfo, sizeof(diskinfo)-1, "Free space: Unknown");
	}
	else
	{
		snprintf(diskinfo, sizeof(diskinfo)-1, "Free space: %ld/%ld MB", fiData.f_bfree*fiData.f_bsize/1000000, fiData.f_blocks*fiData.f_bsize/1000000);
	}
}

Taken from main.cpp of SD Explorer
Re: How do I know the free space of SD card?
June 04, 2009 12:38AM
Thanks!!
Sorry, only registered users may post in this forum.

Click here to login