1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- #ifndef KBF_SPIFFS_H
- #define KBF_SPIFFS_H
- #include <string>
- #include <esp_spiffs.h>
- using std::string;
- namespace kbf {
- /**
- * Filesystem information.
- */
- struct FsInfo {
- /** Total size in bytes. */
- size_t total;
- /** Bytes used. */
- size_t used;
- /** Bytes free. */
- size_t free;
- };
- /**
- * Serial Peripheral Interface Flash File System functions.
- */
- class SPIFFS {
- public:
- /** Tag used for logging. */
- static constexpr const char *TAG = "kbf::SPIFFS";
- /**
- * Creates configuration.
- *
- * @note To actually mount the partition, call this->mount().
- *
- * @param mountPoint
- * @param label partition label; if nullptr, the first partition with subtype=spiffs will be used
- */
- explicit SPIFFS(const string &mountPoint, const char *label = nullptr);
- /**
- * Destructor. Calls unmount().
- */
- ~SPIFFS();
- /**
- * Mounts the filesystem.
- *
- * If the mount fails, the error value is saved in this->error
- *
- * @return true on success; false on failure
- */
- bool mount();
- /**
- * Unmounts the filesystem.
- *
- * @note Called automatically from destructor.
- */
- void unmount() const;
- /**
- * Retrieves filesystem usage information.
- *
- * @return FsInfo object
- */
- [[nodiscard]] FsInfo info() const;
- /** error code for mount failure */
- esp_err_t error{};
- private:
- esp_vfs_spiffs_conf_t config;
- };
- }
- #endif //KBF_SPIFFS_H
|