lfs_emubd.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Block device emulated on standard files
  3. *
  4. * Copyright (c) 2017 Christopher Haster
  5. * Distributed under the MIT license
  6. */
  7. #ifndef LFS_EMUBD_H
  8. #define LFS_EMUBD_H
  9. #include "lfs_config.h"
  10. #include "lfs_bd.h"
  11. // The emu bd state
  12. typedef struct lfs_emubd {
  13. char *path;
  14. char *child;
  15. struct lfs_bd_info info;
  16. } lfs_emubd_t;
  17. // Create a block device using path for the directory to store blocks
  18. lfs_error_t lfs_emubd_create(lfs_emubd_t *emu, const char *path);
  19. // Clean up memory associated with emu block device
  20. void lfs_emubd_destroy(lfs_emubd_t *emu);
  21. // Read a block
  22. lfs_error_t lfs_emubd_read(lfs_emubd_t *bd, uint8_t *buffer,
  23. lfs_ino_t ino, lfs_off_t off, lfs_size_t size);
  24. // Program a block
  25. //
  26. // The block must have previously been erased.
  27. lfs_error_t lfs_emubd_write(lfs_emubd_t *bd, const uint8_t *buffer,
  28. lfs_ino_t ino, lfs_off_t off, lfs_size_t size);
  29. // Erase a block
  30. //
  31. // A block must be erased before being programmed. The
  32. // state of an erased block is undefined.
  33. lfs_error_t lfs_emubd_erase(lfs_emubd_t *bd,
  34. lfs_ino_t ino, lfs_off_t off, lfs_size_t size);
  35. // Sync the block device
  36. lfs_error_t lfs_emubd_sync(lfs_emubd_t *bd);
  37. // Get a description of the block device
  38. //
  39. // Any unknown information may be left unmodified
  40. lfs_error_t lfs_emubd_info(lfs_emubd_t *bd, struct lfs_bd_info *info);
  41. // Block device operations
  42. extern const struct lfs_bd_ops lfs_emubd_ops;
  43. #endif