SPIFFS and fseek beyond file end

LaWi14
Posts: 10
Joined: Wed Nov 20, 2019 6:05 pm

SPIFFS and fseek beyond file end

Postby LaWi14 » Sun Nov 15, 2020 5:06 pm

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);
}

LaWi14
Posts: 10
Joined: Wed Nov 20, 2019 6:05 pm

Re: SPIFFS and fseek beyond file end

Postby LaWi14 » Mon Nov 16, 2020 12:01 pm

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.

davl233
Posts: 1
Joined: Wed Aug 31, 2022 7:12 am

Re: SPIFFS and fseek beyond file end

Postby davl233 » Wed Aug 31, 2022 7:23 am

thank you :!:

Who is online

Users browsing this forum: atx823, Bing [Bot], MicroController and 209 guests