summary.h 6.3 KB

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