4#include "esp_littlefs.h"
16 esp_vfs_littlefs_conf_t conf = {
19 .format_if_mount_failed =
false,
23 esp_err_t ret = esp_vfs_littlefs_register(&conf);
26 if (ret == ESP_FAIL) {
27 LOGE(
"Failed to mount LittleFS or format filesystem");
28 }
else if (ret == ESP_ERR_INVALID_STATE) {
29 LOGE(
"ESP_ERR_INVALID_STATE");
31 LOGE(
"Failed to initialize LittleFS: %s", esp_err_to_name(ret));
38 size_t total = 0, used = 0;
41 LOGI(
"LittleFS mounted at %s. Total: %d bytes, Used: %d bytes",
44 LOGE(
"Failed to get LittleFS information");
60 return ESP_ERR_INVALID_ARG;
64 return ESP_ERR_INVALID_STATE;
67 size_t total = 0, used = 0;
82 LOGI(
"==================================================");
83 LOGI(
"STORAGE INFORMATION");
84 LOGI(
"==================================================");
91 LOGI(
"--------------------------------------------------");
98 LOGI(
"Usage : %.2f %%", usage);
100 LOGE(
"Failed to retrieve storage statistics");
102 LOGI(
"==================================================");
Project-wide logging macros based on ESP-IDF's logging library.
#define LOGI(...)
Log a message at Info level.
#define LOGE(...)
Log a message at Error level.
size_t storage_get_total_bytes(void)
Get the total size of the storage in bytes.
static const char * LITTLEFS_PARTITION_LABEL
Partition label for the LittleFS filesystem.
const char * storage_get_partition_label(void)
Get the partition label for the LittleFS filesystem.
esp_err_t storage_get_info(storage_info_t *info)
Get comprehensive storage information.
size_t storage_get_used_bytes(void)
Get the used size of the storage in bytes.
bool storage_is_mounted(void)
Check if the storage is mounted and ready.
static const char * LITTLEFS_MOUNT_POINT
Mount point for LittleFS filesystem.
esp_err_t storage_init(void)
Initialize and mount LittleFS filesystem.
const char * storage_get_mount_point(void)
Get the mount point for the LittleFS filesystem.
size_t storage_get_free_bytes(void)
Get the free size of the storage in bytes.
void storage_print_info(void)
Print storage information to the log.
static bool is_mounted
Flag indicating if the filesystem is currently mounted.
Storage information structure.
size_t total_bytes
Total size of the storage in bytes.
size_t free_bytes
Free size of the storage in bytes.
size_t used_bytes
Used size of the storage in bytes.