lfs_emubd.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Block device emulated on standard files
  3. *
  4. * Copyright (c) 2017 Christopher Haster
  5. * Distributed under the MIT license
  6. */
  7. #ifndef LFS_EMUBD_H
  8. #define LFS_EMUBD_H
  9. #include "lfs_config.h"
  10. #include "lfs_util.h"
  11. #include "lfs_bd.h"
  12. // Stats for debugging and optimization
  13. struct lfs_bd_stats {
  14. uint64_t read_count;
  15. uint64_t prog_count;
  16. uint64_t erase_count;
  17. };
  18. // The emu bd state
  19. typedef struct lfs_emubd {
  20. char *path;
  21. char *child;
  22. struct lfs_bd_info info;
  23. struct lfs_bd_stats stats;
  24. } lfs_emubd_t;
  25. // Create a block device using path for the directory to store blocks
  26. int lfs_emubd_create(lfs_emubd_t *emu, const char *path);
  27. // Clean up memory associated with emu block device
  28. void lfs_emubd_destroy(lfs_emubd_t *emu);
  29. // Read a block
  30. int lfs_emubd_read(lfs_emubd_t *bd, lfs_block_t block,
  31. lfs_off_t off, lfs_size_t size, void *buffer);
  32. // Program a block
  33. //
  34. // The block must have previously been erased.
  35. int lfs_emubd_prog(lfs_emubd_t *bd, lfs_block_t block,
  36. lfs_off_t off, lfs_size_t size, const void *buffer);
  37. // Erase a block
  38. //
  39. // A block must be erased before being programmed. The
  40. // state of an erased block is undefined.
  41. int lfs_emubd_erase(lfs_emubd_t *bd, lfs_block_t block,
  42. lfs_off_t off, lfs_size_t size);
  43. // Sync the block device
  44. int lfs_emubd_sync(lfs_emubd_t *bd);
  45. // Get a description of the block device
  46. //
  47. // Any unknown information may be left unmodified
  48. int lfs_emubd_info(lfs_emubd_t *bd, struct lfs_bd_info *info);
  49. // Get stats of operations on the block device
  50. //
  51. // Used for debugging and optimizations
  52. int lfs_emubd_stats(lfs_emubd_t *bd, struct lfs_bd_stats *stats);
  53. // Block device operations
  54. extern const struct lfs_bd_ops lfs_emubd_ops;
  55. #endif