lfs_bd.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Block device interface
  3. *
  4. * Copyright (c) 2017 Christopher Haster
  5. * Distributed under the MIT license
  6. */
  7. #ifndef LFS_BD_H
  8. #define LFS_BD_H
  9. #include "lfs_config.h"
  10. // Opaque type for block devices
  11. typedef void lfs_bd_t;
  12. // Description of block devices
  13. struct lfs_bd_info {
  14. lfs_size_t read_size; // Size of readable block
  15. lfs_size_t prog_size; // Size of programmable block
  16. lfs_size_t erase_size; // Size of erase block
  17. uint64_t total_size; // Total size of the device
  18. };
  19. // Block device operations
  20. //
  21. // The little file system takes in a pointer to an opaque type
  22. // and this struct, all operations are passed the opaque pointer
  23. // which can be used to reference any state associated with the
  24. // block device
  25. struct lfs_bd_ops {
  26. // Read a block
  27. int (*read)(lfs_bd_t *bd, lfs_block_t block,
  28. lfs_off_t off, lfs_size_t size, void *buffer);
  29. // Program a block
  30. //
  31. // The block must have previously been erased.
  32. int (*prog)(lfs_bd_t *bd, lfs_block_t block,
  33. lfs_off_t off, lfs_size_t size, const void *buffer);
  34. // Erase a block
  35. //
  36. // A block must be erased before being programmed. The
  37. // state of an erased block is undefined.
  38. int (*erase)(lfs_bd_t *bd, lfs_block_t block,
  39. lfs_off_t off, lfs_size_t size);
  40. // Sync the block device
  41. int (*sync)(lfs_bd_t *bd);
  42. // Get a description of the block device
  43. //
  44. // Any unknown information may be left as zero
  45. int (*info)(lfs_bd_t *bd, struct lfs_bd_info *info);
  46. };
  47. #endif