littlefs-project / littlefs

A little fail-safe filesystem designed for microcontrollers
BSD 3-Clause "New" or "Revised" License
4.9k stars 771 forks source link

lfs_filebd.c seems to assume errno values #946

Open yamt opened 4 months ago

yamt commented 4 months ago

functions in lfs_filebd.c (eg. lfs_filebd_read) returns a negative errno. (eg. -errno) it doesn't necessarily match with enum lfs_error values.

geky commented 4 months ago

Hi @yamt, thanks for creating an issue.

Ah yes, I can see where this could be an problem.

The exact solution though seems a bit unclear. We really shouldn't be mapping all OS errors into littlefs errors in the bd since 1. littlefs doesn't define all OS errors and 2. this can mess up littlefs internals.

These should probably all be mapped to LFS_ERR_IO, though it's a shame to lose the extra error info. At least lfs_filebd_create can return some of the more useful errors, which is where we call open.


I'm curious, did you run into an actual error during use? From what I understand most modern OSs read/write/lseek don't really ever error unless you yank the harddrive out of the machine.

yamt commented 4 months ago

Hi @yamt, thanks for creating an issue.

Ah yes, I can see where this could be an problem.

The exact solution though seems a bit unclear. We really shouldn't be mapping all OS errors into littlefs errors in the bd since 1. littlefs doesn't define all OS errors and 2. this can mess up littlefs internals.

These should probably all be mapped to LFS_ERR_IO, though it's a shame to lose the extra error info. At least lfs_filebd_create can return some of the more useful errors, which is where we call open.

i guess leaving the original errno in LFS_FILEBD_TRACE is good enough.

I'm curious, did you run into an actual error during use? From what I understand most modern OSs read/write/lseek don't really ever error unless you yank the harddrive out of the machine.

no. i was just reading the code.