blob: 8bf34f2fa5ce30b6f50f9d16de3ad5b9df31195e [file] [log] [blame]
Ferenc Havasie631ddb2005-09-07 09:35:26 +01001/*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
David Woodhousec00c3102007-04-25 14:16:47 +01004 * Copyright © 2004 Ferenc Havasi <havasi@inf.u-szeged.hu>,
David Woodhouseef53cb02007-07-10 10:01:22 +01005 * Zoltan Sogor <weth@inf.u-szeged.hu>,
6 * Patrik Kluba <pajko@halom.u-szeged.hu>,
7 * University of Szeged, Hungary
Ferenc Havasie631ddb2005-09-07 09:35:26 +01008 *
9 * For licensing information, see the file 'LICENCE' in this directory.
10 *
Ferenc Havasie631ddb2005-09-07 09:35:26 +010011 */
12
13#ifndef JFFS2_SUMMARY_H
14#define JFFS2_SUMMARY_H
15
16#include <linux/uio.h>
17#include <linux/jffs2.h>
18
Ferenc Havasie631ddb2005-09-07 09:35:26 +010019#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))
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090029#define JFFS2_SUMMARY_XATTR_SIZE (sizeof(struct jffs2_sum_xattr_flash))
30#define JFFS2_SUMMARY_XREF_SIZE (sizeof(struct jffs2_sum_xref_flash))
Ferenc Havasie631ddb2005-09-07 09:35:26 +010031
32/* Summary structures used on flash */
33
34struct jffs2_sum_unknown_flash
35{
36 jint16_t nodetype; /* node type */
37};
38
39struct 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
48struct 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
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090061struct 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
70struct jffs2_sum_xref_flash
71{
72 jint16_t nodetype; /* == JFFS2_NODETYPE_XREF */
73 jint32_t offset; /* offset on jeb */
74} __attribute__((packed));
75
Ferenc Havasie631ddb2005-09-07 09:35:26 +010076union 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;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090081 struct jffs2_sum_xattr_flash x;
82 struct jffs2_sum_xref_flash r;
Ferenc Havasie631ddb2005-09-07 09:35:26 +010083};
84
85/* Summary structures used in the memory */
86
87struct jffs2_sum_unknown_mem
88{
89 union jffs2_sum_mem *next;
90 jint16_t nodetype; /* node type */
91};
92
93struct 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
103struct 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
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900117struct 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
127struct jffs2_sum_xref_mem
128{
129 union jffs2_sum_mem *next;
130 jint16_t nodetype;
131 jint32_t offset;
132} __attribute__((packed));
133
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100134union 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;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900139 struct jffs2_sum_xattr_mem x;
140 struct jffs2_sum_xref_mem r;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100141};
142
143/* Summary related information stored in superblock */
144
145struct 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
158struct 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
Ferenc Havasi2bc97642005-09-26 12:37:25 +0100164#define JFFS2_SUMMARY_FRAME_SIZE (sizeof(struct jffs2_raw_summary) + sizeof(struct jffs2_sum_marker))
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100165
166#ifdef CONFIG_JFFS2_SUMMARY /* SUMMARY SUPPORT ENABLED */
167
168#define jffs2_sum_active() (1)
169int jffs2_sum_init(struct jffs2_sb_info *c);
170void jffs2_sum_exit(struct jffs2_sb_info *c);
171void jffs2_sum_disable_collecting(struct jffs2_summary *s);
172int jffs2_sum_is_disabled(struct jffs2_summary *s);
173void jffs2_sum_reset_collected(struct jffs2_summary *s);
174void jffs2_sum_move_collected(struct jffs2_sb_info *c, struct jffs2_summary *s);
175int jffs2_sum_add_kvec(struct jffs2_sb_info *c, const struct kvec *invecs,
176 unsigned long count, uint32_t to);
177int jffs2_sum_write_sumnode(struct jffs2_sb_info *c);
178int jffs2_sum_add_padding_mem(struct jffs2_summary *s, uint32_t size);
179int jffs2_sum_add_inode_mem(struct jffs2_summary *s, struct jffs2_raw_inode *ri, uint32_t ofs);
180int jffs2_sum_add_dirent_mem(struct jffs2_summary *s, struct jffs2_raw_dirent *rd, uint32_t ofs);
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900181int jffs2_sum_add_xattr_mem(struct jffs2_summary *s, struct jffs2_raw_xattr *rx, uint32_t ofs);
182int jffs2_sum_add_xref_mem(struct jffs2_summary *s, struct jffs2_raw_xref *rr, uint32_t ofs);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100183int jffs2_sum_scan_sumnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
David Woodhouse9641b782006-05-20 16:13:34 +0100184 struct jffs2_raw_summary *summary, uint32_t sumlen,
185 uint32_t *pseudo_random);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100186
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)
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900201#define jffs2_sum_add_xattr_mem(a,b,c)
202#define jffs2_sum_add_xref_mem(a,b,c)
David Woodhouse06c67642006-05-22 11:27:14 +0100203#define jffs2_sum_scan_sumnode(a,b,c,d,e) (0)
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100204
205#endif /* CONFIG_JFFS2_SUMMARY */
206
207#endif /* JFFS2_SUMMARY_H */