Skip to content

Add time to filesystem API #6544

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

Merged
merged 8 commits into from
Oct 31, 2019
Merged

Conversation

earlephilhower
Copy link
Collaborator

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

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
@earlephilhower
Copy link
Collaborator Author

By removing the possibly data-corrupting changes required for SPIFFS time addition (see PR #6315), this PR should be able to be merged at 0 risk and pave the way for a future SPIFFS enhancement to include dynamic metadata and others (possibly w/the 3.0 partition table giving us the FS info as opposed to us manually poisoning things).

@earlephilhower earlephilhower added this to the 2.6.0 milestone Sep 21, 2019
Include the update mklittlefs which generated 't' metadata on imported
files.
	../tools/sdk/lwip2/include/netif/lowpan6_opts.h
Copy link
Collaborator

@d-a-v d-a-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
I'd add a note stating stored time is always local time for LittleFS
(like it's always been in msdos fat but not in modern FSes).

@devyte
Copy link
Collaborator

devyte commented Oct 4, 2019

I understand the FS is using local time stamps. If so, how about using global time instead, like real platforms? That would disallow problems with changing timezone, changing DST, updating time manually, etc.

@earlephilhower
Copy link
Collaborator Author

I understand the FS is using local time stamps. If so, how about using global time instead, like real platforms? That would disallow problems with changing timezone, changing DST, updating time manually, etc.

As we discussed online, this is what we're stuck with for SDFS/SD, since FAT doesn't use UTC, only local time. It is possible, however, for users to override the setTimeCallback() to return UTC if they wish for LittleFS (or even FAT) and documented in the File section.

Clean up some awkward object instantiations.

Remove the _enableTime flag/setter from SPIFFS.

Clean up the FSConfig constructors using C++ style init lists.
@earlephilhower
Copy link
Collaborator Author

I couldn't find a good way to use the enum for FSId (each class' enum was a unique type so there were ugly casts), so I settled on a static constextr uint32_t member in each with the ID. I believe that's the proper way to do it for something like this, but I'm open to suggestions on other ways.

@d-a-v d-a-v merged commit 72dd589 into esp8266:master Oct 31, 2019
@earlephilhower earlephilhower deleted the fs-timestamps branch October 31, 2019 14:27
@hellochenwang
Copy link

where is the function time(NULL) referred in FS.h?

@d-a-v
Copy link
Collaborator

d-a-v commented Nov 4, 2019

In tools/xtensa-lx106-elf/xtensa-lx106-elf/include/time.h
(this is newlib)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants