lfs_emubd.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Block device emulated on standard files
  3. *
  4. * Copyright (c) 2017 ARM Limited
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef LFS_EMUBD_H
  19. #define LFS_EMUBD_H
  20. #include "lfs.h"
  21. #include "lfs_util.h"
  22. // Config options
  23. #ifndef LFS_EMUBD_READ_SIZE
  24. #define LFS_EMUBD_READ_SIZE 1
  25. #endif
  26. #ifndef LFS_EMUBD_PROG_SIZE
  27. #define LFS_EMUBD_PROG_SIZE 1
  28. #endif
  29. #ifndef LFS_EMUBD_ERASE_SIZE
  30. #define LFS_EMUBD_ERASE_SIZE 512
  31. #endif
  32. #ifndef LFS_EMUBD_TOTAL_SIZE
  33. #define LFS_EMUBD_TOTAL_SIZE 524288
  34. #endif
  35. // The emu bd state
  36. typedef struct lfs_emubd {
  37. char *path;
  38. char *child;
  39. struct {
  40. uint64_t read_count;
  41. uint64_t prog_count;
  42. uint64_t erase_count;
  43. } stats;
  44. struct {
  45. uint32_t read_size;
  46. uint32_t prog_size;
  47. uint32_t block_size;
  48. uint32_t block_count;
  49. } cfg;
  50. } lfs_emubd_t;
  51. // Create a block device using path for the directory to store blocks
  52. int lfs_emubd_create(const struct lfs_config *cfg, const char *path);
  53. // Clean up memory associated with emu block device
  54. void lfs_emubd_destroy(const struct lfs_config *cfg);
  55. // Read a block
  56. int lfs_emubd_read(const struct lfs_config *cfg, lfs_block_t block,
  57. lfs_off_t off, void *buffer, lfs_size_t size);
  58. // Program a block
  59. //
  60. // The block must have previously been erased.
  61. int lfs_emubd_prog(const struct lfs_config *cfg, lfs_block_t block,
  62. lfs_off_t off, const void *buffer, lfs_size_t size);
  63. // Erase a block
  64. //
  65. // A block must be erased before being programmed. The
  66. // state of an erased block is undefined.
  67. int lfs_emubd_erase(const struct lfs_config *cfg, lfs_block_t block);
  68. // Sync the block device
  69. int lfs_emubd_sync(const struct lfs_config *cfg);
  70. #endif