lfs.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * The little filesystem
  3. *
  4. * Copyright (c) 2017 Christopher Haster
  5. * Distributed under the MIT license
  6. */
  7. #ifndef LFS_H
  8. #define LFS_H
  9. #include "lfs_config.h"
  10. #include "lfs_bd.h"
  11. // Data structures
  12. typedef struct lfs_free {
  13. lfs_disk_struct lfs_disk_free {
  14. lfs_ino_t head;
  15. lfs_word_t ioff;
  16. lfs_word_t icount;
  17. lfs_word_t rev;
  18. } d;
  19. } lfs_free_t;
  20. typedef struct lfs_dir {
  21. lfs_ino_t dno[2];
  22. lfs_disk_struct lfs_disk_dir {
  23. lfs_word_t rev;
  24. lfs_size_t size;
  25. lfs_ino_t tail[2];
  26. lfs_ino_t parent[2];
  27. struct lfs_disk_free free;
  28. } d;
  29. } lfs_dir_t;
  30. typedef struct lfs_entry {
  31. lfs_ino_t dir[2];
  32. lfs_off_t off;
  33. lfs_disk_struct lfs_disk_entry {
  34. uint16_t type;
  35. uint16_t len;
  36. union {
  37. lfs_disk_struct {
  38. lfs_ino_t head;
  39. lfs_size_t size;
  40. char name[LFS_NAME_MAX];
  41. } file;
  42. lfs_disk_struct {
  43. lfs_ino_t dir[2];
  44. char name[LFS_NAME_MAX];
  45. } dir;
  46. lfs_disk_struct {
  47. char magic[4];
  48. uint32_t read_size;
  49. uint32_t write_size;
  50. uint32_t erase_size;
  51. uint32_t erase_count;
  52. } superblock;
  53. } value;
  54. } d;
  55. } lfs_entry_t;
  56. typedef struct lfs_superblock {
  57. lfs_disk_struct lfs_disk_superblock {
  58. uint32_t rev;
  59. uint32_t count;
  60. lfs_ino_t root[2];
  61. char magic[8];
  62. uint32_t block_size;
  63. uint32_t block_count;
  64. } d;
  65. } lfs_superblock_t;
  66. // Little filesystem type
  67. typedef struct lfs {
  68. lfs_bd_t *bd;
  69. const struct lfs_bd_ops *ops;
  70. lfs_free_t free;
  71. struct lfs_bd_info info;
  72. } lfs_t;
  73. // Functions
  74. lfs_error_t lfs_create(lfs_t *lfs, lfs_bd_t *bd, const struct lfs_bd_ops *bd_ops);
  75. lfs_error_t lfs_format(lfs_t *lfs);
  76. lfs_error_t lfs_mount(lfs_t *lfs);
  77. #endif