Lines Matching +full:offset +full:- +full:x
2 * JFFS2 -- Journalling Flash File System, Version 2.
4 * Copyright © 2001-2007 Red Hat, Inc.
31 (*(noise))--; \
43 * Returning an error will abort the mount - bad checksums etc. should just mark the space
55 if (!jffs2_can_mark_obsolete(c) && min < c->wbuf_pagesize) in min_free()
56 return c->wbuf_pagesize; in min_free()
75 if ((ret = jffs2_scan_dirty_space(c, jeb, jeb->free_size))) in file_dirty()
79 jeb->dirty_size += jeb->wasted_size; in file_dirty()
80 c->dirty_size += jeb->wasted_size; in file_dirty()
81 c->wasted_size -= jeb->wasted_size; in file_dirty()
82 jeb->wasted_size = 0; in file_dirty()
83 if (VERYDIRTY(c, jeb->dirty_size)) { in file_dirty()
84 list_add(&jeb->list, &c->very_dirty_list); in file_dirty()
86 list_add(&jeb->list, &c->dirty_list); in file_dirty()
101 ret = mtd_point(c->mtd, 0, c->mtd->size, &pointlen, in jffs2_scan_medium()
103 if (!ret && pointlen < c->mtd->size) { in jffs2_scan_medium()
105 jffs2_dbg(1, "MTD point returned len too short: 0x%zx\n", in jffs2_scan_medium()
107 mtd_unpoint(c->mtd, 0, pointlen); in jffs2_scan_medium()
110 if (ret && ret != -EOPNOTSUPP) in jffs2_scan_medium()
117 try_size = c->sector_size; in jffs2_scan_medium()
124 flashbuf = mtd_kmalloc_up_to(c->mtd, &try_size); in jffs2_scan_medium()
126 return -ENOMEM; in jffs2_scan_medium()
138 ret = -ENOMEM; in jffs2_scan_medium()
143 for (i=0; i<c->nr_blocks; i++) { in jffs2_scan_medium()
144 struct jffs2_eraseblock *jeb = &c->blocks[i]; in jffs2_scan_medium()
151 ret = jffs2_scan_eraseblock(c, jeb, buf_size?flashbuf:(flashbuf+jeb->offset), in jffs2_scan_medium()
170 list_add(&jeb->list, &c->erase_pending_list); in jffs2_scan_medium()
171 c->nr_erasing_blocks++; in jffs2_scan_medium()
176 if (!jeb->dirty_size) { in jffs2_scan_medium()
178 list_add(&jeb->list, &c->free_list); in jffs2_scan_medium()
179 c->nr_free_blocks++; in jffs2_scan_medium()
182 jffs2_dbg(1, "Adding all-dirty block at 0x%08x to erase_pending_list\n", in jffs2_scan_medium()
183 jeb->offset); in jffs2_scan_medium()
184 list_add(&jeb->list, &c->erase_pending_list); in jffs2_scan_medium()
185 c->nr_erasing_blocks++; in jffs2_scan_medium()
191 list_add(&jeb->list, &c->clean_list); in jffs2_scan_medium()
198 if (jeb->free_size > min_free(c) && in jffs2_scan_medium()
199 (!c->nextblock || c->nextblock->free_size < jeb->free_size)) { in jffs2_scan_medium()
201 if (c->nextblock) { in jffs2_scan_medium()
202 ret = file_dirty(c, c->nextblock); in jffs2_scan_medium()
206 jffs2_sum_reset_collected(c->summary); in jffs2_scan_medium()
210 jffs2_dbg(1, "%s(): new nextblock = 0x%08x\n", in jffs2_scan_medium()
211 __func__, jeb->offset); in jffs2_scan_medium()
212 c->nextblock = jeb; in jffs2_scan_medium()
221 /* Nothing valid - not even a clean marker. Needs erasing. */ in jffs2_scan_medium()
223 jffs2_dbg(1, "Erase block at 0x%08x is not formatted. It will be erased\n", in jffs2_scan_medium()
224 jeb->offset); in jffs2_scan_medium()
225 list_add(&jeb->list, &c->erase_pending_list); in jffs2_scan_medium()
226 c->nr_erasing_blocks++; in jffs2_scan_medium()
230 jffs2_dbg(1, "Block at 0x%08x is bad\n", jeb->offset); in jffs2_scan_medium()
231 list_add(&jeb->list, &c->bad_list); in jffs2_scan_medium()
232 c->bad_size += c->sector_size; in jffs2_scan_medium()
233 c->free_size -= c->sector_size; in jffs2_scan_medium()
243 if (c->nextblock && (c->nextblock->dirty_size)) { in jffs2_scan_medium()
244 c->nextblock->wasted_size += c->nextblock->dirty_size; in jffs2_scan_medium()
245 c->wasted_size += c->nextblock->dirty_size; in jffs2_scan_medium()
246 c->dirty_size -= c->nextblock->dirty_size; in jffs2_scan_medium()
247 c->nextblock->dirty_size = 0; in jffs2_scan_medium()
250 …if (!jffs2_can_mark_obsolete(c) && c->wbuf_pagesize && c->nextblock && (c->nextblock->free_size % … in jffs2_scan_medium()
252 contains data, and the end of the data isn't page-aligned, in jffs2_scan_medium()
255 uint32_t skip = c->nextblock->free_size % c->wbuf_pagesize; in jffs2_scan_medium()
259 jffs2_prealloc_raw_node_refs(c, c->nextblock, 1); in jffs2_scan_medium()
260 jffs2_scan_dirty_space(c, c->nextblock, skip); in jffs2_scan_medium()
263 if (c->nr_erasing_blocks) { in jffs2_scan_medium()
264 if (!c->used_size && !c->unchecked_size && in jffs2_scan_medium()
265 ((c->nr_free_blocks+empty_blocks+bad_blocks) != c->nr_blocks || bad_blocks == c->nr_blocks)) { in jffs2_scan_medium()
267 pr_notice("empty_blocks %d, bad_blocks %d, c->nr_blocks %d\n", in jffs2_scan_medium()
268 empty_blocks, bad_blocks, c->nr_blocks); in jffs2_scan_medium()
269 ret = -EIO; in jffs2_scan_medium()
272 spin_lock(&c->erase_completion_lock); in jffs2_scan_medium()
274 spin_unlock(&c->erase_completion_lock); in jffs2_scan_medium()
282 mtd_unpoint(c->mtd, 0, c->mtd->size); in jffs2_scan_medium()
296 jffs2_dbg(1, "mtd->read(0x%x bytes from 0x%x) returned %d\n", in jffs2_fill_scan_buf()
301 jffs2_dbg(1, "Read at 0x%x gave only 0x%zx bytes\n", in jffs2_fill_scan_buf()
303 return -EIO; in jffs2_fill_scan_buf()
310 if ((jeb->used_size + jeb->unchecked_size) == PAD(c->cleanmarker_size) && !jeb->dirty_size in jffs2_scan_classify_jeb()
311 && (!jeb->first_node || !ref_next(jeb->first_node)) ) in jffs2_scan_classify_jeb()
315 else if (!ISDIRTY(c->sector_size - (jeb->used_size + jeb->unchecked_size))) { in jffs2_scan_classify_jeb()
316 c->dirty_size -= jeb->dirty_size; in jffs2_scan_classify_jeb()
317 c->wasted_size += jeb->dirty_size; in jffs2_scan_classify_jeb()
318 jeb->wasted_size += jeb->dirty_size; in jffs2_scan_classify_jeb()
319 jeb->dirty_size = 0; in jffs2_scan_classify_jeb()
321 } else if (jeb->used_size || jeb->unchecked_size) in jffs2_scan_classify_jeb()
336 crc = crc32(0, rx, sizeof(struct jffs2_raw_xattr) - 4); in jffs2_scan_xattr_node()
337 if (crc != je32_to_cpu(rx->node_crc)) { in jffs2_scan_xattr_node()
338 JFFS2_WARNING("node CRC failed at %#08x, read=%#08x, calc=%#08x\n", in jffs2_scan_xattr_node()
339 ofs, je32_to_cpu(rx->node_crc), crc); in jffs2_scan_xattr_node()
340 if ((err = jffs2_scan_dirty_space(c, jeb, je32_to_cpu(rx->totlen)))) in jffs2_scan_xattr_node()
345 xid = je32_to_cpu(rx->xid); in jffs2_scan_xattr_node()
346 version = je32_to_cpu(rx->version); in jffs2_scan_xattr_node()
349 + rx->name_len + 1 + je16_to_cpu(rx->value_len)); in jffs2_scan_xattr_node()
350 if (totlen != je32_to_cpu(rx->totlen)) { in jffs2_scan_xattr_node()
351 JFFS2_WARNING("node length mismatch at %#08x, read=%u, calc=%u\n", in jffs2_scan_xattr_node()
352 ofs, je32_to_cpu(rx->totlen), totlen); in jffs2_scan_xattr_node()
353 if ((err = jffs2_scan_dirty_space(c, jeb, je32_to_cpu(rx->totlen)))) in jffs2_scan_xattr_node()
362 if (xd->version > version) { in jffs2_scan_xattr_node()
365 raw->next_in_ino = xd->node->next_in_ino; in jffs2_scan_xattr_node()
366 xd->node->next_in_ino = raw; in jffs2_scan_xattr_node()
368 xd->version = version; in jffs2_scan_xattr_node()
369 xd->xprefix = rx->xprefix; in jffs2_scan_xattr_node()
370 xd->name_len = rx->name_len; in jffs2_scan_xattr_node()
371 xd->value_len = je16_to_cpu(rx->value_len); in jffs2_scan_xattr_node()
372 xd->data_crc = je32_to_cpu(rx->data_crc); in jffs2_scan_xattr_node()
378 jffs2_sum_add_xattr_mem(s, rx, ofs - jeb->offset); in jffs2_scan_xattr_node()
379 dbg_xattr("scanning xdatum at %#08x (xid=%u, version=%u)\n", in jffs2_scan_xattr_node()
380 ofs, xd->xid, xd->version); in jffs2_scan_xattr_node()
392 crc = crc32(0, rr, sizeof(*rr) - 4); in jffs2_scan_xref_node()
393 if (crc != je32_to_cpu(rr->node_crc)) { in jffs2_scan_xref_node()
394 JFFS2_WARNING("node CRC failed at %#08x, read=%#08x, calc=%#08x\n", in jffs2_scan_xref_node()
395 ofs, je32_to_cpu(rr->node_crc), crc); in jffs2_scan_xref_node()
396 if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(rr->totlen))))) in jffs2_scan_xref_node()
401 if (PAD(sizeof(struct jffs2_raw_xref)) != je32_to_cpu(rr->totlen)) { in jffs2_scan_xref_node()
402 JFFS2_WARNING("node length mismatch at %#08x, read=%u, calc=%zd\n", in jffs2_scan_xref_node()
403 ofs, je32_to_cpu(rr->totlen), in jffs2_scan_xref_node()
405 if ((err = jffs2_scan_dirty_space(c, jeb, je32_to_cpu(rr->totlen)))) in jffs2_scan_xref_node()
412 return -ENOMEM; in jffs2_scan_xref_node()
416 * ref->xid is used to store 32bit xid, xd is not used in jffs2_scan_xref_node()
417 * ref->ino is used to store 32bit inode-number, ic is not used in jffs2_scan_xref_node()
419 * are exclusive. In a similar way, ref->next is temporarily in jffs2_scan_xref_node()
420 * used to chain all xattr_ref object. It's re-chained to in jffs2_scan_xref_node()
423 ref->ino = je32_to_cpu(rr->ino); in jffs2_scan_xref_node()
424 ref->xid = je32_to_cpu(rr->xid); in jffs2_scan_xref_node()
425 ref->xseqno = je32_to_cpu(rr->xseqno); in jffs2_scan_xref_node()
426 if (ref->xseqno > c->highest_xseqno) in jffs2_scan_xref_node()
427 c->highest_xseqno = (ref->xseqno & ~XREF_DELETE_MARKER); in jffs2_scan_xref_node()
428 ref->next = c->xref_temp; in jffs2_scan_xref_node()
429 c->xref_temp = ref; in jffs2_scan_xref_node()
431 jffs2_link_node_ref(c, jeb, ofs | REF_PRISTINE, PAD(je32_to_cpu(rr->totlen)), (void *)ref); in jffs2_scan_xref_node()
434 jffs2_sum_add_xref_mem(s, rr, ofs - jeb->offset); in jffs2_scan_xref_node()
435 dbg_xattr("scan xref at %#08x (xid=%u, ino=%u)\n", in jffs2_scan_xref_node()
436 ofs, ref->xid, ref->ino); in jffs2_scan_xref_node()
442 the flash, XIP-style */
457 ofs = jeb->offset; in jffs2_scan_eraseblock()
458 prevofs = jeb->offset - 1; in jffs2_scan_eraseblock()
460 jffs2_dbg(1, "%s(): Scanning block at 0x%x\n", __func__, ofs); in jffs2_scan_eraseblock()
466 if (mtd_block_isbad(c->mtd, jeb->offset)) in jffs2_scan_eraseblock()
490 sm = (void *)buf + c->sector_size - sizeof(*sm); in jffs2_scan_eraseblock()
491 if (je32_to_cpu(sm->magic) == JFFS2_SUM_MAGIC) { in jffs2_scan_eraseblock()
492 sumptr = buf + je32_to_cpu(sm->offset); in jffs2_scan_eraseblock()
493 sumlen = c->sector_size - je32_to_cpu(sm->offset); in jffs2_scan_eraseblock()
497 if (c->wbuf_pagesize) in jffs2_scan_eraseblock()
498 buf_len = c->wbuf_pagesize; in jffs2_scan_eraseblock()
503 err = jffs2_fill_scan_buf(c, buf + buf_size - buf_len, in jffs2_scan_eraseblock()
504 jeb->offset + c->sector_size - buf_len, in jffs2_scan_eraseblock()
509 sm = (void *)buf + buf_size - sizeof(*sm); in jffs2_scan_eraseblock()
510 if (je32_to_cpu(sm->magic) == JFFS2_SUM_MAGIC) { in jffs2_scan_eraseblock()
511 sumlen = c->sector_size - je32_to_cpu(sm->offset); in jffs2_scan_eraseblock()
512 sumptr = buf + buf_size - sumlen; in jffs2_scan_eraseblock()
514 /* sm->offset maybe wrong but MAGIC maybe right */ in jffs2_scan_eraseblock()
515 if (sumlen > c->sector_size) in jffs2_scan_eraseblock()
523 return -ENOMEM; in jffs2_scan_eraseblock()
524 memcpy(sumptr + sumlen - buf_len, buf + buf_size - buf_len, buf_len); in jffs2_scan_eraseblock()
529 jeb->offset + c->sector_size - sumlen, in jffs2_scan_eraseblock()
530 sumlen - buf_len); in jffs2_scan_eraseblock()
556 buf_ofs = jeb->offset; in jffs2_scan_eraseblock()
559 /* This is the XIP case -- we're reading _directly_ from the flash chip */ in jffs2_scan_eraseblock()
560 buf_len = c->sector_size; in jffs2_scan_eraseblock()
562 buf_len = EMPTY_SCAN_SIZE(c->sector_size); in jffs2_scan_eraseblock()
570 max_ofs = EMPTY_SCAN_SIZE(c->sector_size); in jffs2_scan_eraseblock()
589 jffs2_dbg(1, "Block at 0x%08x is empty (erased)\n", in jffs2_scan_eraseblock()
590 jeb->offset); in jffs2_scan_eraseblock()
591 if (c->cleanmarker_size == 0) in jffs2_scan_eraseblock()
592 return BLK_STATE_CLEANMARKER; /* don't bother with re-erase */ in jffs2_scan_eraseblock()
597 jffs2_dbg(1, "Free space at %08x ends at %08x\n", jeb->offset, in jffs2_scan_eraseblock()
598 jeb->offset + ofs); in jffs2_scan_eraseblock()
605 /* Now ofs is a complete physical flash offset as it always was... */ in jffs2_scan_eraseblock()
606 ofs += jeb->offset; in jffs2_scan_eraseblock()
610 dbg_summary("no summary found in jeb 0x%08x. Apply original scan.\n",jeb->offset); in jffs2_scan_eraseblock()
613 while(ofs < jeb->offset + c->sector_size) { in jffs2_scan_eraseblock()
625 pr_warn("Eep. ofs 0x%08x not word-aligned!\n", ofs); in jffs2_scan_eraseblock()
630 pr_warn("ofs 0x%08x has already been seen. Skipping\n", in jffs2_scan_eraseblock()
639 if (jeb->offset + c->sector_size < ofs + sizeof(*node)) { in jffs2_scan_eraseblock()
640 jffs2_dbg(1, "Fewer than %zd bytes left to end of block. (%x+%x<%x+%zx) Not reading\n", in jffs2_scan_eraseblock()
642 jeb->offset, c->sector_size, ofs, in jffs2_scan_eraseblock()
644 if ((err = jffs2_scan_dirty_space(c, jeb, (jeb->offset + c->sector_size)-ofs))) in jffs2_scan_eraseblock()
650 buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs); in jffs2_scan_eraseblock()
651 jffs2_dbg(1, "Fewer than %zd bytes (node header) left to end of buf. Reading 0x%x at 0x%08x\n", in jffs2_scan_eraseblock()
660 node = (struct jffs2_unknown_node *)&buf[ofs-buf_ofs]; in jffs2_scan_eraseblock()
662 if (*(uint32_t *)(&buf[ofs-buf_ofs]) == 0xffffffff) { in jffs2_scan_eraseblock()
668 scan_end = min_t(uint32_t, EMPTY_SCAN_SIZE(c->sector_size)/8, buf_len); in jffs2_scan_eraseblock()
670 jffs2_dbg(1, "Found empty flash at 0x%08x\n", ofs); in jffs2_scan_eraseblock()
672 inbuf_ofs = ofs - buf_ofs; in jffs2_scan_eraseblock()
675 pr_warn("Empty flash at 0x%08x ends at 0x%08x\n", in jffs2_scan_eraseblock()
677 if ((err = jffs2_scan_dirty_space(c, jeb, ofs-empty_start))) in jffs2_scan_eraseblock()
686 jffs2_dbg(1, "Empty flash to end of buffer at 0x%08x\n", in jffs2_scan_eraseblock()
691 if (buf_ofs == jeb->offset && jeb->used_size == PAD(c->cleanmarker_size) && in jffs2_scan_eraseblock()
692 c->cleanmarker_size && !jeb->dirty_size && !ref_next(jeb->first_node)) { in jffs2_scan_eraseblock()
694 EMPTY_SCAN_SIZE(c->sector_size)); in jffs2_scan_eraseblock()
703 buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs); in jffs2_scan_eraseblock()
707 jffs2_dbg(1, "Empty flash at %08x runs to end of block. Treating as free_space\n", in jffs2_scan_eraseblock()
713 jffs2_dbg(1, "Reading another 0x%x at 0x%08x\n", in jffs2_scan_eraseblock()
722 if (ofs == jeb->offset && je16_to_cpu(node->magic) == KSAMTIB_CIGAM_2SFFJ) { in jffs2_scan_eraseblock()
723 pr_warn("Magic bitmask is backwards at offset 0x%08x. Wrong endian filesystem?\n", in jffs2_scan_eraseblock()
730 if (je16_to_cpu(node->magic) == JFFS2_DIRTY_BITMASK) { in jffs2_scan_eraseblock()
731 jffs2_dbg(1, "Dirty bitmask at 0x%08x\n", ofs); in jffs2_scan_eraseblock()
737 if (je16_to_cpu(node->magic) == JFFS2_OLD_MAGIC_BITMASK) { in jffs2_scan_eraseblock()
738 pr_warn("Old JFFS2 bitmask found at 0x%08x\n", ofs); in jffs2_scan_eraseblock()
745 if (je16_to_cpu(node->magic) != JFFS2_MAGIC_BITMASK) { in jffs2_scan_eraseblock()
747 noisy_printk(&noise, "%s(): Magic bitmask 0x%04x not found at 0x%08x: 0x%04x instead\n", in jffs2_scan_eraseblock()
750 je16_to_cpu(node->magic)); in jffs2_scan_eraseblock()
757 crcnode.magic = node->magic; in jffs2_scan_eraseblock()
758 crcnode.nodetype = cpu_to_je16( je16_to_cpu(node->nodetype) | JFFS2_NODE_ACCURATE); in jffs2_scan_eraseblock()
759 crcnode.totlen = node->totlen; in jffs2_scan_eraseblock()
760 hdr_crc = crc32(0, &crcnode, sizeof(crcnode)-4); in jffs2_scan_eraseblock()
762 if (hdr_crc != je32_to_cpu(node->hdr_crc)) { in jffs2_scan_eraseblock()
763 …noisy_printk(&noise, "%s(): Node at 0x%08x {0x%04x, 0x%04x, 0x%08x) has invalid CRC 0x%08x (calcul… in jffs2_scan_eraseblock()
765 ofs, je16_to_cpu(node->magic), in jffs2_scan_eraseblock()
766 je16_to_cpu(node->nodetype), in jffs2_scan_eraseblock()
767 je32_to_cpu(node->totlen), in jffs2_scan_eraseblock()
768 je32_to_cpu(node->hdr_crc), in jffs2_scan_eraseblock()
776 if (ofs + je32_to_cpu(node->totlen) > jeb->offset + c->sector_size) { in jffs2_scan_eraseblock()
778 pr_warn("Node at 0x%08x with length 0x%08x would run over the end of the erase block\n", in jffs2_scan_eraseblock()
779 ofs, je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
787 if (!(je16_to_cpu(node->nodetype) & JFFS2_NODE_ACCURATE)) { in jffs2_scan_eraseblock()
789 jffs2_dbg(2, "Node at 0x%08x is obsolete. Skipping\n", in jffs2_scan_eraseblock()
791 if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(node->totlen))))) in jffs2_scan_eraseblock()
793 ofs += PAD(je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
797 switch(je16_to_cpu(node->nodetype)) { in jffs2_scan_eraseblock()
800 buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs); in jffs2_scan_eraseblock()
801 jffs2_dbg(1, "Fewer than %zd bytes (inode node) left to end of buf. Reading 0x%x at 0x%08x\n", in jffs2_scan_eraseblock()
812 ofs += PAD(je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
816 if (buf_ofs + buf_len < ofs + je32_to_cpu(node->totlen)) { in jffs2_scan_eraseblock()
817 buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs); in jffs2_scan_eraseblock()
818 jffs2_dbg(1, "Fewer than %d bytes (dirent node) left to end of buf. Reading 0x%x at 0x%08x\n", in jffs2_scan_eraseblock()
819 je32_to_cpu(node->totlen), buf_len, in jffs2_scan_eraseblock()
829 ofs += PAD(je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
834 if (buf_ofs + buf_len < ofs + je32_to_cpu(node->totlen)) { in jffs2_scan_eraseblock()
835 buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs); in jffs2_scan_eraseblock()
836 jffs2_dbg(1, "Fewer than %d bytes (xattr node) left to end of buf. Reading 0x%x at 0x%08x\n", in jffs2_scan_eraseblock()
837 je32_to_cpu(node->totlen), buf_len, in jffs2_scan_eraseblock()
848 ofs += PAD(je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
851 if (buf_ofs + buf_len < ofs + je32_to_cpu(node->totlen)) { in jffs2_scan_eraseblock()
852 buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs); in jffs2_scan_eraseblock()
853 jffs2_dbg(1, "Fewer than %d bytes (xref node) left to end of buf. Reading 0x%x at 0x%08x\n", in jffs2_scan_eraseblock()
854 je32_to_cpu(node->totlen), buf_len, in jffs2_scan_eraseblock()
865 ofs += PAD(je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
870 jffs2_dbg(1, "CLEANMARKER node found at 0x%08x\n", ofs); in jffs2_scan_eraseblock()
871 if (je32_to_cpu(node->totlen) != c->cleanmarker_size) { in jffs2_scan_eraseblock()
872 pr_notice("CLEANMARKER node found at 0x%08x has totlen 0x%x != normal 0x%x\n", in jffs2_scan_eraseblock()
873 ofs, je32_to_cpu(node->totlen), in jffs2_scan_eraseblock()
874 c->cleanmarker_size); in jffs2_scan_eraseblock()
878 } else if (jeb->first_node) { in jffs2_scan_eraseblock()
879 pr_notice("CLEANMARKER node found at 0x%08x, not first node in block (0x%08x)\n", in jffs2_scan_eraseblock()
880 ofs, jeb->offset); in jffs2_scan_eraseblock()
885 jffs2_link_node_ref(c, jeb, ofs | REF_NORMAL, c->cleanmarker_size, NULL); in jffs2_scan_eraseblock()
887 ofs += PAD(c->cleanmarker_size); in jffs2_scan_eraseblock()
893 jffs2_sum_add_padding_mem(s, je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
894 if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(node->totlen))))) in jffs2_scan_eraseblock()
896 ofs += PAD(je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
900 switch (je16_to_cpu(node->nodetype) & JFFS2_COMPAT_MASK) { in jffs2_scan_eraseblock()
902 pr_notice("Read-only compatible feature node (0x%04x) found at offset 0x%08x\n", in jffs2_scan_eraseblock()
903 je16_to_cpu(node->nodetype), ofs); in jffs2_scan_eraseblock()
904 c->flags |= JFFS2_SB_FLAG_RO; in jffs2_scan_eraseblock()
906 return -EROFS; in jffs2_scan_eraseblock()
907 if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(node->totlen))))) in jffs2_scan_eraseblock()
909 ofs += PAD(je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
913 pr_notice("Incompatible feature node (0x%04x) found at offset 0x%08x\n", in jffs2_scan_eraseblock()
914 je16_to_cpu(node->nodetype), ofs); in jffs2_scan_eraseblock()
915 return -EINVAL; in jffs2_scan_eraseblock()
918 jffs2_dbg(1, "Unknown but compatible feature node (0x%04x) found at offset 0x%08x\n", in jffs2_scan_eraseblock()
919 je16_to_cpu(node->nodetype), ofs); in jffs2_scan_eraseblock()
920 if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(node->totlen))))) in jffs2_scan_eraseblock()
922 ofs += PAD(je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
926 jffs2_dbg(1, "Unknown but compatible feature node (0x%04x) found at offset 0x%08x\n", in jffs2_scan_eraseblock()
927 je16_to_cpu(node->nodetype), ofs); in jffs2_scan_eraseblock()
929 jffs2_link_node_ref(c, jeb, ofs | REF_PRISTINE, PAD(je32_to_cpu(node->totlen)), NULL); in jffs2_scan_eraseblock()
933 ofs += PAD(je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
941 if (PAD(s->sum_size + JFFS2_SUMMARY_FRAME_SIZE) > jeb->free_size) { in jffs2_scan_eraseblock()
948 …jffs2_dbg(1, "Block at 0x%08x: free 0x%08x, dirty 0x%08x, unchecked 0x%08x, used 0x%08x, wasted 0x… in jffs2_scan_eraseblock()
949 jeb->offset, jeb->free_size, jeb->dirty_size, in jffs2_scan_eraseblock()
950 jeb->unchecked_size, jeb->used_size, jeb->wasted_size); in jffs2_scan_eraseblock()
953 if (jeb->wasted_size) { in jffs2_scan_eraseblock()
954 jeb->dirty_size += jeb->wasted_size; in jffs2_scan_eraseblock()
955 c->dirty_size += jeb->wasted_size; in jffs2_scan_eraseblock()
956 c->wasted_size -= jeb->wasted_size; in jffs2_scan_eraseblock()
957 jeb->wasted_size = 0; in jffs2_scan_eraseblock()
971 if (ino > c->highest_ino) in jffs2_scan_make_ino_cache()
972 c->highest_ino = ino; in jffs2_scan_make_ino_cache()
981 ic->ino = ino; in jffs2_scan_make_ino_cache()
982 ic->nodes = (void *)ic; in jffs2_scan_make_ino_cache()
985 ic->pino_nlink = 1; in jffs2_scan_make_ino_cache()
993 uint32_t crc, ino = je32_to_cpu(ri->ino); in jffs2_scan_inode_node()
995 jffs2_dbg(1, "%s(): Node at 0x%08x\n", __func__, ofs); in jffs2_scan_inode_node()
998 this node; we can do all the CRC checking etc. later. There's a tradeoff here -- in jffs2_scan_inode_node()
1000 memory, then building all our in-core data structures and freeing the extra in jffs2_scan_inode_node()
1007 crc = crc32(0, ri, sizeof(*ri)-8); in jffs2_scan_inode_node()
1008 if (crc != je32_to_cpu(ri->node_crc)) { in jffs2_scan_inode_node()
1009 pr_notice("%s(): CRC failed on node at 0x%08x: Read 0x%08x, calculated 0x%08x\n", in jffs2_scan_inode_node()
1010 __func__, ofs, je32_to_cpu(ri->node_crc), crc); in jffs2_scan_inode_node()
1016 PAD(je32_to_cpu(ri->totlen))); in jffs2_scan_inode_node()
1023 return -ENOMEM; in jffs2_scan_inode_node()
1027 jffs2_link_node_ref(c, jeb, ofs | REF_UNCHECKED, PAD(je32_to_cpu(ri->totlen)), ic); in jffs2_scan_inode_node()
1029 jffs2_dbg(1, "Node is ino #%u, version %d. Range 0x%x-0x%x\n", in jffs2_scan_inode_node()
1030 je32_to_cpu(ri->ino), je32_to_cpu(ri->version), in jffs2_scan_inode_node()
1031 je32_to_cpu(ri->offset), in jffs2_scan_inode_node()
1032 je32_to_cpu(ri->offset)+je32_to_cpu(ri->dsize)); in jffs2_scan_inode_node()
1034 pseudo_random += je32_to_cpu(ri->version); in jffs2_scan_inode_node()
1037 jffs2_sum_add_inode_mem(s, ri, ofs - jeb->offset); in jffs2_scan_inode_node()
1052 jffs2_dbg(1, "%s(): Node at 0x%08x\n", __func__, ofs); in jffs2_scan_dirent_node()
1056 crc = crc32(0, rd, sizeof(*rd)-8); in jffs2_scan_dirent_node()
1058 if (crc != je32_to_cpu(rd->node_crc)) { in jffs2_scan_dirent_node()
1059 pr_notice("%s(): Node CRC failed on node at 0x%08x: Read 0x%08x, calculated 0x%08x\n", in jffs2_scan_dirent_node()
1060 __func__, ofs, je32_to_cpu(rd->node_crc), crc); in jffs2_scan_dirent_node()
1062 if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(rd->totlen))))) in jffs2_scan_dirent_node()
1067 pseudo_random += je32_to_cpu(rd->version); in jffs2_scan_dirent_node()
1070 checkedlen = strnlen(rd->name, rd->nsize); in jffs2_scan_dirent_node()
1071 if (checkedlen < rd->nsize) { in jffs2_scan_dirent_node()
1072 pr_err("Dirent at %08x has zeroes in name. Truncating to %d chars\n", in jffs2_scan_dirent_node()
1077 return -ENOMEM; in jffs2_scan_dirent_node()
1079 memcpy(&fd->name, rd->name, checkedlen); in jffs2_scan_dirent_node()
1080 fd->name[checkedlen] = 0; in jffs2_scan_dirent_node()
1082 crc = crc32(0, fd->name, rd->nsize); in jffs2_scan_dirent_node()
1083 if (crc != je32_to_cpu(rd->name_crc)) { in jffs2_scan_dirent_node()
1084 pr_notice("%s(): Name CRC failed on node at 0x%08x: Read 0x%08x, calculated 0x%08x\n", in jffs2_scan_dirent_node()
1085 __func__, ofs, je32_to_cpu(rd->name_crc), crc); in jffs2_scan_dirent_node()
1087 fd->name, je32_to_cpu(rd->ino)); in jffs2_scan_dirent_node()
1091 if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(rd->totlen))))) in jffs2_scan_dirent_node()
1095 ic = jffs2_scan_make_ino_cache(c, je32_to_cpu(rd->pino)); in jffs2_scan_dirent_node()
1098 return -ENOMEM; in jffs2_scan_dirent_node()
1101 fd->raw = jffs2_link_node_ref(c, jeb, ofs | dirent_node_state(rd), in jffs2_scan_dirent_node()
1102 PAD(je32_to_cpu(rd->totlen)), ic); in jffs2_scan_dirent_node()
1104 fd->next = NULL; in jffs2_scan_dirent_node()
1105 fd->version = je32_to_cpu(rd->version); in jffs2_scan_dirent_node()
1106 fd->ino = je32_to_cpu(rd->ino); in jffs2_scan_dirent_node()
1107 fd->nhash = full_name_hash(NULL, fd->name, checkedlen); in jffs2_scan_dirent_node()
1108 fd->type = rd->type; in jffs2_scan_dirent_node()
1109 jffs2_add_fd_to_list(c, fd, &ic->scan_dents); in jffs2_scan_dirent_node()
1112 jffs2_sum_add_dirent_mem(s, rd, ofs - jeb->offset); in jffs2_scan_dirent_node()
1133 struct list_head *n = head->next; in rotate_list()
1136 while(count--) { in rotate_list()
1137 n = n->next; in rotate_list()
1144 uint32_t x; in jffs2_rotate_lists() local
1147 x = count_list(&c->clean_list); in jffs2_rotate_lists()
1148 if (x) { in jffs2_rotate_lists()
1149 rotateby = pseudo_random % x; in jffs2_rotate_lists()
1150 rotate_list((&c->clean_list), rotateby); in jffs2_rotate_lists()
1153 x = count_list(&c->very_dirty_list); in jffs2_rotate_lists()
1154 if (x) { in jffs2_rotate_lists()
1155 rotateby = pseudo_random % x; in jffs2_rotate_lists()
1156 rotate_list((&c->very_dirty_list), rotateby); in jffs2_rotate_lists()
1159 x = count_list(&c->dirty_list); in jffs2_rotate_lists()
1160 if (x) { in jffs2_rotate_lists()
1161 rotateby = pseudo_random % x; in jffs2_rotate_lists()
1162 rotate_list((&c->dirty_list), rotateby); in jffs2_rotate_lists()
1165 x = count_list(&c->erasable_list); in jffs2_rotate_lists()
1166 if (x) { in jffs2_rotate_lists()
1167 rotateby = pseudo_random % x; in jffs2_rotate_lists()
1168 rotate_list((&c->erasable_list), rotateby); in jffs2_rotate_lists()
1171 if (c->nr_erasing_blocks) { in jffs2_rotate_lists()
1172 rotateby = pseudo_random % c->nr_erasing_blocks; in jffs2_rotate_lists()
1173 rotate_list((&c->erase_pending_list), rotateby); in jffs2_rotate_lists()
1176 if (c->nr_free_blocks) { in jffs2_rotate_lists()
1177 rotateby = pseudo_random % c->nr_free_blocks; in jffs2_rotate_lists()
1178 rotate_list((&c->free_list), rotateby); in jffs2_rotate_lists()