77#include " littlefs_FS_Driver.h"
88#include < stdlib.h>
99
10+ #if (HAL_USE_SDC == TRUE)
11+ #include < sdmmc_cmd.h>
12+
13+ // the mounted card and the volume it belongs to, from Target_System_IO_FileSystem.c
14+ extern " C" sdmmc_card_t *card;
15+ extern " C" char cardDriveLetter;
16+ #endif
17+
1018extern FileSystemVolume *g_FS_Volumes;
1119
1220static int32_t RemoveAllFiles (const char *path);
@@ -81,8 +89,6 @@ HRESULT LITTLEFS_FS_Driver::Format(const VOLUME_ID *volume, const char *volumeLa
8189
8290HRESULT LITTLEFS_FS_Driver::GetSizeInfo (const VOLUME_ID *volume, int64_t *totalSize, int64_t *totalFreeSpace)
8391{
84- (void )totalSize;
85-
8692 // FATFS *fsPtr = &fs;
8793 // char buffer[3];
8894 // DWORD freeClusters, freeSectors, totalSectors;
@@ -109,9 +115,30 @@ HRESULT LITTLEFS_FS_Driver::GetSizeInfo(const VOLUME_ID *volume, int64_t *totalS
109115 // // *totalFreeSpace = (int64_t)freeSectors * FF_MAX_SS;
110116 // // #endif
111117
118+ // -1 means "unknown" to the caller
112119 *totalSize = -1 ;
120+
121+ // free space would need f_getfree(), which walks the FAT and trips the watchdog on large cards
113122 *totalFreeSpace = -1 ;
114123
124+ #if (HAL_USE_SDC == TRUE)
125+
126+ // the driver also serves the internal flash, which has no card behind it
127+ FileSystemVolume *currentVolume = FileSystemVolumeList::FindVolume (volume->volumeId );
128+
129+ if (currentVolume != NULL && card != NULL && cardDriveLetter != 0 &&
130+ currentVolume->m_rootName [0 ] == cardDriveLetter)
131+ {
132+ // physical capacity of the card, not of the file system on it
133+ *totalSize = (int64_t )card->csd .capacity * card->csd .sector_size ;
134+ }
135+
136+ #else
137+
138+ (void )volume;
139+
140+ #endif
141+
115142 return S_OK ;
116143}
117144
0 commit comments