|
Open Model Railroad Network (OpenMRN)
|
Generic SPIFFS base class. More...
#include <SPIFFS.hxx>
Classes | |
| struct | OpenDir |
| Open directory metadata structure. More... | |
Public Member Functions | |
| void | mount (const char *mount_point) override |
| Mount the file system. | |
| void | format () override |
| Format the file system, all data will be lost. | |
| bool | is_any_dirty () |
| void | flush_cache () |
| Performs a sync on all files that have had a write but no fsync call since then. | |
Public Member Functions inherited from FileSystem | |
| FileSystem () | |
| Constructor. | |
| virtual | ~FileSystem () |
| Destructor. | |
Static Public Member Functions | |
| static void | extern_lock (struct spiffs_t *fs) |
| Provide mutex lock. | |
| static void | extern_unlock (struct spiffs_t *fs) |
| Provide mutex unlock. | |
Static Public Member Functions inherited from FileSystem | |
| static int | open (struct _reent *reent, const char *path, int flags, int mode) |
| Open a file or device. | |
| static int | close (struct _reent *reent, int fd) |
| Close a file or device. | |
| static int | unlink (struct _reent *reent, const char *path) |
| Remove a file. | |
| static int | stat (struct _reent *reent, const char *path, struct stat *stat) |
| Get the status information of a file or device. | |
| static int | fsync (int fd) |
| Synchronize (flush) a file to disk. | |
| static int | closedir (DIR *dirp) |
| Close a directory. | |
| static DIR * | opendir (const char *name) |
| Open a directory. | |
| static struct dirent * | readdir (DIR *dirp) |
| Read the next entry in a directory. | |
Static Public Member Functions inherited from FileIO | |
| static ssize_t | read (struct _reent *reent, int fd, void *buf, size_t count) |
| Read from a file or device. | |
| static ssize_t | write (struct _reent *reent, int fd, const void *buf, size_t count) |
| Write to a file or device. | |
| static _off_t | lseek (struct _reent *reent, int fd, _off_t offset, int whence) |
| Change the offset index of a file or device. | |
| static int | fstat (struct _reent *reent, int fd, struct stat *stat) |
| Get the status information of a file or device. | |
| static int | ioctl (int fd, unsigned long int key, unsigned long data) |
| Request and ioctl transaction. | |
| static int | fcntl (int fd, int cmd, unsigned long data) |
| Manipulate a file descriptor. | |
| static bool | is_device (int fd) |
| Test if the file descriptor belongs to a device. | |
Protected Member Functions | |
| SPIFFS (size_t physical_address, size_t size_on_disk, size_t erase_block_size, size_t logical_block_size, size_t logical_page_size, size_t max_num_open_descriptors=16, size_t cache_pages=8, std::function< void()> post_format_hook=nullptr) | |
| Constructor. | |
| ~SPIFFS () | |
| Destructor. | |
| void | unmount () |
| Flushes caches and unmounts the filesystem. | |
| virtual int32_t | flash_read (uint32_t addr, uint32_t size, uint8_t *dst)=0 |
| SPIFFS callback to read flash, in context. | |
| virtual int32_t | flash_write (uint32_t addr, uint32_t size, uint8_t *src)=0 |
| SPIFFS callback to write flash, in context. | |
| virtual int32_t | flash_erase (uint32_t addr, uint32_t size)=0 |
| SPIFFS callback to erase flash, in context. | |
Protected Member Functions inherited from FileIO | |
| FileIO (const char *name) | |
| Constructor. | |
| virtual | ~FileIO () |
| Destructor. | |
| virtual int | ioctl (File *file, unsigned long int key, unsigned long data) |
| Request an ioctl transaction. | |
| virtual int | fcntl (File *file, int cmd, unsigned long data) |
| Manipulate a file descriptor. | |
| virtual bool | select (File *file, int mode) |
| Device select method. | |
Static Protected Member Functions | |
| static int | flash_read (struct spiffs_t *fs, unsigned addr, unsigned size, uint8_t *dst) |
| SPIFFS callback to read flash. | |
| static int | flash_write (struct spiffs_t *fs, unsigned addr, unsigned size, uint8_t *src) |
| SPIFFS callback to write flash. | |
| static int | flash_erase (struct spiffs_t *fs, unsigned addr, unsigned size) |
| SPIFFS callback to erase flash. | |
Static Protected Member Functions inherited from FileIO | |
| static int | fd_alloc (void) |
| Allocate a free file descriptor. | |
| static void | fd_free (int fd) |
| Free up a file descriptor. | |
| static File * | file_lookup (int fd) |
| Looks up a reference to a File corresponding to a given file descriptor. | |
| static int | fd_lookup (File *file) |
| Looks up a file descriptor corresponding to a given File reference. | |
Protected Attributes | |
| spiffs * | fs_ |
| file system instance metadata | |
Protected Attributes inherited from FileIO | |
| const char * | name |
| device name | |
Private Member Functions | |
| int | open (File *file, const char *path, int flags, int mode) override |
| Open a file or device. | |
| int | close (File *file) override |
| Close a file or device. | |
| int | unlink (const char *path) override |
| Remove a file. | |
| ssize_t | read (File *file, void *buf, size_t count) override |
| Read from a file or device. | |
| ssize_t | write (File *file, const void *buf, size_t count) override |
| Write to 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 | stat (const char *path, struct stat *stat) override |
| Get the status information of a file or device. | |
| int | fsync (File *file) override |
| Synchronize (flush) a file to disk. | |
| int | closedir (File *file) override |
| Close a directory. | |
| File * | opendir (File *file, const char *name) override |
| Open a directory. | |
| struct dirent * | readdir (File *file) override |
| Read the next entry in a directory. | |
| int | errno_translate (int spiffs_error) |
| Translate a SPIFFS specific error number to a standard POSIX errno. | |
| int | do_mount () |
| Helper to mount the file system. | |
| DISALLOW_COPY_AND_ASSIGN (SPIFFS) | |
Private Member Functions inherited from Atomic | |
| void | lock () |
| void | unlock () |
Private Attributes | |
| std::function< void()> | postFormatHook_ |
| callback to be called post a formating operation | |
| OSMutex | lock_ |
| whole file system lock | |
| uint8_t * | workBuffer_ |
| work buffer for the file system | |
| uint32_t | fdSpaceSize_ |
| size in bytes of the fdSpace_ | |
| uint8_t * | fdSpace_ |
| file descriptor metadata | |
| uint32_t | cacheSize_ |
| size in bytes of cache_ | |
| void * | cache_ |
| memory for cache | |
| bool | formatted_: 1 |
| has the file system been formatted since last reboot? | |
| bool | anyDirty_: 1 |
| Bit that is set to 1 when any write operation happens to this FS. | |
Additional Inherited Members | |
Static Protected Attributes inherited from FileIO | |
| static const unsigned int | numOpenFiles = 20 |
| static File | files [] |
| File descriptor pool. | |
| static OSMutex | mutex |
| mutual exclusion for fileio | |
Generic SPIFFS base class.
Definition at line 48 of file SPIFFS.hxx.
|
protected |
Constructor.
| post_format_hook | method to be called after a clean format of the file system. This allows the user to prime a clean or factory reset file system with an initial set files. |
Definition at line 102 of file SPIFFS.cxx.
|
protected |
Destructor.
Definition at line 137 of file SPIFFS.cxx.
|
overrideprivatevirtual |
Close a file or device.
| file | file reference for this device |
| fd | file descriptor to close |
Implements FileIO.
Definition at line 253 of file SPIFFS.cxx.
|
overrideprivatevirtual |
Close a directory.
| file | file reference for this device |
Implements FileSystem.
Definition at line 455 of file SPIFFS.cxx.
|
private |
Helper to mount the file system.
Definition at line 189 of file SPIFFS.cxx.
|
private |
Translate a SPIFFS specific error number to a standard POSIX errno.
| spiffs_error | SPIFFS specific error number |
Definition at line 526 of file SPIFFS.cxx.
|
inlinestatic |
Provide mutex lock.
| fs | reference to the file system instance |
Definition at line 49 of file SPIFFS.cxx.
|
inlinestatic |
Provide mutex unlock.
| fs | reference to the file system instance |
Definition at line 54 of file SPIFFS.cxx.
|
staticprotected |
SPIFFS callback to erase flash.
| fs | reference to SPIFFS instance |
| addr | adddress location to erase |
| size | size of erase region in bytes |
Definition at line 94 of file SPIFFS.cxx.
|
protectedpure virtual |
SPIFFS callback to erase flash, in context.
| addr | adddress location to erase |
| size | size of erase region in bytes |
Implemented in TiSPIFFS< ERASE_PAGE_SIZE >, SpiSPIFFS, and Stm32SPIFFS.
|
staticprotected |
SPIFFS callback to read flash.
| fs | reference to SPIFFS instance |
| addr | adddress location to read |
| size | size of read in bytes |
| dst | destination buffer for read |
Definition at line 80 of file SPIFFS.cxx.
|
protectedpure virtual |
SPIFFS callback to read flash, in context.
| addr | adddress location to read |
| size | size of read in bytes |
| dst | destination buffer for read |
Implemented in TiSPIFFS< ERASE_PAGE_SIZE >, SpiSPIFFS, and Stm32SPIFFS.
|
staticprotected |
SPIFFS callback to write flash.
| fs | reference to SPIFFS instance |
| addr | adddress location to write |
| size | size of write in bytes |
| src | source buffer for write |
Definition at line 87 of file SPIFFS.cxx.
|
protectedpure virtual |
SPIFFS callback to write flash, in context.
| addr | adddress location to write |
| size | size of write in bytes |
| src | source buffer for write |
Implemented in TiSPIFFS< ERASE_PAGE_SIZE >, SpiSPIFFS, and Stm32SPIFFS.
|
inline |
Performs a sync on all files that have had a write but no fsync call since then.
This can be used by the caller to implement a background flush thread.
Definition at line 101 of file SPIFFS.hxx.
|
overridevirtual |
Format the file system, all data will be lost.
The file system must not be mounted at the time of calling this.
Implements FileSystem.
Definition at line 172 of file SPIFFS.cxx.
Get the status information of a file or device.
| file | file reference for this device |
| stat | structure to fill status info into |
Reimplemented from FileSystem.
Definition at line 390 of file SPIFFS.cxx.
|
overrideprivatevirtual |
Synchronize (flush) a file to disk.
| file | file reference for this device |
Implements FileSystem.
Definition at line 439 of file SPIFFS.cxx.
|
inline |
Definition at line 87 of file SPIFFS.hxx.
|
overrideprivatevirtual |
Seek method.
| f | file reference for this device |
| offset | offset in bytes from whence directive |
| whence | SEEK_SET if to set the file offset to an abosolute position, SEEK_CUR if to set the file offset from current position SEEK_END if to set the file offset to the end of the file |
Reimplemented from FileIO.
Definition at line 326 of file SPIFFS.cxx.
|
inlineoverridevirtual |
Mount the file system.
| mount_point | path in the root file system for the mount point. Must not contain any trailing '/' characters, e.g. "/usr", not "/usr/". Unlike in linux, each mount must be entirely unique point in the system. For example, mounting of both "/usr" and "/usr/bin" is is not supported. However, "/usr" and "/usr1" is supported. This saves on file open logic. |
Implements FileSystem.
Definition at line 59 of file SPIFFS.hxx.
|
overrideprivatevirtual |
Open a file or device.
| file | file reference for this device |
| path | file or device name |
| flags | open flags |
| mode | open mode, ignored in this implementation |
Implements FileIO.
Definition at line 200 of file SPIFFS.cxx.
Open a directory.
| file | file reference for this device |
| name | directory path |
Implements FileSystem.
Definition at line 474 of file SPIFFS.cxx.
|
overrideprivatevirtual |
Read from a file or device.
| file | file reference for this device |
| buf | location to place read data |
| count | number of bytes to read |
Implements FileIO.
Definition at line 286 of file SPIFFS.cxx.
Read the next entry in a directory.
| file | file reference for this device |
Implements FileSystem.
Definition at line 502 of file SPIFFS.cxx.
|
overrideprivatevirtual |
Get the status information of a file or device.
| path | file or device name |
| stat | structure to fill status info into |
Implements FileSystem.
Definition at line 410 of file SPIFFS.cxx.
|
overrideprivatevirtual |
Remove a file.
| path | file name |
Implements FileSystem.
Definition at line 271 of file SPIFFS.cxx.
|
protected |
Flushes caches and unmounts the filesystem.
The destructor of the derived class MUST call this function.
Definition at line 151 of file SPIFFS.cxx.
|
overrideprivatevirtual |
Write to a file or device.
| file | file reference for this device |
| buf | location to find write data |
| count | number of bytes to write |
Implements FileIO.
Definition at line 303 of file SPIFFS.cxx.
|
private |
Bit that is set to 1 when any write operation happens to this FS.
Definition at line 302 of file SPIFFS.hxx.
|
private |
memory for cache
Definition at line 296 of file SPIFFS.hxx.
|
private |
size in bytes of cache_
Definition at line 293 of file SPIFFS.hxx.
|
private |
file descriptor metadata
Definition at line 290 of file SPIFFS.hxx.
|
private |
size in bytes of the fdSpace_
Definition at line 287 of file SPIFFS.hxx.
|
private |
has the file system been formatted since last reboot?
Definition at line 299 of file SPIFFS.hxx.
|
protected |
file system instance metadata
Definition at line 182 of file SPIFFS.hxx.
|
private |
whole file system lock
Definition at line 281 of file SPIFFS.hxx.
|
private |
callback to be called post a formating operation
Definition at line 278 of file SPIFFS.hxx.
|
private |
work buffer for the file system
Definition at line 284 of file SPIFFS.hxx.