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