lfs_bd.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. // Description of block devices
  11. struct lfs_bd_info {
  12. lfs_size_t read_size; // Size of readable block
  13. lfs_size_t write_size; // Size of programmable block
  14. lfs_size_t erase_size; // Size of erase block
  15. lfs_lsize_t total_size; // Total size of the device
  16. };
  17. // Block device operations
  18. //
  19. // The little file system takes in a pointer to an opaque type
  20. // and this struct, all operations are passed the opaque pointer
  21. // which can be used to reference any state associated with the
  22. // block device
  23. struct lfs_bd_ops {
  24. // Read a block
  25. lfs_error_t (*read)(void *bd, uint8_t *buffer,
  26. lfs_ino_t ino, lfs_off_t off, lfs_size_t size);
  27. // Program a block
  28. //
  29. // The block must have previously been erased.
  30. lfs_error_t (*write)(void *bd, const uint8_t *buffer,
  31. lfs_ino_t ino, lfs_off_t off, lfs_size_t size);
  32. // Erase a block
  33. //
  34. // A block must be erased before being programmed. The
  35. // state of an erased block is undefined.
  36. lfs_error_t (*erase)(void *bd,
  37. lfs_ino_t ino, lfs_off_t off, lfs_size_t size);
  38. // Sync the block device
  39. lfs_error_t (*sync)(void *bd);
  40. // Get a description of the block device
  41. //
  42. // Any unknown information may be left as zero
  43. lfs_error_t (*info)(void *bd, struct lfs_bd_info *info);
  44. };
  45. #endif