lfs_filebd.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // filebd config (optional)
  16. struct lfs_filebd_config {
  17. // 8-bit erase value to use for simulating erases. -1 does not simulate
  18. // erases, which can speed up testing by avoiding all the extra block-device
  19. // operations to store the erase value.
  20. int32_t erase_value;
  21. };
  22. // filebd state
  23. typedef struct lfs_filebd {
  24. int fd;
  25. const struct lfs_filebd_config *cfg;
  26. } lfs_filebd_t;
  27. // Create a file block device using the geometry in lfs_config
  28. int lfs_filebd_create(const struct lfs_config *cfg, const char *path);
  29. int lfs_filebd_createcfg(const struct lfs_config *cfg, const char *path,
  30. const struct lfs_filebd_config *bdcfg);
  31. // Clean up memory associated with block device
  32. int lfs_filebd_destroy(const struct lfs_config *cfg);
  33. // Read a block
  34. int lfs_filebd_read(const struct lfs_config *cfg, lfs_block_t block,
  35. lfs_off_t off, void *buffer, lfs_size_t size);
  36. // Program a block
  37. //
  38. // The block must have previously been erased.
  39. int lfs_filebd_prog(const struct lfs_config *cfg, lfs_block_t block,
  40. lfs_off_t off, const void *buffer, lfs_size_t size);
  41. // Erase a block
  42. //
  43. // A block must be erased before being programmed. The
  44. // state of an erased block is undefined.
  45. int lfs_filebd_erase(const struct lfs_config *cfg, lfs_block_t block);
  46. // Sync the block device
  47. int lfs_filebd_sync(const struct lfs_config *cfg);
  48. #ifdef __cplusplus
  49. } /* extern "C" */
  50. #endif
  51. #endif