Skip to content

Commit a9302bc

Browse files
Free space of overwritten files in LittleFS
Fixes esp8266#7426 LittleFS doesn't update the on-flash data structures when a file is reopened as O_TRUNC until the file is closed. This means the space of the original, inaccessible file cannot be used, causing OOS errors in cases when a large file is being overwritten. Explicitly call the file sync operation to update the on-flash metadata as soon as a file is opened. For normal files it's a no-op, but for O_TRUNC modes it will free the space, allowing full overwrite of large files.
1 parent 7b48b9d commit a9302bc

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

libraries/LittleFS/src/LittleFS.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ FileImplPtr LittleFSImpl::open(const char* path, OpenMode openMode, AccessMode a
8787
// a directory whose name we are carrying around but which cannot be read or written
8888
return std::make_shared<LittleFSFileImpl>(this, path, nullptr, flags, creation);
8989
} else if (rc == 0) {
90+
lfs_file_sync(&_lfs, fd.get());
9091
return std::make_shared<LittleFSFileImpl>(this, path, fd, flags, creation);
9192
} else {
9293
DEBUGV("LittleFSDirImpl::openFile: rc=%d fd=%p path=`%s` openMode=%d accessMode=%d err=%d\n",

0 commit comments

Comments
 (0)