Find free and total space bytes on sd card

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Find free and total space bytes on sd card

Postby snahmad75 » Tue Mar 12, 2019 6:55 pm

Hi,

https://github.com/espressif/esp-idf/issues/1660

Code: Select all

        FATFS *fs;
	DWORD fre_clust, fre_sect, tot_sect;

	/* Get volume information and free clusters of sdcard */
	auto res = f_getfree("/sdcard/", &fre_clust, &fs);
	if (res) {
		return ES_Unspecified;
	}

	/* Get total sectors and free sectors */
	tot_sect = (fs->n_fatent - 2) * fs->csize;
	fre_sect = fre_clust * fs->csize;

	
	u64 tmp_total_bytes = tot_sect * FF_SS_SDCARD;
	u64 tmp_free_bytes = fre_sect * FF_SS_SDCARD;

	/* Print the free space in bytes */
	print("%llu total bytes. %llu free bytes. sector_size=%u", tmp_total_bytes, tmp_free_bytes, FF_SS_SDCARD);
Strange results for 8 and 4 GB sd card.

-

8GB CARD.

3644850176 total bytes. 3644620800 free bytes. sector_size=512

Getting about 3,6 GB ???

2-

16 GB Card

2772434944 total bytes. 2772205568 free bytes. sector_size=512

Getting about 2.7 GB ???

3-

1GB Card.

966656000 total bytes. 966262784 free bytes. sector_size=512

0.96 GB. looks correct.

Any idea why less?

How Do I find sector size for SDCard.

Is it CONFIG_WL_SECTOR_SIZE=??? define in menuconfig.

I specified allocation unit=64k for SD card mount

Code: Select all

// This initializes the slot without card detect (CD) and write protect (WP) signals.
// Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
 // Options for mounting the filesystem.
// If format_if_mount_failed is set to true, SD card will be partitioned and
// formatted in case when mounting fails.
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
    .format_if_mount_failed = true,
    .max_files = 5,
    .allocation_unit_size = 64 * 1024

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: Find free and total space bytes on sd card

Postby snahmad75 » Wed Mar 13, 2019 12:49 pm

Working now. My mistakes.

cast DWORD 32-bit to 64 bit before multiple.


u64 tmp_total_bytes = (64)tot_sect * FF_SS_SDCARD;
u64 tmp_free_bytes = (64)fre_sect * FF_SS_SDCARD;

Who is online

Users browsing this forum: Bing [Bot] and 183 guests