lfs_filebd.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Block device emulated in a file
  3. *
  4. * Copyright (c) 2017, Arm Limited. All rights reserved.
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef LFS_FILEBD_H
  8. #define LFS_FILEBD_H
  9. #include "lfs.h"
  10. #include "lfs_util.h"
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif
  15. // Block device specific tracing
  16. #ifdef LFS_FILEBD_YES_TRACE
  17. #define LFS_FILEBD_TRACE(...) LFS_TRACE(__VA_ARGS__)
  18. #else
  19. #define LFS_FILEBD_TRACE(...)
  20. #endif
  21. // filebd config (optional)
  22. struct lfs_filebd_config {
  23. // 8-bit erase value to use for simulating erases. -1 does not simulate
  24. // erases, which can speed up testing by avoiding all the extra block-device
  25. // operations to store the erase value.
  26. int32_t erase_value;
  27. };
  28. // filebd state
  29. typedef struct lfs_filebd {
  30. int fd;
  31. const struct lfs_filebd_config *cfg;
  32. } lfs_filebd_t;
  33. // Create a file block device using the geometry in lfs_config
  34. int lfs_filebd_create(const struct lfs_config *cfg, const char *path);
  35. int lfs_filebd_createcfg(const struct lfs_config *cfg, const char *path,
  36. const struct lfs_filebd_config *bdcfg);
  37. // Clean up memory associated with block device
  38. int lfs_filebd_destroy(const struct lfs_config *cfg);
  39. // Read a block
  40. int lfs_filebd_read(const struct lfs_config *cfg, lfs_block_t block,
  41. lfs_off_t off, void *buffer, lfs_size_t size);
  42. // Program a block
  43. //
  44. // The block must have previously been erased.
  45. int lfs_filebd_prog(const struct lfs_config *cfg, lfs_block_t block,
  46. lfs_off_t off, const void *buffer, lfs_size_t size);
  47. // Erase a block
  48. //
  49. // A block must be erased before being programmed. The
  50. // state of an erased block is undefined.
  51. int lfs_filebd_erase(const struct lfs_config *cfg, lfs_block_t block);
  52. // Sync the block device
  53. int lfs_filebd_sync(const struct lfs_config *cfg);
  54. #ifdef __cplusplus
  55. } /* extern "C" */
  56. #endif
  57. #endif