Review comments
This commit is contained in:
+13
-5
@@ -4,6 +4,7 @@
|
|||||||
#include <FS.h> // need to be included before SdFat.h for compatibility with FS.h's File class
|
#include <FS.h> // need to be included before SdFat.h for compatibility with FS.h's File class
|
||||||
#include <Logging.h>
|
#include <Logging.h>
|
||||||
#include <SDCardManager.h>
|
#include <SDCardManager.h>
|
||||||
|
#include <SdFat.h>
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
@@ -11,6 +12,9 @@
|
|||||||
|
|
||||||
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);
|
||||||
@@ -56,21 +60,25 @@ bool HalStorage::ensureDirectoryExists(const char* path) { HAL_STORAGE_WRAPPED_C
|
|||||||
|
|
||||||
uint64_t HalStorage::sdTotalBytes() const {
|
uint64_t HalStorage::sdTotalBytes() const {
|
||||||
StorageLock lock;
|
StorageLock lock;
|
||||||
if (!SDCard.ready()) return 0;
|
// Try to initialize if not already
|
||||||
const auto* vol = FsVolume::cwv();
|
if (!halStorageSdFat.begin()) return 0;
|
||||||
|
auto* vol = halStorageSdFat.vol();
|
||||||
if (!vol) return 0;
|
if (!vol) return 0;
|
||||||
return (uint64_t)vol->clusterCount() * vol->bytesPerCluster();
|
return (uint64_t)vol->clusterCount() * vol->bytesPerCluster();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t HalStorage::sdUsedBytes() const {
|
uint64_t HalStorage::sdUsedBytes() const {
|
||||||
StorageLock lock;
|
StorageLock lock;
|
||||||
if (!SDCard.ready()) return 0;
|
if (!halStorageSdFat.begin()) return 0;
|
||||||
const auto* vol = FsVolume::cwv();
|
auto* vol = halStorageSdFat.vol();
|
||||||
if (!vol) return 0;
|
if (!vol) return 0;
|
||||||
const int32_t freeClusters = vol->freeClusterCount();
|
const int32_t freeClusters = vol->freeClusterCount();
|
||||||
if (freeClusters < 0) return 0; // error reading FAT
|
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();
|
const uint64_t bytesPerCluster = vol->bytesPerCluster();
|
||||||
return ((uint64_t)vol->clusterCount() - freeClusters) * bytesPerCluster;
|
return (clusterCount - cappedFreeClusters) * bytesPerCluster;
|
||||||
}
|
}
|
||||||
|
|
||||||
class HalFile::Impl {
|
class HalFile::Impl {
|
||||||
|
|||||||
@@ -136,13 +136,13 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
function formatBytes(bytes) {
|
function formatBytes(bytes) {
|
||||||
if (!bytes) return 'N/A';
|
if (bytes == null) return 'N/A';
|
||||||
const units = ['B', 'KB', 'MB', 'GB'];
|
const units = ['B', 'KB', 'MB', 'GB'];
|
||||||
let val = bytes, i = 0;
|
let val = bytes, i = 0;
|
||||||
while (val >= 1024 && i < units.length - 1) { val /= 1024; i++; }
|
while (val >= 1024 && i < units.length - 1) { val /= 1024; i++; }
|
||||||
return parseFloat(val.toFixed(2)).toLocaleString() + ' ' + units[i];
|
return parseFloat(val.toFixed(2)).toLocaleString() + ' ' + units[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchStatus() {
|
async function fetchStatus() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user