56 lines
1.5 KiB
C
56 lines
1.5 KiB
C
/*
|
|
* MTG RFID Companion - LittleFS storage manager
|
|
*
|
|
* Phase 2: Mounts LittleFS at /spiffs on the "storage" partition, seeds the
|
|
* default database files on first boot, and exposes file helpers used by the
|
|
* RFID/cache/web subsystems.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "esp_err.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define STORAGE_BASE_PATH "/spiffs"
|
|
#define STORAGE_MAPPINGS STORAGE_BASE_PATH "/mappings.json"
|
|
#define STORAGE_CARDS_DIR STORAGE_BASE_PATH "/cards"
|
|
|
|
/**
|
|
* @brief Mount LittleFS and seed default files.
|
|
* @return ESP_OK on success.
|
|
*/
|
|
esp_err_t storage_manager_init(void);
|
|
|
|
/**
|
|
* @brief Check whether a file exists on the filesystem.
|
|
*/
|
|
bool storage_file_exists(const char *path);
|
|
|
|
/**
|
|
* @brief Read an entire file into a heap allocated buffer (caller frees).
|
|
* @param[out] out_buf NULL terminated buffer; NULL and out_len=0 if missing.
|
|
*/
|
|
esp_err_t storage_read_text(const char *path, char **out_buf, size_t *out_len);
|
|
|
|
/**
|
|
* @brief Write text (plus terminating newline) to a file atomically.
|
|
*/
|
|
esp_err_t storage_write_text(const char *path, const char *text);
|
|
|
|
/**
|
|
* @brief Add/replace a UID->card-name mapping in /spiffs/mappings.json.
|
|
*/
|
|
esp_err_t storage_manager_bind_uid(const char *uid, const char *card_name);
|
|
|
|
/**
|
|
* @brief Lookup a card name for a UID in mappings.json. Caller frees *out.
|
|
* @return ESP_OK and non-NULL *out on success; ESP_ERR_NOT_FOUND otherwise.
|
|
*/
|
|
esp_err_t storage_manager_lookup_name(const char *uid, char **out);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif |