Add totalBytes / usedBytes to SD/SDMMC (#673)

to be same as SPIFFS
This commit is contained in:
Luc 2017-09-28 10:01:02 +08:00 committed by Me No Dev
parent a66b544d18
commit 3ba46c7fbc
6 changed files with 65 additions and 0 deletions

View File

@ -212,6 +212,8 @@ void setup(){
renameFile(SD, "/hello.txt", "/foo.txt");
readFile(SD, "/foo.txt");
testFileIO(SD, "/test.txt");
Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024));
Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024));
}
void loop(){

View File

@ -14,6 +14,7 @@
#include "vfs_api.h"
#include "sd_diskio.h"
#include "ff.h"
#include "FS.h"
#include "SD.h"
@ -73,4 +74,32 @@ uint64_t SDFS::cardSize()
return (uint64_t)sectors * sectorSize;
}
uint64_t SDFS::totalBytes()
{
FATFS* fsinfo;
DWORD fre_clust;
if(f_getfree("0:",&fre_clust,&fsinfo)!= 0) return 0;
uint64_t size = (fsinfo->csize)*(fsinfo->n_fatent - 2)
#if _MAX_SS != 512
*(fsinfo->ssize);
#else
*512;
#endif
return size;
}
uint64_t SDFS::usedBytes()
{
FATFS* fsinfo;
DWORD fre_clust;
if(f_getfree("0:",&fre_clust,&fsinfo)!= 0) return 0;
uint64_t size = (fsinfo->csize)*((fsinfo->n_fatent - 2) - (fsinfo->free_clst))
#if _MAX_SS != 512
*(fsinfo->ssize);
#else
*512;
#endif
return size;
}
SDFS SD = SDFS(FSImplPtr(new VFSImpl()));

View File

@ -32,6 +32,8 @@ public:
void end();
sdcard_type_t cardType();
uint64_t cardSize();
uint64_t totalBytes();
uint64_t usedBytes();
};
}

View File

@ -209,6 +209,8 @@ void setup(){
renameFile(SD_MMC, "/hello.txt", "/foo.txt");
readFile(SD_MMC, "/foo.txt");
testFileIO(SD_MMC, "/test.txt");
Serial.printf("Total space: %lluMB\n", SD_MMC.totalBytes() / (1024 * 1024));
Serial.printf("Used space: %lluMB\n", SD_MMC.usedBytes() / (1024 * 1024));
}
void loop(){

View File

@ -23,6 +23,7 @@ extern "C" {
#include "driver/sdmmc_defs.h"
#include "sdmmc_cmd.h"
}
#include "ff.h"
#include "SD_MMC.h"
using namespace fs;
@ -98,5 +99,32 @@ uint64_t SDMMCFS::cardSize()
return (uint64_t)_card->csd.capacity * _card->csd.sector_size;
}
uint64_t SDMMCFS::totalBytes()
{
FATFS* fsinfo;
DWORD fre_clust;
if(f_getfree("0:",&fre_clust,&fsinfo)!= 0) return 0;
uint64_t size = (fsinfo->csize)*(fsinfo->n_fatent - 2)
#if _MAX_SS != 512
*(fsinfo->ssize);
#else
*512;
#endif
return size;
}
uint64_t SDMMCFS::usedBytes()
{
FATFS* fsinfo;
DWORD fre_clust;
if(f_getfree("0:",&fre_clust,&fsinfo)!= 0) return 0;
uint64_t size = (fsinfo->csize)*((fsinfo->n_fatent - 2) - (fsinfo->free_clst))
#if _MAX_SS != 512
*(fsinfo->ssize);
#else
*512;
#endif
return size;
}
SDMMCFS SD_MMC = SDMMCFS(FSImplPtr(new VFSImpl()));

View File

@ -32,6 +32,8 @@ public:
void end();
sdcard_type_t cardType();
uint64_t cardSize();
uint64_t totalBytes();
uint64_t usedBytes();
};
}