lfs_emubd.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_bd.h"
  11. // Stats for debugging and optimization
  12. struct lfs_bd_stats {
  13. lfs_lword_t read_count;
  14. lfs_lword_t write_count;
  15. lfs_lword_t erase_count;
  16. };
  17. // The emu bd state
  18. typedef struct lfs_emubd {
  19. char *path;
  20. char *child;
  21. struct lfs_bd_info info;
  22. struct lfs_bd_stats stats;
  23. } lfs_emubd_t;
  24. // Create a block device using path for the directory to store blocks
  25. lfs_error_t lfs_emubd_create(lfs_emubd_t *emu, const char *path);
  26. // Clean up memory associated with emu block device
  27. void lfs_emubd_destroy(lfs_emubd_t *emu);
  28. // Read a block
  29. lfs_error_t lfs_emubd_read(lfs_emubd_t *bd, uint8_t *buffer,
  30. lfs_ino_t ino, lfs_off_t off, lfs_size_t size);
  31. // Program a block
  32. //
  33. // The block must have previously been erased.
  34. lfs_error_t lfs_emubd_write(lfs_emubd_t *bd, const uint8_t *buffer,
  35. lfs_ino_t ino, lfs_off_t off, lfs_size_t size);
  36. // Erase a block
  37. //
  38. // A block must be erased before being programmed. The
  39. // state of an erased block is undefined.
  40. lfs_error_t lfs_emubd_erase(lfs_emubd_t *bd,
  41. lfs_ino_t ino, lfs_off_t off, lfs_size_t size);
  42. // Sync the block device
  43. lfs_error_t lfs_emubd_sync(lfs_emubd_t *bd);
  44. // Get a description of the block device
  45. //
  46. // Any unknown information may be left unmodified
  47. lfs_error_t lfs_emubd_info(lfs_emubd_t *bd, struct lfs_bd_info *info);
  48. // Get stats of operations on the block device
  49. //
  50. // Used for debugging and optimizations
  51. lfs_error_t lfs_emubd_stats(lfs_emubd_t *bd, struct lfs_bd_stats *stats);
  52. // Block device operations
  53. extern const struct lfs_bd_ops lfs_emubd_ops;
  54. #endif