spiffs.cpp 939 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "kbf/spiffs.h"
  2. #include <esp_log.h>
  3. #include "kbf/macros.h"
  4. kbf::SPIFFS::SPIFFS(const string &mountPoint, const char *label) :
  5. config({
  6. .base_path = mountPoint.c_str(),
  7. .partition_label = label,
  8. .max_files = 5,
  9. .format_if_mount_failed = true}) {}
  10. kbf::SPIFFS::~SPIFFS() {
  11. unmount();
  12. }
  13. bool kbf::SPIFFS::mount() {
  14. ESP_LOGI(TAG, "mount()");
  15. esp_err_t err;
  16. if ((err = esp_vfs_spiffs_register(&config)) != ESP_OK) {
  17. error = err;
  18. return false;
  19. }
  20. return true;
  21. }
  22. void kbf::SPIFFS::unmount() const {
  23. ESP_LOGI(TAG, "unmount()");
  24. esp_vfs_spiffs_unregister(config.partition_label);
  25. }
  26. kbf::FsInfo kbf::SPIFFS::info() const {
  27. kbf::FsInfo info{};
  28. CHECK(esp_spiffs_info(config.partition_label, &info.total, &info.used));
  29. info.free = info.total - info.used;
  30. return info;
  31. }