Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

LittleFS: add overrides for Stream::send #8386

Merged
merged 3 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cores/esp8266/FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ class File : public Stream
time_t getCreationTime();
void setTimeCallback(time_t (*cb)(void));

// Stream::send configuration

bool inputCanTimeout () override {
// unavailable data can't become later available
return false;
}

bool outputCanTimeout () override {
// free space for write can't increase later
return false;
}

protected:
FileImplPtr _p;
time_t (*_timeCallback)(void) = nullptr;
Expand Down
11 changes: 11 additions & 0 deletions libraries/LittleFS/examples/SpeedTest/SpeedTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,24 @@ void DoTest(FS *fs) {
f.close();
stop = millis();
Serial.printf("==> Time to read 64KB in 1b chunks = %lu milliseconds = %s\n", stop - start, rate(start, stop, 65536));


start = millis();
auto dest = fs->open("/test1bw.bin", "w");
f = fs->open("/test1b.bin", "r");
auto copysize = f.sendAll(dest);
dest.close();
stop = millis();
Serial.printf("==> Time to copy %d = %zd bytes = %lu milliseconds = %s\n", f.size(), copysize, stop - start, rate(start, stop, f.size()));
f.close();
}

void setup() {
Serial.begin(115200);
Serial.printf("Beginning test\n");
Serial.flush();
DoTest(&TESTFS);
Serial.println("done");
}

void loop() {
Expand Down
26 changes: 25 additions & 1 deletion libraries/LittleFS/src/LittleFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class LittleFSImpl : public FSImpl
DEBUGV("lfs_format, lfs_setattr 't': rc=%d\n", rc);
return false;
}

lfs_unmount(&_lfs);
_mounted = false;
}
Expand Down Expand Up @@ -372,6 +372,30 @@ class LittleFSFileImpl : public FileImpl
}
}

int availableForWrite () override {
if (!_opened || !_fd) {
return 0;
}

const auto f = _getFD();
const auto fs = _fs->getFS();

// check for remaining size in current block
// ignore inline feature (per code in lfs_file_rawwrite())
auto afw = fs->cfg->block_size - f->off;

if (afw == 0) {
// current block is full
// check for filesystem full (per code in lfs_alloc())
if (!(fs->free.i == fs->free.size && fs->free.ack == 0)) {
// fs is not full, return a full sector as free space
afw = fs->cfg->block_size;
}
}

return afw;
}

size_t write(const uint8_t *buf, size_t size) override {
if (!_opened || !_fd || !buf) {
return 0;
Expand Down