34 std::unique_ptr<StorageFileReader>
openReader(
const std::string& path)
override;
40 bool mount()
override;
59 bool exists(
const std::string &path)
override;
66 bool remove(
const std::string &path)
override;
74 bool rename(
const std::string &from,
const std::string &to)
override;
82 bool readFile(
const std::string &path, std::vector<uint8_t> &out)
override;
92 bool readFileString(
const std::string &path, uint32_t startPosition, uint32_t length, std::string &buffer);
100 bool writeFile(
const std::string &path,
const std::vector<uint8_t> &data)
override;
101 bool writeFile(
const std::string& path,
const unsigned char* data,
size_t size)
override;
110 bool appendToFile(
const std::string &path,
const uint8_t *data,
size_t size)
override;
118 bool streamFile(
const std::string &path, std::function<
void(
const uint8_t *,
size_t)> chunkCallback)
override;
125 size_t getFileSize(
const std::string &path)
override;
133 bool listDirectory(
const std::string &path, std::vector<FileInfo> &out)
override;
191 static int lfs_read_cb(
const struct lfs_config *c, lfs_block_t block, lfs_off_t off,
void *buffer, lfs_size_t size);
192 static int lfs_prog_cb(
const struct lfs_config *c, lfs_block_t block, lfs_off_t off,
const void *buffer, lfs_size_t size);
193 static int lfs_erase_cb(
const struct lfs_config *c, lfs_block_t block);
194 static int lfs_prog_cb_singlecore(
const struct lfs_config *c, lfs_block_t block, lfs_off_t off,
const void *buffer, lfs_size_t size);
196 static int lfs_prog_cb_multicore(
const struct lfs_config *c, lfs_block_t block, lfs_off_t off,
const void *buffer, lfs_size_t size);
198 static int lfs_lock(
const struct lfs_config *c);
199 static int lfs_unlock(
const struct lfs_config *c);
Abstract interface for file and directory storage backends.
A LittleFS-based implementation of StorageManager, storing files in flash memory.
static constexpr size_t PROG_SIZE
bool unmount() override
Unmount the LittleFS filesystem.
bool rename(const std::string &from, const std::string &to) override
Rename a file or directory.
static constexpr size_t BLOCK_COUNT
bool formatStorage() override
Format the filesystem.
bool appendToFile(const std::string &path, const uint8_t *data, size_t size) override
Append data to a file.
static int lfs_erase_cb_multicore(const struct lfs_config *c, lfs_block_t block)
static int lfs_lock(const struct lfs_config *c)
bool writeFile(const std::string &path, const std::vector< uint8_t > &data) override
Write a byte vector to a file (overwrite).
uintptr_t getFlashBase() const
get Flash base address
void formatInner(bool *result)
std::unique_ptr< StorageFileReader > openReader(const std::string &path) override
open a file for streaming read line access.
static int lfs_prog_cb_multicore(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size)
static StaticSemaphore_t lfs_mutex_buf
static constexpr size_t LOOKAHEAD_SIZE
bool autoMountIfNeeded()
Mount automatically if not mounted yet.
static int lfs_unlock(const struct lfs_config *c)
bool streamFile(const std::string &path, std::function< void(const uint8_t *, size_t)> chunkCallback) override
Stream a file in chunks using a callback.
bool createDirectory(const std::string &path) override
Create a new directory.
bool removeDirectory(const std::string &path) override
Remove a directory.
bool remove(const std::string &path) override
Remove a file or directory.
static constexpr size_t FLASH_SIZE
128 KB
bool isMounted() const override
Check if the filesystem is mounted.
static int lfs_prog_cb(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size)
LittleFsStorageManager()
Construct the manager and configure the filesystem.
bool readFileString(const std::string &path, uint32_t startPosition, uint32_t length, std::string &buffer)
Read a file string into a memory buffer.
static constexpr size_t CACHE_SIZE
bool mount() override
Mount the LittleFS filesystem.
static constexpr uint32_t FLASH_BASE
static int lfs_read_cb(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size)
bool exists(const std::string &path) override
Check if a file or directory exists.
static int lfs_erase_cb_singlecore(const struct lfs_config *c, lfs_block_t block)
static int lfs_prog_cb_singlecore(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size)
bool listDirectory(const std::string &path, std::vector< FileInfo > &out) override
List files in a directory.
size_t getFileSize(const std::string &path) override
Get the size of a file.
bool readFile(const std::string &path, std::vector< uint8_t > &out) override
Read a file into a byte vector.
static SemaphoreHandle_t lfs_mutex
static int lfs_erase_cb(const struct lfs_config *c, lfs_block_t block)
static constexpr size_t READ_SIZE
static constexpr size_t BLOCK_SIZE
Abstract base class for storage access and file operations.