Change lfs_dir_read to return 0 on success #512
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If #491 is merged, it means breaking changes to the API, and a major version bump of some form (but not disk-breaking). This means it's a good time to look at open issues we couldn't fix early without breaking the API.
Here's a requested change to
lfs_dir_read
discussed in #114Before:
lfs_dir_read
returns 1lfs_dir_read
returns 0After:
lfs_dir_read
returns 0lfs_dir_read
returns LFS_ERR_NOENTFor some background:
lfs_dir_read
is a bit of an odd function. It's supposed to matchlfs_file_read
, but instead of reading bytes, it reads directory entries.Its POSIX equivalent, readdir, indicates whether or not we reached the end of the directory by returning a NULL pointer:
But this API needed to change for littlefs, since we don't use errno, instead returning errors as signed integers through all API functions, including
lfs_dir_read
. So, in an effort to matchlfs_file_read
,lfs_dir_read
returned the "number" of directory entries read, limited to either 0 or 1.Perhaps unsurprisingly, this turned out to be confusing to users, and a better API was proposed @hathach to instead return either 0 or LFS_ERR_NOENT, an error which can't occur for other reasons in lfs_dir_read.
Suggested by @hathach
Should fix #114