-
Notifications
You must be signed in to change notification settings - Fork 13.3k
WIP - Add time to SPIFFS for 3.0.0 #6315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
e315d0a
to
04c9ff9
Compare
Support the ESP32 File::getLastWrite() call and setting the time on all filesystems automatically (assuming the system clock has been set properly and time(NULL) returns the proper time!). Adds Dir::fileTime() to get the time of a file being listed, similar to Dir::fileName() and Dir::fileSize(). Adds ::setTimeCallback(time_t (*cb)()) to File, Dir, and FS, allowing users to override the default timestamp on a per-file, directory, or filesystem basis. By default, a simple callback returning time(nullptr) is implemented. LittleFS uses the 't' attribute and should be backwards compatible. SD/SDFS work and include wrappers for obsolete SdFat timestamp callbacks using the MSDOS time. SPIFFS has been updated to support either the existing on-flash format without any timestamps, or a new on-flash format with a flag area and a timestamp metadata element added. SPIFFS will try and mount any existing filesystem as non-timestamp, and continue to write them in the old format. New filesystems may be formatted to include timestamps (default) or in the old format, configurable via the SPIFFS.setConfig call. The SPIFFS work took as starting point all of work of @luc-github in esp8266#3730 and extended it into a backwards compatible mode by doing much surgery on the SPIFFS library itself and the on-flash format. Includes an updated SD/listfiles and SPIFFS_time example.
It seems more appropriate to use the config struct tio hold the meta-len and not the spiffs fs object itself. Cleans up the higher layewr code a bit, too.
Allow user overrides of SDFat configuration settings in platform.txt by bracketing the config.h file defines with ifndefs.
|
@luc-github, can you give this a look-see? I've got a way to make your SPIFFS change #3730 compatible with the existing flash layout, so that we don't have to wait until 3.0 or make people wipe their existing FSes. As you found out, SPIFFS unfortunately doesn't have anything like a FSInfo block describing the filesystem config options and it will happily mount a metadata=4 filesystem with a metadata=0 application (resulting in silent data corruption on reads and writes). The way I handled it was to add a poison page to the beginning of the FS flash space. At runtime I now check and see if the poison is there, and if so we know it's a new md=4 FS and mount(flashstart+4K). If it's not, then it's mounted as a md=0 FS. The poison also makes sure that old code can't mount and read/write corrupted data to a md=4 FS. |
Ho looks good - the trick is clever - thank you ^_^ |
Add time to filesystem and mkfs utility Fixes #3. Adds a 't' metadata attribute to all files added, and when listing or extracting restore according to the 't' attribute, if present. Compatible w/o an w/ esp8266/Arduino#6315 since LittleFS always has metadata support (and can silently ignore them if present but not used).
Functionality is there, but moving to WIP because I want to include a data protection test to either host tests or device tests that will verify the correct behavior (i.e. guarantee no corruption of a non-time, older FS, and that it preserves existing older FS w/o metadata when run with the new code; and guarantee that the new FS can not be mounted by the old code (which would also cause corruption since the old code cannot handle metadata). |
@earlephilhower postpone affect LittleFS also ? |
@luc-github ,For LittleFS there is 0 risk in adding this (attributes are part and parcel of the FS and don't affect any layout considerations), but unfortunately with this PR I've upgraded everything. So if SPIFFS doesn't go in, neither does SD or LittleFS. I will try to get a host test this weekend with a pre-built old-format and new-format FS. If that doesn't happen I can probably split this PR into one for LittleFS+SD and one for SPIFFS. The LittleFS can go in the next rev, no question, and the SPIFFS will be a matter of if it gets enough testing. I've worked at data storage companies for a long time, and the two worst words I can hear are "data corruption," so I want to make sure SPIFFS is solid. |
Thank you for your great contribution. I have implemented LittleFS support in my project. I was just checking if I can enable time support, and saw the postpone comment. |
Support the ESP32 File::getLastWrite() call and setting the time on all filesystems automatically (assuming the system clock has been set properly and time(NULL) returns the proper time!). Adds Dir::fileTime() to get the time of a file being listed, similar to Dir::fileName() and Dir::fileSize(). Adds ::setTimeCallback(time_t (*cb)()) to File, Dir, and FS, allowing users to override the default timestamp on a per-file, directory, or filesystem basis. By default, a simple callback returning time(nullptr) is implemented. LittleFS uses the 't' attribute and should be backwards compatible. SD/SDFS work and include wrappers for obsolete SdFat timestamp callbacks using the MSDOS time. This PR does not update SPIFFS, due to compatability concerns and a possible massive rewrite which would make it possible to determine if an old-style ot metadata enabled FS is present at mount time. Includes an updated SD/listfiles and LittleFS_time example. Replaces esp8266#6315
Replaced by #6544 |
Reopening just because, once #6544 is done, this PR will end up just being the changes to SPIFFS to make it support the metadata size as a variable. It's lots of little things, and will be used if/when we go to a partition setup with embedded FS info blocks to avoid the poison page added. So, not for 2.x, but I don't want to lose the SPIFFS changes which will still be needed (I think). |
* Add time to filesystem API Support the ESP32 File::getLastWrite() call and setting the time on all filesystems automatically (assuming the system clock has been set properly and time(NULL) returns the proper time!). Adds Dir::fileTime() to get the time of a file being listed, similar to Dir::fileName() and Dir::fileSize(). Adds ::setTimeCallback(time_t (*cb)()) to File, Dir, and FS, allowing users to override the default timestamp on a per-file, directory, or filesystem basis. By default, a simple callback returning time(nullptr) is implemented. LittleFS uses the 't' attribute and should be backwards compatible. SD/SDFS work and include wrappers for obsolete SdFat timestamp callbacks using the MSDOS time. This PR does not update SPIFFS, due to compatability concerns and a possible massive rewrite which would make it possible to determine if an old-style ot metadata enabled FS is present at mount time. Includes an updated SD/listfiles and LittleFS_time example. Replaces #6315 * Add links to new mklittlefs w/timestamp support Include the update mklittlefs which generated 't' metadata on imported files. ../tools/sdk/lwip2/include/netif/lowpan6_opts.h * Add explicit note about timestamp being local time * Address review concerns Clean up some awkward object instantiations. Remove the _enableTime flag/setter from SPIFFS. Clean up the FSConfig constructors using C++ style init lists.
According to the documentation of the file system |
@NicoZuid if you use LittleFS and SD, you'll be all set with a file write time. I updated SPIFFS to support it, too, but because it is a massive change and relies on a hack to determine which FS version is in use, you'll have to wait for V3.0 for SPIFFs. |
@earlephilhower, Thanks for your answer. |
That really sounds like a hardware issue. You need to be very careful with the voltages applied and pinout on the card/adapter. A SW issue could only scramble the data, at worst, and the card itself would still be recognized (but your OS would probably ask you to reformat). This really isn't the right spot for this, though. You'll be able to get more help on https://gitter.im/esp8266/Arduino . |
As mentioned above, the SD card was suddenly no longer usable on both the esp hardware and on a Windows PC. I have just been able to view the SD card with a PC with Ubuntu. |
Closing due to SPIFFS deprecation. I think the code's pretty solid, but I don't think it's appropriate to do such a massive change to a dead-end codebase. |
Support the ESP32 File::getLastWrite() call and setting the time on
all filesystems automatically (assuming the system clock has
been set properly and time(NULL) returns the proper time!).
Adds Dir::fileTime() to get the time of a file being listed, similar to
Dir::fileName() and Dir::fileSize().
Adds ::setTimeCallback(time_t (*cb)()) to File, Dir, and FS, allowing
users to override the default timestamp on a per-file, directory, or
filesystem basis. By default, a simple callback returning time(nullptr)
is implemented.
LittleFS uses the 't' attribute and should be backwards compatible.
SD/SDFS work and include wrappers for obsolete SdFat timestamp callbacks
using the MSDOS time.
SPIFFS has been updated to support either the existing on-flash format
without any timestamps, or a new on-flash format with a flag area and a
timestamp metadata element added.
SPIFFS will try and mount any existing filesystem as non-timestamp, and
continue to write them in the old format.
New filesystems may be formatted to include timestamps (default) or in
the old format, configurable via the SPIFFS.setConfig call.
The SPIFFS work took as starting point all of work of @luc-github in #3730
and extended it into a backwards compatible mode by doing much surgery
on the SPIFFS library itself and the on-flash format.
Includes an updated SD/listfiles and SPIFFS_time example.