lfs_bd.h 1.6 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 write_size; // Size of programmable block
  16. lfs_size_t erase_size; // Size of erase block
  17. lfs_lsize_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. lfs_error_t (*read)(lfs_bd_t *bd, uint8_t *buffer,
  28. lfs_ino_t ino, lfs_off_t off, lfs_size_t size);
  29. // Program a block
  30. //
  31. // The block must have previously been erased.
  32. lfs_error_t (*write)(lfs_bd_t *bd, const uint8_t *buffer,
  33. lfs_ino_t ino, lfs_off_t off, lfs_size_t size);
  34. // Erase a block
  35. //
  36. // A block must be erased before being programmed. The
  37. // state of an erased block is undefined.
  38. lfs_error_t (*erase)(lfs_bd_t *bd,
  39. lfs_ino_t ino, lfs_off_t off, lfs_size_t size);
  40. // Sync the block device
  41. lfs_error_t (*sync)(lfs_bd_t *bd);
  42. // Get a description of the block device
  43. //
  44. // Any unknown information may be left as zero
  45. lfs_error_t (*info)(lfs_bd_t *bd, struct lfs_bd_info *info);
  46. };
  47. #endif