summary.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * JFFS2 -- Journalling Flash File System, Version 2.
  3. *
  4. * Copyright © 2004 Ferenc Havasi <havasi@inf.u-szeged.hu>,
  5. * Zoltan Sogor <weth@inf.u-szeged.hu>,
  6. * Patrik Kluba <pajko@halom.u-szeged.hu>,
  7. * University of Szeged, Hungary
  8. *
  9. * For licensing information, see the file 'LICENCE' in this directory.
  10. *
  11. */
  12. #ifndef JFFS2_SUMMARY_H
  13. #define JFFS2_SUMMARY_H
  14. #include <linux/uio.h>
  15. #include <linux/jffs2.h>
  16. #define BLK_STATE_ALLFF 0
  17. #define BLK_STATE_CLEAN 1
  18. #define BLK_STATE_PARTDIRTY 2
  19. #define BLK_STATE_CLEANMARKER 3
  20. #define BLK_STATE_ALLDIRTY 4
  21. #define BLK_STATE_BADBLOCK 5
  22. #define JFFS2_SUMMARY_NOSUM_SIZE 0xffffffff
  23. #define JFFS2_SUMMARY_INODE_SIZE (sizeof(struct jffs2_sum_inode_flash))
  24. #define JFFS2_SUMMARY_DIRENT_SIZE(x) (sizeof(struct jffs2_sum_dirent_flash) + (x))
  25. #define JFFS2_SUMMARY_XATTR_SIZE (sizeof(struct jffs2_sum_xattr_flash))
  26. #define JFFS2_SUMMARY_XREF_SIZE (sizeof(struct jffs2_sum_xref_flash))
  27. /* Summary structures used on flash */
  28. struct jffs2_sum_unknown_flash
  29. {
  30. jint16_t nodetype; /* node type */
  31. };
  32. struct jffs2_sum_inode_flash
  33. {
  34. jint16_t nodetype; /* node type */
  35. jint32_t inode; /* inode number */
  36. jint32_t version; /* inode version */
  37. jint32_t offset; /* offset on jeb */
  38. jint32_t totlen; /* record length */
  39. } __attribute__((packed));
  40. struct jffs2_sum_dirent_flash
  41. {
  42. jint16_t nodetype; /* == JFFS_NODETYPE_DIRENT */
  43. jint32_t totlen; /* record length */
  44. jint32_t offset; /* offset on jeb */
  45. jint32_t pino; /* parent inode */
  46. jint32_t version; /* dirent version */
  47. jint32_t ino; /* == zero for unlink */
  48. uint8_t nsize; /* dirent name size */
  49. uint8_t type; /* dirent type */
  50. uint8_t name[0]; /* dirent name */
  51. } __attribute__((packed));
  52. struct jffs2_sum_xattr_flash
  53. {
  54. jint16_t nodetype; /* == JFFS2_NODETYPE_XATR */
  55. jint32_t xid; /* xattr identifier */
  56. jint32_t version; /* version number */
  57. jint32_t offset; /* offset on jeb */
  58. jint32_t totlen; /* node length */
  59. } __attribute__((packed));
  60. struct jffs2_sum_xref_flash
  61. {
  62. jint16_t nodetype; /* == JFFS2_NODETYPE_XREF */
  63. jint32_t offset; /* offset on jeb */
  64. } __attribute__((packed));
  65. union jffs2_sum_flash
  66. {
  67. struct jffs2_sum_unknown_flash u;
  68. struct jffs2_sum_inode_flash i;
  69. struct jffs2_sum_dirent_flash d;
  70. struct jffs2_sum_xattr_flash x;
  71. struct jffs2_sum_xref_flash r;
  72. };
  73. /* Summary structures used in the memory */
  74. struct jffs2_sum_unknown_mem
  75. {
  76. union jffs2_sum_mem *next;
  77. jint16_t nodetype; /* node type */
  78. };
  79. struct jffs2_sum_inode_mem
  80. {
  81. union jffs2_sum_mem *next;
  82. jint16_t nodetype; /* node type */
  83. jint32_t inode; /* inode number */
  84. jint32_t version; /* inode version */
  85. jint32_t offset; /* offset on jeb */
  86. jint32_t totlen; /* record length */
  87. } __attribute__((packed));
  88. struct jffs2_sum_dirent_mem
  89. {
  90. union jffs2_sum_mem *next;
  91. jint16_t nodetype; /* == JFFS_NODETYPE_DIRENT */
  92. jint32_t totlen; /* record length */
  93. jint32_t offset; /* ofset on jeb */
  94. jint32_t pino; /* parent inode */
  95. jint32_t version; /* dirent version */
  96. jint32_t ino; /* == zero for unlink */
  97. uint8_t nsize; /* dirent name size */
  98. uint8_t type; /* dirent type */
  99. uint8_t name[0]; /* dirent name */
  100. } __attribute__((packed));
  101. struct jffs2_sum_xattr_mem
  102. {
  103. union jffs2_sum_mem *next;
  104. jint16_t nodetype;
  105. jint32_t xid;
  106. jint32_t version;
  107. jint32_t offset;
  108. jint32_t totlen;
  109. } __attribute__((packed));
  110. struct jffs2_sum_xref_mem
  111. {
  112. union jffs2_sum_mem *next;
  113. jint16_t nodetype;
  114. jint32_t offset;
  115. } __attribute__((packed));
  116. union jffs2_sum_mem
  117. {
  118. struct jffs2_sum_unknown_mem u;
  119. struct jffs2_sum_inode_mem i;
  120. struct jffs2_sum_dirent_mem d;
  121. struct jffs2_sum_xattr_mem x;
  122. struct jffs2_sum_xref_mem r;
  123. };
  124. /* Summary related information stored in superblock */
  125. struct jffs2_summary
  126. {
  127. uint32_t sum_size; /* collected summary information for nextblock */
  128. uint32_t sum_num;
  129. uint32_t sum_padded;
  130. union jffs2_sum_mem *sum_list_head;
  131. union jffs2_sum_mem *sum_list_tail;
  132. jint32_t *sum_buf; /* buffer for writing out summary */
  133. };
  134. /* Summary marker is stored at the end of every sumarized erase block */
  135. struct jffs2_sum_marker
  136. {
  137. jint32_t offset; /* offset of the summary node in the jeb */
  138. jint32_t magic; /* == JFFS2_SUM_MAGIC */
  139. };
  140. #define JFFS2_SUMMARY_FRAME_SIZE (sizeof(struct jffs2_raw_summary) + sizeof(struct jffs2_sum_marker))
  141. #ifdef CONFIG_JFFS2_SUMMARY /* SUMMARY SUPPORT ENABLED */
  142. #define jffs2_sum_active() (1)
  143. int jffs2_sum_init(struct jffs2_sb_info *c);
  144. void jffs2_sum_exit(struct jffs2_sb_info *c);
  145. void jffs2_sum_disable_collecting(struct jffs2_summary *s);
  146. int jffs2_sum_is_disabled(struct jffs2_summary *s);
  147. void jffs2_sum_reset_collected(struct jffs2_summary *s);
  148. void jffs2_sum_move_collected(struct jffs2_sb_info *c, struct jffs2_summary *s);
  149. int jffs2_sum_add_kvec(struct jffs2_sb_info *c, const struct kvec *invecs,
  150. unsigned long count, uint32_t to);
  151. int jffs2_sum_write_sumnode(struct jffs2_sb_info *c);
  152. int jffs2_sum_add_padding_mem(struct jffs2_summary *s, uint32_t size);
  153. int jffs2_sum_add_inode_mem(struct jffs2_summary *s, struct jffs2_raw_inode *ri, uint32_t ofs);
  154. int jffs2_sum_add_dirent_mem(struct jffs2_summary *s, struct jffs2_raw_dirent *rd, uint32_t ofs);
  155. int jffs2_sum_add_xattr_mem(struct jffs2_summary *s, struct jffs2_raw_xattr *rx, uint32_t ofs);
  156. int jffs2_sum_add_xref_mem(struct jffs2_summary *s, struct jffs2_raw_xref *rr, uint32_t ofs);
  157. int jffs2_sum_scan_sumnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
  158. struct jffs2_raw_summary *summary, uint32_t sumlen,
  159. uint32_t *pseudo_random);
  160. #else /* SUMMARY DISABLED */
  161. #define jffs2_sum_active() (0)
  162. #define jffs2_sum_init(a) (0)
  163. #define jffs2_sum_exit(a)
  164. #define jffs2_sum_disable_collecting(a)
  165. #define jffs2_sum_is_disabled(a) (0)
  166. #define jffs2_sum_reset_collected(a)
  167. #define jffs2_sum_add_kvec(a,b,c,d) (0)
  168. #define jffs2_sum_move_collected(a,b)
  169. #define jffs2_sum_write_sumnode(a) (0)
  170. #define jffs2_sum_add_padding_mem(a,b)
  171. #define jffs2_sum_add_inode_mem(a,b,c)
  172. #define jffs2_sum_add_dirent_mem(a,b,c)
  173. #define jffs2_sum_add_xattr_mem(a,b,c)
  174. #define jffs2_sum_add_xref_mem(a,b,c)
  175. #define jffs2_sum_scan_sumnode(a,b,c,d,e) (0)
  176. #endif /* CONFIG_JFFS2_SUMMARY */
  177. #endif /* JFFS2_SUMMARY_H */