FSFAT maximal size

Reiner1210
Posts: 39
Joined: Tue Mar 20, 2018 6:28 pm

FSFAT maximal size

Postby Reiner1210 » Wed Dec 11, 2019 3:30 pm

Hello,

is there a limit in the file system size of the FAT32 implementation ?
So if I have a 32 GB SD card driven via SPI can I create a 32 GB FAT FS on it ?
On my site there it seams to be a 2 GB limit.

I use the following to get the free space

Code: Select all

bool sd_get_free(const sd_data_t* sd_data, uint64_t* free, uint64_t* total, uint64_t* card_size, uint32_t* cluster_size, uint32_t* sector_size)
{
	bool flag = false;
	FATFS* fs;
	size_t free_clusters;
	char drv[3] = {(char)('0' + sd_data->pdrv), ':', '\0'};
	if (f_getfree(drv, &free_clusters, &fs) == FR_OK)
	{
		if (cluster_size)
			*cluster_size = fs->csize;
		if (sector_size)
			*sector_size = fs->ssize;
		size_t total_sectors = ((uint64_t)(fs->n_fatent - 2)) * ((uint64_t)fs->csize);
		size_t free_sectors = ((uint64_t)free_clusters) * ((uint64_t)fs->csize);
		if (total)
			*total = total_sectors * fs->ssize;
		if (free)
			*free = free_sectors * fs->ssize;
		if (card_size)
			*card_size = ((uint64_t)sd_data->card.csd.capacity) * ((uint64_t)sd_data->card.csd.sector_size);

		flag = true;
	}
	return flag;
}
The card capacity says ~32 GB, but the totla says ~ 1.72 GB

If I insert the microSD card in a card holder and look at it on Linux with sudo dosfsck -nv /dev/sdc1
I get

Code: Select all

Boot sector contents:
System ID "MSDOS5.0"
Media byte 0xf8 (hard disk)
       512 bytes per logical sector
     65536 bytes per cluster
        32 reserved sectors
First FAT starts at byte 16384 (sector 32)
         1 FATs, 32 bit entries
   1948160 bytes per FAT (= 3805 sectors)
Root directory start at cluster 2 (arbitrary size)
Data area starts at byte 1964544 (sector 3837)
    486953 data clusters (31912951808 bytes)
63 sectors/track, 255 heads
        63 hidden sectors
  62333889 sectors total
Checking for unused clusters.
Checking free cluster summary.
Free cluster summary wrong (416855 vs. really 416811)
  Auto-correcting.
Leaving filesystem unchanged.

Thanks

Reiner

Who is online

Users browsing this forum: No registered users and 115 guests