Files
MTGcompanion/main/storage_manager.h

45 lines
1.1 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);
#ifdef __cplusplus
}
#endif