Commit | Line | Data |
---|---|---|
e631ddba FH |
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 | * $Id: summary.h,v 1.1 2005/09/07 08:34:54 havasi Exp $ | |
12 | * | |
13 | */ | |
14 | ||
15 | #ifndef JFFS2_SUMMARY_H | |
16 | #define JFFS2_SUMMARY_H | |
17 | ||
18 | #include <linux/uio.h> | |
19 | #include <linux/jffs2.h> | |
20 | ||
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; \ | |
24 | }while(0) | |
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; \ | |
28 | }while(0) | |
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; \ | |
32 | }while(0) | |
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; \ | |
36 | }while(0) | |
37 | ||
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 | |
44 | ||
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 | ||
49 | /* Summary structures used on flash */ | |
50 | ||
51 | struct jffs2_sum_unknown_flash | |
52 | { | |
53 | jint16_t nodetype; /* node type */ | |
54 | }; | |
55 | ||
56 | struct jffs2_sum_inode_flash | |
57 | { | |
58 | jint16_t nodetype; /* node type */ | |
59 | jint32_t inode; /* inode number */ | |
60 | jint32_t version; /* inode version */ | |
61 | jint32_t offset; /* offset on jeb */ | |
62 | jint32_t totlen; /* record length */ | |
63 | } __attribute__((packed)); | |
64 | ||
65 | struct jffs2_sum_dirent_flash | |
66 | { | |
67 | jint16_t nodetype; /* == JFFS_NODETYPE_DIRENT */ | |
68 | jint32_t totlen; /* record length */ | |
69 | jint32_t offset; /* offset on jeb */ | |
70 | jint32_t pino; /* parent inode */ | |
71 | jint32_t version; /* dirent version */ | |
72 | jint32_t ino; /* == zero for unlink */ | |
73 | uint8_t nsize; /* dirent name size */ | |
74 | uint8_t type; /* dirent type */ | |
75 | uint8_t name[0]; /* dirent name */ | |
76 | } __attribute__((packed)); | |
77 | ||
78 | union 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; | |
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 | union jffs2_sum_mem | |
118 | { | |
119 | struct jffs2_sum_unknown_mem u; | |
120 | struct jffs2_sum_inode_mem i; | |
121 | struct jffs2_sum_dirent_mem d; | |
122 | }; | |
123 | ||
124 | /* Summary related information stored in superblock */ | |
125 | ||
126 | struct jffs2_summary | |
127 | { | |
128 | uint32_t sum_size; /* collected summary information for nextblock */ | |
129 | uint32_t sum_num; | |
130 | uint32_t sum_padded; | |
131 | union jffs2_sum_mem *sum_list_head; | |
132 | union jffs2_sum_mem *sum_list_tail; | |
133 | ||
134 | jint32_t *sum_buf; /* buffer for writing out summary */ | |
135 | }; | |
136 | ||
137 | /* Summary marker is stored at the end of every sumarized erase block */ | |
138 | ||
139 | struct jffs2_sum_marker | |
140 | { | |
141 | jint32_t offset; /* offset of the summary node in the jeb */ | |
142 | jint32_t magic; /* == JFFS2_SUM_MAGIC */ | |
143 | }; | |
144 | ||
145 | #define JFFS2_SUMMARY_FRAME_SIZE (sizeof(struct jffs2_summary_node) + sizeof(struct jffs2_sum_marker)) | |
146 | ||
147 | #ifdef CONFIG_JFFS2_SUMMARY /* SUMMARY SUPPORT ENABLED */ | |
148 | ||
149 | #define jffs2_sum_active() (1) | |
150 | int jffs2_sum_init(struct jffs2_sb_info *c); | |
151 | void jffs2_sum_exit(struct jffs2_sb_info *c); | |
152 | void jffs2_sum_disable_collecting(struct jffs2_summary *s); | |
153 | int jffs2_sum_is_disabled(struct jffs2_summary *s); | |
154 | void jffs2_sum_reset_collected(struct jffs2_summary *s); | |
155 | void jffs2_sum_move_collected(struct jffs2_sb_info *c, struct jffs2_summary *s); | |
156 | int jffs2_sum_add_kvec(struct jffs2_sb_info *c, const struct kvec *invecs, | |
157 | unsigned long count, uint32_t to); | |
158 | int jffs2_sum_write_sumnode(struct jffs2_sb_info *c); | |
159 | int jffs2_sum_add_padding_mem(struct jffs2_summary *s, uint32_t size); | |
160 | int jffs2_sum_add_inode_mem(struct jffs2_summary *s, struct jffs2_raw_inode *ri, uint32_t ofs); | |
161 | int jffs2_sum_add_dirent_mem(struct jffs2_summary *s, struct jffs2_raw_dirent *rd, uint32_t ofs); | |
162 | int jffs2_sum_scan_sumnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, | |
163 | uint32_t ofs, uint32_t *pseudo_random); | |
164 | ||
165 | #else /* SUMMARY DISABLED */ | |
166 | ||
167 | #define jffs2_sum_active() (0) | |
168 | #define jffs2_sum_init(a) (0) | |
169 | #define jffs2_sum_exit(a) | |
170 | #define jffs2_sum_disable_collecting(a) | |
171 | #define jffs2_sum_is_disabled(a) (0) | |
172 | #define jffs2_sum_reset_collected(a) | |
173 | #define jffs2_sum_add_kvec(a,b,c,d) (0) | |
174 | #define jffs2_sum_move_collected(a,b) | |
175 | #define jffs2_sum_write_sumnode(a) (0) | |
176 | #define jffs2_sum_add_padding_mem(a,b) | |
177 | #define jffs2_sum_add_inode_mem(a,b,c) | |
178 | #define jffs2_sum_add_dirent_mem(a,b,c) | |
179 | #define jffs2_sum_scan_sumnode(a,b,c,d) (0) | |
180 | ||
181 | #endif /* CONFIG_JFFS2_SUMMARY */ | |
182 | ||
183 | #endif /* JFFS2_SUMMARY_H */ |