littlefs icon indicating copy to clipboard operation
littlefs copied to clipboard

[question] confirm short-read/write behavior of lfs_file_{read,write}()

Open swetland opened this issue 3 years ago • 0 comments

As the documentation is sparse here, I read through the code to attempt to answer the question "do I need to be prepared to call lfs_file_read() or lfs_file_write() repeatedly for large reads or writes?" and I believe the answer is "no" and the return situation for those API calls can be summarized as:

lfs_file_read()

  • returns a negative error code on error
  • if data was partially read before the error occurred, this is not indicated
  • returns requested read size on a successful (full) read
  • returns smaller read size on a successful (partial) read that reaches the end of file

lfs_file_write()

  • returns a negative error code on error
  • if data was partially written before the error occurred, this is not indicated
  • returns requested write size on successful (full) write

If these are correct summaries and especially if this is the intended behavior and not expected to change, it would be nice to update the documentation in lfs.h to reflect it.

swetland avatar Aug 31 '22 08:08 swetland