Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
FatFsStorageManager.h
Go to the documentation of this file.
1
16#pragma once
17
18#include <string>
19#include <vector>
20#include <functional>
21#include <cstdint>
22#include "StorageManager.h"
23#include "FreeRTOS.h"
24#include "semphr.h"
25
31{
32public:
37
42 bool mount() override;
43
48 bool unmount() override;
49
54 bool exists(const std::string &path) override;
55
61 bool remove(const std::string &path) override;
62
70 bool rename(const std::string &from, const std::string &to) override;
71
78 bool readFile(const std::string &path, std::vector<uint8_t> &buffer) override;
79
88 bool readFileString(const std::string &path, uint32_t startPosition, uint32_t length, std::string &buffer);
89
96 bool writeFile(const std::string &path, const std::vector<uint8_t> &data) override;
97
105 bool writeFile(const std::string& path, const unsigned char* data, size_t size) override;
106
114 bool streamFile(const std::string &path, std::function<void(const uint8_t *, size_t)> chunkCallback) override;
115
122 bool listDirectory(const std::string &path, std::vector<FileInfo> &out) override;
123
129 bool createDirectory(const std::string &path) override;
130
137 bool removeDirectory(const std::string &path) override;
138
144 size_t getFileSize(const std::string &path) override;
145
156 bool appendToFile(const std::string &path, const uint8_t *data, size_t size) override;
157
163 bool isMounted() const override;
164
170 bool formatStorage() override;
171
177 std::unique_ptr<StorageFileReader> openReader(const std::string& path) override;
178
179
180private:
181 bool mounted = false;
182 std::string mountPoint = "sd0";
183
184 SemaphoreHandle_t mutex;
185
186 std::string resolvePath(const std::string &path) const;
187
188 bool ensureMounted();
189
190 bool probeMountPoint(); // Check if the mount point is valid
191
192 void refreshMountState();
193};
Abstract interface for file and directory storage backends.
Concrete implementation of StorageManager using FatFs.
bool rename(const std::string &from, const std::string &to) override
Rename a file or directory.
bool exists(const std::string &path) override
Check if the path exists.
bool formatStorage() override
Format the storage device.
bool unmount() override
Unmount the filesystem.
FatFsStorageManager()
Construct a new FatFsStorageManager object.
bool mount() override
Mount the filesystem at the specified mount point.
bool createDirectory(const std::string &path) override
Create a directory at the specified path.
bool writeFile(const std::string &path, const std::vector< uint8_t > &data) override
Write a memory buffer to a file.
bool mounted
Indicates if the filesystem is currently mounted.
bool readFileString(const std::string &path, uint32_t startPosition, uint32_t length, std::string &buffer)
Read a file string into a std::string.
bool streamFile(const std::string &path, std::function< void(const uint8_t *, size_t)> chunkCallback) override
Stream a file in chunks via callback.
std::string mountPoint
Default mount point.
size_t getFileSize(const std::string &path) override
Get the size of a file.
bool appendToFile(const std::string &path, const uint8_t *data, size_t size) override
Append data to a file.
bool removeDirectory(const std::string &path) override
Remove a directory at the specified path.
bool listDirectory(const std::string &path, std::vector< FileInfo > &out) override
List the contents of a directory.
std::string resolvePath(const std::string &path) const
Helper function to normalize full path based on mountPoint and relative path.
bool isMounted() const override
Check if the filesystem is currently mounted.
bool readFile(const std::string &path, std::vector< uint8_t > &buffer) override
Read a file into a memory buffer.
bool remove(const std::string &path) override
Remove a file or directory at the specified path.
std::unique_ptr< StorageFileReader > openReader(const std::string &path) override
open a file for streaming read access.
SemaphoreHandle_t mutex
Optional lock for thread safety.
Abstract base class for storage access and file operations.