summary.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. #ifndef JFFS2_SUMMARY_H
  12. #define JFFS2_SUMMARY_H
  13. #include <linux/jffs2.h>
  14. #define DIRTY_SPACE(x) do { typeof(x) _x = (x); \
  15. c->free_size -= _x; c->dirty_size += _x; \
  16. jeb->free_size -= _x ; jeb->dirty_size += _x; \
  17. }while(0)
  18. #define USED_SPACE(x) do { typeof(x) _x = (x); \
  19. c->free_size -= _x; c->used_size += _x; \
  20. jeb->free_size -= _x ; jeb->used_size += _x; \
  21. }while(0)
  22. #define WASTED_SPACE(x) do { typeof(x) _x = (x); \
  23. c->free_size -= _x; c->wasted_size += _x; \
  24. jeb->free_size -= _x ; jeb->wasted_size += _x; \
  25. }while(0)
  26. #define UNCHECKED_SPACE(x) do { typeof(x) _x = (x); \
  27. c->free_size -= _x; c->unchecked_size += _x; \
  28. jeb->free_size -= _x ; jeb->unchecked_size += _x; \
  29. }while(0)
  30. #define BLK_STATE_ALLFF 0
  31. #define BLK_STATE_CLEAN 1
  32. #define BLK_STATE_PARTDIRTY 2
  33. #define BLK_STATE_CLEANMARKER 3
  34. #define BLK_STATE_ALLDIRTY 4
  35. #define BLK_STATE_BADBLOCK 5
  36. #define JFFS2_SUMMARY_NOSUM_SIZE 0xffffffff
  37. #define JFFS2_SUMMARY_INODE_SIZE (sizeof(struct jffs2_sum_inode_flash))
  38. #define JFFS2_SUMMARY_DIRENT_SIZE(x) (sizeof(struct jffs2_sum_dirent_flash) + (x))
  39. #define JFFS2_SUMMARY_XATTR_SIZE (sizeof(struct jffs2_sum_xattr_flash))
  40. #define JFFS2_SUMMARY_XREF_SIZE (sizeof(struct jffs2_sum_xref_flash))
  41. /* Summary structures used on flash */
  42. struct jffs2_sum_unknown_flash
  43. {
  44. jint16_t nodetype; /* node type */
  45. } __attribute__((packed));
  46. struct jffs2_sum_inode_flash
  47. {
  48. jint16_t nodetype; /* node type */
  49. jint32_t inode; /* inode number */
  50. jint32_t version; /* inode version */
  51. jint32_t offset; /* offset on jeb */
  52. jint32_t totlen; /* record length */
  53. } __attribute__((packed));
  54. struct jffs2_sum_dirent_flash
  55. {
  56. jint16_t nodetype; /* == JFFS_NODETYPE_DIRENT */
  57. jint32_t totlen; /* record length */
  58. jint32_t offset; /* ofset on jeb */
  59. jint32_t pino; /* parent inode */
  60. jint32_t version; /* dirent version */
  61. jint32_t ino; /* == zero for unlink */
  62. uint8_t nsize; /* dirent name size */
  63. uint8_t type; /* dirent type */
  64. uint8_t name[0]; /* dirent name */
  65. } __attribute__((packed));
  66. struct jffs2_sum_xattr_flash
  67. {
  68. jint16_t nodetype; /* == JFFS2_NODETYPE_XATR */
  69. jint32_t xid; /* xattr identifier */
  70. jint32_t version; /* version number */
  71. jint32_t offset; /* offset on jeb */
  72. jint32_t totlen; /* node length */
  73. } __attribute__((packed));
  74. struct jffs2_sum_xref_flash
  75. {
  76. jint16_t nodetype; /* == JFFS2_NODETYPE_XREF */
  77. jint32_t offset; /* offset on jeb */
  78. } __attribute__((packed));
  79. union jffs2_sum_flash
  80. {
  81. struct jffs2_sum_unknown_flash u;
  82. struct jffs2_sum_inode_flash i;
  83. struct jffs2_sum_dirent_flash d;
  84. struct jffs2_sum_xattr_flash x;
  85. struct jffs2_sum_xref_flash r;
  86. };
  87. /* Summary structures used in the memory */
  88. struct jffs2_sum_unknown_mem
  89. {
  90. union jffs2_sum_mem *next;
  91. jint16_t nodetype; /* node type */
  92. } __attribute__((packed));
  93. struct jffs2_sum_inode_mem
  94. {
  95. union jffs2_sum_mem *next;
  96. jint16_t nodetype; /* node type */
  97. jint32_t inode; /* inode number */
  98. jint32_t version; /* inode version */
  99. jint32_t offset; /* offset on jeb */
  100. jint32_t totlen; /* record length */
  101. } __attribute__((packed));
  102. struct jffs2_sum_dirent_mem
  103. {
  104. union jffs2_sum_mem *next;
  105. jint16_t nodetype; /* == JFFS_NODETYPE_DIRENT */
  106. jint32_t totlen; /* record length */
  107. jint32_t offset; /* ofset on jeb */
  108. jint32_t pino; /* parent inode */
  109. jint32_t version; /* dirent version */
  110. jint32_t ino; /* == zero for unlink */
  111. uint8_t nsize; /* dirent name size */
  112. uint8_t type; /* dirent type */
  113. uint8_t name[0]; /* dirent name */
  114. } __attribute__((packed));
  115. struct jffs2_sum_xattr_mem
  116. {
  117. union jffs2_sum_mem *next;
  118. jint16_t nodetype;
  119. jint32_t xid;
  120. jint32_t version;
  121. jint32_t offset;
  122. jint32_t totlen;
  123. } __attribute__((packed));
  124. struct jffs2_sum_xref_mem
  125. {
  126. union jffs2_sum_mem *next;
  127. jint16_t nodetype;
  128. jint32_t offset;
  129. } __attribute__((packed));
  130. union jffs2_sum_mem
  131. {
  132. struct jffs2_sum_unknown_mem u;
  133. struct jffs2_sum_inode_mem i;
  134. struct jffs2_sum_dirent_mem d;
  135. struct jffs2_sum_xattr_mem x;
  136. struct jffs2_sum_xref_mem r;
  137. };
  138. struct jffs2_summary
  139. {
  140. uint32_t sum_size;
  141. uint32_t sum_num;
  142. uint32_t sum_padded;
  143. union jffs2_sum_mem *sum_list_head;
  144. union jffs2_sum_mem *sum_list_tail;
  145. };
  146. /* Summary marker is stored at the end of every sumarized erase block */
  147. struct jffs2_sum_marker
  148. {
  149. jint32_t offset; /* offset of the summary node in the jeb */
  150. jint32_t magic; /* == JFFS2_SUM_MAGIC */
  151. };
  152. #define JFFS2_SUMMARY_FRAME_SIZE (sizeof(struct jffs2_raw_summary) + sizeof(struct jffs2_sum_marker))
  153. #endif