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