diff options
Diffstat (limited to 'fs/jffs2/scan.c')
-rw-r--r-- | fs/jffs2/scan.c | 442 |
1 files changed, 302 insertions, 140 deletions
diff --git a/fs/jffs2/scan.c b/fs/jffs2/scan.c index cf55b221fc2b..61618080b86f 100644 --- a/fs/jffs2/scan.c +++ b/fs/jffs2/scan.c | |||
@@ -65,6 +65,28 @@ static inline uint32_t EMPTY_SCAN_SIZE(uint32_t sector_size) { | |||
65 | return DEFAULT_EMPTY_SCAN_SIZE; | 65 | return DEFAULT_EMPTY_SCAN_SIZE; |
66 | } | 66 | } |
67 | 67 | ||
68 | static int file_dirty(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) | ||
69 | { | ||
70 | int ret; | ||
71 | |||
72 | if ((ret = jffs2_prealloc_raw_node_refs(c, jeb, 1))) | ||
73 | return ret; | ||
74 | if ((ret = jffs2_scan_dirty_space(c, jeb, jeb->free_size))) | ||
75 | return ret; | ||
76 | /* Turned wasted size into dirty, since we apparently | ||
77 | think it's recoverable now. */ | ||
78 | jeb->dirty_size += jeb->wasted_size; | ||
79 | c->dirty_size += jeb->wasted_size; | ||
80 | c->wasted_size -= jeb->wasted_size; | ||
81 | jeb->wasted_size = 0; | ||
82 | if (VERYDIRTY(c, jeb->dirty_size)) { | ||
83 | list_add(&jeb->list, &c->very_dirty_list); | ||
84 | } else { | ||
85 | list_add(&jeb->list, &c->dirty_list); | ||
86 | } | ||
87 | return 0; | ||
88 | } | ||
89 | |||
68 | int jffs2_scan_medium(struct jffs2_sb_info *c) | 90 | int jffs2_scan_medium(struct jffs2_sb_info *c) |
69 | { | 91 | { |
70 | int i, ret; | 92 | int i, ret; |
@@ -170,34 +192,20 @@ int jffs2_scan_medium(struct jffs2_sb_info *c) | |||
170 | (!c->nextblock || c->nextblock->free_size < jeb->free_size)) { | 192 | (!c->nextblock || c->nextblock->free_size < jeb->free_size)) { |
171 | /* Better candidate for the next writes to go to */ | 193 | /* Better candidate for the next writes to go to */ |
172 | if (c->nextblock) { | 194 | if (c->nextblock) { |
173 | c->nextblock->dirty_size += c->nextblock->free_size + c->nextblock->wasted_size; | 195 | ret = file_dirty(c, c->nextblock); |
174 | c->dirty_size += c->nextblock->free_size + c->nextblock->wasted_size; | 196 | if (ret) |
175 | c->free_size -= c->nextblock->free_size; | 197 | return ret; |
176 | c->wasted_size -= c->nextblock->wasted_size; | ||
177 | c->nextblock->free_size = c->nextblock->wasted_size = 0; | ||
178 | if (VERYDIRTY(c, c->nextblock->dirty_size)) { | ||
179 | list_add(&c->nextblock->list, &c->very_dirty_list); | ||
180 | } else { | ||
181 | list_add(&c->nextblock->list, &c->dirty_list); | ||
182 | } | ||
183 | /* deleting summary information of the old nextblock */ | 198 | /* deleting summary information of the old nextblock */ |
184 | jffs2_sum_reset_collected(c->summary); | 199 | jffs2_sum_reset_collected(c->summary); |
185 | } | 200 | } |
186 | /* update collected summary infromation for the current nextblock */ | 201 | /* update collected summary information for the current nextblock */ |
187 | jffs2_sum_move_collected(c, s); | 202 | jffs2_sum_move_collected(c, s); |
188 | D1(printk(KERN_DEBUG "jffs2_scan_medium(): new nextblock = 0x%08x\n", jeb->offset)); | 203 | D1(printk(KERN_DEBUG "jffs2_scan_medium(): new nextblock = 0x%08x\n", jeb->offset)); |
189 | c->nextblock = jeb; | 204 | c->nextblock = jeb; |
190 | } else { | 205 | } else { |
191 | jeb->dirty_size += jeb->free_size + jeb->wasted_size; | 206 | ret = file_dirty(c, jeb); |
192 | c->dirty_size += jeb->free_size + jeb->wasted_size; | 207 | if (ret) |
193 | c->free_size -= jeb->free_size; | 208 | return ret; |
194 | c->wasted_size -= jeb->wasted_size; | ||
195 | jeb->free_size = jeb->wasted_size = 0; | ||
196 | if (VERYDIRTY(c, jeb->dirty_size)) { | ||
197 | list_add(&jeb->list, &c->very_dirty_list); | ||
198 | } else { | ||
199 | list_add(&jeb->list, &c->dirty_list); | ||
200 | } | ||
201 | } | 209 | } |
202 | break; | 210 | break; |
203 | 211 | ||
@@ -222,9 +230,6 @@ int jffs2_scan_medium(struct jffs2_sb_info *c) | |||
222 | } | 230 | } |
223 | } | 231 | } |
224 | 232 | ||
225 | if (jffs2_sum_active() && s) | ||
226 | kfree(s); | ||
227 | |||
228 | /* Nextblock dirty is always seen as wasted, because we cannot recycle it now */ | 233 | /* Nextblock dirty is always seen as wasted, because we cannot recycle it now */ |
229 | if (c->nextblock && (c->nextblock->dirty_size)) { | 234 | if (c->nextblock && (c->nextblock->dirty_size)) { |
230 | c->nextblock->wasted_size += c->nextblock->dirty_size; | 235 | c->nextblock->wasted_size += c->nextblock->dirty_size; |
@@ -242,11 +247,8 @@ int jffs2_scan_medium(struct jffs2_sb_info *c) | |||
242 | 247 | ||
243 | D1(printk(KERN_DEBUG "jffs2_scan_medium(): Skipping %d bytes in nextblock to ensure page alignment\n", | 248 | D1(printk(KERN_DEBUG "jffs2_scan_medium(): Skipping %d bytes in nextblock to ensure page alignment\n", |
244 | skip)); | 249 | skip)); |
245 | c->nextblock->wasted_size += skip; | 250 | jffs2_prealloc_raw_node_refs(c, c->nextblock, 1); |
246 | c->wasted_size += skip; | 251 | jffs2_scan_dirty_space(c, c->nextblock, skip); |
247 | |||
248 | c->nextblock->free_size -= skip; | ||
249 | c->free_size -= skip; | ||
250 | } | 252 | } |
251 | #endif | 253 | #endif |
252 | if (c->nr_erasing_blocks) { | 254 | if (c->nr_erasing_blocks) { |
@@ -266,6 +268,9 @@ int jffs2_scan_medium(struct jffs2_sb_info *c) | |||
266 | else | 268 | else |
267 | c->mtd->unpoint(c->mtd, flashbuf, 0, c->mtd->size); | 269 | c->mtd->unpoint(c->mtd, flashbuf, 0, c->mtd->size); |
268 | #endif | 270 | #endif |
271 | if (s) | ||
272 | kfree(s); | ||
273 | |||
269 | return ret; | 274 | return ret; |
270 | } | 275 | } |
271 | 276 | ||
@@ -290,7 +295,7 @@ int jffs2_fill_scan_buf (struct jffs2_sb_info *c, void *buf, | |||
290 | int jffs2_scan_classify_jeb(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) | 295 | int jffs2_scan_classify_jeb(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) |
291 | { | 296 | { |
292 | if ((jeb->used_size + jeb->unchecked_size) == PAD(c->cleanmarker_size) && !jeb->dirty_size | 297 | if ((jeb->used_size + jeb->unchecked_size) == PAD(c->cleanmarker_size) && !jeb->dirty_size |
293 | && (!jeb->first_node || !jeb->first_node->next_phys) ) | 298 | && (!jeb->first_node || !ref_next(jeb->first_node)) ) |
294 | return BLK_STATE_CLEANMARKER; | 299 | return BLK_STATE_CLEANMARKER; |
295 | 300 | ||
296 | /* move blocks with max 4 byte dirty space to cleanlist */ | 301 | /* move blocks with max 4 byte dirty space to cleanlist */ |
@@ -306,11 +311,119 @@ int jffs2_scan_classify_jeb(struct jffs2_sb_info *c, struct jffs2_eraseblock *je | |||
306 | return BLK_STATE_ALLDIRTY; | 311 | return BLK_STATE_ALLDIRTY; |
307 | } | 312 | } |
308 | 313 | ||
314 | #ifdef CONFIG_JFFS2_FS_XATTR | ||
315 | static int jffs2_scan_xattr_node(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, | ||
316 | struct jffs2_raw_xattr *rx, uint32_t ofs, | ||
317 | struct jffs2_summary *s) | ||
318 | { | ||
319 | struct jffs2_xattr_datum *xd; | ||
320 | uint32_t totlen, crc; | ||
321 | int err; | ||
322 | |||
323 | crc = crc32(0, rx, sizeof(struct jffs2_raw_xattr) - 4); | ||
324 | if (crc != je32_to_cpu(rx->node_crc)) { | ||
325 | if (je32_to_cpu(rx->node_crc) != 0xffffffff) | ||
326 | JFFS2_WARNING("node CRC failed at %#08x, read=%#08x, calc=%#08x\n", | ||
327 | ofs, je32_to_cpu(rx->node_crc), crc); | ||
328 | if ((err = jffs2_scan_dirty_space(c, jeb, je32_to_cpu(rx->totlen)))) | ||
329 | return err; | ||
330 | return 0; | ||
331 | } | ||
332 | |||
333 | totlen = PAD(sizeof(*rx) + rx->name_len + 1 + je16_to_cpu(rx->value_len)); | ||
334 | if (totlen != je32_to_cpu(rx->totlen)) { | ||
335 | JFFS2_WARNING("node length mismatch at %#08x, read=%u, calc=%u\n", | ||
336 | ofs, je32_to_cpu(rx->totlen), totlen); | ||
337 | if ((err = jffs2_scan_dirty_space(c, jeb, je32_to_cpu(rx->totlen)))) | ||
338 | return err; | ||
339 | return 0; | ||
340 | } | ||
341 | |||
342 | xd = jffs2_setup_xattr_datum(c, je32_to_cpu(rx->xid), je32_to_cpu(rx->version)); | ||
343 | if (IS_ERR(xd)) { | ||
344 | if (PTR_ERR(xd) == -EEXIST) { | ||
345 | if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(rx->totlen))))) | ||
346 | return err; | ||
347 | return 0; | ||
348 | } | ||
349 | return PTR_ERR(xd); | ||
350 | } | ||
351 | xd->xprefix = rx->xprefix; | ||
352 | xd->name_len = rx->name_len; | ||
353 | xd->value_len = je16_to_cpu(rx->value_len); | ||
354 | xd->data_crc = je32_to_cpu(rx->data_crc); | ||
355 | |||
356 | xd->node = jffs2_link_node_ref(c, jeb, ofs | REF_PRISTINE, totlen, NULL); | ||
357 | /* FIXME */ xd->node->next_in_ino = (void *)xd; | ||
358 | |||
359 | if (jffs2_sum_active()) | ||
360 | jffs2_sum_add_xattr_mem(s, rx, ofs - jeb->offset); | ||
361 | dbg_xattr("scaning xdatum at %#08x (xid=%u, version=%u)\n", | ||
362 | ofs, xd->xid, xd->version); | ||
363 | return 0; | ||
364 | } | ||
365 | |||
366 | static int jffs2_scan_xref_node(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, | ||
367 | struct jffs2_raw_xref *rr, uint32_t ofs, | ||
368 | struct jffs2_summary *s) | ||
369 | { | ||
370 | struct jffs2_xattr_ref *ref; | ||
371 | uint32_t crc; | ||
372 | int err; | ||
373 | |||
374 | crc = crc32(0, rr, sizeof(*rr) - 4); | ||
375 | if (crc != je32_to_cpu(rr->node_crc)) { | ||
376 | if (je32_to_cpu(rr->node_crc) != 0xffffffff) | ||
377 | JFFS2_WARNING("node CRC failed at %#08x, read=%#08x, calc=%#08x\n", | ||
378 | ofs, je32_to_cpu(rr->node_crc), crc); | ||
379 | if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(rr->totlen))))) | ||
380 | return err; | ||
381 | return 0; | ||
382 | } | ||
383 | |||
384 | if (PAD(sizeof(struct jffs2_raw_xref)) != je32_to_cpu(rr->totlen)) { | ||
385 | JFFS2_WARNING("node length mismatch at %#08x, read=%u, calc=%zd\n", | ||
386 | ofs, je32_to_cpu(rr->totlen), | ||
387 | PAD(sizeof(struct jffs2_raw_xref))); | ||
388 | if ((err = jffs2_scan_dirty_space(c, jeb, je32_to_cpu(rr->totlen)))) | ||
389 | return err; | ||
390 | return 0; | ||
391 | } | ||
392 | |||
393 | ref = jffs2_alloc_xattr_ref(); | ||
394 | if (!ref) | ||
395 | return -ENOMEM; | ||
396 | |||
397 | /* BEFORE jffs2_build_xattr_subsystem() called, | ||
398 | * ref->xid is used to store 32bit xid, xd is not used | ||
399 | * ref->ino is used to store 32bit inode-number, ic is not used | ||
400 | * Thoes variables are declared as union, thus using those | ||
401 | * are exclusive. In a similar way, ref->next is temporarily | ||
402 | * used to chain all xattr_ref object. It's re-chained to | ||
403 | * jffs2_inode_cache in jffs2_build_xattr_subsystem() correctly. | ||
404 | */ | ||
405 | ref->ino = je32_to_cpu(rr->ino); | ||
406 | ref->xid = je32_to_cpu(rr->xid); | ||
407 | ref->next = c->xref_temp; | ||
408 | c->xref_temp = ref; | ||
409 | |||
410 | ref->node = jffs2_link_node_ref(c, jeb, ofs | REF_PRISTINE, PAD(je32_to_cpu(rr->totlen)), NULL); | ||
411 | /* FIXME */ ref->node->next_in_ino = (void *)ref; | ||
412 | |||
413 | if (jffs2_sum_active()) | ||
414 | jffs2_sum_add_xref_mem(s, rr, ofs - jeb->offset); | ||
415 | dbg_xattr("scan xref at %#08x (xid=%u, ino=%u)\n", | ||
416 | ofs, ref->xid, ref->ino); | ||
417 | return 0; | ||
418 | } | ||
419 | #endif | ||
420 | |||
421 | /* Called with 'buf_size == 0' if buf is in fact a pointer _directly_ into | ||
422 | the flash, XIP-style */ | ||
309 | static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, | 423 | static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, |
310 | unsigned char *buf, uint32_t buf_size, struct jffs2_summary *s) { | 424 | unsigned char *buf, uint32_t buf_size, struct jffs2_summary *s) { |
311 | struct jffs2_unknown_node *node; | 425 | struct jffs2_unknown_node *node; |
312 | struct jffs2_unknown_node crcnode; | 426 | struct jffs2_unknown_node crcnode; |
313 | struct jffs2_sum_marker *sm; | ||
314 | uint32_t ofs, prevofs; | 427 | uint32_t ofs, prevofs; |
315 | uint32_t hdr_crc, buf_ofs, buf_len; | 428 | uint32_t hdr_crc, buf_ofs, buf_len; |
316 | int err; | 429 | int err; |
@@ -344,44 +457,75 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo | |||
344 | #endif | 457 | #endif |
345 | 458 | ||
346 | if (jffs2_sum_active()) { | 459 | if (jffs2_sum_active()) { |
347 | sm = kmalloc(sizeof(struct jffs2_sum_marker), GFP_KERNEL); | 460 | struct jffs2_sum_marker *sm; |
348 | if (!sm) { | 461 | void *sumptr = NULL; |
349 | return -ENOMEM; | 462 | uint32_t sumlen; |
350 | } | 463 | |
351 | 464 | if (!buf_size) { | |
352 | err = jffs2_fill_scan_buf(c, (unsigned char *) sm, jeb->offset + c->sector_size - | 465 | /* XIP case. Just look, point at the summary if it's there */ |
353 | sizeof(struct jffs2_sum_marker), sizeof(struct jffs2_sum_marker)); | 466 | sm = (void *)buf + c->sector_size - sizeof(*sm); |
354 | if (err) { | 467 | if (je32_to_cpu(sm->magic) == JFFS2_SUM_MAGIC) { |
355 | kfree(sm); | 468 | sumptr = buf + je32_to_cpu(sm->offset); |
356 | return err; | 469 | sumlen = c->sector_size - je32_to_cpu(sm->offset); |
357 | } | 470 | } |
358 | 471 | } else { | |
359 | if (je32_to_cpu(sm->magic) == JFFS2_SUM_MAGIC ) { | 472 | /* If NAND flash, read a whole page of it. Else just the end */ |
360 | err = jffs2_sum_scan_sumnode(c, jeb, je32_to_cpu(sm->offset), &pseudo_random); | 473 | if (c->wbuf_pagesize) |
361 | if (err) { | 474 | buf_len = c->wbuf_pagesize; |
362 | kfree(sm); | 475 | else |
476 | buf_len = sizeof(*sm); | ||
477 | |||
478 | /* Read as much as we want into the _end_ of the preallocated buffer */ | ||
479 | err = jffs2_fill_scan_buf(c, buf + buf_size - buf_len, | ||
480 | jeb->offset + c->sector_size - buf_len, | ||
481 | buf_len); | ||
482 | if (err) | ||
363 | return err; | 483 | return err; |
484 | |||
485 | sm = (void *)buf + buf_size - sizeof(*sm); | ||
486 | if (je32_to_cpu(sm->magic) == JFFS2_SUM_MAGIC) { | ||
487 | sumlen = c->sector_size - je32_to_cpu(sm->offset); | ||
488 | sumptr = buf + buf_size - sumlen; | ||
489 | |||
490 | /* Now, make sure the summary itself is available */ | ||
491 | if (sumlen > buf_size) { | ||
492 | /* Need to kmalloc for this. */ | ||
493 | sumptr = kmalloc(sumlen, GFP_KERNEL); | ||
494 | if (!sumptr) | ||
495 | return -ENOMEM; | ||
496 | memcpy(sumptr + sumlen - buf_len, buf + buf_size - buf_len, buf_len); | ||
497 | } | ||
498 | if (buf_len < sumlen) { | ||
499 | /* Need to read more so that the entire summary node is present */ | ||
500 | err = jffs2_fill_scan_buf(c, sumptr, | ||
501 | jeb->offset + c->sector_size - sumlen, | ||
502 | sumlen - buf_len); | ||
503 | if (err) | ||
504 | return err; | ||
505 | } | ||
364 | } | 506 | } |
507 | |||
365 | } | 508 | } |
366 | 509 | ||
367 | kfree(sm); | 510 | if (sumptr) { |
511 | err = jffs2_sum_scan_sumnode(c, jeb, sumptr, sumlen, &pseudo_random); | ||
368 | 512 | ||
369 | ofs = jeb->offset; | 513 | if (buf_size && sumlen > buf_size) |
370 | prevofs = jeb->offset - 1; | 514 | kfree(sumptr); |
515 | /* If it returns with a real error, bail. | ||
516 | If it returns positive, that's a block classification | ||
517 | (i.e. BLK_STATE_xxx) so return that too. | ||
518 | If it returns zero, fall through to full scan. */ | ||
519 | if (err) | ||
520 | return err; | ||
521 | } | ||
371 | } | 522 | } |
372 | 523 | ||
373 | buf_ofs = jeb->offset; | 524 | buf_ofs = jeb->offset; |
374 | 525 | ||
375 | if (!buf_size) { | 526 | if (!buf_size) { |
527 | /* This is the XIP case -- we're reading _directly_ from the flash chip */ | ||
376 | buf_len = c->sector_size; | 528 | buf_len = c->sector_size; |
377 | |||
378 | if (jffs2_sum_active()) { | ||
379 | /* must reread because of summary test */ | ||
380 | err = jffs2_fill_scan_buf(c, buf, buf_ofs, buf_len); | ||
381 | if (err) | ||
382 | return err; | ||
383 | } | ||
384 | |||
385 | } else { | 529 | } else { |
386 | buf_len = EMPTY_SCAN_SIZE(c->sector_size); | 530 | buf_len = EMPTY_SCAN_SIZE(c->sector_size); |
387 | err = jffs2_fill_scan_buf(c, buf, buf_ofs, buf_len); | 531 | err = jffs2_fill_scan_buf(c, buf, buf_ofs, buf_len); |
@@ -418,7 +562,10 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo | |||
418 | if (ofs) { | 562 | if (ofs) { |
419 | D1(printk(KERN_DEBUG "Free space at %08x ends at %08x\n", jeb->offset, | 563 | D1(printk(KERN_DEBUG "Free space at %08x ends at %08x\n", jeb->offset, |
420 | jeb->offset + ofs)); | 564 | jeb->offset + ofs)); |
421 | DIRTY_SPACE(ofs); | 565 | if ((err = jffs2_prealloc_raw_node_refs(c, jeb, 1))) |
566 | return err; | ||
567 | if ((err = jffs2_scan_dirty_space(c, jeb, ofs))) | ||
568 | return err; | ||
422 | } | 569 | } |
423 | 570 | ||
424 | /* Now ofs is a complete physical flash offset as it always was... */ | 571 | /* Now ofs is a complete physical flash offset as it always was... */ |
@@ -433,6 +580,11 @@ scan_more: | |||
433 | 580 | ||
434 | jffs2_dbg_acct_paranoia_check_nolock(c, jeb); | 581 | jffs2_dbg_acct_paranoia_check_nolock(c, jeb); |
435 | 582 | ||
583 | /* Make sure there are node refs available for use */ | ||
584 | err = jffs2_prealloc_raw_node_refs(c, jeb, 2); | ||
585 | if (err) | ||
586 | return err; | ||
587 | |||
436 | cond_resched(); | 588 | cond_resched(); |
437 | 589 | ||
438 | if (ofs & 3) { | 590 | if (ofs & 3) { |
@@ -442,7 +594,8 @@ scan_more: | |||
442 | } | 594 | } |
443 | if (ofs == prevofs) { | 595 | if (ofs == prevofs) { |
444 | printk(KERN_WARNING "ofs 0x%08x has already been seen. Skipping\n", ofs); | 596 | printk(KERN_WARNING "ofs 0x%08x has already been seen. Skipping\n", ofs); |
445 | DIRTY_SPACE(4); | 597 | if ((err = jffs2_scan_dirty_space(c, jeb, 4))) |
598 | return err; | ||
446 | ofs += 4; | 599 | ofs += 4; |
447 | continue; | 600 | continue; |
448 | } | 601 | } |
@@ -451,7 +604,8 @@ scan_more: | |||
451 | if (jeb->offset + c->sector_size < ofs + sizeof(*node)) { | 604 | if (jeb->offset + c->sector_size < ofs + sizeof(*node)) { |
452 | D1(printk(KERN_DEBUG "Fewer than %zd bytes left to end of block. (%x+%x<%x+%zx) Not reading\n", sizeof(struct jffs2_unknown_node), | 605 | D1(printk(KERN_DEBUG "Fewer than %zd bytes left to end of block. (%x+%x<%x+%zx) Not reading\n", sizeof(struct jffs2_unknown_node), |
453 | jeb->offset, c->sector_size, ofs, sizeof(*node))); | 606 | jeb->offset, c->sector_size, ofs, sizeof(*node))); |
454 | DIRTY_SPACE((jeb->offset + c->sector_size)-ofs); | 607 | if ((err = jffs2_scan_dirty_space(c, jeb, (jeb->offset + c->sector_size)-ofs))) |
608 | return err; | ||
455 | break; | 609 | break; |
456 | } | 610 | } |
457 | 611 | ||
@@ -481,7 +635,8 @@ scan_more: | |||
481 | if (*(uint32_t *)(&buf[inbuf_ofs]) != 0xffffffff) { | 635 | if (*(uint32_t *)(&buf[inbuf_ofs]) != 0xffffffff) { |
482 | printk(KERN_WARNING "Empty flash at 0x%08x ends at 0x%08x\n", | 636 | printk(KERN_WARNING "Empty flash at 0x%08x ends at 0x%08x\n", |
483 | empty_start, ofs); | 637 | empty_start, ofs); |
484 | DIRTY_SPACE(ofs-empty_start); | 638 | if ((err = jffs2_scan_dirty_space(c, jeb, ofs-empty_start))) |
639 | return err; | ||
485 | goto scan_more; | 640 | goto scan_more; |
486 | } | 641 | } |
487 | 642 | ||
@@ -494,7 +649,7 @@ scan_more: | |||
494 | /* If we're only checking the beginning of a block with a cleanmarker, | 649 | /* If we're only checking the beginning of a block with a cleanmarker, |
495 | bail now */ | 650 | bail now */ |
496 | if (buf_ofs == jeb->offset && jeb->used_size == PAD(c->cleanmarker_size) && | 651 | if (buf_ofs == jeb->offset && jeb->used_size == PAD(c->cleanmarker_size) && |
497 | c->cleanmarker_size && !jeb->dirty_size && !jeb->first_node->next_phys) { | 652 | c->cleanmarker_size && !jeb->dirty_size && !ref_next(jeb->first_node)) { |
498 | D1(printk(KERN_DEBUG "%d bytes at start of block seems clean... assuming all clean\n", EMPTY_SCAN_SIZE(c->sector_size))); | 653 | D1(printk(KERN_DEBUG "%d bytes at start of block seems clean... assuming all clean\n", EMPTY_SCAN_SIZE(c->sector_size))); |
499 | return BLK_STATE_CLEANMARKER; | 654 | return BLK_STATE_CLEANMARKER; |
500 | } | 655 | } |
@@ -518,20 +673,23 @@ scan_more: | |||
518 | 673 | ||
519 | if (ofs == jeb->offset && je16_to_cpu(node->magic) == KSAMTIB_CIGAM_2SFFJ) { | 674 | if (ofs == jeb->offset && je16_to_cpu(node->magic) == KSAMTIB_CIGAM_2SFFJ) { |
520 | printk(KERN_WARNING "Magic bitmask is backwards at offset 0x%08x. Wrong endian filesystem?\n", ofs); | 675 | printk(KERN_WARNING "Magic bitmask is backwards at offset 0x%08x. Wrong endian filesystem?\n", ofs); |
521 | DIRTY_SPACE(4); | 676 | if ((err = jffs2_scan_dirty_space(c, jeb, 4))) |
677 | return err; | ||
522 | ofs += 4; | 678 | ofs += 4; |
523 | continue; | 679 | continue; |
524 | } | 680 | } |
525 | if (je16_to_cpu(node->magic) == JFFS2_DIRTY_BITMASK) { | 681 | if (je16_to_cpu(node->magic) == JFFS2_DIRTY_BITMASK) { |
526 | D1(printk(KERN_DEBUG "Dirty bitmask at 0x%08x\n", ofs)); | 682 | D1(printk(KERN_DEBUG "Dirty bitmask at 0x%08x\n", ofs)); |
527 | DIRTY_SPACE(4); | 683 | if ((err = jffs2_scan_dirty_space(c, jeb, 4))) |
684 | return err; | ||
528 | ofs += 4; | 685 | ofs += 4; |
529 | continue; | 686 | continue; |
530 | } | 687 | } |
531 | if (je16_to_cpu(node->magic) == JFFS2_OLD_MAGIC_BITMASK) { | 688 | if (je16_to_cpu(node->magic) == JFFS2_OLD_MAGIC_BITMASK) { |
532 | printk(KERN_WARNING "Old JFFS2 bitmask found at 0x%08x\n", ofs); | 689 | printk(KERN_WARNING "Old JFFS2 bitmask found at 0x%08x\n", ofs); |
533 | printk(KERN_WARNING "You cannot use older JFFS2 filesystems with newer kernels\n"); | 690 | printk(KERN_WARNING "You cannot use older JFFS2 filesystems with newer kernels\n"); |
534 | DIRTY_SPACE(4); | 691 | if ((err = jffs2_scan_dirty_space(c, jeb, 4))) |
692 | return err; | ||
535 | ofs += 4; | 693 | ofs += 4; |
536 | continue; | 694 | continue; |
537 | } | 695 | } |
@@ -540,7 +698,8 @@ scan_more: | |||
540 | noisy_printk(&noise, "jffs2_scan_eraseblock(): Magic bitmask 0x%04x not found at 0x%08x: 0x%04x instead\n", | 698 | noisy_printk(&noise, "jffs2_scan_eraseblock(): Magic bitmask 0x%04x not found at 0x%08x: 0x%04x instead\n", |
541 | JFFS2_MAGIC_BITMASK, ofs, | 699 | JFFS2_MAGIC_BITMASK, ofs, |
542 | je16_to_cpu(node->magic)); | 700 | je16_to_cpu(node->magic)); |
543 | DIRTY_SPACE(4); | 701 | if ((err = jffs2_scan_dirty_space(c, jeb, 4))) |
702 | return err; | ||
544 | ofs += 4; | 703 | ofs += 4; |
545 | continue; | 704 | continue; |
546 | } | 705 | } |
@@ -557,7 +716,8 @@ scan_more: | |||
557 | je32_to_cpu(node->totlen), | 716 | je32_to_cpu(node->totlen), |
558 | je32_to_cpu(node->hdr_crc), | 717 | je32_to_cpu(node->hdr_crc), |
559 | hdr_crc); | 718 | hdr_crc); |
560 | DIRTY_SPACE(4); | 719 | if ((err = jffs2_scan_dirty_space(c, jeb, 4))) |
720 | return err; | ||
561 | ofs += 4; | 721 | ofs += 4; |
562 | continue; | 722 | continue; |
563 | } | 723 | } |
@@ -568,7 +728,8 @@ scan_more: | |||
568 | printk(KERN_WARNING "Node at 0x%08x with length 0x%08x would run over the end of the erase block\n", | 728 | printk(KERN_WARNING "Node at 0x%08x with length 0x%08x would run over the end of the erase block\n", |
569 | ofs, je32_to_cpu(node->totlen)); | 729 | ofs, je32_to_cpu(node->totlen)); |
570 | printk(KERN_WARNING "Perhaps the file system was created with the wrong erase size?\n"); | 730 | printk(KERN_WARNING "Perhaps the file system was created with the wrong erase size?\n"); |
571 | DIRTY_SPACE(4); | 731 | if ((err = jffs2_scan_dirty_space(c, jeb, 4))) |
732 | return err; | ||
572 | ofs += 4; | 733 | ofs += 4; |
573 | continue; | 734 | continue; |
574 | } | 735 | } |
@@ -576,7 +737,8 @@ scan_more: | |||
576 | if (!(je16_to_cpu(node->nodetype) & JFFS2_NODE_ACCURATE)) { | 737 | if (!(je16_to_cpu(node->nodetype) & JFFS2_NODE_ACCURATE)) { |
577 | /* Wheee. This is an obsoleted node */ | 738 | /* Wheee. This is an obsoleted node */ |
578 | D2(printk(KERN_DEBUG "Node at 0x%08x is obsolete. Skipping\n", ofs)); | 739 | D2(printk(KERN_DEBUG "Node at 0x%08x is obsolete. Skipping\n", ofs)); |
579 | DIRTY_SPACE(PAD(je32_to_cpu(node->totlen))); | 740 | if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(node->totlen))))) |
741 | return err; | ||
580 | ofs += PAD(je32_to_cpu(node->totlen)); | 742 | ofs += PAD(je32_to_cpu(node->totlen)); |
581 | continue; | 743 | continue; |
582 | } | 744 | } |
@@ -614,30 +776,59 @@ scan_more: | |||
614 | ofs += PAD(je32_to_cpu(node->totlen)); | 776 | ofs += PAD(je32_to_cpu(node->totlen)); |
615 | break; | 777 | break; |
616 | 778 | ||
779 | #ifdef CONFIG_JFFS2_FS_XATTR | ||
780 | case JFFS2_NODETYPE_XATTR: | ||
781 | if (buf_ofs + buf_len < ofs + je32_to_cpu(node->totlen)) { | ||
782 | buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs); | ||
783 | D1(printk(KERN_DEBUG "Fewer than %d bytes (xattr node)" | ||
784 | " left to end of buf. Reading 0x%x at 0x%08x\n", | ||
785 | je32_to_cpu(node->totlen), buf_len, ofs)); | ||
786 | err = jffs2_fill_scan_buf(c, buf, ofs, buf_len); | ||
787 | if (err) | ||
788 | return err; | ||
789 | buf_ofs = ofs; | ||
790 | node = (void *)buf; | ||
791 | } | ||
792 | err = jffs2_scan_xattr_node(c, jeb, (void *)node, ofs, s); | ||
793 | if (err) | ||
794 | return err; | ||
795 | ofs += PAD(je32_to_cpu(node->totlen)); | ||
796 | break; | ||
797 | case JFFS2_NODETYPE_XREF: | ||
798 | if (buf_ofs + buf_len < ofs + je32_to_cpu(node->totlen)) { | ||
799 | buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs); | ||
800 | D1(printk(KERN_DEBUG "Fewer than %d bytes (xref node)" | ||
801 | " left to end of buf. Reading 0x%x at 0x%08x\n", | ||
802 | je32_to_cpu(node->totlen), buf_len, ofs)); | ||
803 | err = jffs2_fill_scan_buf(c, buf, ofs, buf_len); | ||
804 | if (err) | ||
805 | return err; | ||
806 | buf_ofs = ofs; | ||
807 | node = (void *)buf; | ||
808 | } | ||
809 | err = jffs2_scan_xref_node(c, jeb, (void *)node, ofs, s); | ||
810 | if (err) | ||
811 | return err; | ||
812 | ofs += PAD(je32_to_cpu(node->totlen)); | ||
813 | break; | ||
814 | #endif /* CONFIG_JFFS2_FS_XATTR */ | ||
815 | |||
617 | case JFFS2_NODETYPE_CLEANMARKER: | 816 | case JFFS2_NODETYPE_CLEANMARKER: |
618 | D1(printk(KERN_DEBUG "CLEANMARKER node found at 0x%08x\n", ofs)); | 817 | D1(printk(KERN_DEBUG "CLEANMARKER node found at 0x%08x\n", ofs)); |
619 | if (je32_to_cpu(node->totlen) != c->cleanmarker_size) { | 818 | if (je32_to_cpu(node->totlen) != c->cleanmarker_size) { |
620 | printk(KERN_NOTICE "CLEANMARKER node found at 0x%08x has totlen 0x%x != normal 0x%x\n", | 819 | printk(KERN_NOTICE "CLEANMARKER node found at 0x%08x has totlen 0x%x != normal 0x%x\n", |
621 | ofs, je32_to_cpu(node->totlen), c->cleanmarker_size); | 820 | ofs, je32_to_cpu(node->totlen), c->cleanmarker_size); |
622 | DIRTY_SPACE(PAD(sizeof(struct jffs2_unknown_node))); | 821 | if ((err = jffs2_scan_dirty_space(c, jeb, PAD(sizeof(struct jffs2_unknown_node))))) |
822 | return err; | ||
623 | ofs += PAD(sizeof(struct jffs2_unknown_node)); | 823 | ofs += PAD(sizeof(struct jffs2_unknown_node)); |
624 | } else if (jeb->first_node) { | 824 | } else if (jeb->first_node) { |
625 | printk(KERN_NOTICE "CLEANMARKER node found at 0x%08x, not first node in block (0x%08x)\n", ofs, jeb->offset); | 825 | printk(KERN_NOTICE "CLEANMARKER node found at 0x%08x, not first node in block (0x%08x)\n", ofs, jeb->offset); |
626 | DIRTY_SPACE(PAD(sizeof(struct jffs2_unknown_node))); | 826 | if ((err = jffs2_scan_dirty_space(c, jeb, PAD(sizeof(struct jffs2_unknown_node))))) |
827 | return err; | ||
627 | ofs += PAD(sizeof(struct jffs2_unknown_node)); | 828 | ofs += PAD(sizeof(struct jffs2_unknown_node)); |
628 | } else { | 829 | } else { |
629 | struct jffs2_raw_node_ref *marker_ref = jffs2_alloc_raw_node_ref(); | 830 | jffs2_link_node_ref(c, jeb, ofs | REF_NORMAL, c->cleanmarker_size, NULL); |
630 | if (!marker_ref) { | ||
631 | printk(KERN_NOTICE "Failed to allocate node ref for clean marker\n"); | ||
632 | return -ENOMEM; | ||
633 | } | ||
634 | marker_ref->next_in_ino = NULL; | ||
635 | marker_ref->next_phys = NULL; | ||
636 | marker_ref->flash_offset = ofs | REF_NORMAL; | ||
637 | marker_ref->__totlen = c->cleanmarker_size; | ||
638 | jeb->first_node = jeb->last_node = marker_ref; | ||
639 | 831 | ||
640 | USED_SPACE(PAD(c->cleanmarker_size)); | ||
641 | ofs += PAD(c->cleanmarker_size); | 832 | ofs += PAD(c->cleanmarker_size); |
642 | } | 833 | } |
643 | break; | 834 | break; |
@@ -645,7 +836,8 @@ scan_more: | |||
645 | case JFFS2_NODETYPE_PADDING: | 836 | case JFFS2_NODETYPE_PADDING: |
646 | if (jffs2_sum_active()) | 837 | if (jffs2_sum_active()) |
647 | jffs2_sum_add_padding_mem(s, je32_to_cpu(node->totlen)); | 838 | jffs2_sum_add_padding_mem(s, je32_to_cpu(node->totlen)); |
648 | DIRTY_SPACE(PAD(je32_to_cpu(node->totlen))); | 839 | if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(node->totlen))))) |
840 | return err; | ||
649 | ofs += PAD(je32_to_cpu(node->totlen)); | 841 | ofs += PAD(je32_to_cpu(node->totlen)); |
650 | break; | 842 | break; |
651 | 843 | ||
@@ -656,7 +848,8 @@ scan_more: | |||
656 | c->flags |= JFFS2_SB_FLAG_RO; | 848 | c->flags |= JFFS2_SB_FLAG_RO; |
657 | if (!(jffs2_is_readonly(c))) | 849 | if (!(jffs2_is_readonly(c))) |
658 | return -EROFS; | 850 | return -EROFS; |
659 | DIRTY_SPACE(PAD(je32_to_cpu(node->totlen))); | 851 | if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(node->totlen))))) |
852 | return err; | ||
660 | ofs += PAD(je32_to_cpu(node->totlen)); | 853 | ofs += PAD(je32_to_cpu(node->totlen)); |
661 | break; | 854 | break; |
662 | 855 | ||
@@ -666,15 +859,21 @@ scan_more: | |||
666 | 859 | ||
667 | case JFFS2_FEATURE_RWCOMPAT_DELETE: | 860 | case JFFS2_FEATURE_RWCOMPAT_DELETE: |
668 | D1(printk(KERN_NOTICE "Unknown but compatible feature node (0x%04x) found at offset 0x%08x\n", je16_to_cpu(node->nodetype), ofs)); | 861 | D1(printk(KERN_NOTICE "Unknown but compatible feature node (0x%04x) found at offset 0x%08x\n", je16_to_cpu(node->nodetype), ofs)); |
669 | DIRTY_SPACE(PAD(je32_to_cpu(node->totlen))); | 862 | if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(node->totlen))))) |
863 | return err; | ||
670 | ofs += PAD(je32_to_cpu(node->totlen)); | 864 | ofs += PAD(je32_to_cpu(node->totlen)); |
671 | break; | 865 | break; |
672 | 866 | ||
673 | case JFFS2_FEATURE_RWCOMPAT_COPY: | 867 | case JFFS2_FEATURE_RWCOMPAT_COPY: { |
674 | D1(printk(KERN_NOTICE "Unknown but compatible feature node (0x%04x) found at offset 0x%08x\n", je16_to_cpu(node->nodetype), ofs)); | 868 | D1(printk(KERN_NOTICE "Unknown but compatible feature node (0x%04x) found at offset 0x%08x\n", je16_to_cpu(node->nodetype), ofs)); |
675 | USED_SPACE(PAD(je32_to_cpu(node->totlen))); | 869 | |
870 | jffs2_link_node_ref(c, jeb, ofs | REF_PRISTINE, PAD(je32_to_cpu(node->totlen)), NULL); | ||
871 | |||
872 | /* We can't summarise nodes we don't grok */ | ||
873 | jffs2_sum_disable_collecting(s); | ||
676 | ofs += PAD(je32_to_cpu(node->totlen)); | 874 | ofs += PAD(je32_to_cpu(node->totlen)); |
677 | break; | 875 | break; |
876 | } | ||
678 | } | 877 | } |
679 | } | 878 | } |
680 | } | 879 | } |
@@ -687,9 +886,9 @@ scan_more: | |||
687 | } | 886 | } |
688 | } | 887 | } |
689 | 888 | ||
690 | D1(printk(KERN_DEBUG "Block at 0x%08x: free 0x%08x, dirty 0x%08x, unchecked 0x%08x, used 0x%08x\n", jeb->offset, | 889 | D1(printk(KERN_DEBUG "Block at 0x%08x: free 0x%08x, dirty 0x%08x, unchecked 0x%08x, used 0x%08x, wasted 0x%08x\n", |
691 | jeb->free_size, jeb->dirty_size, jeb->unchecked_size, jeb->used_size)); | 890 | jeb->offset,jeb->free_size, jeb->dirty_size, jeb->unchecked_size, jeb->used_size, jeb->wasted_size)); |
692 | 891 | ||
693 | /* mark_node_obsolete can add to wasted !! */ | 892 | /* mark_node_obsolete can add to wasted !! */ |
694 | if (jeb->wasted_size) { | 893 | if (jeb->wasted_size) { |
695 | jeb->dirty_size += jeb->wasted_size; | 894 | jeb->dirty_size += jeb->wasted_size; |
@@ -730,9 +929,9 @@ struct jffs2_inode_cache *jffs2_scan_make_ino_cache(struct jffs2_sb_info *c, uin | |||
730 | static int jffs2_scan_inode_node(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, | 929 | static int jffs2_scan_inode_node(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, |
731 | struct jffs2_raw_inode *ri, uint32_t ofs, struct jffs2_summary *s) | 930 | struct jffs2_raw_inode *ri, uint32_t ofs, struct jffs2_summary *s) |
732 | { | 931 | { |
733 | struct jffs2_raw_node_ref *raw; | ||
734 | struct jffs2_inode_cache *ic; | 932 | struct jffs2_inode_cache *ic; |
735 | uint32_t ino = je32_to_cpu(ri->ino); | 933 | uint32_t ino = je32_to_cpu(ri->ino); |
934 | int err; | ||
736 | 935 | ||
737 | D1(printk(KERN_DEBUG "jffs2_scan_inode_node(): Node at 0x%08x\n", ofs)); | 936 | D1(printk(KERN_DEBUG "jffs2_scan_inode_node(): Node at 0x%08x\n", ofs)); |
738 | 937 | ||
@@ -745,12 +944,6 @@ static int jffs2_scan_inode_node(struct jffs2_sb_info *c, struct jffs2_erasebloc | |||
745 | Which means that the _full_ amount of time to get to proper write mode with GC | 944 | Which means that the _full_ amount of time to get to proper write mode with GC |
746 | operational may actually be _longer_ than before. Sucks to be me. */ | 945 | operational may actually be _longer_ than before. Sucks to be me. */ |
747 | 946 | ||
748 | raw = jffs2_alloc_raw_node_ref(); | ||
749 | if (!raw) { | ||
750 | printk(KERN_NOTICE "jffs2_scan_inode_node(): allocation of node reference failed\n"); | ||
751 | return -ENOMEM; | ||
752 | } | ||
753 | |||
754 | ic = jffs2_get_ino_cache(c, ino); | 947 | ic = jffs2_get_ino_cache(c, ino); |
755 | if (!ic) { | 948 | if (!ic) { |
756 | /* Inocache get failed. Either we read a bogus ino# or it's just genuinely the | 949 | /* Inocache get failed. Either we read a bogus ino# or it's just genuinely the |
@@ -762,30 +955,17 @@ static int jffs2_scan_inode_node(struct jffs2_sb_info *c, struct jffs2_erasebloc | |||
762 | printk(KERN_NOTICE "jffs2_scan_inode_node(): CRC failed on node at 0x%08x: Read 0x%08x, calculated 0x%08x\n", | 955 | printk(KERN_NOTICE "jffs2_scan_inode_node(): CRC failed on node at 0x%08x: Read 0x%08x, calculated 0x%08x\n", |
763 | ofs, je32_to_cpu(ri->node_crc), crc); | 956 | ofs, je32_to_cpu(ri->node_crc), crc); |
764 | /* We believe totlen because the CRC on the node _header_ was OK, just the node itself failed. */ | 957 | /* We believe totlen because the CRC on the node _header_ was OK, just the node itself failed. */ |
765 | DIRTY_SPACE(PAD(je32_to_cpu(ri->totlen))); | 958 | if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(ri->totlen))))) |
766 | jffs2_free_raw_node_ref(raw); | 959 | return err; |
767 | return 0; | 960 | return 0; |
768 | } | 961 | } |
769 | ic = jffs2_scan_make_ino_cache(c, ino); | 962 | ic = jffs2_scan_make_ino_cache(c, ino); |
770 | if (!ic) { | 963 | if (!ic) |
771 | jffs2_free_raw_node_ref(raw); | ||
772 | return -ENOMEM; | 964 | return -ENOMEM; |
773 | } | ||
774 | } | 965 | } |
775 | 966 | ||
776 | /* Wheee. It worked */ | 967 | /* Wheee. It worked */ |
777 | 968 | jffs2_link_node_ref(c, jeb, ofs | REF_UNCHECKED, PAD(je32_to_cpu(ri->totlen)), ic); | |
778 | raw->flash_offset = ofs | REF_UNCHECKED; | ||
779 | raw->__totlen = PAD(je32_to_cpu(ri->totlen)); | ||
780 | raw->next_phys = NULL; | ||
781 | raw->next_in_ino = ic->nodes; | ||
782 | |||
783 | ic->nodes = raw; | ||
784 | if (!jeb->first_node) | ||
785 | jeb->first_node = raw; | ||
786 | if (jeb->last_node) | ||
787 | jeb->last_node->next_phys = raw; | ||
788 | jeb->last_node = raw; | ||
789 | 969 | ||
790 | D1(printk(KERN_DEBUG "Node is ino #%u, version %d. Range 0x%x-0x%x\n", | 970 | D1(printk(KERN_DEBUG "Node is ino #%u, version %d. Range 0x%x-0x%x\n", |
791 | je32_to_cpu(ri->ino), je32_to_cpu(ri->version), | 971 | je32_to_cpu(ri->ino), je32_to_cpu(ri->version), |
@@ -794,8 +974,6 @@ static int jffs2_scan_inode_node(struct jffs2_sb_info *c, struct jffs2_erasebloc | |||
794 | 974 | ||
795 | pseudo_random += je32_to_cpu(ri->version); | 975 | pseudo_random += je32_to_cpu(ri->version); |
796 | 976 | ||
797 | UNCHECKED_SPACE(PAD(je32_to_cpu(ri->totlen))); | ||
798 | |||
799 | if (jffs2_sum_active()) { | 977 | if (jffs2_sum_active()) { |
800 | jffs2_sum_add_inode_mem(s, ri, ofs - jeb->offset); | 978 | jffs2_sum_add_inode_mem(s, ri, ofs - jeb->offset); |
801 | } | 979 | } |
@@ -806,10 +984,10 @@ static int jffs2_scan_inode_node(struct jffs2_sb_info *c, struct jffs2_erasebloc | |||
806 | static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, | 984 | static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, |
807 | struct jffs2_raw_dirent *rd, uint32_t ofs, struct jffs2_summary *s) | 985 | struct jffs2_raw_dirent *rd, uint32_t ofs, struct jffs2_summary *s) |
808 | { | 986 | { |
809 | struct jffs2_raw_node_ref *raw; | ||
810 | struct jffs2_full_dirent *fd; | 987 | struct jffs2_full_dirent *fd; |
811 | struct jffs2_inode_cache *ic; | 988 | struct jffs2_inode_cache *ic; |
812 | uint32_t crc; | 989 | uint32_t crc; |
990 | int err; | ||
813 | 991 | ||
814 | D1(printk(KERN_DEBUG "jffs2_scan_dirent_node(): Node at 0x%08x\n", ofs)); | 992 | D1(printk(KERN_DEBUG "jffs2_scan_dirent_node(): Node at 0x%08x\n", ofs)); |
815 | 993 | ||
@@ -821,7 +999,8 @@ static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblo | |||
821 | printk(KERN_NOTICE "jffs2_scan_dirent_node(): Node CRC failed on node at 0x%08x: Read 0x%08x, calculated 0x%08x\n", | 999 | printk(KERN_NOTICE "jffs2_scan_dirent_node(): Node CRC failed on node at 0x%08x: Read 0x%08x, calculated 0x%08x\n", |
822 | ofs, je32_to_cpu(rd->node_crc), crc); | 1000 | ofs, je32_to_cpu(rd->node_crc), crc); |
823 | /* We believe totlen because the CRC on the node _header_ was OK, just the node itself failed. */ | 1001 | /* We believe totlen because the CRC on the node _header_ was OK, just the node itself failed. */ |
824 | DIRTY_SPACE(PAD(je32_to_cpu(rd->totlen))); | 1002 | if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(rd->totlen))))) |
1003 | return err; | ||
825 | return 0; | 1004 | return 0; |
826 | } | 1005 | } |
827 | 1006 | ||
@@ -842,40 +1021,23 @@ static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblo | |||
842 | jffs2_free_full_dirent(fd); | 1021 | jffs2_free_full_dirent(fd); |
843 | /* FIXME: Why do we believe totlen? */ | 1022 | /* FIXME: Why do we believe totlen? */ |
844 | /* We believe totlen because the CRC on the node _header_ was OK, just the name failed. */ | 1023 | /* We believe totlen because the CRC on the node _header_ was OK, just the name failed. */ |
845 | DIRTY_SPACE(PAD(je32_to_cpu(rd->totlen))); | 1024 | if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(rd->totlen))))) |
1025 | return err; | ||
846 | return 0; | 1026 | return 0; |
847 | } | 1027 | } |
848 | raw = jffs2_alloc_raw_node_ref(); | ||
849 | if (!raw) { | ||
850 | jffs2_free_full_dirent(fd); | ||
851 | printk(KERN_NOTICE "jffs2_scan_dirent_node(): allocation of node reference failed\n"); | ||
852 | return -ENOMEM; | ||
853 | } | ||
854 | ic = jffs2_scan_make_ino_cache(c, je32_to_cpu(rd->pino)); | 1028 | ic = jffs2_scan_make_ino_cache(c, je32_to_cpu(rd->pino)); |
855 | if (!ic) { | 1029 | if (!ic) { |
856 | jffs2_free_full_dirent(fd); | 1030 | jffs2_free_full_dirent(fd); |
857 | jffs2_free_raw_node_ref(raw); | ||
858 | return -ENOMEM; | 1031 | return -ENOMEM; |
859 | } | 1032 | } |
860 | 1033 | ||
861 | raw->__totlen = PAD(je32_to_cpu(rd->totlen)); | 1034 | fd->raw = jffs2_link_node_ref(c, jeb, ofs | REF_PRISTINE, PAD(je32_to_cpu(rd->totlen)), ic); |
862 | raw->flash_offset = ofs | REF_PRISTINE; | ||
863 | raw->next_phys = NULL; | ||
864 | raw->next_in_ino = ic->nodes; | ||
865 | ic->nodes = raw; | ||
866 | if (!jeb->first_node) | ||
867 | jeb->first_node = raw; | ||
868 | if (jeb->last_node) | ||
869 | jeb->last_node->next_phys = raw; | ||
870 | jeb->last_node = raw; | ||
871 | 1035 | ||
872 | fd->raw = raw; | ||
873 | fd->next = NULL; | 1036 | fd->next = NULL; |
874 | fd->version = je32_to_cpu(rd->version); | 1037 | fd->version = je32_to_cpu(rd->version); |
875 | fd->ino = je32_to_cpu(rd->ino); | 1038 | fd->ino = je32_to_cpu(rd->ino); |
876 | fd->nhash = full_name_hash(fd->name, rd->nsize); | 1039 | fd->nhash = full_name_hash(fd->name, rd->nsize); |
877 | fd->type = rd->type; | 1040 | fd->type = rd->type; |
878 | USED_SPACE(PAD(je32_to_cpu(rd->totlen))); | ||
879 | jffs2_add_fd_to_list(c, fd, &ic->scan_dents); | 1041 | jffs2_add_fd_to_list(c, fd, &ic->scan_dents); |
880 | 1042 | ||
881 | if (jffs2_sum_active()) { | 1043 | if (jffs2_sum_active()) { |