12345678910111213141516171819202122232425262728293031323334353637383940 |
- #include "kbf/spiffs.h"
- #include <esp_log.h>
- #include "kbf/macros.h"
- kbf::SPIFFS::SPIFFS(const string &mountPoint, const char *label) :
- config({
- .base_path = mountPoint.c_str(),
- .partition_label = label,
- .max_files = 5,
- .format_if_mount_failed = true}) {}
- kbf::SPIFFS::~SPIFFS() {
- unmount();
- }
- bool kbf::SPIFFS::mount() {
- ESP_LOGI(TAG, "mount()");
- esp_err_t err;
- if ((err = esp_vfs_spiffs_register(&config)) != ESP_OK) {
- error = err;
- return false;
- }
- return true;
- }
- void kbf::SPIFFS::unmount() const {
- ESP_LOGI(TAG, "unmount()");
- esp_vfs_spiffs_unregister(config.partition_label);
- }
- kbf::FsInfo kbf::SPIFFS::info() const {
- kbf::FsInfo info{};
- CHECK(esp_spiffs_info(config.partition_label, &info.total, &info.used));
- info.free = info.total - info.used;
- return info;
- }
|