• It turns out you can reproduce reliably with:

    function dump() {
      var addr = 0x60000000;
      for (var p=0;p<2;p++) {
        print("PAGE +"+p);
        for (var i=0;i<4096;i+=32) {
          print(addr.toString(16).padStart(8,0), require("Flash").read(32,addr).slice().map(x=>x.toString(16).padStart(2,0)).join(" "));
          addr += 32;
        }
      }
    }
    
    var s = require("Storage");
    s.eraseAll();
    a = new Uint8Array(5000); a.fill(255);
    s.write("test1",a)
    s.write("test2","This is my test that I hope will have disappeared")
    a = new Uint8Array(4090); a.fill(255);
    s.write("test3",a)
    s.erase("test1");
    s.compact();
    // Get address of last file's beginning
    var fileName = require("Storage").list().pop();
    var addr = peek32(E.getAddressOf(require("Storage").read(fileName)));
    print(fileName, "0x"+addr.toString(16), require("Storage").read(fileName).length+" bytes", "end 0x"+(addr+require("Storage").read(fileName).length).toString(16));
    // shows data in middle of second page, past the end of the last file
    dump(); 
    // if you write now you get 'Uncaught Error: File already written with different data' 
    for (var i=0;i<20;i++) require("Storage").write("newfile","Hello World "+Math.random());
    

    So it's a tricky one because often right after a compact the storage will look ok, but it's only when you start writing new files to it that soon you'll get an error and everything falls apart.

    The absolute latest firmware build should now have this fixed!

About

Avatar for Gordon @Gordon started