lfs_filebd.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 simulate erasing with. -1 indicates no erase
  18. // occurs, which is still a valid block device
  19. int32_t erase_value;
  20. };
  21. // filebd state
  22. typedef struct lfs_filebd {
  23. int fd;
  24. const struct lfs_filebd_config *cfg;
  25. } lfs_filebd_t;
  26. // Create a file block device using the geometry in lfs_config
  27. int lfs_filebd_create(const struct lfs_config *cfg, const char *path);
  28. int lfs_filebd_createcfg(const struct lfs_config *cfg, const char *path,
  29. const struct lfs_filebd_config *ramcfg);
  30. // Clean up memory associated with block device
  31. void lfs_filebd_destroy(const struct lfs_config *cfg);
  32. // Read a block
  33. int lfs_filebd_read(const struct lfs_config *cfg, lfs_block_t block,
  34. lfs_off_t off, void *buffer, lfs_size_t size);
  35. // Program a block
  36. //
  37. // The block must have previously been erased.
  38. int lfs_filebd_prog(const struct lfs_config *cfg, lfs_block_t block,
  39. lfs_off_t off, const void *buffer, lfs_size_t size);
  40. // Erase a block
  41. //
  42. // A block must be erased before being programmed. The
  43. // state of an erased block is undefined.
  44. int lfs_filebd_erase(const struct lfs_config *cfg, lfs_block_t block);
  45. // Sync the block device
  46. int lfs_filebd_sync(const struct lfs_config *cfg);
  47. #ifdef __cplusplus
  48. } /* extern "C" */
  49. #endif
  50. #endif