Reuse SDCArdManager logic
This commit is contained in:
+2
-18
@@ -12,9 +12,6 @@
|
|||||||
|
|
||||||
HalStorage HalStorage::instance;
|
HalStorage HalStorage::instance;
|
||||||
|
|
||||||
// Local SdFat instance for volume stats only
|
|
||||||
static SdFat halStorageSdFat;
|
|
||||||
|
|
||||||
HalStorage::HalStorage() {
|
HalStorage::HalStorage() {
|
||||||
storageMutex = xSemaphoreCreateMutex();
|
storageMutex = xSemaphoreCreateMutex();
|
||||||
assert(storageMutex != nullptr);
|
assert(storageMutex != nullptr);
|
||||||
@@ -60,25 +57,12 @@ bool HalStorage::ensureDirectoryExists(const char* path) { HAL_STORAGE_WRAPPED_C
|
|||||||
|
|
||||||
uint64_t HalStorage::sdTotalBytes() const {
|
uint64_t HalStorage::sdTotalBytes() const {
|
||||||
StorageLock lock;
|
StorageLock lock;
|
||||||
// Try to initialize if not already
|
return SDCard.sdTotalBytes();
|
||||||
if (!halStorageSdFat.begin()) return 0;
|
|
||||||
auto* vol = halStorageSdFat.vol();
|
|
||||||
if (!vol) return 0;
|
|
||||||
return (uint64_t)vol->clusterCount() * vol->bytesPerCluster();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t HalStorage::sdUsedBytes() const {
|
uint64_t HalStorage::sdUsedBytes() const {
|
||||||
StorageLock lock;
|
StorageLock lock;
|
||||||
if (!halStorageSdFat.begin()) return 0;
|
return SDCard.sdUsedBytes();
|
||||||
auto* vol = halStorageSdFat.vol();
|
|
||||||
if (!vol) return 0;
|
|
||||||
const int32_t freeClusters = vol->freeClusterCount();
|
|
||||||
if (freeClusters < 0) return 0; // error reading FAT
|
|
||||||
const uint64_t clusterCount = vol->clusterCount();
|
|
||||||
uint64_t cappedFreeClusters = freeClusters < 0 ? 0 : (uint64_t)freeClusters;
|
|
||||||
if (cappedFreeClusters > clusterCount) cappedFreeClusters = clusterCount;
|
|
||||||
const uint64_t bytesPerCluster = vol->bytesPerCluster();
|
|
||||||
return (clusterCount - cappedFreeClusters) * bytesPerCluster;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t HalStorage::sdFreeBytes() const {
|
uint64_t HalStorage::sdFreeBytes() const {
|
||||||
|
|||||||
Reference in New Issue
Block a user