Modifying SPIFFS to allow direct sector access
Posted: Wed Oct 31, 2018 5:57 pm
I need random access to write sectors of a file. I receive data in mostly sequential order, but I need to go back to patch some sectors when I receive them (ESPNOW). All access is sector-sized (1kB). Only 2 functions would be needed:
- spiffs_allocate(file, size) - sets the file-size and reserves the necessary amount of sectors
- spiffs_write_sector(file, sector, contents) - write a sector (once suffices)
Maybe these functions already exist?? spiffs_allocate() would be similar to ftruncate() under POSIX.
fopen, fread, fwrite would continue to work as normal.
Alternatively, I could give up on the wear levelling and the flexibility SPIFFS offers and use an OTA partition to receive and compose the file at known sector locations. Most files are in fact several types of firmwares.
I'm new to the spiffs internals, any help much appreciated!
PS note that using the C API would be possible, but cumbersome, slow, destructive to the flash, and energy inefficient to the point of not being viable.
- spiffs_allocate(file, size) - sets the file-size and reserves the necessary amount of sectors
- spiffs_write_sector(file, sector, contents) - write a sector (once suffices)
Maybe these functions already exist?? spiffs_allocate() would be similar to ftruncate() under POSIX.
fopen, fread, fwrite would continue to work as normal.
Alternatively, I could give up on the wear levelling and the flexibility SPIFFS offers and use an OTA partition to receive and compose the file at known sector locations. Most files are in fact several types of firmwares.
I'm new to the spiffs internals, any help much appreciated!
PS note that using the C API would be possible, but cumbersome, slow, destructive to the flash, and energy inefficient to the point of not being viable.