1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

Track creation time of LittleFS FS (#7873)

This commit is contained in:
Chris van Marle 2021-03-03 02:50:00 +01:00 committed by GitHub
parent 22442f0873
commit c90c329a48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 0 deletions

View File

@ -441,6 +441,13 @@ bool FS::rename(const String& pathFrom, const String& pathTo) {
return rename(pathFrom.c_str(), pathTo.c_str()); return rename(pathFrom.c_str(), pathTo.c_str());
} }
time_t FS::getCreationTime() {
if (!_impl) {
return 0;
}
return _impl->getCreationTime();
}
void FS::setTimeCallback(time_t (*cb)(void)) { void FS::setTimeCallback(time_t (*cb)(void)) {
if (!_impl) if (!_impl)
return; return;

View File

@ -235,6 +235,8 @@ public:
bool gc(); bool gc();
bool check(); bool check();
time_t getCreationTime();
void setTimeCallback(time_t (*cb)(void)); void setTimeCallback(time_t (*cb)(void));
friend class ::SDClass; // More of a frenemy, but SD needs internal implementation to get private FAT bits friend class ::SDClass; // More of a frenemy, but SD needs internal implementation to get private FAT bits

View File

@ -115,6 +115,7 @@ public:
virtual bool rmdir(const char* path) = 0; virtual bool rmdir(const char* path) = 0;
virtual bool gc() { return true; } // May not be implemented in all file systems. virtual bool gc() { return true; } // May not be implemented in all file systems.
virtual bool check() { return true; } // May not be implemented in all file systems. virtual bool check() { return true; } // May not be implemented in all file systems.
virtual time_t getCreationTime() { return 0; } // May not be implemented in all file systems.
// Filesystems *may* support a timestamp per-file, so allow the user to override with // Filesystems *may* support a timestamp per-file, so allow the user to override with
// their own callback for all files on this FS. The default implementation simply // their own callback for all files on this FS. The default implementation simply

View File

@ -221,6 +221,26 @@ public:
return false; return false;
} }
if(_timeCallback && _tryMount()) {
// Mounting is required to set attributes
time_t t = _timeCallback();
rc = lfs_setattr(&_lfs, "/", 'c', &t, 8);
if (rc != 0) {
DEBUGV("lfs_format, lfs_setattr 'c': rc=%d\n", rc);
return false;
}
rc = lfs_setattr(&_lfs, "/", 't', &t, 8);
if (rc != 0) {
DEBUGV("lfs_format, lfs_setattr 't': rc=%d\n", rc);
return false;
}
lfs_unmount(&_lfs);
_mounted = false;
}
if (wasMounted) { if (wasMounted) {
return _tryMount(); return _tryMount();
} }
@ -228,6 +248,19 @@ public:
return true; return true;
} }
time_t getCreationTime() override {
time_t t;
uint32_t t32b;
if (lfs_getattr(&_lfs, "/", 'c', &t, 8) == 8) {
return t;
} else if (lfs_getattr(&_lfs, "/", 'c', &t32b, 4) == 4) {
return (time_t)t32b;
} else {
return 0;
}
}
protected: protected:
friend class LittleFSFileImpl; friend class LittleFSFileImpl;