-
Notifications
You must be signed in to change notification settings - Fork 133
Description
Environment
Using Sloeber 4.4 product on Macos 10.13.6; compiling for Wemos D1 mini board, using esp8266 platform 3.0.2 (SloeberProduct-V4.4.0_mac64.2021-07-04_06-48-31).
Problem
Some specific combinations of writes & seeks put DEL characters (0xff) into files, usually in place of CRLF (0x0d+0x0a). This problem only presents on Sloeber with SPIFFS. Compiling on the Arduino IDE or using LittleFS instead of SPIFFS on Sloeber eliminates the problem.
Here is an example program demonstrating the problem behaviour:
#include "Arduino.h"
#include <FS.h>
#define USE_SPIFFS X
#ifdef USE_SPIFFS
#define FileSys SPIFFS
#else
#include <LittleFS.h>
#define FileSys LittleFS
#endif
void setup()
{
/*
* write out 80 x's, then go back 6 characters and write 4 y's and a CR-LF
*/
FileSys.begin();
File f = FileSys.open("/writetest.txt", "w");
f.print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
f.seek(-6, SeekCur);
f.print("yyyy\r\n");
f.close();
/*
* dump the last 10 characters as bytes in hex
*/
unsigned char buff[120] = "";
char cbuff[120] = "";
f = FileSys.open("/writetest.txt", "r");
f.read(buff, 80);
for (int i=70; i<80; i++) {
sprintf(cbuff+(i-70)*3, "%02x ", buff[i]);
}
f.close();
/*
* print the dump out to the serial monitor
*/
Serial.begin(115200);
Serial.printf("output: |%s|\n", cbuff);
}
void loop()
{
delay(100);
}Incorrect output using SPIFFS
SDK:2.2.2-dev(38a443e)/Core:3.0.2=30002000/lwIP:STABLE-2_1_2_RELEASE/glue:1.2-48-g7421258/BearSSL:6105635
output: |78 78 78 78 79 79 79 79 ff ff |
Expected output produced using LittleFS
SDK:2.2.2-dev(38a443e)/Core:3.0.2=30002000/lwIP:STABLE-2_1_2_RELEASE/glue:1.2-48-g7421258/BearSSL:6105635
output: |78 78 78 78 79 79 79 79 0d 0a |
Notes
My apologies if this is the wrong forum for this problem, but I can only reproduce the bad behaviour using Sloeber. I have tried it out with a second Wemos board in case the first had a fault.
Deleting or adding an 'x' or a 'y' from the example above makes the problem go away. Also, it is possible the problem crops up without any seeks but I have not yet isolated an example.
I have now switched to using LittleFS, but I thought I should report this anyway. I would appreciate knowing if someone else can reproduce the problem.
I first encountered the problem using Log4Esp and it may be related to this report: hunsalz/log4Esp#9; however I was able to reduce the code to the short example above that does not use the logging library.
