Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc90c329

Browse files
authored
Track creation time of LittleFS FS (#7873)
1 parent22442f0 commitc90c329

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-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
returnrename(pathFrom.c_str(), pathTo.c_str());
442442
}
443443

444+
time_tFS::getCreationTime() {
445+
if (!_impl) {
446+
return0;
447+
}
448+
return _impl->getCreationTime();
449+
}
450+
444451
voidFS::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
boolgc();
236236
boolcheck();
237237

238+
time_tgetCreationTime();
239+
238240
voidsetTimeCallback(time_t (*cb)(void));
239241

240242
friendclass ::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
virtualboolrmdir(constchar* path) = 0;
116116
virtualboolgc() {returntrue; }// May not be implemented in all file systems.
117117
virtualboolcheck() {returntrue; }// May not be implemented in all file systems.
118+
virtualtime_tgetCreationTime() {return0; }// 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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,46 @@ class LittleFSImpl : public FSImpl
221221
returnfalse;
222222
}
223223

224+
if(_timeCallback &&_tryMount()) {
225+
// Mounting is required to set attributes
226+
227+
time_t t =_timeCallback();
228+
rc =lfs_setattr(&_lfs,"/",'c', &t,8);
229+
if (rc !=0) {
230+
DEBUGV("lfs_format, lfs_setattr 'c': rc=%d\n", rc);
231+
returnfalse;
232+
}
233+
234+
rc =lfs_setattr(&_lfs,"/",'t', &t,8);
235+
if (rc !=0) {
236+
DEBUGV("lfs_format, lfs_setattr 't': rc=%d\n", rc);
237+
returnfalse;
238+
}
239+
240+
lfs_unmount(&_lfs);
241+
_mounted =false;
242+
}
243+
224244
if (wasMounted) {
225245
return_tryMount();
226246
}
227247

228248
returntrue;
229249
}
230250

251+
time_tgetCreationTime()override {
252+
time_t t;
253+
uint32_t t32b;
254+
255+
if (lfs_getattr(&_lfs,"/",'c', &t,8) ==8) {
256+
return t;
257+
}elseif (lfs_getattr(&_lfs,"/",'c', &t32b,4) ==4) {
258+
return (time_t)t32b;
259+
}else {
260+
return0;
261+
}
262+
}
263+
231264

232265
protected:
233266
friendclassLittleFSFileImpl;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp