Skip to content

Commit d8b1fc8

Browse files
authored
Added usedBytes to match other filesystems (#4534)
1 parent 378b6ac commit d8b1fc8

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

libraries/FFat/src/FFat.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,21 @@ size_t F_Fat::totalBytes()
135135
return tot_sect * sect_size;
136136
}
137137

138+
size_t F_Fat::usedBytes()
139+
{
140+
FATFS *fs;
141+
DWORD free_clust, used_sect, sect_size;
142+
143+
BYTE pdrv = ff_diskio_get_pdrv_wl(_wl_handle);
144+
char drv[3] = {(char)(48+pdrv), ':', 0};
145+
if ( f_getfree(drv, &free_clust, &fs) != FR_OK){
146+
return 0;
147+
}
148+
used_sect = (fs->n_fatent - 2 - free_clust) * fs->csize;
149+
sect_size = CONFIG_WL_SECTOR_SIZE;
150+
return used_sect * sect_size;
151+
}
152+
138153
size_t F_Fat::freeBytes()
139154
{
140155

libraries/FFat/src/FFat.h

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class F_Fat : public FS
3131
bool begin(bool formatOnFail=false, const char * basePath="/ffat", uint8_t maxOpenFiles=10, const char * partitionLabel = (char*)FFAT_PARTITION_LABEL);
3232
bool format(bool full_wipe = FFAT_WIPE_QUICK, char* partitionLabel = (char*)FFAT_PARTITION_LABEL);
3333
size_t totalBytes();
34+
size_t usedBytes();
3435
size_t freeBytes();
3536
void end();
3637
bool exists(const char* path);

0 commit comments

Comments
 (0)