inode_format.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _BCACHEFS_INODE_FORMAT_H
  3. #define _BCACHEFS_INODE_FORMAT_H
  4. #define BLOCKDEV_INODE_MAX 4096
  5. #define BCACHEFS_ROOT_INO 4096
  6. struct bch_inode {
  7. struct bch_val v;
  8. __le64 bi_hash_seed;
  9. __le32 bi_flags;
  10. __le16 bi_mode;
  11. __u8 fields[];
  12. } __packed __aligned(8);
  13. struct bch_inode_v2 {
  14. struct bch_val v;
  15. __le64 bi_journal_seq;
  16. __le64 bi_hash_seed;
  17. __le64 bi_flags;
  18. __le16 bi_mode;
  19. __u8 fields[];
  20. } __packed __aligned(8);
  21. struct bch_inode_v3 {
  22. struct bch_val v;
  23. __le64 bi_journal_seq;
  24. __le64 bi_hash_seed;
  25. __le64 bi_flags;
  26. __le64 bi_sectors;
  27. __le64 bi_size;
  28. __le64 bi_version;
  29. __u8 fields[];
  30. } __packed __aligned(8);
  31. #define INODEv3_FIELDS_START_INITIAL 6
  32. #define INODEv3_FIELDS_START_CUR (offsetof(struct bch_inode_v3, fields) / sizeof(__u64))
  33. struct bch_inode_generation {
  34. struct bch_val v;
  35. __le32 bi_generation;
  36. __le32 pad;
  37. } __packed __aligned(8);
  38. /*
  39. * bi_subvol and bi_parent_subvol are only set for subvolume roots:
  40. */
  41. #define BCH_INODE_FIELDS_v2() \
  42. x(bi_atime, 96) \
  43. x(bi_ctime, 96) \
  44. x(bi_mtime, 96) \
  45. x(bi_otime, 96) \
  46. x(bi_size, 64) \
  47. x(bi_sectors, 64) \
  48. x(bi_uid, 32) \
  49. x(bi_gid, 32) \
  50. x(bi_nlink, 32) \
  51. x(bi_generation, 32) \
  52. x(bi_dev, 32) \
  53. x(bi_data_checksum, 8) \
  54. x(bi_compression, 8) \
  55. x(bi_project, 32) \
  56. x(bi_background_compression, 8) \
  57. x(bi_data_replicas, 8) \
  58. x(bi_promote_target, 16) \
  59. x(bi_foreground_target, 16) \
  60. x(bi_background_target, 16) \
  61. x(bi_erasure_code, 16) \
  62. x(bi_fields_set, 16) \
  63. x(bi_dir, 64) \
  64. x(bi_dir_offset, 64) \
  65. x(bi_subvol, 32) \
  66. x(bi_parent_subvol, 32)
  67. #define BCH_INODE_FIELDS_v3() \
  68. x(bi_atime, 96) \
  69. x(bi_ctime, 96) \
  70. x(bi_mtime, 96) \
  71. x(bi_otime, 96) \
  72. x(bi_uid, 32) \
  73. x(bi_gid, 32) \
  74. x(bi_nlink, 32) \
  75. x(bi_generation, 32) \
  76. x(bi_dev, 32) \
  77. x(bi_data_checksum, 8) \
  78. x(bi_compression, 8) \
  79. x(bi_project, 32) \
  80. x(bi_background_compression, 8) \
  81. x(bi_data_replicas, 8) \
  82. x(bi_promote_target, 16) \
  83. x(bi_foreground_target, 16) \
  84. x(bi_background_target, 16) \
  85. x(bi_erasure_code, 16) \
  86. x(bi_fields_set, 16) \
  87. x(bi_dir, 64) \
  88. x(bi_dir_offset, 64) \
  89. x(bi_subvol, 32) \
  90. x(bi_parent_subvol, 32) \
  91. x(bi_nocow, 8)
  92. /* subset of BCH_INODE_FIELDS */
  93. #define BCH_INODE_OPTS() \
  94. x(data_checksum, 8) \
  95. x(compression, 8) \
  96. x(project, 32) \
  97. x(background_compression, 8) \
  98. x(data_replicas, 8) \
  99. x(promote_target, 16) \
  100. x(foreground_target, 16) \
  101. x(background_target, 16) \
  102. x(erasure_code, 16) \
  103. x(nocow, 8)
  104. enum inode_opt_id {
  105. #define x(name, ...) \
  106. Inode_opt_##name,
  107. BCH_INODE_OPTS()
  108. #undef x
  109. Inode_opt_nr,
  110. };
  111. #define BCH_INODE_FLAGS() \
  112. x(sync, 0) \
  113. x(immutable, 1) \
  114. x(append, 2) \
  115. x(nodump, 3) \
  116. x(noatime, 4) \
  117. x(i_size_dirty, 5) \
  118. x(i_sectors_dirty, 6) \
  119. x(unlinked, 7) \
  120. x(backptr_untrusted, 8) \
  121. x(has_child_snapshot, 9)
  122. /* bits 20+ reserved for packed fields below: */
  123. enum bch_inode_flags {
  124. #define x(t, n) BCH_INODE_##t = 1U << n,
  125. BCH_INODE_FLAGS()
  126. #undef x
  127. };
  128. enum __bch_inode_flags {
  129. #define x(t, n) __BCH_INODE_##t = n,
  130. BCH_INODE_FLAGS()
  131. #undef x
  132. };
  133. LE32_BITMASK(INODEv1_STR_HASH, struct bch_inode, bi_flags, 20, 24);
  134. LE32_BITMASK(INODEv1_NR_FIELDS, struct bch_inode, bi_flags, 24, 31);
  135. LE32_BITMASK(INODEv1_NEW_VARINT,struct bch_inode, bi_flags, 31, 32);
  136. LE64_BITMASK(INODEv2_STR_HASH, struct bch_inode_v2, bi_flags, 20, 24);
  137. LE64_BITMASK(INODEv2_NR_FIELDS, struct bch_inode_v2, bi_flags, 24, 31);
  138. LE64_BITMASK(INODEv3_STR_HASH, struct bch_inode_v3, bi_flags, 20, 24);
  139. LE64_BITMASK(INODEv3_NR_FIELDS, struct bch_inode_v3, bi_flags, 24, 31);
  140. LE64_BITMASK(INODEv3_FIELDS_START,
  141. struct bch_inode_v3, bi_flags, 31, 36);
  142. LE64_BITMASK(INODEv3_MODE, struct bch_inode_v3, bi_flags, 36, 52);
  143. #endif /* _BCACHEFS_INODE_FORMAT_H */