upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/components/wisp_relay/flash_monitor.c
diff options
context:
space:
mode:
Diffstat (limited to 'components/wisp_relay/flash_monitor.c')
-rw-r--r--components/wisp_relay/flash_monitor.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/components/wisp_relay/flash_monitor.c b/components/wisp_relay/flash_monitor.c
new file mode 100644
index 0000000..ceb8c3b
--- /dev/null
+++ b/components/wisp_relay/flash_monitor.c
@@ -0,0 +1,30 @@
1#include "flash_monitor.h"
2#include "esp_littlefs.h"
3#include "esp_log.h"
4#include <string.h>
5
6static const char *TAG = "flash_monitor";
7
8void flash_get_health(const char *partition_label, flash_health_t *health)
9{
10 memset(health, 0, sizeof(flash_health_t));
11
12 esp_err_t ret = esp_littlefs_info(partition_label,
13 &health->total_bytes,
14 &health->used_bytes);
15 if (ret != ESP_OK) {
16 ESP_LOGE(TAG, "Failed to get LittleFS info: %s", esp_err_to_name(ret));
17 return;
18 }
19
20 if (health->total_bytes == 0) {
21 health->free_bytes = 0;
22 health->usage_percent = 0.0f;
23 } else {
24 health->free_bytes = health->total_bytes - health->used_bytes;
25 health->usage_percent = (float)health->used_bytes / health->total_bytes * 100.0f;
26 }
27
28 ESP_LOGD(TAG, "Flash: %.1f%% used (%zu/%zu bytes)",
29 health->usage_percent, health->used_bytes, health->total_bytes);
30}