34#ifndef _FREERTOS_DRIVERS_SPIFFS_SPIFFS_HXX_
35#define _FREERTOS_DRIVERS_SPIFFS_SPIFFS_HXX_
44typedef struct spiffs_t spiffs;
59 void mount(
const char *mount_point)
override
116 inline static void extern_lock(
struct spiffs_t *fs);
128 SPIFFS(
size_t physical_address,
size_t size_on_disk,
129 size_t erase_block_size,
size_t logical_block_size,
130 size_t logical_page_size,
size_t max_num_open_descriptors = 16,
131 size_t cache_pages = 8,
132 std::function<
void()> post_format_hook =
nullptr);
147 struct spiffs_t *fs,
unsigned addr,
unsigned size, uint8_t *dst);
155 struct spiffs_t *fs,
unsigned addr,
unsigned size, uint8_t *src);
162 struct spiffs_t *fs,
unsigned addr,
unsigned size);
168 virtual int32_t
flash_read(uint32_t addr, uint32_t size, uint8_t *dst) = 0;
174 virtual int32_t
flash_write(uint32_t addr, uint32_t size, uint8_t *src) = 0;
194 int open(
File *file,
const char *path,
int flags,
int mode)
override;
205 int unlink(
const char *path)
override;
213 ssize_t
read(
File *file,
void *buf,
size_t count)
override;
221 ssize_t
write(
File *file,
const void *buf,
size_t count)
override;
230 off_t
lseek(
File* f, off_t offset,
int whence)
override;
See OSMutexLock in os/OS.hxx.
Lightweight locking class for protecting small critical sections.
static const unsigned int numOpenFiles
static File files[]
File descriptor pool.
const char * name
device name
static OSMutex mutex
mutual exclusion for fileio
Base class for all File systems.
This class provides a mutex API.
void unlock()
Unlock a mutex.
Generic SPIFFS base class.
OSMutex lock_
whole file system lock
static void extern_unlock(struct spiffs_t *fs)
Provide mutex unlock.
ssize_t read(File *file, void *buf, size_t count) override
Read from a file or device.
int errno_translate(int spiffs_error)
Translate a SPIFFS specific error number to a standard POSIX errno.
ssize_t write(File *file, const void *buf, size_t count) override
Write to a file or device.
File * opendir(File *file, const char *name) override
Open a directory.
int fsync(File *file) override
Synchronize (flush) a file to disk.
void mount(const char *mount_point) override
Mount the file system.
int open(File *file, const char *path, int flags, int mode) override
Open a file or device.
off_t lseek(File *f, off_t offset, int whence) override
Seek method.
int fstat(File *file, struct stat *stat) override
Get the status information of a file or device.
int close(File *file) override
Close a file or device.
static int flash_read(struct spiffs_t *fs, unsigned addr, unsigned size, uint8_t *dst)
SPIFFS callback to read flash.
int closedir(File *file) override
Close a directory.
void unmount()
Flushes caches and unmounts the filesystem.
spiffs * fs_
file system instance metadata
std::function< void()> postFormatHook_
callback to be called post a formating operation
void flush_cache()
Performs a sync on all files that have had a write but no fsync call since then.
int stat(const char *path, struct stat *stat) override
Get the status information of a file or device.
int unlink(const char *path) override
Remove a file.
virtual int32_t flash_erase(uint32_t addr, uint32_t size)=0
SPIFFS callback to erase flash, in context.
static int flash_write(struct spiffs_t *fs, unsigned addr, unsigned size, uint8_t *src)
SPIFFS callback to write flash.
uint32_t fdSpaceSize_
size in bytes of the fdSpace_
static void extern_lock(struct spiffs_t *fs)
Provide mutex lock.
uint8_t * fdSpace_
file descriptor metadata
virtual int32_t flash_read(uint32_t addr, uint32_t size, uint8_t *dst)=0
SPIFFS callback to read flash, in context.
void * cache_
memory for cache
static int flash_erase(struct spiffs_t *fs, unsigned addr, unsigned size)
SPIFFS callback to erase flash.
struct dirent * readdir(File *file) override
Read the next entry in a directory.
void format() override
Format the file system, all data will be lost.
virtual int32_t flash_write(uint32_t addr, uint32_t size, uint8_t *src)=0
SPIFFS callback to write flash, in context.
uint32_t cacheSize_
size in bytes of cache_
uint8_t * workBuffer_
work buffer for the file system
bool formatted_
has the file system been formatted since last reboot?
bool anyDirty_
Bit that is set to 1 when any write operation happens to this FS.
int do_mount()
Helper to mount the file system.
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
Open directory metadata structure.
Directory entry structure.