summary.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * JFFS2 -- Journalling Flash File System, Version 2.
  3. *
  4. * Copyright (C) 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. * $Id: summary.h,v 1.2 2005/09/26 11:37:21 havasi Exp $
  12. *
  13. */
  14. #ifndef JFFS2_SUMMARY_H
  15. #define JFFS2_SUMMARY_H
  16. #include <linux/uio.h>
  17. #include <linux/jffs2.h>
  18. #define DIRTY_SPACE(x) do { typeof(x) _x = (x); \
  19. c->free_size -= _x; c->dirty_size += _x; \
  20. jeb->free_size -= _x ; jeb->dirty_size += _x; \
  21. }while(0)
  22. #define USED_SPACE(x) do { typeof(x) _x = (x); \
  23. c->free_size -= _x; c->used_size += _x; \
  24. jeb->free_size -= _x ; jeb->used_size += _x; \
  25. }while(0)
  26. #define WASTED_SPACE(x) do { typeof(x) _x = (x); \
  27. c->free_size -= _x; c->wasted_size += _x; \
  28. jeb->free_size -= _x ; jeb->wasted_size += _x; \
  29. }while(0)
  30. #define UNCHECKED_SPACE(x) do { typeof(x) _x = (x); \
  31. c->free_size -= _x; c->unchecked_size += _x; \
  32. jeb->free_size -= _x ; jeb->unchecked_size += _x; \
  33. }while(0)
  34. #define BLK_STATE_ALLFF 0
  35. #define BLK_STATE_CLEAN 1
  36. #define BLK_STATE_PARTDIRTY 2
  37. #define BLK_STATE_CLEANMARKER 3
  38. #define BLK_STATE_ALLDIRTY 4
  39. #define BLK_STATE_BADBLOCK 5
  40. #define JFFS2_SUMMARY_NOSUM_SIZE 0xffffffff
  41. #define JFFS2_SUMMARY_INODE_SIZE (sizeof(struct jffs2_sum_inode_flash))
  42. #define JFFS2_SUMMARY_DIRENT_SIZE(x) (sizeof(struct jffs2_sum_dirent_flash) + (x))
  43. /* Summary structures used on flash */
  44. struct jffs2_sum_unknown_flash
  45. {
  46. jint16_t nodetype; /* node type */
  47. };
  48. struct jffs2_sum_inode_flash
  49. {
  50. jint16_t nodetype; /* node type */
  51. jint32_t inode; /* inode number */
  52. jint32_t version; /* inode version */
  53. jint32_t offset; /* offset on jeb */
  54. jint32_t totlen; /* record length */
  55. } __attribute__((packed));
  56. struct jffs2_sum_dirent_flash
  57. {
  58. jint16_t nodetype; /* == JFFS_NODETYPE_DIRENT */
  59. jint32_t totlen; /* record length */
  60. jint32_t offset; /* offset on jeb */
  61. jint32_t pino; /* parent inode */
  62. jint32_t version; /* dirent version */
  63. jint32_t ino; /* == zero for unlink */
  64. uint8_t nsize; /* dirent name size */
  65. uint8_t type; /* dirent type */
  66. uint8_t name[0]; /* dirent name */
  67. } __attribute__((packed));
  68. union jffs2_sum_flash
  69. {
  70. struct jffs2_sum_unknown_flash u;
  71. struct jffs2_sum_inode_flash i;
  72. struct jffs2_sum_dirent_flash d;
  73. };
  74. /* Summary structures used in the memory */
  75. struct jffs2_sum_unknown_mem
  76. {
  77. union jffs2_sum_mem *next;
  78. jint16_t nodetype; /* node type */
  79. };
  80. struct jffs2_sum_inode_mem
  81. {
  82. union jffs2_sum_mem *next;
  83. jint16_t nodetype; /* node type */
  84. jint32_t inode; /* inode number */
  85. jint32_t version; /* inode version */
  86. jint32_t offset; /* offset on jeb */
  87. jint32_t totlen; /* record length */
  88. } __attribute__((packed));
  89. struct jffs2_sum_dirent_mem
  90. {
  91. union jffs2_sum_mem *next;
  92. jint16_t nodetype; /* == JFFS_NODETYPE_DIRENT */
  93. jint32_t totlen; /* record length */
  94. jint32_t offset; /* ofset on jeb */
  95. jint32_t pino; /* parent inode */
  96. jint32_t version; /* dirent version */
  97. jint32_t ino; /* == zero for unlink */
  98. uint8_t nsize; /* dirent name size */
  99. uint8_t type; /* dirent type */
  100. uint8_t name[0]; /* dirent name */
  101. } __attribute__((packed));
  102. union jffs2_sum_mem
  103. {
  104. struct jffs2_sum_unknown_mem u;
  105. struct jffs2_sum_inode_mem i;
  106. struct jffs2_sum_dirent_mem d;
  107. };
  108. /* Summary related information stored in superblock */
  109. struct jffs2_summary
  110. {
  111. uint32_t sum_size; /* collected summary information for nextblock */
  112. uint32_t sum_num;
  113. uint32_t sum_padded;
  114. union jffs2_sum_mem *sum_list_head;
  115. union jffs2_sum_mem *sum_list_tail;
  116. jint32_t *sum_buf; /* buffer for writing out summary */
  117. };
  118. /* Summary marker is stored at the end of every sumarized erase block */
  119. struct jffs2_sum_marker
  120. {
  121. jint32_t offset; /* offset of the summary node in the jeb */
  122. jint32_t magic; /* == JFFS2_SUM_MAGIC */
  123. };
  124. #define JFFS2_SUMMARY_FRAME_SIZE (sizeof(struct jffs2_raw_summary) + sizeof(struct jffs2_sum_marker))
  125. #ifdef CONFIG_JFFS2_SUMMARY /* SUMMARY SUPPORT ENABLED */
  126. #define jffs2_sum_active() (1)
  127. int jffs2_sum_init(struct jffs2_sb_info *c);
  128. void jffs2_sum_exit(struct jffs2_sb_info *c);
  129. void jffs2_sum_disable_collecting(struct jffs2_summary *s);
  130. int jffs2_sum_is_disabled(struct jffs2_summary *s);
  131. void jffs2_sum_reset_collected(struct jffs2_summary *s);
  132. void jffs2_sum_move_collected(struct jffs2_sb_info *c, struct jffs2_summary *s);
  133. int jffs2_sum_add_kvec(struct jffs2_sb_info *c, const struct kvec *invecs,
  134. unsigned long count, uint32_t to);
  135. int jffs2_sum_write_sumnode(struct jffs2_sb_info *c);
  136. int jffs2_sum_add_padding_mem(struct jffs2_summary *s, uint32_t size);
  137. int jffs2_sum_add_inode_mem(struct jffs2_summary *s, struct jffs2_raw_inode *ri, uint32_t ofs);
  138. int jffs2_sum_add_dirent_mem(struct jffs2_summary *s, struct jffs2_raw_dirent *rd, uint32_t ofs);
  139. int jffs2_sum_scan_sumnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
  140. uint32_t ofs, uint32_t *pseudo_random);
  141. #else /* SUMMARY DISABLED */
  142. #define jffs2_sum_active() (0)
  143. #define jffs2_sum_init(a) (0)
  144. #define jffs2_sum_exit(a)
  145. #define jffs2_sum_disable_collecting(a)
  146. #define jffs2_sum_is_disabled(a) (0)
  147. #define jffs2_sum_reset_collected(a)
  148. #define jffs2_sum_add_kvec(a,b,c,d) (0)
  149. #define jffs2_sum_move_collected(a,b)
  150. #define jffs2_sum_write_sumnode(a) (0)
  151. #define jffs2_sum_add_padding_mem(a,b)
  152. #define jffs2_sum_add_inode_mem(a,b,c)
  153. #define jffs2_sum_add_dirent_mem(a,b,c)
  154. #define jffs2_sum_scan_sumnode(a,b,c,d) (0)
  155. #endif /* CONFIG_JFFS2_SUMMARY */
  156. #endif /* JFFS2_SUMMARY_H */