lfs_emubd.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Block device emulated on standard files
  3. *
  4. * Copyright (c) 2017, Arm Limited. All rights reserved.
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef LFS_EMUBD_H
  8. #define LFS_EMUBD_H
  9. #include "lfs.h"
  10. #include "lfs_util.h"
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif
  15. // Config options
  16. #ifndef LFS_EMUBD_ERASE_VALUE
  17. #define LFS_EMUBD_ERASE_VALUE 0x00
  18. #endif
  19. // The emu bd state
  20. typedef struct lfs_emubd {
  21. char *path;
  22. char *child;
  23. struct {
  24. uint64_t read_count;
  25. uint64_t prog_count;
  26. uint64_t erase_count;
  27. } stats;
  28. struct {
  29. lfs_block_t blocks[4];
  30. } history;
  31. struct {
  32. uint32_t read_size;
  33. uint32_t prog_size;
  34. uint32_t block_size;
  35. uint32_t block_count;
  36. } cfg;
  37. } lfs_emubd_t;
  38. // Create a block device using path for the directory to store blocks
  39. int lfs_emubd_create(const struct lfs_config *cfg, const char *path);
  40. // Clean up memory associated with emu block device
  41. void lfs_emubd_destroy(const struct lfs_config *cfg);
  42. // Read a block
  43. int lfs_emubd_read(const struct lfs_config *cfg, lfs_block_t block,
  44. lfs_off_t off, void *buffer, lfs_size_t size);
  45. // Program a block
  46. //
  47. // The block must have previously been erased.
  48. int lfs_emubd_prog(const struct lfs_config *cfg, lfs_block_t block,
  49. lfs_off_t off, const void *buffer, lfs_size_t size);
  50. // Erase a block
  51. //
  52. // A block must be erased before being programmed. The
  53. // state of an erased block is undefined.
  54. int lfs_emubd_erase(const struct lfs_config *cfg, lfs_block_t block);
  55. // Sync the block device
  56. int lfs_emubd_sync(const struct lfs_config *cfg);
  57. #ifdef __cplusplus
  58. } /* extern "C" */
  59. #endif
  60. #endif