A LittleFS-based implementation of StorageManager, storing files in flash memory. More...
#include <LittleFsStorageManager.h>
Inheritance diagram for LittleFsStorageManager:
Collaboration diagram for LittleFsStorageManager:Public Member Functions | |
| LittleFsStorageManager () | |
| Construct the manager and configure the filesystem. | |
| std::unique_ptr< StorageFileReader > | openReader (const std::string &path) override |
| open a file for streaming read line access. | |
| bool | mount () override |
| Mount the LittleFS filesystem. | |
| bool | unmount () override |
| Unmount the LittleFS filesystem. | |
| bool | isMounted () const override |
| Check if the filesystem is mounted. | |
| bool | exists (const std::string &path) override |
| Check if a file or directory exists. | |
| bool | remove (const std::string &path) override |
| Remove a file or directory. | |
| bool | rename (const std::string &from, const std::string &to) override |
| Rename a file or directory. | |
| bool | readFile (const std::string &path, std::vector< uint8_t > &out) override |
| Read a file into a byte vector. | |
| bool | readFileString (const std::string &path, uint32_t startPosition, uint32_t length, std::string &buffer) |
| Read a file string into a memory buffer. | |
| bool | writeFile (const std::string &path, const std::vector< uint8_t > &data) override |
| Write a byte vector to a file (overwrite). | |
| bool | writeFile (const std::string &path, const unsigned char *data, size_t size) override |
| Write from a raw buffer. | |
| bool | appendToFile (const std::string &path, const uint8_t *data, size_t size) override |
| Append data to a file. | |
| bool | streamFile (const std::string &path, std::function< void(const uint8_t *, size_t)> chunkCallback) override |
| Stream a file in chunks using a callback. | |
| size_t | getFileSize (const std::string &path) override |
| Get the size of a file. | |
| bool | listDirectory (const std::string &path, std::vector< FileInfo > &out) override |
| List files in a directory. | |
| bool | createDirectory (const std::string &path) override |
| Create a new directory. | |
| bool | removeDirectory (const std::string &path) override |
| Remove a directory. | |
| bool | formatStorage () override |
| Format the filesystem. | |
| uintptr_t | getFlashBase () const |
| get Flash base address | |
| void | formatInner (bool *result) |
Public Member Functions inherited from StorageManager | |
| virtual | ~StorageManager ()=default |
Private Member Functions | |
| void | configure () |
| bool | autoMountIfNeeded () |
| Mount automatically if not mounted yet. | |
Static Private Member Functions | |
| static int | lfs_read_cb (const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) |
| 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) |
| static int | lfs_erase_cb (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) |
| static int | lfs_erase_cb_singlecore (const struct lfs_config *c, lfs_block_t block) |
| 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 int | lfs_erase_cb_multicore (const struct lfs_config *c, lfs_block_t block) |
| static int | lfs_lock (const struct lfs_config *c) |
| static int | lfs_unlock (const struct lfs_config *c) |
Private Attributes | |
| uintptr_t | flashBase = 0 |
| size_t | flashSize = 0 |
| lfs_t | lfs |
| struct lfs_config | config |
| bool | mounted = false |
Static Private Attributes | |
| static constexpr uint32_t | FLASH_BASE = 0x101E0000 |
| static constexpr size_t | FLASH_SIZE = 128 * 1024 |
| 128 KB | |
| static constexpr size_t | READ_SIZE = 256 |
| static constexpr size_t | PROG_SIZE = 256 |
| static constexpr size_t | BLOCK_SIZE = 4096 |
| static constexpr size_t | BLOCK_COUNT = FLASH_SIZE / BLOCK_SIZE |
| static constexpr size_t | CACHE_SIZE = 256 |
| static constexpr size_t | LOOKAHEAD_SIZE = 256 |
| static StaticSemaphore_t | lfs_mutex_buf |
| static SemaphoreHandle_t | lfs_mutex = xSemaphoreCreateMutexStatic(&lfs_mutex_buf) |
Automatically mounts on first access if not already mounted.
Definition at line 25 of file LittleFsStorageManager.h.
| LittleFsStorageManager::LittleFsStorageManager | ( | ) |
Definition at line 27 of file LittleFsStorageManager.cpp.
References configure().
Here is the call graph for this function:
|
overridevirtual |
| path | Path to the file. |
| data | Pointer to data. |
| size | Size of data in bytes. |
Implements StorageManager.
Definition at line 315 of file LittleFsStorageManager.cpp.
References lfs.
|
private |
|
private |
Definition at line 169 of file LittleFsStorageManager.cpp.
References __flash_lfs_end, __flash_lfs_start, config, flashBase, flashSize, lfs_erase_cb(), lfs_lock(), lfs_prog_cb(), lfs_read_cb(), and lfs_unlock().
Referenced by LittleFsStorageManager().
Here is the call graph for this function:
Here is the caller graph for this function:
|
overridevirtual |
| path | Path of directory. |
Implements StorageManager.
Definition at line 403 of file LittleFsStorageManager.cpp.
|
overridevirtual |
| path | Path to the file or directory. |
Implements StorageManager.
Definition at line 232 of file LittleFsStorageManager.cpp.
References lfs.
| void LittleFsStorageManager::formatInner | ( | bool * | result | ) |
|
overridevirtual |
Implements StorageManager.
Definition at line 420 of file LittleFsStorageManager.cpp.
References config, lfs, mount(), mounted, TRACE, and unmount().
Here is the call graph for this function:
|
overridevirtual |
| path | Path to the file. |
Implements StorageManager.
Definition at line 360 of file LittleFsStorageManager.cpp.
References lfs.
|
inline |
Definition at line 159 of file LittleFsStorageManager.h.
References flashBase.
Referenced by lfs_erase_cb_flashsafe(), and lfs_prog_multicore().
Here is the caller graph for this function:
|
overridevirtual |
Implements StorageManager.
Definition at line 227 of file LittleFsStorageManager.cpp.
References mounted.
|
staticprivate |
Definition at line 110 of file LittleFsStorageManager.cpp.
References lfs_erase_cb_multicore(), and lfs_erase_cb_singlecore().
Referenced by configure().
Here is the call graph for this function:
Here is the caller graph for this function:
|
staticprivate |
Definition at line 155 of file LittleFsStorageManager.cpp.
References flashBase, and lfs_erase_cb_flashsafe().
Referenced by lfs_erase_cb().
Here is the call graph for this function:
Here is the caller graph for this function:
|
staticprivate |
Definition at line 119 of file LittleFsStorageManager.cpp.
References flashBase.
Referenced by lfs_erase_cb().
Here is the caller graph for this function:
|
staticprivate |
Definition at line 32 of file LittleFsStorageManager.cpp.
References lfs_mutex.
Referenced by configure().
Here is the caller graph for this function:
|
staticprivate |
Definition at line 51 of file LittleFsStorageManager.cpp.
References lfs_prog_cb_multicore(), and lfs_prog_cb_singlecore().
Referenced by configure().
Here is the call graph for this function:
Here is the caller graph for this function:
|
staticprivate |
Definition at line 103 of file LittleFsStorageManager.cpp.
References flashBase, and lfs_prog_multicore().
Referenced by lfs_prog_cb().
Here is the call graph for this function:
Here is the caller graph for this function:
|
staticprivate |
Definition at line 62 of file LittleFsStorageManager.cpp.
References flashBase.
Referenced by lfs_prog_cb().
Here is the caller graph for this function:
|
staticprivate |
Definition at line 41 of file LittleFsStorageManager.cpp.
References flashBase.
Referenced by configure().
Here is the caller graph for this function:
|
staticprivate |
Definition at line 37 of file LittleFsStorageManager.cpp.
References lfs_mutex.
Referenced by configure().
Here is the caller graph for this function:
|
overridevirtual |
| path | Path to directory. |
| out | Vector to receive file entries. |
Implements StorageManager.
Definition at line 373 of file LittleFsStorageManager.cpp.
References FileInfo::isDirectory, FileInfo::isReadOnly, lfs, mount(), mounted, FileInfo::name, and FileInfo::size.
Here is the call graph for this function:
|
overridevirtual |
Implements StorageManager.
Definition at line 199 of file LittleFsStorageManager.cpp.
References config, lfs, mounted, and TRACE.
Referenced by formatStorage(), listDirectory(), and openReader().
Here is the caller graph for this function:
|
overridevirtual |
Implements StorageManager.
Definition at line 449 of file LittleFsStorageManager.cpp.
Here is the call graph for this function:
|
overridevirtual |
| path | Path to the file. |
| out | Output vector with file contents. |
Implements StorageManager.
Definition at line 249 of file LittleFsStorageManager.cpp.
References lfs.
|
virtual |
| path | Path to the file. |
| startPosition | Start position in the file. |
| length | Length of data to read. |
| buffer | Output string to fill with data. |
Implements StorageManager.
Definition at line 268 of file LittleFsStorageManager.cpp.
References lfs.
|
overridevirtual |
| path | Path to the file or directory. |
Implements StorageManager.
Definition at line 239 of file LittleFsStorageManager.cpp.
References lfs.
|
overridevirtual |
| path | Path of directory. |
Implements StorageManager.
Definition at line 415 of file LittleFsStorageManager.cpp.
References lfs.
|
overridevirtual |
| from | Source path. |
| to | Destination path. |
Implements StorageManager.
Definition at line 244 of file LittleFsStorageManager.cpp.
References lfs.
|
overridevirtual |
| path | Path to the file. |
| chunkCallback | Callback to receive chunks. |
Implements StorageManager.
Definition at line 335 of file LittleFsStorageManager.cpp.
References HTTP_BUFFER_SIZE, and lfs.
|
overridevirtual |
Implements StorageManager.
Definition at line 217 of file LittleFsStorageManager.cpp.
Referenced by formatStorage().
Here is the caller graph for this function:
|
overridevirtual |
| path | Path to the file. |
| data | Data to write. |
Implements StorageManager.
Definition at line 290 of file LittleFsStorageManager.cpp.
References lfs.
|
overridevirtual |
Implements StorageManager.
Definition at line 300 of file LittleFsStorageManager.cpp.
|
staticconstexprprivate |
Definition at line 176 of file LittleFsStorageManager.h.
|
staticconstexprprivate |
Definition at line 175 of file LittleFsStorageManager.h.
|
staticconstexprprivate |
Definition at line 177 of file LittleFsStorageManager.h.
|
private |
Definition at line 181 of file LittleFsStorageManager.h.
Referenced by configure(), formatStorage(), and mount().
|
staticconstexprprivate |
Definition at line 170 of file LittleFsStorageManager.h.
|
staticconstexprprivate |
Definition at line 171 of file LittleFsStorageManager.h.
|
private |
Definition at line 167 of file LittleFsStorageManager.h.
Referenced by configure(), getFlashBase(), lfs_erase_cb_multicore(), lfs_erase_cb_singlecore(), lfs_prog_cb_multicore(), lfs_prog_cb_singlecore(), and lfs_read_cb().
|
private |
Definition at line 168 of file LittleFsStorageManager.h.
Referenced by configure().
|
private |
Definition at line 180 of file LittleFsStorageManager.h.
Referenced by appendToFile(), createDirectory(), exists(), formatStorage(), getFileSize(), listDirectory(), mount(), openReader(), readFile(), readFileString(), remove(), removeDirectory(), rename(), streamFile(), unmount(), writeFile(), and writeFile().
|
staticprivate |
Definition at line 188 of file LittleFsStorageManager.h.
Referenced by lfs_lock(), and lfs_unlock().
|
staticprivate |
Definition at line 187 of file LittleFsStorageManager.h.
|
staticconstexprprivate |
Definition at line 178 of file LittleFsStorageManager.h.
|
private |
Definition at line 183 of file LittleFsStorageManager.h.
Referenced by formatStorage(), isMounted(), listDirectory(), mount(), unmount(), and writeFile().
|
staticconstexprprivate |
Definition at line 174 of file LittleFsStorageManager.h.
|
staticconstexprprivate |
Definition at line 173 of file LittleFsStorageManager.h.