diff --git a/libraries/FFat/src/FFat.cpp b/libraries/FFat/src/FFat.cpp index 0d2b2cb26ab05868682712c6aeb8e89b8c369186..6441dfca4e444799f43812155564f3ba28ff3359 100644 --- a/libraries/FFat/src/FFat.cpp +++ b/libraries/FFat/src/FFat.cpp @@ -135,6 +135,21 @@ size_t F_Fat::totalBytes() return tot_sect * sect_size; } +size_t F_Fat::usedBytes() +{ + FATFS *fs; + DWORD free_clust, used_sect, sect_size; + + BYTE pdrv = ff_diskio_get_pdrv_wl(_wl_handle); + char drv[3] = {(char)(48+pdrv), ':', 0}; + if ( f_getfree(drv, &free_clust, &fs) != FR_OK){ + return 0; + } + used_sect = (fs->n_fatent - 2 - free_clust) * fs->csize; + sect_size = CONFIG_WL_SECTOR_SIZE; + return used_sect * sect_size; +} + size_t F_Fat::freeBytes() { diff --git a/libraries/FFat/src/FFat.h b/libraries/FFat/src/FFat.h index a32c950bb6e626fab22c7e5ccbc8f2457d0dfa12..ed20e23b294a25ea6718fc6a2d369cc61ac13f2a 100644 --- a/libraries/FFat/src/FFat.h +++ b/libraries/FFat/src/FFat.h @@ -31,6 +31,7 @@ public: bool begin(bool formatOnFail=false, const char * basePath="/ffat", uint8_t maxOpenFiles=10, const char * partitionLabel = (char*)FFAT_PARTITION_LABEL); bool format(bool full_wipe = FFAT_WIPE_QUICK, char* partitionLabel = (char*)FFAT_PARTITION_LABEL); size_t totalBytes(); + size_t usedBytes(); size_t freeBytes(); void end(); bool exists(const char* path);