lfs_sfd.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #
  2. #include "luat_base.h"
  3. #include "luat_sfd.h"
  4. #include "luat_mem.h"
  5. #include "lfs.h"
  6. #define LUAT_LOG_TAG "lfs2"
  7. #include "luat_log.h"
  8. int lfs_sfd_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) {
  9. sfd_drv_t *drv = (sfd_drv_t *)c->context;
  10. int ret = drv->opts->read(drv, buffer, block*4096+off, size);
  11. if (ret >= 0 && size >= ret) return LFS_ERR_OK;
  12. return LFS_ERR_IO;
  13. }
  14. // Program a region in a block. The block must have previously
  15. // been erased. Negative error codes are propogated to the user.
  16. // May return LFS_ERR_CORRUPT if the block should be considered bad.
  17. int lfs_sfd_prog(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) {
  18. sfd_drv_t *drv = (sfd_drv_t *)c->context;
  19. int ret = drv->opts->write(drv, buffer, block*4096+off, size);
  20. if (ret >= 0 && size >= ret) return LFS_ERR_OK;
  21. return LFS_ERR_IO;
  22. }
  23. // Erase a block. A block must be erased before being programmed.
  24. // The state of an erased block is undefined. Negative error codes
  25. // are propogated to the user.
  26. // May return LFS_ERR_CORRUPT if the block should be considered bad.
  27. int lfs_sfd_erase(const struct lfs_config *c, lfs_block_t block) {
  28. sfd_drv_t *drv = (sfd_drv_t *)c->context;
  29. int ret = drv->opts->erase(drv, block*4096, 4096);
  30. if (ret == 0) return LFS_ERR_OK;
  31. return LFS_ERR_IO;
  32. }
  33. // Sync the state of the underlying block device. Negative error codes
  34. // are propogated to the user.
  35. int lfs_sfd_sync(const struct lfs_config *c) {
  36. // sfd_drv_t *drv = (sfd_drv_t *)c->context;
  37. //drv->opts->ioctl(drv, ???);
  38. return 0;
  39. }