Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Zero-size files cannot be read #44

Closed
rojer opened this issue Sep 3, 2015 · 2 comments
Closed

Zero-size files cannot be read #44

rojer opened this issue Sep 3, 2015 · 2 comments

Comments

@rojer
Copy link
Contributor

rojer commented Sep 3, 2015

An empty file (zero bytes) can be successfully written but cannot be read.
The errno returned is -10015 (SPIFFS_ERR_INDEX_REF_FREE)

@rojer
Copy link
Contributor Author

rojer commented Sep 3, 2015

code:

    FILE *f = fopen("fs2.spiffs", "r");
    int n = fread(image, 1, image_size, f);
    printf("%d bytes\n", n);
    mem_spiffs_mount(); /* this mounts SPIFFS at global fs variable */

    char x[1000];
    int sfd = SPIFFS_open(&fs, "0.bytes", SPIFFS_RDONLY, 0);
    printf("sfd = %d\n", sfd);
    int nr = SPIFFS_read(&fs, sfd, x, 100);
    printf("nr = %d errno = %d\n", nr, SPIFFS_errno(&fs));

output:

65536 bytes
sfd = 1
nr = -1 errno = -10015

if i change it to read 2.bytes instead (another file on the same filesystem), it works:

65536 bytes
sfd = 1
nr = 2 errno = 0

@pellepl
Copy link
Owner

pellepl commented Sep 3, 2015

Ah, good finding! Hadn't thought of that. Will fix after next week, on a
trip.

Cheers!
Den 3 sep 2015 19:10 skrev "rojer" notifications@github.com:

code:

FILE *f = fopen("fs2.spiffs", "r");
int n = fread(image, 1, image_size, f);
printf("%d bytes\n", n);
mem_spiffs_mount(); /* this mounts SPIFFS at global fs variable */

char x[1000];
int sfd = SPIFFS_open(&fs, "0.bytes", SPIFFS_RDONLY, 0);
printf("sfd = %d\n", sfd);
int nr = SPIFFS_read(&fs, sfd, x, 100);
printf("nr = %d errno = %d\n", nr, SPIFFS_errno(&fs));

output:

65536 bytes
sfd = 1
nr = -1 errno = -10015

if i change it to read 2.bytes instead (another file on the same
filesystem), it works:

65536 bytes
sfd = 1
nr = 2 errno = 0


Reply to this email directly or view it on GitHub
#44 (comment).

pellepl added a commit that referenced this issue Sep 14, 2015
Will now return correct error code.
@pellepl pellepl closed this as completed Sep 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants