Skip to content

Commit f9bd73c

Browse files
committed
LittleFS: add reading FS creation time
1 parent f42ab61 commit f9bd73c

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

cores/esp8266/FS.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,13 @@ bool FS::rename(const String& pathFrom, const String& pathTo) {
441441
return rename(pathFrom.c_str(), pathTo.c_str());
442442
}
443443

444+
time_t FS::getCreationTime() {
445+
if (!_impl) {
446+
return 0;
447+
}
448+
return _impl->getCreationTime();
449+
}
450+
444451
void FS::setTimeCallback(time_t (*cb)(void)) {
445452
if (!_impl)
446453
return;

cores/esp8266/FS.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ class FS
235235
bool gc();
236236
bool check();
237237

238+
time_t getCreationTime();
239+
238240
void setTimeCallback(time_t (*cb)(void));
239241

240242
friend class ::SDClass; // More of a frenemy, but SD needs internal implementation to get private FAT bits

cores/esp8266/FSImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class FSImpl {
115115
virtual bool rmdir(const char* path) = 0;
116116
virtual bool gc() { return true; } // May not be implemented in all file systems.
117117
virtual bool check() { return true; } // May not be implemented in all file systems.
118+
virtual time_t getCreationTime() { return -1; } // May not be implemented in all file systems.
118119

119120
// Filesystems *may* support a timestamp per-file, so allow the user to override with
120121
// their own callback for all files on this FS. The default implementation simply

libraries/LittleFS/src/LittleFS.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,19 @@ class LittleFSImpl : public FSImpl
228228
return true;
229229
}
230230

231+
time_t getCreationTime() override {
232+
time_t t;
233+
uint32_t t32b;
234+
235+
if (lfs_getattr(&_lfs, "/", 'c', &t, 8) == 8) {
236+
return t;
237+
} else if (lfs_getattr(&_lfs, "/", 'c', &t32b, 4) == 4) {
238+
return (time_t)t32b;
239+
} else {
240+
return 0;
241+
}
242+
}
243+
231244

232245
protected:
233246
friend class LittleFSFileImpl;

0 commit comments

Comments
 (0)