Page 1 of 1

SPIFFS and fseek beyond file end

Posted: Sun Nov 15, 2020 5:06 pm
by LaWi14
I tried to enlarge an existing file by positioning the file pointer beyond the end of the file and writing a character there, expecting to have filled the characters in between w/ zeros. The code below works okay under Linux, but fseek fails with errno 5 (EIO) when tried on SPIFFS. Is this a known limitation?

Code:

Code: Select all

#include <stdio.h>

static const char *fname = "rota.log";
FILE *f;

int main(void)
{
    f = fopen(fname, "w");
    fputs("teststring", f);
    fclose(f);

    f = fopen(fname, "r+");
    fseek(f, 200, SEEK_END);
    fputc('Y', f);
    fclose(f);
}

Re: SPIFFS and fseek beyond file end

Posted: Mon Nov 16, 2020 12:01 pm
by LaWi14
To answer myself: SPIFFS cannot do this. Should have looked up this before posting.

From the SPIFFS wiki:

Seeking in a file

As opposed to posix, spiffs cannot create gaps in files. Sorry. You can seek around, but seeking beyond file end will promptly put the offset at the file end.


Sorry for having bothered you with this.

Re: SPIFFS and fseek beyond file end

Posted: Wed Aug 31, 2022 7:23 am
by davl233
thank you :!: