2 * JFFS2 -- Journalling Flash File System, Version 2.
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
9 * For licensing information, see the file 'LICENCE' in this directory.
11 * $Id: summary.h,v 1.2 2005/09/26 11:37:21 havasi Exp $
15 #ifndef JFFS2_SUMMARY_H
16 #define JFFS2_SUMMARY_H
18 #include <linux/uio.h>
19 #include <linux/jffs2.h>
21 #define DIRTY_SPACE(x) do { typeof(x) _x = (x); \
22 c->free_size -= _x; c->dirty_size += _x; \
23 jeb->free_size -= _x ; jeb->dirty_size += _x; \
25 #define USED_SPACE(x) do { typeof(x) _x = (x); \
26 c->free_size -= _x; c->used_size += _x; \
27 jeb->free_size -= _x ; jeb->used_size += _x; \
29 #define WASTED_SPACE(x) do { typeof(x) _x = (x); \
30 c->free_size -= _x; c->wasted_size += _x; \
31 jeb->free_size -= _x ; jeb->wasted_size += _x; \
33 #define UNCHECKED_SPACE(x) do { typeof(x) _x = (x); \
34 c->free_size -= _x; c->unchecked_size += _x; \
35 jeb->free_size -= _x ; jeb->unchecked_size += _x; \
38 #define BLK_STATE_ALLFF 0
39 #define BLK_STATE_CLEAN 1
40 #define BLK_STATE_PARTDIRTY 2
41 #define BLK_STATE_CLEANMARKER 3
42 #define BLK_STATE_ALLDIRTY 4
43 #define BLK_STATE_BADBLOCK 5
45 #define JFFS2_SUMMARY_NOSUM_SIZE 0xffffffff
46 #define JFFS2_SUMMARY_INODE_SIZE (sizeof(struct jffs2_sum_inode_flash))
47 #define JFFS2_SUMMARY_DIRENT_SIZE(x) (sizeof(struct jffs2_sum_dirent_flash) + (x))
48 #define JFFS2_SUMMARY_XATTR_SIZE (sizeof(struct jffs2_sum_xattr_flash))
49 #define JFFS2_SUMMARY_XREF_SIZE (sizeof(struct jffs2_sum_xref_flash))
51 /* Summary structures used on flash */
53 struct jffs2_sum_unknown_flash
55 jint16_t nodetype; /* node type */
58 struct jffs2_sum_inode_flash
60 jint16_t nodetype; /* node type */
61 jint32_t inode; /* inode number */
62 jint32_t version; /* inode version */
63 jint32_t offset; /* offset on jeb */
64 jint32_t totlen; /* record length */
65 } __attribute__((packed));
67 struct jffs2_sum_dirent_flash
69 jint16_t nodetype; /* == JFFS_NODETYPE_DIRENT */
70 jint32_t totlen; /* record length */
71 jint32_t offset; /* offset on jeb */
72 jint32_t pino; /* parent inode */
73 jint32_t version; /* dirent version */
74 jint32_t ino; /* == zero for unlink */
75 uint8_t nsize; /* dirent name size */
76 uint8_t type; /* dirent type */
77 uint8_t name[0]; /* dirent name */
78 } __attribute__((packed));
80 struct jffs2_sum_xattr_flash
82 jint16_t nodetype; /* == JFFS2_NODETYPE_XATR */
83 jint32_t xid; /* xattr identifier */
84 jint32_t version; /* version number */
85 jint32_t offset; /* offset on jeb */
86 jint32_t totlen; /* node length */
87 } __attribute__((packed));
89 struct jffs2_sum_xref_flash
91 jint16_t nodetype; /* == JFFS2_NODETYPE_XREF */
92 jint32_t offset; /* offset on jeb */
93 } __attribute__((packed));
97 struct jffs2_sum_unknown_flash u;
98 struct jffs2_sum_inode_flash i;
99 struct jffs2_sum_dirent_flash d;
100 struct jffs2_sum_xattr_flash x;
101 struct jffs2_sum_xref_flash r;
104 /* Summary structures used in the memory */
106 struct jffs2_sum_unknown_mem
108 union jffs2_sum_mem *next;
109 jint16_t nodetype; /* node type */
112 struct jffs2_sum_inode_mem
114 union jffs2_sum_mem *next;
115 jint16_t nodetype; /* node type */
116 jint32_t inode; /* inode number */
117 jint32_t version; /* inode version */
118 jint32_t offset; /* offset on jeb */
119 jint32_t totlen; /* record length */
120 } __attribute__((packed));
122 struct jffs2_sum_dirent_mem
124 union jffs2_sum_mem *next;
125 jint16_t nodetype; /* == JFFS_NODETYPE_DIRENT */
126 jint32_t totlen; /* record length */
127 jint32_t offset; /* ofset on jeb */
128 jint32_t pino; /* parent inode */
129 jint32_t version; /* dirent version */
130 jint32_t ino; /* == zero for unlink */
131 uint8_t nsize; /* dirent name size */
132 uint8_t type; /* dirent type */
133 uint8_t name[0]; /* dirent name */
134 } __attribute__((packed));
136 struct jffs2_sum_xattr_mem
138 union jffs2_sum_mem *next;
144 } __attribute__((packed));
146 struct jffs2_sum_xref_mem
148 union jffs2_sum_mem *next;
151 } __attribute__((packed));
155 struct jffs2_sum_unknown_mem u;
156 struct jffs2_sum_inode_mem i;
157 struct jffs2_sum_dirent_mem d;
158 struct jffs2_sum_xattr_mem x;
159 struct jffs2_sum_xref_mem r;
162 /* Summary related information stored in superblock */
166 uint32_t sum_size; /* collected summary information for nextblock */
169 union jffs2_sum_mem *sum_list_head;
170 union jffs2_sum_mem *sum_list_tail;
172 jint32_t *sum_buf; /* buffer for writing out summary */
175 /* Summary marker is stored at the end of every sumarized erase block */
177 struct jffs2_sum_marker
179 jint32_t offset; /* offset of the summary node in the jeb */
180 jint32_t magic; /* == JFFS2_SUM_MAGIC */
183 #define JFFS2_SUMMARY_FRAME_SIZE (sizeof(struct jffs2_raw_summary) + sizeof(struct jffs2_sum_marker))
185 #ifdef CONFIG_JFFS2_SUMMARY /* SUMMARY SUPPORT ENABLED */
187 #define jffs2_sum_active() (1)
188 int jffs2_sum_init(struct jffs2_sb_info *c);
189 void jffs2_sum_exit(struct jffs2_sb_info *c);
190 void jffs2_sum_disable_collecting(struct jffs2_summary *s);
191 int jffs2_sum_is_disabled(struct jffs2_summary *s);
192 void jffs2_sum_reset_collected(struct jffs2_summary *s);
193 void jffs2_sum_move_collected(struct jffs2_sb_info *c, struct jffs2_summary *s);
194 int jffs2_sum_add_kvec(struct jffs2_sb_info *c, const struct kvec *invecs,
195 unsigned long count, uint32_t to);
196 int jffs2_sum_write_sumnode(struct jffs2_sb_info *c);
197 int jffs2_sum_add_padding_mem(struct jffs2_summary *s, uint32_t size);
198 int jffs2_sum_add_inode_mem(struct jffs2_summary *s, struct jffs2_raw_inode *ri, uint32_t ofs);
199 int jffs2_sum_add_dirent_mem(struct jffs2_summary *s, struct jffs2_raw_dirent *rd, uint32_t ofs);
200 int jffs2_sum_add_xattr_mem(struct jffs2_summary *s, struct jffs2_raw_xattr *rx, uint32_t ofs);
201 int jffs2_sum_add_xref_mem(struct jffs2_summary *s, struct jffs2_raw_xref *rr, uint32_t ofs);
202 int jffs2_sum_scan_sumnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
203 uint32_t ofs, uint32_t *pseudo_random);
205 #else /* SUMMARY DISABLED */
207 #define jffs2_sum_active() (0)
208 #define jffs2_sum_init(a) (0)
209 #define jffs2_sum_exit(a)
210 #define jffs2_sum_disable_collecting(a)
211 #define jffs2_sum_is_disabled(a) (0)
212 #define jffs2_sum_reset_collected(a)
213 #define jffs2_sum_add_kvec(a,b,c,d) (0)
214 #define jffs2_sum_move_collected(a,b)
215 #define jffs2_sum_write_sumnode(a) (0)
216 #define jffs2_sum_add_padding_mem(a,b)
217 #define jffs2_sum_add_inode_mem(a,b,c)
218 #define jffs2_sum_add_dirent_mem(a,b,c)
219 #define jffs2_sum_add_xattr_mem(a,b,c)
220 #define jffs2_sum_add_xref_mem(a,b,c)
221 #define jffs2_sum_scan_sumnode(a,b,c,d) (0)
223 #endif /* CONFIG_JFFS2_SUMMARY */
225 #endif /* JFFS2_SUMMARY_H */