blob: 629af01e5ade432c33c3c06506e6bc557125da08 [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
8 * 2006 KaiGai Kohei <kaigai@ak.jp.nec.com>
Ferenc Havasie631ddb2005-09-07 09:35:26 +01009 *
10 * For licensing information, see the file 'LICENCE' in this directory.
11 *
Ferenc Havasie631ddb2005-09-07 09:35:26 +010012 */
13
14#include <linux/kernel.h>
Ferenc Havasie631ddb2005-09-07 09:35:26 +010015#include <linux/slab.h>
16#include <linux/mtd/mtd.h>
17#include <linux/pagemap.h>
18#include <linux/crc32.h>
19#include <linux/compiler.h>
20#include <linux/vmalloc.h>
21#include "nodelist.h"
22#include "debug.h"
23
24int jffs2_sum_init(struct jffs2_sb_info *c)
25{
Yan Burman3d375d92006-12-04 15:03:01 -080026 c->summary = kzalloc(sizeof(struct jffs2_summary), GFP_KERNEL);
Ferenc Havasie631ddb2005-09-07 09:35:26 +010027
28 if (!c->summary) {
29 JFFS2_WARNING("Can't allocate memory for summary information!\n");
30 return -ENOMEM;
31 }
32
Ferenc Havasie631ddb2005-09-07 09:35:26 +010033 c->summary->sum_buf = vmalloc(c->sector_size);
34
35 if (!c->summary->sum_buf) {
36 JFFS2_WARNING("Can't allocate buffer for writing out summary information!\n");
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +010037 kfree(c->summary);
Ferenc Havasie631ddb2005-09-07 09:35:26 +010038 return -ENOMEM;
39 }
40
Andreas Mohrd6e05ed2006-06-26 18:35:02 +020041 dbg_summary("returned successfully\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +010042
43 return 0;
44}
45
46void jffs2_sum_exit(struct jffs2_sb_info *c)
47{
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +010048 dbg_summary("called\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +010049
50 jffs2_sum_disable_collecting(c->summary);
51
52 vfree(c->summary->sum_buf);
53 c->summary->sum_buf = NULL;
54
55 kfree(c->summary);
56 c->summary = NULL;
57}
58
59static int jffs2_sum_add_mem(struct jffs2_summary *s, union jffs2_sum_mem *item)
60{
61 if (!s->sum_list_head)
62 s->sum_list_head = (union jffs2_sum_mem *) item;
63 if (s->sum_list_tail)
64 s->sum_list_tail->u.next = (union jffs2_sum_mem *) item;
65 s->sum_list_tail = (union jffs2_sum_mem *) item;
66
67 switch (je16_to_cpu(item->u.nodetype)) {
68 case JFFS2_NODETYPE_INODE:
69 s->sum_size += JFFS2_SUMMARY_INODE_SIZE;
70 s->sum_num++;
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +010071 dbg_summary("inode (%u) added to summary\n",
Ferenc Havasie631ddb2005-09-07 09:35:26 +010072 je32_to_cpu(item->i.inode));
73 break;
74 case JFFS2_NODETYPE_DIRENT:
75 s->sum_size += JFFS2_SUMMARY_DIRENT_SIZE(item->d.nsize);
76 s->sum_num++;
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +010077 dbg_summary("dirent (%u) added to summary\n",
Ferenc Havasie631ddb2005-09-07 09:35:26 +010078 je32_to_cpu(item->d.ino));
79 break;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090080#ifdef CONFIG_JFFS2_FS_XATTR
81 case JFFS2_NODETYPE_XATTR:
82 s->sum_size += JFFS2_SUMMARY_XATTR_SIZE;
83 s->sum_num++;
84 dbg_summary("xattr (xid=%u, version=%u) added to summary\n",
85 je32_to_cpu(item->x.xid), je32_to_cpu(item->x.version));
86 break;
87 case JFFS2_NODETYPE_XREF:
88 s->sum_size += JFFS2_SUMMARY_XREF_SIZE;
89 s->sum_num++;
90 dbg_summary("xref added to summary\n");
91 break;
92#endif
Ferenc Havasie631ddb2005-09-07 09:35:26 +010093 default:
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000094 JFFS2_WARNING("UNKNOWN node type %u\n",
Ferenc Havasie631ddb2005-09-07 09:35:26 +010095 je16_to_cpu(item->u.nodetype));
96 return 1;
97 }
98 return 0;
99}
100
101
102/* The following 3 functions are called from scan.c to collect summary info for not closed jeb */
103
104int jffs2_sum_add_padding_mem(struct jffs2_summary *s, uint32_t size)
105{
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100106 dbg_summary("called with %u\n", size);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100107 s->sum_padded += size;
108 return 0;
109}
110
111int jffs2_sum_add_inode_mem(struct jffs2_summary *s, struct jffs2_raw_inode *ri,
112 uint32_t ofs)
113{
114 struct jffs2_sum_inode_mem *temp = kmalloc(sizeof(struct jffs2_sum_inode_mem), GFP_KERNEL);
115
116 if (!temp)
117 return -ENOMEM;
118
119 temp->nodetype = ri->nodetype;
120 temp->inode = ri->ino;
121 temp->version = ri->version;
122 temp->offset = cpu_to_je32(ofs); /* relative offset from the begining of the jeb */
123 temp->totlen = ri->totlen;
124 temp->next = NULL;
125
126 return jffs2_sum_add_mem(s, (union jffs2_sum_mem *)temp);
127}
128
129int jffs2_sum_add_dirent_mem(struct jffs2_summary *s, struct jffs2_raw_dirent *rd,
130 uint32_t ofs)
131{
132 struct jffs2_sum_dirent_mem *temp =
133 kmalloc(sizeof(struct jffs2_sum_dirent_mem) + rd->nsize, GFP_KERNEL);
134
135 if (!temp)
136 return -ENOMEM;
137
138 temp->nodetype = rd->nodetype;
139 temp->totlen = rd->totlen;
140 temp->offset = cpu_to_je32(ofs); /* relative from the begining of the jeb */
141 temp->pino = rd->pino;
142 temp->version = rd->version;
143 temp->ino = rd->ino;
144 temp->nsize = rd->nsize;
145 temp->type = rd->type;
146 temp->next = NULL;
147
148 memcpy(temp->name, rd->name, rd->nsize);
149
150 return jffs2_sum_add_mem(s, (union jffs2_sum_mem *)temp);
151}
152
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900153#ifdef CONFIG_JFFS2_FS_XATTR
154int jffs2_sum_add_xattr_mem(struct jffs2_summary *s, struct jffs2_raw_xattr *rx, uint32_t ofs)
155{
156 struct jffs2_sum_xattr_mem *temp;
157
158 temp = kmalloc(sizeof(struct jffs2_sum_xattr_mem), GFP_KERNEL);
159 if (!temp)
160 return -ENOMEM;
161
162 temp->nodetype = rx->nodetype;
163 temp->xid = rx->xid;
164 temp->version = rx->version;
165 temp->offset = cpu_to_je32(ofs);
166 temp->totlen = rx->totlen;
167 temp->next = NULL;
168
169 return jffs2_sum_add_mem(s, (union jffs2_sum_mem *)temp);
170}
171
172int jffs2_sum_add_xref_mem(struct jffs2_summary *s, struct jffs2_raw_xref *rr, uint32_t ofs)
173{
174 struct jffs2_sum_xref_mem *temp;
175
176 temp = kmalloc(sizeof(struct jffs2_sum_xref_mem), GFP_KERNEL);
177 if (!temp)
178 return -ENOMEM;
179
180 temp->nodetype = rr->nodetype;
181 temp->offset = cpu_to_je32(ofs);
182 temp->next = NULL;
183
184 return jffs2_sum_add_mem(s, (union jffs2_sum_mem *)temp);
185}
186#endif
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100187/* Cleanup every collected summary information */
188
189static void jffs2_sum_clean_collected(struct jffs2_summary *s)
190{
191 union jffs2_sum_mem *temp;
192
193 if (!s->sum_list_head) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100194 dbg_summary("already empty\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100195 }
196 while (s->sum_list_head) {
197 temp = s->sum_list_head;
198 s->sum_list_head = s->sum_list_head->u.next;
199 kfree(temp);
200 }
201 s->sum_list_tail = NULL;
202 s->sum_padded = 0;
203 s->sum_num = 0;
204}
205
206void jffs2_sum_reset_collected(struct jffs2_summary *s)
207{
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100208 dbg_summary("called\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100209 jffs2_sum_clean_collected(s);
210 s->sum_size = 0;
211}
212
213void jffs2_sum_disable_collecting(struct jffs2_summary *s)
214{
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100215 dbg_summary("called\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100216 jffs2_sum_clean_collected(s);
217 s->sum_size = JFFS2_SUMMARY_NOSUM_SIZE;
218}
219
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000220int jffs2_sum_is_disabled(struct jffs2_summary *s)
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100221{
222 return (s->sum_size == JFFS2_SUMMARY_NOSUM_SIZE);
223}
224
225/* Move the collected summary information into sb (called from scan.c) */
226
227void jffs2_sum_move_collected(struct jffs2_sb_info *c, struct jffs2_summary *s)
228{
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100229 dbg_summary("oldsize=0x%x oldnum=%u => newsize=0x%x newnum=%u\n",
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100230 c->summary->sum_size, c->summary->sum_num,
231 s->sum_size, s->sum_num);
232
233 c->summary->sum_size = s->sum_size;
234 c->summary->sum_num = s->sum_num;
235 c->summary->sum_padded = s->sum_padded;
236 c->summary->sum_list_head = s->sum_list_head;
237 c->summary->sum_list_tail = s->sum_list_tail;
238
239 s->sum_list_head = s->sum_list_tail = NULL;
240}
241
242/* Called from wbuf.c to collect writed node info */
243
244int jffs2_sum_add_kvec(struct jffs2_sb_info *c, const struct kvec *invecs,
245 unsigned long count, uint32_t ofs)
246{
247 union jffs2_node_union *node;
248 struct jffs2_eraseblock *jeb;
249
Zoltan Sogor27bea322006-09-16 12:15:59 -0700250 if (c->summary->sum_size == JFFS2_SUMMARY_NOSUM_SIZE) {
251 dbg_summary("Summary is disabled for this jeb! Skipping summary info!\n");
252 return 0;
253 }
254
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100255 node = invecs[0].iov_base;
256 jeb = &c->blocks[ofs / c->sector_size];
257 ofs -= jeb->offset;
258
259 switch (je16_to_cpu(node->u.nodetype)) {
260 case JFFS2_NODETYPE_INODE: {
261 struct jffs2_sum_inode_mem *temp =
262 kmalloc(sizeof(struct jffs2_sum_inode_mem), GFP_KERNEL);
263
264 if (!temp)
265 goto no_mem;
266
267 temp->nodetype = node->i.nodetype;
268 temp->inode = node->i.ino;
269 temp->version = node->i.version;
270 temp->offset = cpu_to_je32(ofs);
271 temp->totlen = node->i.totlen;
272 temp->next = NULL;
273
274 return jffs2_sum_add_mem(c->summary, (union jffs2_sum_mem *)temp);
275 }
276
277 case JFFS2_NODETYPE_DIRENT: {
278 struct jffs2_sum_dirent_mem *temp =
279 kmalloc(sizeof(struct jffs2_sum_dirent_mem) + node->d.nsize, GFP_KERNEL);
280
281 if (!temp)
282 goto no_mem;
283
284 temp->nodetype = node->d.nodetype;
285 temp->totlen = node->d.totlen;
286 temp->offset = cpu_to_je32(ofs);
287 temp->pino = node->d.pino;
288 temp->version = node->d.version;
289 temp->ino = node->d.ino;
290 temp->nsize = node->d.nsize;
291 temp->type = node->d.type;
292 temp->next = NULL;
293
294 switch (count) {
295 case 1:
296 memcpy(temp->name,node->d.name,node->d.nsize);
297 break;
298
299 case 2:
300 memcpy(temp->name,invecs[1].iov_base,node->d.nsize);
301 break;
302
303 default:
304 BUG(); /* impossible count value */
305 break;
306 }
307
308 return jffs2_sum_add_mem(c->summary, (union jffs2_sum_mem *)temp);
309 }
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900310#ifdef CONFIG_JFFS2_FS_XATTR
311 case JFFS2_NODETYPE_XATTR: {
312 struct jffs2_sum_xattr_mem *temp;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900313 temp = kmalloc(sizeof(struct jffs2_sum_xattr_mem), GFP_KERNEL);
314 if (!temp)
315 goto no_mem;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100316
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900317 temp->nodetype = node->x.nodetype;
318 temp->xid = node->x.xid;
319 temp->version = node->x.version;
320 temp->totlen = node->x.totlen;
321 temp->offset = cpu_to_je32(ofs);
322 temp->next = NULL;
323
324 return jffs2_sum_add_mem(c->summary, (union jffs2_sum_mem *)temp);
325 }
326 case JFFS2_NODETYPE_XREF: {
327 struct jffs2_sum_xref_mem *temp;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900328 temp = kmalloc(sizeof(struct jffs2_sum_xref_mem), GFP_KERNEL);
329 if (!temp)
330 goto no_mem;
331 temp->nodetype = node->r.nodetype;
332 temp->offset = cpu_to_je32(ofs);
333 temp->next = NULL;
334
335 return jffs2_sum_add_mem(c->summary, (union jffs2_sum_mem *)temp);
336 }
337#endif
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100338 case JFFS2_NODETYPE_PADDING:
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100339 dbg_summary("node PADDING\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100340 c->summary->sum_padded += je32_to_cpu(node->u.totlen);
341 break;
342
343 case JFFS2_NODETYPE_CLEANMARKER:
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100344 dbg_summary("node CLEANMARKER\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100345 break;
346
347 case JFFS2_NODETYPE_SUMMARY:
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100348 dbg_summary("node SUMMARY\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100349 break;
350
351 default:
352 /* If you implement a new node type you should also implement
353 summary support for it or disable summary.
354 */
355 BUG();
356 break;
357 }
358
359 return 0;
360
361no_mem:
362 JFFS2_WARNING("MEMORY ALLOCATION ERROR!");
363 return -ENOMEM;
364}
365
David Woodhouse2f785402006-05-24 02:04:45 +0100366static struct jffs2_raw_node_ref *sum_link_node_ref(struct jffs2_sb_info *c,
367 struct jffs2_eraseblock *jeb,
368 uint32_t ofs, uint32_t len,
369 struct jffs2_inode_cache *ic)
David Woodhouse49f11d42006-05-21 04:00:01 +0100370{
David Woodhouse49f11d42006-05-21 04:00:01 +0100371 /* If there was a gap, mark it dirty */
David Woodhouse2f785402006-05-24 02:04:45 +0100372 if ((ofs & ~3) > c->sector_size - jeb->free_size) {
373 /* Ew. Summary doesn't actually tell us explicitly about dirty space */
374 jffs2_scan_dirty_space(c, jeb, (ofs & ~3) - (c->sector_size - jeb->free_size));
David Woodhouse49f11d42006-05-21 04:00:01 +0100375 }
David Woodhouse49f11d42006-05-21 04:00:01 +0100376
David Woodhouse2f785402006-05-24 02:04:45 +0100377 return jffs2_link_node_ref(c, jeb, jeb->offset + ofs, len, ic);
David Woodhouse49f11d42006-05-21 04:00:01 +0100378}
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100379
380/* Process the stored summary information - helper function for jffs2_sum_scan_sumnode() */
381
382static int jffs2_sum_process_sum_data(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
Ferenc Havasi2bc97642005-09-26 12:37:25 +0100383 struct jffs2_raw_summary *summary, uint32_t *pseudo_random)
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100384{
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100385 struct jffs2_inode_cache *ic;
386 struct jffs2_full_dirent *fd;
387 void *sp;
388 int i, ino;
David Woodhouse68270992006-05-21 03:46:05 +0100389 int err;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100390
391 sp = summary->sum;
392
393 for (i=0; i<je32_to_cpu(summary->sum_num); i++) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100394 dbg_summary("processing summary index %d\n", i);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100395
Artem Bityutskiya2166b92006-12-28 12:01:41 +0200396 cond_resched();
397
David Woodhouse2f785402006-05-24 02:04:45 +0100398 /* Make sure there's a spare ref for dirty space */
David Woodhouse046b8b92006-05-25 01:50:35 +0100399 err = jffs2_prealloc_raw_node_refs(c, jeb, 2);
David Woodhouse2f785402006-05-24 02:04:45 +0100400 if (err)
401 return err;
402
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100403 switch (je16_to_cpu(((struct jffs2_sum_unknown_flash *)sp)->nodetype)) {
404 case JFFS2_NODETYPE_INODE: {
405 struct jffs2_sum_inode_flash *spi;
406 spi = sp;
407
408 ino = je32_to_cpu(spi->inode);
409
David Woodhouse9167e0f2006-05-21 13:13:45 +0100410 dbg_summary("Inode at 0x%08x-0x%08x\n",
411 jeb->offset + je32_to_cpu(spi->offset),
David Woodhouse8b9e9fe2006-05-25 01:53:09 +0100412 jeb->offset + je32_to_cpu(spi->offset) + je32_to_cpu(spi->totlen));
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100413
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100414 ic = jffs2_scan_make_ino_cache(c, ino);
415 if (!ic) {
416 JFFS2_NOTICE("scan_make_ino_cache failed\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100417 return -ENOMEM;
418 }
419
David Woodhouse2f785402006-05-24 02:04:45 +0100420 sum_link_node_ref(c, jeb, je32_to_cpu(spi->offset) | REF_UNCHECKED,
421 PAD(je32_to_cpu(spi->totlen)), ic);
David Woodhousef1f96712006-05-20 19:45:26 +0100422
423 *pseudo_random += je32_to_cpu(spi->version);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100424
425 sp += JFFS2_SUMMARY_INODE_SIZE;
426
427 break;
428 }
429
430 case JFFS2_NODETYPE_DIRENT: {
431 struct jffs2_sum_dirent_flash *spd;
David Woodhouseb534e702007-10-13 11:35:58 +0100432 int checkedlen;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100433 spd = sp;
434
David Woodhouse8b9e9fe2006-05-25 01:53:09 +0100435 dbg_summary("Dirent at 0x%08x-0x%08x\n",
David Woodhouse9167e0f2006-05-21 13:13:45 +0100436 jeb->offset + je32_to_cpu(spd->offset),
437 jeb->offset + je32_to_cpu(spd->offset) + je32_to_cpu(spd->totlen));
438
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100439
David Woodhouseb534e702007-10-13 11:35:58 +0100440 /* This should never happen, but https://dev.laptop.org/ticket/4184 */
441 checkedlen = strnlen(spd->name, spd->nsize);
442 if (!checkedlen) {
443 printk(KERN_ERR "Dirent at %08x has zero at start of name. Aborting mount.\n",
444 jeb->offset + je32_to_cpu(spd->offset));
445 return -EIO;
446 }
447 if (checkedlen < spd->nsize) {
448 printk(KERN_ERR "Dirent at %08x has zeroes in name. Truncating to %d chars\n",
449 jeb->offset + je32_to_cpu(spd->offset), checkedlen);
450 }
451
452
453 fd = jffs2_alloc_full_dirent(checkedlen+1);
David Woodhouse9641b782006-05-20 16:13:34 +0100454 if (!fd)
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100455 return -ENOMEM;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100456
David Woodhouseb534e702007-10-13 11:35:58 +0100457 memcpy(&fd->name, spd->name, checkedlen);
458 fd->name[checkedlen] = 0;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100459
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100460 ic = jffs2_scan_make_ino_cache(c, je32_to_cpu(spd->pino));
461 if (!ic) {
462 jffs2_free_full_dirent(fd);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100463 return -ENOMEM;
464 }
465
David Woodhouse1046d882006-06-18 22:44:21 +0100466 fd->raw = sum_link_node_ref(c, jeb, je32_to_cpu(spd->offset) | REF_UNCHECKED,
David Woodhouse2f785402006-05-24 02:04:45 +0100467 PAD(je32_to_cpu(spd->totlen)), ic);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100468
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100469 fd->next = NULL;
470 fd->version = je32_to_cpu(spd->version);
471 fd->ino = je32_to_cpu(spd->ino);
David Woodhouseb534e702007-10-13 11:35:58 +0100472 fd->nhash = full_name_hash(fd->name, checkedlen);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100473 fd->type = spd->type;
David Woodhousef1f96712006-05-20 19:45:26 +0100474
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100475 jffs2_add_fd_to_list(c, fd, &ic->scan_dents);
476
477 *pseudo_random += je32_to_cpu(spd->version);
478
479 sp += JFFS2_SUMMARY_DIRENT_SIZE(spd->nsize);
480
481 break;
482 }
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900483#ifdef CONFIG_JFFS2_FS_XATTR
484 case JFFS2_NODETYPE_XATTR: {
485 struct jffs2_xattr_datum *xd;
486 struct jffs2_sum_xattr_flash *spx;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100487
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900488 spx = (struct jffs2_sum_xattr_flash *)sp;
David Woodhouse9167e0f2006-05-21 13:13:45 +0100489 dbg_summary("xattr at %#08x-%#08x (xid=%u, version=%u)\n",
David Woodhouse49f11d42006-05-21 04:00:01 +0100490 jeb->offset + je32_to_cpu(spx->offset),
David Woodhouse9167e0f2006-05-21 13:13:45 +0100491 jeb->offset + je32_to_cpu(spx->offset) + je32_to_cpu(spx->totlen),
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900492 je32_to_cpu(spx->xid), je32_to_cpu(spx->version));
David Woodhouse2f785402006-05-24 02:04:45 +0100493
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900494 xd = jffs2_setup_xattr_datum(c, je32_to_cpu(spx->xid),
495 je32_to_cpu(spx->version));
KaiGai Koheic9f700f2006-06-11 10:35:15 +0900496 if (IS_ERR(xd))
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900497 return PTR_ERR(xd);
KaiGai Koheic9f700f2006-06-11 10:35:15 +0900498 if (xd->version > je32_to_cpu(spx->version)) {
499 /* node is not the newest one */
500 struct jffs2_raw_node_ref *raw
501 = sum_link_node_ref(c, jeb, je32_to_cpu(spx->offset) | REF_UNCHECKED,
502 PAD(je32_to_cpu(spx->totlen)), NULL);
503 raw->next_in_ino = xd->node->next_in_ino;
504 xd->node->next_in_ino = raw;
505 } else {
506 xd->version = je32_to_cpu(spx->version);
507 sum_link_node_ref(c, jeb, je32_to_cpu(spx->offset) | REF_UNCHECKED,
508 PAD(je32_to_cpu(spx->totlen)), (void *)xd);
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900509 }
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900510 *pseudo_random += je32_to_cpu(spx->xid);
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900511 sp += JFFS2_SUMMARY_XATTR_SIZE;
512
513 break;
514 }
515 case JFFS2_NODETYPE_XREF: {
516 struct jffs2_xattr_ref *ref;
517 struct jffs2_sum_xref_flash *spr;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900518
519 spr = (struct jffs2_sum_xref_flash *)sp;
David Woodhouse9167e0f2006-05-21 13:13:45 +0100520 dbg_summary("xref at %#08x-%#08x\n",
David Woodhouse49f11d42006-05-21 04:00:01 +0100521 jeb->offset + je32_to_cpu(spr->offset),
David Woodhouse9bfeb692006-05-26 21:19:05 +0100522 jeb->offset + je32_to_cpu(spr->offset) +
523 (uint32_t)PAD(sizeof(struct jffs2_raw_xref)));
David Woodhouse9167e0f2006-05-21 13:13:45 +0100524
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900525 ref = jffs2_alloc_xattr_ref();
526 if (!ref) {
527 JFFS2_NOTICE("allocation of xattr_datum failed\n");
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900528 return -ENOMEM;
529 }
KaiGai Kohei8f2b6f42006-05-13 15:15:07 +0900530 ref->next = c->xref_temp;
531 c->xref_temp = ref;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900532
KaiGai Koheic9f700f2006-06-11 10:35:15 +0900533 sum_link_node_ref(c, jeb, je32_to_cpu(spr->offset) | REF_UNCHECKED,
534 PAD(sizeof(struct jffs2_raw_xref)), (void *)ref);
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900535
David Woodhouse2f785402006-05-24 02:04:45 +0100536 *pseudo_random += ref->node->flash_offset;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900537 sp += JFFS2_SUMMARY_XREF_SIZE;
538
539 break;
540 }
541#endif
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100542 default : {
David Woodhouse7807ef72006-05-21 03:45:27 +0100543 uint16_t nodetype = je16_to_cpu(((struct jffs2_sum_unknown_flash *)sp)->nodetype);
544 JFFS2_WARNING("Unsupported node type %x found in summary! Exiting...\n", nodetype);
545 if ((nodetype & JFFS2_COMPAT_MASK) == JFFS2_FEATURE_INCOMPAT)
546 return -EIO;
547
548 /* For compatible node types, just fall back to the full scan */
549 c->wasted_size -= jeb->wasted_size;
550 c->free_size += c->sector_size - jeb->free_size;
551 c->used_size -= jeb->used_size;
552 c->dirty_size -= jeb->dirty_size;
553 jeb->wasted_size = jeb->used_size = jeb->dirty_size = 0;
554 jeb->free_size = c->sector_size;
555
David Woodhousec38c1b62006-05-25 01:38:27 +0100556 jffs2_free_jeb_node_refs(c, jeb);
David Woodhouse7807ef72006-05-21 03:45:27 +0100557 return -ENOTRECOVERABLE;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100558 }
559 }
560 }
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100561 return 0;
562}
563
564/* Process the summary node - called from jffs2_scan_eraseblock() */
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100565int jffs2_sum_scan_sumnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
David Woodhouse9641b782006-05-20 16:13:34 +0100566 struct jffs2_raw_summary *summary, uint32_t sumsize,
567 uint32_t *pseudo_random)
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100568{
569 struct jffs2_unknown_node crcnode;
David Woodhouse9641b782006-05-20 16:13:34 +0100570 int ret, ofs;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100571 uint32_t crc;
572
David Woodhouse49f11d42006-05-21 04:00:01 +0100573 ofs = c->sector_size - sumsize;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100574
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100575 dbg_summary("summary found for 0x%08x at 0x%08x (0x%x bytes)\n",
David Woodhouse49f11d42006-05-21 04:00:01 +0100576 jeb->offset, jeb->offset + ofs, sumsize);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100577
578 /* OK, now check for node validity and CRC */
579 crcnode.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
580 crcnode.nodetype = cpu_to_je16(JFFS2_NODETYPE_SUMMARY);
581 crcnode.totlen = summary->totlen;
582 crc = crc32(0, &crcnode, sizeof(crcnode)-4);
583
584 if (je32_to_cpu(summary->hdr_crc) != crc) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100585 dbg_summary("Summary node header is corrupt (bad CRC or "
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100586 "no summary at all)\n");
587 goto crc_err;
588 }
589
590 if (je32_to_cpu(summary->totlen) != sumsize) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100591 dbg_summary("Summary node is corrupt (wrong erasesize?)\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100592 goto crc_err;
593 }
594
Ferenc Havasi2bc97642005-09-26 12:37:25 +0100595 crc = crc32(0, summary, sizeof(struct jffs2_raw_summary)-8);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100596
597 if (je32_to_cpu(summary->node_crc) != crc) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100598 dbg_summary("Summary node is corrupt (bad CRC)\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100599 goto crc_err;
600 }
601
Ferenc Havasi2bc97642005-09-26 12:37:25 +0100602 crc = crc32(0, summary->sum, sumsize - sizeof(struct jffs2_raw_summary));
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100603
604 if (je32_to_cpu(summary->sum_crc) != crc) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100605 dbg_summary("Summary node data is corrupt (bad CRC)\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100606 goto crc_err;
607 }
608
609 if ( je32_to_cpu(summary->cln_mkr) ) {
610
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100611 dbg_summary("Summary : CLEANMARKER node \n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100612
David Woodhouse098a1982006-05-30 09:00:14 +0100613 ret = jffs2_prealloc_raw_node_refs(c, jeb, 1);
614 if (ret)
615 return ret;
616
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100617 if (je32_to_cpu(summary->cln_mkr) != c->cleanmarker_size) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100618 dbg_summary("CLEANMARKER node has totlen 0x%x != normal 0x%x\n",
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100619 je32_to_cpu(summary->cln_mkr), c->cleanmarker_size);
David Woodhouse098a1982006-05-30 09:00:14 +0100620 if ((ret = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(summary->cln_mkr)))))
621 return ret;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100622 } else if (jeb->first_node) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100623 dbg_summary("CLEANMARKER node not first node in block "
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100624 "(0x%08x)\n", jeb->offset);
David Woodhouse098a1982006-05-30 09:00:14 +0100625 if ((ret = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(summary->cln_mkr)))))
626 return ret;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100627 } else {
David Woodhouse2f785402006-05-24 02:04:45 +0100628 jffs2_link_node_ref(c, jeb, jeb->offset | REF_NORMAL,
629 je32_to_cpu(summary->cln_mkr), NULL);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100630 }
631 }
632
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100633 ret = jffs2_sum_process_sum_data(c, jeb, summary, pseudo_random);
David Woodhouse7807ef72006-05-21 03:45:27 +0100634 /* -ENOTRECOVERABLE isn't a fatal error -- it means we should do a full
635 scan of this eraseblock. So return zero */
636 if (ret == -ENOTRECOVERABLE)
637 return 0;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100638 if (ret)
David Woodhouse7807ef72006-05-21 03:45:27 +0100639 return ret; /* real error */
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100640
641 /* for PARANOIA_CHECK */
David Woodhouse046b8b92006-05-25 01:50:35 +0100642 ret = jffs2_prealloc_raw_node_refs(c, jeb, 2);
David Woodhouse2f785402006-05-24 02:04:45 +0100643 if (ret)
644 return ret;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100645
David Woodhousef61579c32006-05-25 01:42:40 +0100646 sum_link_node_ref(c, jeb, ofs | REF_NORMAL, sumsize, NULL);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100647
David Woodhouse49f11d42006-05-21 04:00:01 +0100648 if (unlikely(jeb->free_size)) {
649 JFFS2_WARNING("Free size 0x%x bytes in eraseblock @0x%08x with summary?\n",
650 jeb->free_size, jeb->offset);
651 jeb->wasted_size += jeb->free_size;
652 c->wasted_size += jeb->free_size;
653 c->free_size -= jeb->free_size;
654 jeb->free_size = 0;
655 }
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100656
657 return jffs2_scan_classify_jeb(c, jeb);
658
659crc_err:
660 JFFS2_WARNING("Summary node crc error, skipping summary information.\n");
661
662 return 0;
663}
664
665/* Write summary data to flash - helper function for jffs2_sum_write_sumnode() */
666
667static int jffs2_sum_write_data(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
668 uint32_t infosize, uint32_t datasize, int padsize)
669{
Ferenc Havasi2bc97642005-09-26 12:37:25 +0100670 struct jffs2_raw_summary isum;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100671 union jffs2_sum_mem *temp;
672 struct jffs2_sum_marker *sm;
673 struct kvec vecs[2];
David Woodhouse2f785402006-05-24 02:04:45 +0100674 uint32_t sum_ofs;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100675 void *wpage;
676 int ret;
677 size_t retlen;
678
679 memset(c->summary->sum_buf, 0xff, datasize);
680 memset(&isum, 0, sizeof(isum));
681
682 isum.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
683 isum.nodetype = cpu_to_je16(JFFS2_NODETYPE_SUMMARY);
684 isum.totlen = cpu_to_je32(infosize);
685 isum.hdr_crc = cpu_to_je32(crc32(0, &isum, sizeof(struct jffs2_unknown_node) - 4));
686 isum.padded = cpu_to_je32(c->summary->sum_padded);
687 isum.cln_mkr = cpu_to_je32(c->cleanmarker_size);
688 isum.sum_num = cpu_to_je32(c->summary->sum_num);
689 wpage = c->summary->sum_buf;
690
691 while (c->summary->sum_num) {
Jesper Juhl20ffdcb2006-05-12 11:55:51 +0100692 temp = c->summary->sum_list_head;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100693
Jesper Juhl20ffdcb2006-05-12 11:55:51 +0100694 switch (je16_to_cpu(temp->u.nodetype)) {
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100695 case JFFS2_NODETYPE_INODE: {
696 struct jffs2_sum_inode_flash *sino_ptr = wpage;
697
Jesper Juhl20ffdcb2006-05-12 11:55:51 +0100698 sino_ptr->nodetype = temp->i.nodetype;
699 sino_ptr->inode = temp->i.inode;
700 sino_ptr->version = temp->i.version;
701 sino_ptr->offset = temp->i.offset;
702 sino_ptr->totlen = temp->i.totlen;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100703
704 wpage += JFFS2_SUMMARY_INODE_SIZE;
705
706 break;
707 }
708
709 case JFFS2_NODETYPE_DIRENT: {
710 struct jffs2_sum_dirent_flash *sdrnt_ptr = wpage;
711
Jesper Juhl20ffdcb2006-05-12 11:55:51 +0100712 sdrnt_ptr->nodetype = temp->d.nodetype;
713 sdrnt_ptr->totlen = temp->d.totlen;
714 sdrnt_ptr->offset = temp->d.offset;
715 sdrnt_ptr->pino = temp->d.pino;
716 sdrnt_ptr->version = temp->d.version;
717 sdrnt_ptr->ino = temp->d.ino;
718 sdrnt_ptr->nsize = temp->d.nsize;
719 sdrnt_ptr->type = temp->d.type;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100720
Jesper Juhl20ffdcb2006-05-12 11:55:51 +0100721 memcpy(sdrnt_ptr->name, temp->d.name,
722 temp->d.nsize);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100723
Jesper Juhl20ffdcb2006-05-12 11:55:51 +0100724 wpage += JFFS2_SUMMARY_DIRENT_SIZE(temp->d.nsize);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100725
726 break;
727 }
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900728#ifdef CONFIG_JFFS2_FS_XATTR
729 case JFFS2_NODETYPE_XATTR: {
730 struct jffs2_sum_xattr_flash *sxattr_ptr = wpage;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100731
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900732 temp = c->summary->sum_list_head;
733 sxattr_ptr->nodetype = temp->x.nodetype;
734 sxattr_ptr->xid = temp->x.xid;
735 sxattr_ptr->version = temp->x.version;
736 sxattr_ptr->offset = temp->x.offset;
737 sxattr_ptr->totlen = temp->x.totlen;
738
739 wpage += JFFS2_SUMMARY_XATTR_SIZE;
740 break;
741 }
742 case JFFS2_NODETYPE_XREF: {
743 struct jffs2_sum_xref_flash *sxref_ptr = wpage;
744
745 temp = c->summary->sum_list_head;
746 sxref_ptr->nodetype = temp->r.nodetype;
747 sxref_ptr->offset = temp->r.offset;
748
749 wpage += JFFS2_SUMMARY_XREF_SIZE;
750 break;
751 }
752#endif
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100753 default : {
David Woodhouse61715862006-05-21 00:02:06 +0100754 if ((je16_to_cpu(temp->u.nodetype) & JFFS2_COMPAT_MASK)
755 == JFFS2_FEATURE_RWCOMPAT_COPY) {
756 dbg_summary("Writing unknown RWCOMPAT_COPY node type %x\n",
757 je16_to_cpu(temp->u.nodetype));
758 jffs2_sum_disable_collecting(c->summary);
759 } else {
760 BUG(); /* unknown node in summary information */
761 }
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100762 }
763 }
764
Jesper Juhl20ffdcb2006-05-12 11:55:51 +0100765 c->summary->sum_list_head = temp->u.next;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100766 kfree(temp);
767
768 c->summary->sum_num--;
769 }
770
771 jffs2_sum_reset_collected(c->summary);
772
773 wpage += padsize;
774
775 sm = wpage;
776 sm->offset = cpu_to_je32(c->sector_size - jeb->free_size);
777 sm->magic = cpu_to_je32(JFFS2_SUM_MAGIC);
778
779 isum.sum_crc = cpu_to_je32(crc32(0, c->summary->sum_buf, datasize));
780 isum.node_crc = cpu_to_je32(crc32(0, &isum, sizeof(isum) - 8));
781
782 vecs[0].iov_base = &isum;
783 vecs[0].iov_len = sizeof(isum);
784 vecs[1].iov_base = c->summary->sum_buf;
785 vecs[1].iov_len = datasize;
786
David Woodhouse2f785402006-05-24 02:04:45 +0100787 sum_ofs = jeb->offset + c->sector_size - jeb->free_size;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100788
David Woodhouse2f785402006-05-24 02:04:45 +0100789 dbg_summary("JFFS2: writing out data to flash to pos : 0x%08x\n",
790 sum_ofs);
791
792 ret = jffs2_flash_writev(c, vecs, 2, sum_ofs, &retlen, 0);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100793
794 if (ret || (retlen != infosize)) {
David Woodhouse010b06d2006-05-21 13:15:59 +0100795
David Woodhousec41ff6e2006-05-16 17:05:33 +0100796 JFFS2_WARNING("Write of %u bytes at 0x%08x failed. returned %d, retlen %zd\n",
David Woodhouse2f785402006-05-24 02:04:45 +0100797 infosize, sum_ofs, ret, retlen);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100798
David Woodhouse9bfeb692006-05-26 21:19:05 +0100799 if (retlen) {
800 /* Waste remaining space */
801 spin_lock(&c->erase_completion_lock);
802 jffs2_link_node_ref(c, jeb, sum_ofs | REF_OBSOLETE, infosize, NULL);
803 spin_unlock(&c->erase_completion_lock);
804 }
David Woodhouse010b06d2006-05-21 13:15:59 +0100805
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100806 c->summary->sum_size = JFFS2_SUMMARY_NOSUM_SIZE;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100807
David Woodhouse2f785402006-05-24 02:04:45 +0100808 return 0;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100809 }
810
David Woodhouse010b06d2006-05-21 13:15:59 +0100811 spin_lock(&c->erase_completion_lock);
David Woodhouse2f785402006-05-24 02:04:45 +0100812 jffs2_link_node_ref(c, jeb, sum_ofs | REF_NORMAL, infosize, NULL);
813 spin_unlock(&c->erase_completion_lock);
David Woodhouse010b06d2006-05-21 13:15:59 +0100814
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100815 return 0;
816}
817
818/* Write out summary information - called from jffs2_do_reserve_space */
819
820int jffs2_sum_write_sumnode(struct jffs2_sb_info *c)
821{
David Woodhouse2f785402006-05-24 02:04:45 +0100822 int datasize, infosize, padsize;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100823 struct jffs2_eraseblock *jeb;
David Woodhouse2f785402006-05-24 02:04:45 +0100824 int ret;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100825
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100826 dbg_summary("called\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100827
David Woodhouse2f785402006-05-24 02:04:45 +0100828 spin_unlock(&c->erase_completion_lock);
David Woodhouse2f785402006-05-24 02:04:45 +0100829
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100830 jeb = c->nextblock;
David Woodhouse046b8b92006-05-25 01:50:35 +0100831 jffs2_prealloc_raw_node_refs(c, jeb, 1);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100832
833 if (!c->summary->sum_num || !c->summary->sum_list_head) {
834 JFFS2_WARNING("Empty summary info!!!\n");
835 BUG();
836 }
837
838 datasize = c->summary->sum_size + sizeof(struct jffs2_sum_marker);
Ferenc Havasi2bc97642005-09-26 12:37:25 +0100839 infosize = sizeof(struct jffs2_raw_summary) + datasize;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100840 padsize = jeb->free_size - infosize;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000841 infosize += padsize;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100842 datasize += padsize;
843
844 /* Is there enough space for summary? */
845 if (padsize < 0) {
846 /* don't try to write out summary for this jeb */
847 jffs2_sum_disable_collecting(c->summary);
848
849 JFFS2_WARNING("Not enough space for summary, padsize = %d\n", padsize);
David Woodhouse9bfeb692006-05-26 21:19:05 +0100850 spin_lock(&c->erase_completion_lock);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100851 return 0;
852 }
853
854 ret = jffs2_sum_write_data(c, jeb, infosize, datasize, padsize);
David Woodhouse010b06d2006-05-21 13:15:59 +0100855 spin_lock(&c->erase_completion_lock);
David Woodhouse2f785402006-05-24 02:04:45 +0100856 return ret;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100857}