spiffs_storage.c 736 B

123456789101112131415161718192021222324252627282930313233
  1. #include "spiffs_storage.h"
  2. #include "esp_log.h"
  3. #include "esp_spiffs.h"
  4. static const char *TAG = "spiffs";
  5. static bool s_mounted = false;
  6. esp_err_t spiffs_storage_init(void) {
  7. if (s_mounted) {
  8. return ESP_OK;
  9. }
  10. esp_vfs_spiffs_conf_t conf = {
  11. .base_path = "/spiffs",
  12. .partition_label = "storage",
  13. .max_files = 5,
  14. .format_if_mount_failed = true,
  15. };
  16. esp_err_t err = esp_vfs_spiffs_register(&conf);
  17. if (err != ESP_OK) {
  18. ESP_LOGE(TAG, "Failed to mount SPIFFS: %s", esp_err_to_name(err));
  19. return err;
  20. }
  21. size_t total = 0, used = 0;
  22. esp_spiffs_info("storage", &total, &used);
  23. ESP_LOGI(TAG, "SPIFFS mounted: %zu/%zu bytes used", used, total);
  24. s_mounted = true;
  25. return ESP_OK;
  26. }