blob: bc5385471a6e3f2b1088d93bed109b185f4d8256 [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
Joe Perches5a528952012-02-15 15:56:45 -080014#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
Ferenc Havasie631ddb2005-09-07 09:35:26 +010016#include <linux/kernel.h>
Ferenc Havasie631ddb2005-09-07 09:35:26 +010017#include <linux/slab.h>
18#include <linux/mtd/mtd.h>
19#include <linux/pagemap.h>
20#include <linux/crc32.h>
21#include <linux/compiler.h>
22#include <linux/vmalloc.h>
23#include "nodelist.h"
24#include "debug.h"
25
26int jffs2_sum_init(struct jffs2_sb_info *c)
27{
Roel Kluin0fed7842009-11-21 16:34:36 +010028 uint32_t sum_size = min_t(uint32_t, c->sector_size, MAX_SUMMARY_SIZE);
David Woodhouseb7600db2008-08-01 10:07:51 +010029
Yan Burman3d375d92006-12-04 15:03:01 -080030 c->summary = kzalloc(sizeof(struct jffs2_summary), GFP_KERNEL);
Ferenc Havasie631ddb2005-09-07 09:35:26 +010031
32 if (!c->summary) {
33 JFFS2_WARNING("Can't allocate memory for summary information!\n");
34 return -ENOMEM;
35 }
36
David Woodhouseb7600db2008-08-01 10:07:51 +010037 c->summary->sum_buf = kmalloc(sum_size, GFP_KERNEL);
Ferenc Havasie631ddb2005-09-07 09:35:26 +010038
39 if (!c->summary->sum_buf) {
40 JFFS2_WARNING("Can't allocate buffer for writing out summary information!\n");
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +010041 kfree(c->summary);
Ferenc Havasie631ddb2005-09-07 09:35:26 +010042 return -ENOMEM;
43 }
44
Andreas Mohrd6e05ed2006-06-26 18:35:02 +020045 dbg_summary("returned successfully\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +010046
47 return 0;
48}
49
50void jffs2_sum_exit(struct jffs2_sb_info *c)
51{
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +010052 dbg_summary("called\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +010053
54 jffs2_sum_disable_collecting(c->summary);
55
David Woodhouseb7600db2008-08-01 10:07:51 +010056 kfree(c->summary->sum_buf);
Ferenc Havasie631ddb2005-09-07 09:35:26 +010057 c->summary->sum_buf = NULL;
58
59 kfree(c->summary);
60 c->summary = NULL;
61}
62
63static int jffs2_sum_add_mem(struct jffs2_summary *s, union jffs2_sum_mem *item)
64{
65 if (!s->sum_list_head)
66 s->sum_list_head = (union jffs2_sum_mem *) item;
67 if (s->sum_list_tail)
68 s->sum_list_tail->u.next = (union jffs2_sum_mem *) item;
69 s->sum_list_tail = (union jffs2_sum_mem *) item;
70
71 switch (je16_to_cpu(item->u.nodetype)) {
72 case JFFS2_NODETYPE_INODE:
73 s->sum_size += JFFS2_SUMMARY_INODE_SIZE;
74 s->sum_num++;
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +010075 dbg_summary("inode (%u) added to summary\n",
Ferenc Havasie631ddb2005-09-07 09:35:26 +010076 je32_to_cpu(item->i.inode));
77 break;
78 case JFFS2_NODETYPE_DIRENT:
79 s->sum_size += JFFS2_SUMMARY_DIRENT_SIZE(item->d.nsize);
80 s->sum_num++;
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +010081 dbg_summary("dirent (%u) added to summary\n",
Ferenc Havasie631ddb2005-09-07 09:35:26 +010082 je32_to_cpu(item->d.ino));
83 break;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090084#ifdef CONFIG_JFFS2_FS_XATTR
85 case JFFS2_NODETYPE_XATTR:
86 s->sum_size += JFFS2_SUMMARY_XATTR_SIZE;
87 s->sum_num++;
88 dbg_summary("xattr (xid=%u, version=%u) added to summary\n",
89 je32_to_cpu(item->x.xid), je32_to_cpu(item->x.version));
90 break;
91 case JFFS2_NODETYPE_XREF:
92 s->sum_size += JFFS2_SUMMARY_XREF_SIZE;
93 s->sum_num++;
94 dbg_summary("xref added to summary\n");
95 break;
96#endif
Ferenc Havasie631ddb2005-09-07 09:35:26 +010097 default:
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000098 JFFS2_WARNING("UNKNOWN node type %u\n",
Ferenc Havasie631ddb2005-09-07 09:35:26 +010099 je16_to_cpu(item->u.nodetype));
100 return 1;
101 }
102 return 0;
103}
104
105
106/* The following 3 functions are called from scan.c to collect summary info for not closed jeb */
107
108int jffs2_sum_add_padding_mem(struct jffs2_summary *s, uint32_t size)
109{
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100110 dbg_summary("called with %u\n", size);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100111 s->sum_padded += size;
112 return 0;
113}
114
115int jffs2_sum_add_inode_mem(struct jffs2_summary *s, struct jffs2_raw_inode *ri,
116 uint32_t ofs)
117{
118 struct jffs2_sum_inode_mem *temp = kmalloc(sizeof(struct jffs2_sum_inode_mem), GFP_KERNEL);
119
120 if (!temp)
121 return -ENOMEM;
122
123 temp->nodetype = ri->nodetype;
124 temp->inode = ri->ino;
125 temp->version = ri->version;
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300126 temp->offset = cpu_to_je32(ofs); /* relative offset from the beginning of the jeb */
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100127 temp->totlen = ri->totlen;
128 temp->next = NULL;
129
130 return jffs2_sum_add_mem(s, (union jffs2_sum_mem *)temp);
131}
132
133int jffs2_sum_add_dirent_mem(struct jffs2_summary *s, struct jffs2_raw_dirent *rd,
134 uint32_t ofs)
135{
136 struct jffs2_sum_dirent_mem *temp =
137 kmalloc(sizeof(struct jffs2_sum_dirent_mem) + rd->nsize, GFP_KERNEL);
138
139 if (!temp)
140 return -ENOMEM;
141
142 temp->nodetype = rd->nodetype;
143 temp->totlen = rd->totlen;
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300144 temp->offset = cpu_to_je32(ofs); /* relative from the beginning of the jeb */
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100145 temp->pino = rd->pino;
146 temp->version = rd->version;
147 temp->ino = rd->ino;
148 temp->nsize = rd->nsize;
149 temp->type = rd->type;
150 temp->next = NULL;
151
152 memcpy(temp->name, rd->name, rd->nsize);
153
154 return jffs2_sum_add_mem(s, (union jffs2_sum_mem *)temp);
155}
156
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900157#ifdef CONFIG_JFFS2_FS_XATTR
158int jffs2_sum_add_xattr_mem(struct jffs2_summary *s, struct jffs2_raw_xattr *rx, uint32_t ofs)
159{
160 struct jffs2_sum_xattr_mem *temp;
161
162 temp = kmalloc(sizeof(struct jffs2_sum_xattr_mem), GFP_KERNEL);
163 if (!temp)
164 return -ENOMEM;
165
166 temp->nodetype = rx->nodetype;
167 temp->xid = rx->xid;
168 temp->version = rx->version;
169 temp->offset = cpu_to_je32(ofs);
170 temp->totlen = rx->totlen;
171 temp->next = NULL;
172
173 return jffs2_sum_add_mem(s, (union jffs2_sum_mem *)temp);
174}
175
176int jffs2_sum_add_xref_mem(struct jffs2_summary *s, struct jffs2_raw_xref *rr, uint32_t ofs)
177{
178 struct jffs2_sum_xref_mem *temp;
179
180 temp = kmalloc(sizeof(struct jffs2_sum_xref_mem), GFP_KERNEL);
181 if (!temp)
182 return -ENOMEM;
183
184 temp->nodetype = rr->nodetype;
185 temp->offset = cpu_to_je32(ofs);
186 temp->next = NULL;
187
188 return jffs2_sum_add_mem(s, (union jffs2_sum_mem *)temp);
189}
190#endif
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100191/* Cleanup every collected summary information */
192
193static void jffs2_sum_clean_collected(struct jffs2_summary *s)
194{
195 union jffs2_sum_mem *temp;
196
197 if (!s->sum_list_head) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100198 dbg_summary("already empty\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100199 }
200 while (s->sum_list_head) {
201 temp = s->sum_list_head;
202 s->sum_list_head = s->sum_list_head->u.next;
203 kfree(temp);
204 }
205 s->sum_list_tail = NULL;
206 s->sum_padded = 0;
207 s->sum_num = 0;
208}
209
210void jffs2_sum_reset_collected(struct jffs2_summary *s)
211{
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100212 dbg_summary("called\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100213 jffs2_sum_clean_collected(s);
214 s->sum_size = 0;
215}
216
217void jffs2_sum_disable_collecting(struct jffs2_summary *s)
218{
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100219 dbg_summary("called\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100220 jffs2_sum_clean_collected(s);
221 s->sum_size = JFFS2_SUMMARY_NOSUM_SIZE;
222}
223
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000224int jffs2_sum_is_disabled(struct jffs2_summary *s)
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100225{
226 return (s->sum_size == JFFS2_SUMMARY_NOSUM_SIZE);
227}
228
229/* Move the collected summary information into sb (called from scan.c) */
230
231void jffs2_sum_move_collected(struct jffs2_sb_info *c, struct jffs2_summary *s)
232{
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100233 dbg_summary("oldsize=0x%x oldnum=%u => newsize=0x%x newnum=%u\n",
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100234 c->summary->sum_size, c->summary->sum_num,
235 s->sum_size, s->sum_num);
236
237 c->summary->sum_size = s->sum_size;
238 c->summary->sum_num = s->sum_num;
239 c->summary->sum_padded = s->sum_padded;
240 c->summary->sum_list_head = s->sum_list_head;
241 c->summary->sum_list_tail = s->sum_list_tail;
242
243 s->sum_list_head = s->sum_list_tail = NULL;
244}
245
246/* Called from wbuf.c to collect writed node info */
247
248int jffs2_sum_add_kvec(struct jffs2_sb_info *c, const struct kvec *invecs,
249 unsigned long count, uint32_t ofs)
250{
251 union jffs2_node_union *node;
252 struct jffs2_eraseblock *jeb;
253
Zoltan Sogor27bea322006-09-16 12:15:59 -0700254 if (c->summary->sum_size == JFFS2_SUMMARY_NOSUM_SIZE) {
255 dbg_summary("Summary is disabled for this jeb! Skipping summary info!\n");
256 return 0;
257 }
258
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100259 node = invecs[0].iov_base;
260 jeb = &c->blocks[ofs / c->sector_size];
261 ofs -= jeb->offset;
262
263 switch (je16_to_cpu(node->u.nodetype)) {
264 case JFFS2_NODETYPE_INODE: {
265 struct jffs2_sum_inode_mem *temp =
266 kmalloc(sizeof(struct jffs2_sum_inode_mem), GFP_KERNEL);
267
268 if (!temp)
269 goto no_mem;
270
271 temp->nodetype = node->i.nodetype;
272 temp->inode = node->i.ino;
273 temp->version = node->i.version;
274 temp->offset = cpu_to_je32(ofs);
275 temp->totlen = node->i.totlen;
276 temp->next = NULL;
277
278 return jffs2_sum_add_mem(c->summary, (union jffs2_sum_mem *)temp);
279 }
280
281 case JFFS2_NODETYPE_DIRENT: {
282 struct jffs2_sum_dirent_mem *temp =
283 kmalloc(sizeof(struct jffs2_sum_dirent_mem) + node->d.nsize, GFP_KERNEL);
284
285 if (!temp)
286 goto no_mem;
287
288 temp->nodetype = node->d.nodetype;
289 temp->totlen = node->d.totlen;
290 temp->offset = cpu_to_je32(ofs);
291 temp->pino = node->d.pino;
292 temp->version = node->d.version;
293 temp->ino = node->d.ino;
294 temp->nsize = node->d.nsize;
295 temp->type = node->d.type;
296 temp->next = NULL;
297
298 switch (count) {
299 case 1:
300 memcpy(temp->name,node->d.name,node->d.nsize);
301 break;
302
303 case 2:
304 memcpy(temp->name,invecs[1].iov_base,node->d.nsize);
305 break;
306
307 default:
308 BUG(); /* impossible count value */
309 break;
310 }
311
312 return jffs2_sum_add_mem(c->summary, (union jffs2_sum_mem *)temp);
313 }
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900314#ifdef CONFIG_JFFS2_FS_XATTR
315 case JFFS2_NODETYPE_XATTR: {
316 struct jffs2_sum_xattr_mem *temp;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900317 temp = kmalloc(sizeof(struct jffs2_sum_xattr_mem), GFP_KERNEL);
318 if (!temp)
319 goto no_mem;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100320
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900321 temp->nodetype = node->x.nodetype;
322 temp->xid = node->x.xid;
323 temp->version = node->x.version;
324 temp->totlen = node->x.totlen;
325 temp->offset = cpu_to_je32(ofs);
326 temp->next = NULL;
327
328 return jffs2_sum_add_mem(c->summary, (union jffs2_sum_mem *)temp);
329 }
330 case JFFS2_NODETYPE_XREF: {
331 struct jffs2_sum_xref_mem *temp;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900332 temp = kmalloc(sizeof(struct jffs2_sum_xref_mem), GFP_KERNEL);
333 if (!temp)
334 goto no_mem;
335 temp->nodetype = node->r.nodetype;
336 temp->offset = cpu_to_je32(ofs);
337 temp->next = NULL;
338
339 return jffs2_sum_add_mem(c->summary, (union jffs2_sum_mem *)temp);
340 }
341#endif
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100342 case JFFS2_NODETYPE_PADDING:
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100343 dbg_summary("node PADDING\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100344 c->summary->sum_padded += je32_to_cpu(node->u.totlen);
345 break;
346
347 case JFFS2_NODETYPE_CLEANMARKER:
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100348 dbg_summary("node CLEANMARKER\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100349 break;
350
351 case JFFS2_NODETYPE_SUMMARY:
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100352 dbg_summary("node SUMMARY\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100353 break;
354
355 default:
356 /* If you implement a new node type you should also implement
357 summary support for it or disable summary.
358 */
359 BUG();
360 break;
361 }
362
363 return 0;
364
365no_mem:
366 JFFS2_WARNING("MEMORY ALLOCATION ERROR!");
367 return -ENOMEM;
368}
369
David Woodhouse2f785402006-05-24 02:04:45 +0100370static struct jffs2_raw_node_ref *sum_link_node_ref(struct jffs2_sb_info *c,
371 struct jffs2_eraseblock *jeb,
372 uint32_t ofs, uint32_t len,
373 struct jffs2_inode_cache *ic)
David Woodhouse49f11d42006-05-21 04:00:01 +0100374{
David Woodhouse49f11d42006-05-21 04:00:01 +0100375 /* If there was a gap, mark it dirty */
David Woodhouse2f785402006-05-24 02:04:45 +0100376 if ((ofs & ~3) > c->sector_size - jeb->free_size) {
377 /* Ew. Summary doesn't actually tell us explicitly about dirty space */
378 jffs2_scan_dirty_space(c, jeb, (ofs & ~3) - (c->sector_size - jeb->free_size));
David Woodhouse49f11d42006-05-21 04:00:01 +0100379 }
David Woodhouse49f11d42006-05-21 04:00:01 +0100380
David Woodhouse2f785402006-05-24 02:04:45 +0100381 return jffs2_link_node_ref(c, jeb, jeb->offset + ofs, len, ic);
David Woodhouse49f11d42006-05-21 04:00:01 +0100382}
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100383
384/* Process the stored summary information - helper function for jffs2_sum_scan_sumnode() */
385
386static int jffs2_sum_process_sum_data(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
Ferenc Havasi2bc97642005-09-26 12:37:25 +0100387 struct jffs2_raw_summary *summary, uint32_t *pseudo_random)
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100388{
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100389 struct jffs2_inode_cache *ic;
390 struct jffs2_full_dirent *fd;
391 void *sp;
392 int i, ino;
David Woodhouse68270992006-05-21 03:46:05 +0100393 int err;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100394
395 sp = summary->sum;
396
397 for (i=0; i<je32_to_cpu(summary->sum_num); i++) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100398 dbg_summary("processing summary index %d\n", i);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100399
Artem Bityutskiya2166b92006-12-28 12:01:41 +0200400 cond_resched();
401
David Woodhouse2f785402006-05-24 02:04:45 +0100402 /* Make sure there's a spare ref for dirty space */
David Woodhouse046b8b92006-05-25 01:50:35 +0100403 err = jffs2_prealloc_raw_node_refs(c, jeb, 2);
David Woodhouse2f785402006-05-24 02:04:45 +0100404 if (err)
405 return err;
406
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100407 switch (je16_to_cpu(((struct jffs2_sum_unknown_flash *)sp)->nodetype)) {
408 case JFFS2_NODETYPE_INODE: {
409 struct jffs2_sum_inode_flash *spi;
410 spi = sp;
411
412 ino = je32_to_cpu(spi->inode);
413
David Woodhouse9167e0f2006-05-21 13:13:45 +0100414 dbg_summary("Inode at 0x%08x-0x%08x\n",
415 jeb->offset + je32_to_cpu(spi->offset),
David Woodhouse8b9e9fe2006-05-25 01:53:09 +0100416 jeb->offset + je32_to_cpu(spi->offset) + je32_to_cpu(spi->totlen));
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100417
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100418 ic = jffs2_scan_make_ino_cache(c, ino);
419 if (!ic) {
420 JFFS2_NOTICE("scan_make_ino_cache failed\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100421 return -ENOMEM;
422 }
423
David Woodhouse2f785402006-05-24 02:04:45 +0100424 sum_link_node_ref(c, jeb, je32_to_cpu(spi->offset) | REF_UNCHECKED,
425 PAD(je32_to_cpu(spi->totlen)), ic);
David Woodhousef1f96712006-05-20 19:45:26 +0100426
427 *pseudo_random += je32_to_cpu(spi->version);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100428
429 sp += JFFS2_SUMMARY_INODE_SIZE;
430
431 break;
432 }
433
434 case JFFS2_NODETYPE_DIRENT: {
435 struct jffs2_sum_dirent_flash *spd;
David Woodhouseb534e702007-10-13 11:35:58 +0100436 int checkedlen;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100437 spd = sp;
438
David Woodhouse8b9e9fe2006-05-25 01:53:09 +0100439 dbg_summary("Dirent at 0x%08x-0x%08x\n",
David Woodhouse9167e0f2006-05-21 13:13:45 +0100440 jeb->offset + je32_to_cpu(spd->offset),
441 jeb->offset + je32_to_cpu(spd->offset) + je32_to_cpu(spd->totlen));
442
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100443
David Woodhouseb534e702007-10-13 11:35:58 +0100444 /* This should never happen, but https://dev.laptop.org/ticket/4184 */
445 checkedlen = strnlen(spd->name, spd->nsize);
446 if (!checkedlen) {
Joe Perchesda320f02012-02-15 15:56:44 -0800447 pr_err("Dirent at %08x has zero at start of name. Aborting mount.\n",
448 jeb->offset +
449 je32_to_cpu(spd->offset));
David Woodhouseb534e702007-10-13 11:35:58 +0100450 return -EIO;
451 }
452 if (checkedlen < spd->nsize) {
Joe Perchesda320f02012-02-15 15:56:44 -0800453 pr_err("Dirent at %08x has zeroes in name. Truncating to %d chars\n",
454 jeb->offset +
455 je32_to_cpu(spd->offset),
456 checkedlen);
David Woodhouseb534e702007-10-13 11:35:58 +0100457 }
458
459
460 fd = jffs2_alloc_full_dirent(checkedlen+1);
David Woodhouse9641b782006-05-20 16:13:34 +0100461 if (!fd)
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100462 return -ENOMEM;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100463
David Woodhouseb534e702007-10-13 11:35:58 +0100464 memcpy(&fd->name, spd->name, checkedlen);
465 fd->name[checkedlen] = 0;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100466
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100467 ic = jffs2_scan_make_ino_cache(c, je32_to_cpu(spd->pino));
468 if (!ic) {
469 jffs2_free_full_dirent(fd);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100470 return -ENOMEM;
471 }
472
David Woodhouse1046d882006-06-18 22:44:21 +0100473 fd->raw = sum_link_node_ref(c, jeb, je32_to_cpu(spd->offset) | REF_UNCHECKED,
David Woodhouse2f785402006-05-24 02:04:45 +0100474 PAD(je32_to_cpu(spd->totlen)), ic);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100475
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100476 fd->next = NULL;
477 fd->version = je32_to_cpu(spd->version);
478 fd->ino = je32_to_cpu(spd->ino);
David Woodhouseb534e702007-10-13 11:35:58 +0100479 fd->nhash = full_name_hash(fd->name, checkedlen);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100480 fd->type = spd->type;
David Woodhousef1f96712006-05-20 19:45:26 +0100481
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100482 jffs2_add_fd_to_list(c, fd, &ic->scan_dents);
483
484 *pseudo_random += je32_to_cpu(spd->version);
485
486 sp += JFFS2_SUMMARY_DIRENT_SIZE(spd->nsize);
487
488 break;
489 }
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900490#ifdef CONFIG_JFFS2_FS_XATTR
491 case JFFS2_NODETYPE_XATTR: {
492 struct jffs2_xattr_datum *xd;
493 struct jffs2_sum_xattr_flash *spx;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100494
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900495 spx = (struct jffs2_sum_xattr_flash *)sp;
David Woodhouse9167e0f2006-05-21 13:13:45 +0100496 dbg_summary("xattr at %#08x-%#08x (xid=%u, version=%u)\n",
David Woodhouse49f11d42006-05-21 04:00:01 +0100497 jeb->offset + je32_to_cpu(spx->offset),
David Woodhouse9167e0f2006-05-21 13:13:45 +0100498 jeb->offset + je32_to_cpu(spx->offset) + je32_to_cpu(spx->totlen),
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900499 je32_to_cpu(spx->xid), je32_to_cpu(spx->version));
David Woodhouse2f785402006-05-24 02:04:45 +0100500
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900501 xd = jffs2_setup_xattr_datum(c, je32_to_cpu(spx->xid),
502 je32_to_cpu(spx->version));
KaiGai Koheic9f700f2006-06-11 10:35:15 +0900503 if (IS_ERR(xd))
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900504 return PTR_ERR(xd);
KaiGai Koheic9f700f2006-06-11 10:35:15 +0900505 if (xd->version > je32_to_cpu(spx->version)) {
506 /* node is not the newest one */
507 struct jffs2_raw_node_ref *raw
508 = sum_link_node_ref(c, jeb, je32_to_cpu(spx->offset) | REF_UNCHECKED,
509 PAD(je32_to_cpu(spx->totlen)), NULL);
510 raw->next_in_ino = xd->node->next_in_ino;
511 xd->node->next_in_ino = raw;
512 } else {
513 xd->version = je32_to_cpu(spx->version);
514 sum_link_node_ref(c, jeb, je32_to_cpu(spx->offset) | REF_UNCHECKED,
515 PAD(je32_to_cpu(spx->totlen)), (void *)xd);
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900516 }
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900517 *pseudo_random += je32_to_cpu(spx->xid);
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900518 sp += JFFS2_SUMMARY_XATTR_SIZE;
519
520 break;
521 }
522 case JFFS2_NODETYPE_XREF: {
523 struct jffs2_xattr_ref *ref;
524 struct jffs2_sum_xref_flash *spr;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900525
526 spr = (struct jffs2_sum_xref_flash *)sp;
David Woodhouse9167e0f2006-05-21 13:13:45 +0100527 dbg_summary("xref at %#08x-%#08x\n",
David Woodhouse49f11d42006-05-21 04:00:01 +0100528 jeb->offset + je32_to_cpu(spr->offset),
David Woodhouse9bfeb692006-05-26 21:19:05 +0100529 jeb->offset + je32_to_cpu(spr->offset) +
530 (uint32_t)PAD(sizeof(struct jffs2_raw_xref)));
David Woodhouse9167e0f2006-05-21 13:13:45 +0100531
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900532 ref = jffs2_alloc_xattr_ref();
533 if (!ref) {
534 JFFS2_NOTICE("allocation of xattr_datum failed\n");
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900535 return -ENOMEM;
536 }
KaiGai Kohei8f2b6f42006-05-13 15:15:07 +0900537 ref->next = c->xref_temp;
538 c->xref_temp = ref;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900539
KaiGai Koheic9f700f2006-06-11 10:35:15 +0900540 sum_link_node_ref(c, jeb, je32_to_cpu(spr->offset) | REF_UNCHECKED,
541 PAD(sizeof(struct jffs2_raw_xref)), (void *)ref);
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900542
David Woodhouse2f785402006-05-24 02:04:45 +0100543 *pseudo_random += ref->node->flash_offset;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900544 sp += JFFS2_SUMMARY_XREF_SIZE;
545
546 break;
547 }
548#endif
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100549 default : {
David Woodhouse7807ef72006-05-21 03:45:27 +0100550 uint16_t nodetype = je16_to_cpu(((struct jffs2_sum_unknown_flash *)sp)->nodetype);
551 JFFS2_WARNING("Unsupported node type %x found in summary! Exiting...\n", nodetype);
552 if ((nodetype & JFFS2_COMPAT_MASK) == JFFS2_FEATURE_INCOMPAT)
553 return -EIO;
554
555 /* For compatible node types, just fall back to the full scan */
556 c->wasted_size -= jeb->wasted_size;
557 c->free_size += c->sector_size - jeb->free_size;
558 c->used_size -= jeb->used_size;
559 c->dirty_size -= jeb->dirty_size;
560 jeb->wasted_size = jeb->used_size = jeb->dirty_size = 0;
561 jeb->free_size = c->sector_size;
562
David Woodhousec38c1b62006-05-25 01:38:27 +0100563 jffs2_free_jeb_node_refs(c, jeb);
David Woodhouse7807ef72006-05-21 03:45:27 +0100564 return -ENOTRECOVERABLE;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100565 }
566 }
567 }
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100568 return 0;
569}
570
571/* Process the summary node - called from jffs2_scan_eraseblock() */
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100572int jffs2_sum_scan_sumnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
David Woodhouse9641b782006-05-20 16:13:34 +0100573 struct jffs2_raw_summary *summary, uint32_t sumsize,
574 uint32_t *pseudo_random)
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100575{
576 struct jffs2_unknown_node crcnode;
David Woodhouse9641b782006-05-20 16:13:34 +0100577 int ret, ofs;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100578 uint32_t crc;
579
David Woodhouse49f11d42006-05-21 04:00:01 +0100580 ofs = c->sector_size - sumsize;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100581
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100582 dbg_summary("summary found for 0x%08x at 0x%08x (0x%x bytes)\n",
David Woodhouse49f11d42006-05-21 04:00:01 +0100583 jeb->offset, jeb->offset + ofs, sumsize);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100584
585 /* OK, now check for node validity and CRC */
586 crcnode.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
587 crcnode.nodetype = cpu_to_je16(JFFS2_NODETYPE_SUMMARY);
588 crcnode.totlen = summary->totlen;
589 crc = crc32(0, &crcnode, sizeof(crcnode)-4);
590
591 if (je32_to_cpu(summary->hdr_crc) != crc) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100592 dbg_summary("Summary node header is corrupt (bad CRC or "
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100593 "no summary at all)\n");
594 goto crc_err;
595 }
596
597 if (je32_to_cpu(summary->totlen) != sumsize) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100598 dbg_summary("Summary node is corrupt (wrong erasesize?)\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, sizeof(struct jffs2_raw_summary)-8);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100603
604 if (je32_to_cpu(summary->node_crc) != crc) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100605 dbg_summary("Summary node is corrupt (bad CRC)\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100606 goto crc_err;
607 }
608
Ferenc Havasi2bc97642005-09-26 12:37:25 +0100609 crc = crc32(0, summary->sum, sumsize - sizeof(struct jffs2_raw_summary));
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100610
611 if (je32_to_cpu(summary->sum_crc) != crc) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100612 dbg_summary("Summary node data is corrupt (bad CRC)\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100613 goto crc_err;
614 }
615
616 if ( je32_to_cpu(summary->cln_mkr) ) {
617
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100618 dbg_summary("Summary : CLEANMARKER node \n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100619
David Woodhouse098a1982006-05-30 09:00:14 +0100620 ret = jffs2_prealloc_raw_node_refs(c, jeb, 1);
621 if (ret)
622 return ret;
623
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100624 if (je32_to_cpu(summary->cln_mkr) != c->cleanmarker_size) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100625 dbg_summary("CLEANMARKER node has totlen 0x%x != normal 0x%x\n",
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100626 je32_to_cpu(summary->cln_mkr), c->cleanmarker_size);
David Woodhouse098a1982006-05-30 09:00:14 +0100627 if ((ret = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(summary->cln_mkr)))))
628 return ret;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100629 } else if (jeb->first_node) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100630 dbg_summary("CLEANMARKER node not first node in block "
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100631 "(0x%08x)\n", jeb->offset);
David Woodhouse098a1982006-05-30 09:00:14 +0100632 if ((ret = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(summary->cln_mkr)))))
633 return ret;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100634 } else {
David Woodhouse2f785402006-05-24 02:04:45 +0100635 jffs2_link_node_ref(c, jeb, jeb->offset | REF_NORMAL,
636 je32_to_cpu(summary->cln_mkr), NULL);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100637 }
638 }
639
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100640 ret = jffs2_sum_process_sum_data(c, jeb, summary, pseudo_random);
David Woodhouse7807ef72006-05-21 03:45:27 +0100641 /* -ENOTRECOVERABLE isn't a fatal error -- it means we should do a full
642 scan of this eraseblock. So return zero */
643 if (ret == -ENOTRECOVERABLE)
644 return 0;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100645 if (ret)
David Woodhouse7807ef72006-05-21 03:45:27 +0100646 return ret; /* real error */
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100647
648 /* for PARANOIA_CHECK */
David Woodhouse046b8b92006-05-25 01:50:35 +0100649 ret = jffs2_prealloc_raw_node_refs(c, jeb, 2);
David Woodhouse2f785402006-05-24 02:04:45 +0100650 if (ret)
651 return ret;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100652
David Woodhousef61579c32006-05-25 01:42:40 +0100653 sum_link_node_ref(c, jeb, ofs | REF_NORMAL, sumsize, NULL);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100654
David Woodhouse49f11d42006-05-21 04:00:01 +0100655 if (unlikely(jeb->free_size)) {
656 JFFS2_WARNING("Free size 0x%x bytes in eraseblock @0x%08x with summary?\n",
657 jeb->free_size, jeb->offset);
658 jeb->wasted_size += jeb->free_size;
659 c->wasted_size += jeb->free_size;
660 c->free_size -= jeb->free_size;
661 jeb->free_size = 0;
662 }
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100663
664 return jffs2_scan_classify_jeb(c, jeb);
665
666crc_err:
667 JFFS2_WARNING("Summary node crc error, skipping summary information.\n");
668
669 return 0;
670}
671
672/* Write summary data to flash - helper function for jffs2_sum_write_sumnode() */
673
674static int jffs2_sum_write_data(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
David Woodhouseb7600db2008-08-01 10:07:51 +0100675 uint32_t infosize, uint32_t datasize, int padsize)
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100676{
Ferenc Havasi2bc97642005-09-26 12:37:25 +0100677 struct jffs2_raw_summary isum;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100678 union jffs2_sum_mem *temp;
679 struct jffs2_sum_marker *sm;
680 struct kvec vecs[2];
David Woodhouse2f785402006-05-24 02:04:45 +0100681 uint32_t sum_ofs;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100682 void *wpage;
683 int ret;
684 size_t retlen;
685
David Woodhouseb7600db2008-08-01 10:07:51 +0100686 if (padsize + datasize > MAX_SUMMARY_SIZE) {
687 /* It won't fit in the buffer. Abort summary for this jeb */
688 jffs2_sum_disable_collecting(c->summary);
689
690 JFFS2_WARNING("Summary too big (%d data, %d pad) in eraseblock at %08x\n",
691 datasize, padsize, jeb->offset);
692 /* Non-fatal */
693 return 0;
694 }
695 /* Is there enough space for summary? */
696 if (padsize < 0) {
697 /* don't try to write out summary for this jeb */
698 jffs2_sum_disable_collecting(c->summary);
699
700 JFFS2_WARNING("Not enough space for summary, padsize = %d\n",
701 padsize);
702 /* Non-fatal */
703 return 0;
704 }
705
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100706 memset(c->summary->sum_buf, 0xff, datasize);
707 memset(&isum, 0, sizeof(isum));
708
709 isum.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
710 isum.nodetype = cpu_to_je16(JFFS2_NODETYPE_SUMMARY);
711 isum.totlen = cpu_to_je32(infosize);
712 isum.hdr_crc = cpu_to_je32(crc32(0, &isum, sizeof(struct jffs2_unknown_node) - 4));
713 isum.padded = cpu_to_je32(c->summary->sum_padded);
714 isum.cln_mkr = cpu_to_je32(c->cleanmarker_size);
715 isum.sum_num = cpu_to_je32(c->summary->sum_num);
716 wpage = c->summary->sum_buf;
717
718 while (c->summary->sum_num) {
Jesper Juhl20ffdcb2006-05-12 11:55:51 +0100719 temp = c->summary->sum_list_head;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100720
Jesper Juhl20ffdcb2006-05-12 11:55:51 +0100721 switch (je16_to_cpu(temp->u.nodetype)) {
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100722 case JFFS2_NODETYPE_INODE: {
723 struct jffs2_sum_inode_flash *sino_ptr = wpage;
724
Jesper Juhl20ffdcb2006-05-12 11:55:51 +0100725 sino_ptr->nodetype = temp->i.nodetype;
726 sino_ptr->inode = temp->i.inode;
727 sino_ptr->version = temp->i.version;
728 sino_ptr->offset = temp->i.offset;
729 sino_ptr->totlen = temp->i.totlen;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100730
731 wpage += JFFS2_SUMMARY_INODE_SIZE;
732
733 break;
734 }
735
736 case JFFS2_NODETYPE_DIRENT: {
737 struct jffs2_sum_dirent_flash *sdrnt_ptr = wpage;
738
Jesper Juhl20ffdcb2006-05-12 11:55:51 +0100739 sdrnt_ptr->nodetype = temp->d.nodetype;
740 sdrnt_ptr->totlen = temp->d.totlen;
741 sdrnt_ptr->offset = temp->d.offset;
742 sdrnt_ptr->pino = temp->d.pino;
743 sdrnt_ptr->version = temp->d.version;
744 sdrnt_ptr->ino = temp->d.ino;
745 sdrnt_ptr->nsize = temp->d.nsize;
746 sdrnt_ptr->type = temp->d.type;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100747
Jesper Juhl20ffdcb2006-05-12 11:55:51 +0100748 memcpy(sdrnt_ptr->name, temp->d.name,
749 temp->d.nsize);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100750
Jesper Juhl20ffdcb2006-05-12 11:55:51 +0100751 wpage += JFFS2_SUMMARY_DIRENT_SIZE(temp->d.nsize);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100752
753 break;
754 }
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900755#ifdef CONFIG_JFFS2_FS_XATTR
756 case JFFS2_NODETYPE_XATTR: {
757 struct jffs2_sum_xattr_flash *sxattr_ptr = wpage;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100758
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900759 temp = c->summary->sum_list_head;
760 sxattr_ptr->nodetype = temp->x.nodetype;
761 sxattr_ptr->xid = temp->x.xid;
762 sxattr_ptr->version = temp->x.version;
763 sxattr_ptr->offset = temp->x.offset;
764 sxattr_ptr->totlen = temp->x.totlen;
765
766 wpage += JFFS2_SUMMARY_XATTR_SIZE;
767 break;
768 }
769 case JFFS2_NODETYPE_XREF: {
770 struct jffs2_sum_xref_flash *sxref_ptr = wpage;
771
772 temp = c->summary->sum_list_head;
773 sxref_ptr->nodetype = temp->r.nodetype;
774 sxref_ptr->offset = temp->r.offset;
775
776 wpage += JFFS2_SUMMARY_XREF_SIZE;
777 break;
778 }
779#endif
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100780 default : {
David Woodhouse61715862006-05-21 00:02:06 +0100781 if ((je16_to_cpu(temp->u.nodetype) & JFFS2_COMPAT_MASK)
782 == JFFS2_FEATURE_RWCOMPAT_COPY) {
783 dbg_summary("Writing unknown RWCOMPAT_COPY node type %x\n",
784 je16_to_cpu(temp->u.nodetype));
785 jffs2_sum_disable_collecting(c->summary);
786 } else {
787 BUG(); /* unknown node in summary information */
788 }
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100789 }
790 }
791
Jesper Juhl20ffdcb2006-05-12 11:55:51 +0100792 c->summary->sum_list_head = temp->u.next;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100793 kfree(temp);
794
795 c->summary->sum_num--;
796 }
797
798 jffs2_sum_reset_collected(c->summary);
799
800 wpage += padsize;
801
802 sm = wpage;
803 sm->offset = cpu_to_je32(c->sector_size - jeb->free_size);
804 sm->magic = cpu_to_je32(JFFS2_SUM_MAGIC);
805
806 isum.sum_crc = cpu_to_je32(crc32(0, c->summary->sum_buf, datasize));
807 isum.node_crc = cpu_to_je32(crc32(0, &isum, sizeof(isum) - 8));
808
809 vecs[0].iov_base = &isum;
810 vecs[0].iov_len = sizeof(isum);
811 vecs[1].iov_base = c->summary->sum_buf;
812 vecs[1].iov_len = datasize;
813
David Woodhouse2f785402006-05-24 02:04:45 +0100814 sum_ofs = jeb->offset + c->sector_size - jeb->free_size;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100815
Joe Perches5a528952012-02-15 15:56:45 -0800816 dbg_summary("writing out data to flash to pos : 0x%08x\n", sum_ofs);
David Woodhouse2f785402006-05-24 02:04:45 +0100817
818 ret = jffs2_flash_writev(c, vecs, 2, sum_ofs, &retlen, 0);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100819
820 if (ret || (retlen != infosize)) {
David Woodhouse010b06d2006-05-21 13:15:59 +0100821
David Woodhousec41ff6e2006-05-16 17:05:33 +0100822 JFFS2_WARNING("Write of %u bytes at 0x%08x failed. returned %d, retlen %zd\n",
David Woodhouse2f785402006-05-24 02:04:45 +0100823 infosize, sum_ofs, ret, retlen);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100824
David Woodhouse9bfeb692006-05-26 21:19:05 +0100825 if (retlen) {
826 /* Waste remaining space */
827 spin_lock(&c->erase_completion_lock);
828 jffs2_link_node_ref(c, jeb, sum_ofs | REF_OBSOLETE, infosize, NULL);
829 spin_unlock(&c->erase_completion_lock);
830 }
David Woodhouse010b06d2006-05-21 13:15:59 +0100831
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100832 c->summary->sum_size = JFFS2_SUMMARY_NOSUM_SIZE;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100833
David Woodhouse2f785402006-05-24 02:04:45 +0100834 return 0;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100835 }
836
David Woodhouse010b06d2006-05-21 13:15:59 +0100837 spin_lock(&c->erase_completion_lock);
David Woodhouse2f785402006-05-24 02:04:45 +0100838 jffs2_link_node_ref(c, jeb, sum_ofs | REF_NORMAL, infosize, NULL);
839 spin_unlock(&c->erase_completion_lock);
David Woodhouse010b06d2006-05-21 13:15:59 +0100840
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100841 return 0;
842}
843
844/* Write out summary information - called from jffs2_do_reserve_space */
845
846int jffs2_sum_write_sumnode(struct jffs2_sb_info *c)
Fabian Frederick7f4028b2014-09-28 21:26:32 +0200847 __must_hold(&c->erase_completion_block)
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100848{
David Woodhouse2f785402006-05-24 02:04:45 +0100849 int datasize, infosize, padsize;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100850 struct jffs2_eraseblock *jeb;
David Woodhouseb7600db2008-08-01 10:07:51 +0100851 int ret = 0;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100852
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100853 dbg_summary("called\n");
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100854
David Woodhouse2f785402006-05-24 02:04:45 +0100855 spin_unlock(&c->erase_completion_lock);
David Woodhouse2f785402006-05-24 02:04:45 +0100856
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100857 jeb = c->nextblock;
David Woodhouse046b8b92006-05-25 01:50:35 +0100858 jffs2_prealloc_raw_node_refs(c, jeb, 1);
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100859
860 if (!c->summary->sum_num || !c->summary->sum_list_head) {
861 JFFS2_WARNING("Empty summary info!!!\n");
862 BUG();
863 }
864
865 datasize = c->summary->sum_size + sizeof(struct jffs2_sum_marker);
Ferenc Havasi2bc97642005-09-26 12:37:25 +0100866 infosize = sizeof(struct jffs2_raw_summary) + datasize;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100867 padsize = jeb->free_size - infosize;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000868 infosize += padsize;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100869 datasize += padsize;
870
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100871 ret = jffs2_sum_write_data(c, jeb, infosize, datasize, padsize);
David Woodhouse010b06d2006-05-21 13:15:59 +0100872 spin_lock(&c->erase_completion_lock);
David Woodhouse2f785402006-05-24 02:04:45 +0100873 return ret;
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100874}