lfs_emubd.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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_READ_SIZE
  17. #define LFS_EMUBD_READ_SIZE 1
  18. #endif
  19. #ifndef LFS_EMUBD_PROG_SIZE
  20. #define LFS_EMUBD_PROG_SIZE 1
  21. #endif
  22. #ifndef LFS_EMUBD_ERASE_SIZE
  23. #define LFS_EMUBD_ERASE_SIZE 512
  24. #endif
  25. #ifndef LFS_EMUBD_TOTAL_SIZE
  26. #define LFS_EMUBD_TOTAL_SIZE 524288
  27. #endif
  28. // The emu bd state
  29. typedef struct lfs_emubd {
  30. char *path;
  31. char *child;
  32. struct {
  33. uint64_t read_count;
  34. uint64_t prog_count;
  35. uint64_t erase_count;
  36. } stats;
  37. struct {
  38. uint32_t read_size;
  39. uint32_t prog_size;
  40. uint32_t block_size;
  41. uint32_t block_count;
  42. } cfg;
  43. } lfs_emubd_t;
  44. // Create a block device using path for the directory to store blocks
  45. int lfs_emubd_create(const struct lfs_config *cfg, const char *path);
  46. // Clean up memory associated with emu block device
  47. void lfs_emubd_destroy(const struct lfs_config *cfg);
  48. // Read a block
  49. int lfs_emubd_read(const struct lfs_config *cfg, lfs_block_t block,
  50. lfs_off_t off, void *buffer, lfs_size_t size);
  51. // Program a block
  52. //
  53. // The block must have previously been erased.
  54. int lfs_emubd_prog(const struct lfs_config *cfg, lfs_block_t block,
  55. lfs_off_t off, const void *buffer, lfs_size_t size);
  56. // Erase a block
  57. //
  58. // A block must be erased before being programmed. The
  59. // state of an erased block is undefined.
  60. int lfs_emubd_erase(const struct lfs_config *cfg, lfs_block_t block);
  61. // Sync the block device
  62. int lfs_emubd_sync(const struct lfs_config *cfg);
  63. #ifdef __cplusplus
  64. } /* extern "C" */
  65. #endif
  66. #endif