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()
285 mtd_unpoint(c->mtd, 0, c->mtd->size); in jffs2_scan_medium()
298 jffs2_dbg(1, "mtd->read(0x%x bytes from 0x%x) returned %d\n", in jffs2_fill_scan_buf()
303 jffs2_dbg(1, "Read at 0x%x gave only 0x%zx bytes\n", in jffs2_fill_scan_buf()
305 return -EIO; in jffs2_fill_scan_buf()
312 if ((jeb->used_size + jeb->unchecked_size) == PAD(c->cleanmarker_size) && !jeb->dirty_size in jffs2_scan_classify_jeb()
313 && (!jeb->first_node || !ref_next(jeb->first_node)) ) in jffs2_scan_classify_jeb()
317 else if (!ISDIRTY(c->sector_size - (jeb->used_size + jeb->unchecked_size))) { in jffs2_scan_classify_jeb()
318 c->dirty_size -= jeb->dirty_size; in jffs2_scan_classify_jeb()
319 c->wasted_size += jeb->dirty_size; in jffs2_scan_classify_jeb()
320 jeb->wasted_size += jeb->dirty_size; in jffs2_scan_classify_jeb()
321 jeb->dirty_size = 0; in jffs2_scan_classify_jeb()
323 } else if (jeb->used_size || jeb->unchecked_size) in jffs2_scan_classify_jeb()
338 crc = crc32(0, rx, sizeof(struct jffs2_raw_xattr) - 4); in jffs2_scan_xattr_node()
339 if (crc != je32_to_cpu(rx->node_crc)) { in jffs2_scan_xattr_node()
340 JFFS2_WARNING("node CRC failed at %#08x, read=%#08x, calc=%#08x\n", in jffs2_scan_xattr_node()
341 ofs, je32_to_cpu(rx->node_crc), crc); in jffs2_scan_xattr_node()
342 if ((err = jffs2_scan_dirty_space(c, jeb, je32_to_cpu(rx->totlen)))) in jffs2_scan_xattr_node()
347 xid = je32_to_cpu(rx->xid); in jffs2_scan_xattr_node()
348 version = je32_to_cpu(rx->version); in jffs2_scan_xattr_node()
351 + rx->name_len + 1 + je16_to_cpu(rx->value_len)); in jffs2_scan_xattr_node()
352 if (totlen != je32_to_cpu(rx->totlen)) { in jffs2_scan_xattr_node()
353 JFFS2_WARNING("node length mismatch at %#08x, read=%u, calc=%u\n", in jffs2_scan_xattr_node()
354 ofs, je32_to_cpu(rx->totlen), totlen); in jffs2_scan_xattr_node()
355 if ((err = jffs2_scan_dirty_space(c, jeb, je32_to_cpu(rx->totlen)))) in jffs2_scan_xattr_node()
364 if (xd->version > version) { in jffs2_scan_xattr_node()
367 raw->next_in_ino = xd->node->next_in_ino; in jffs2_scan_xattr_node()
368 xd->node->next_in_ino = raw; in jffs2_scan_xattr_node()
370 xd->version = version; in jffs2_scan_xattr_node()
371 xd->xprefix = rx->xprefix; in jffs2_scan_xattr_node()
372 xd->name_len = rx->name_len; in jffs2_scan_xattr_node()
373 xd->value_len = je16_to_cpu(rx->value_len); in jffs2_scan_xattr_node()
374 xd->data_crc = je32_to_cpu(rx->data_crc); in jffs2_scan_xattr_node()
380 jffs2_sum_add_xattr_mem(s, rx, ofs - jeb->offset); in jffs2_scan_xattr_node()
381 dbg_xattr("scanning xdatum at %#08x (xid=%u, version=%u)\n", in jffs2_scan_xattr_node()
382 ofs, xd->xid, xd->version); in jffs2_scan_xattr_node()
394 crc = crc32(0, rr, sizeof(*rr) - 4); in jffs2_scan_xref_node()
395 if (crc != je32_to_cpu(rr->node_crc)) { in jffs2_scan_xref_node()
396 JFFS2_WARNING("node CRC failed at %#08x, read=%#08x, calc=%#08x\n", in jffs2_scan_xref_node()
397 ofs, je32_to_cpu(rr->node_crc), crc); in jffs2_scan_xref_node()
398 if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(rr->totlen))))) in jffs2_scan_xref_node()
403 if (PAD(sizeof(struct jffs2_raw_xref)) != je32_to_cpu(rr->totlen)) { in jffs2_scan_xref_node()
404 JFFS2_WARNING("node length mismatch at %#08x, read=%u, calc=%zd\n", in jffs2_scan_xref_node()
405 ofs, je32_to_cpu(rr->totlen), in jffs2_scan_xref_node()
407 if ((err = jffs2_scan_dirty_space(c, jeb, je32_to_cpu(rr->totlen)))) in jffs2_scan_xref_node()
414 return -ENOMEM; in jffs2_scan_xref_node()
418 * ref->xid is used to store 32bit xid, xd is not used in jffs2_scan_xref_node()
419 * ref->ino is used to store 32bit inode-number, ic is not used in jffs2_scan_xref_node()
421 * are exclusive. In a similar way, ref->next is temporarily in jffs2_scan_xref_node()
422 * used to chain all xattr_ref object. It's re-chained to in jffs2_scan_xref_node()
425 ref->ino = je32_to_cpu(rr->ino); in jffs2_scan_xref_node()
426 ref->xid = je32_to_cpu(rr->xid); in jffs2_scan_xref_node()
427 ref->xseqno = je32_to_cpu(rr->xseqno); in jffs2_scan_xref_node()
428 if (ref->xseqno > c->highest_xseqno) in jffs2_scan_xref_node()
429 c->highest_xseqno = (ref->xseqno & ~XREF_DELETE_MARKER); in jffs2_scan_xref_node()
430 ref->next = c->xref_temp; in jffs2_scan_xref_node()
431 c->xref_temp = ref; in jffs2_scan_xref_node()
433 jffs2_link_node_ref(c, jeb, ofs | REF_PRISTINE, PAD(je32_to_cpu(rr->totlen)), (void *)ref); in jffs2_scan_xref_node()
436 jffs2_sum_add_xref_mem(s, rr, ofs - jeb->offset); in jffs2_scan_xref_node()
437 dbg_xattr("scan xref at %#08x (xid=%u, ino=%u)\n", in jffs2_scan_xref_node()
438 ofs, ref->xid, ref->ino); in jffs2_scan_xref_node()
444 the flash, XIP-style */
459 ofs = jeb->offset; in jffs2_scan_eraseblock()
460 prevofs = jeb->offset - 1; in jffs2_scan_eraseblock()
462 jffs2_dbg(1, "%s(): Scanning block at 0x%x\n", __func__, ofs); in jffs2_scan_eraseblock()
468 if (mtd_block_isbad(c->mtd, jeb->offset)) in jffs2_scan_eraseblock()
492 sm = (void *)buf + c->sector_size - sizeof(*sm); in jffs2_scan_eraseblock()
493 if (je32_to_cpu(sm->magic) == JFFS2_SUM_MAGIC) { in jffs2_scan_eraseblock()
494 sumptr = buf + je32_to_cpu(sm->offset); in jffs2_scan_eraseblock()
495 sumlen = c->sector_size - je32_to_cpu(sm->offset); in jffs2_scan_eraseblock()
499 if (c->wbuf_pagesize) in jffs2_scan_eraseblock()
500 buf_len = c->wbuf_pagesize; in jffs2_scan_eraseblock()
505 err = jffs2_fill_scan_buf(c, buf + buf_size - buf_len, in jffs2_scan_eraseblock()
506 jeb->offset + c->sector_size - buf_len, in jffs2_scan_eraseblock()
511 sm = (void *)buf + buf_size - sizeof(*sm); in jffs2_scan_eraseblock()
512 if (je32_to_cpu(sm->magic) == JFFS2_SUM_MAGIC) { in jffs2_scan_eraseblock()
513 sumlen = c->sector_size - je32_to_cpu(sm->offset); in jffs2_scan_eraseblock()
514 sumptr = buf + buf_size - sumlen; in jffs2_scan_eraseblock()
516 /* sm->offset maybe wrong but MAGIC maybe right */ in jffs2_scan_eraseblock()
517 if (sumlen > c->sector_size) in jffs2_scan_eraseblock()
525 return -ENOMEM; in jffs2_scan_eraseblock()
526 memcpy(sumptr + sumlen - buf_len, buf + buf_size - buf_len, buf_len); in jffs2_scan_eraseblock()
531 jeb->offset + c->sector_size - sumlen, in jffs2_scan_eraseblock()
532 sumlen - buf_len); in jffs2_scan_eraseblock()
558 buf_ofs = jeb->offset; in jffs2_scan_eraseblock()
561 /* This is the XIP case -- we're reading _directly_ from the flash chip */ in jffs2_scan_eraseblock()
562 buf_len = c->sector_size; in jffs2_scan_eraseblock()
564 buf_len = EMPTY_SCAN_SIZE(c->sector_size); in jffs2_scan_eraseblock()
572 max_ofs = EMPTY_SCAN_SIZE(c->sector_size); in jffs2_scan_eraseblock()
591 jffs2_dbg(1, "Block at 0x%08x is empty (erased)\n", in jffs2_scan_eraseblock()
592 jeb->offset); in jffs2_scan_eraseblock()
593 if (c->cleanmarker_size == 0) in jffs2_scan_eraseblock()
594 return BLK_STATE_CLEANMARKER; /* don't bother with re-erase */ in jffs2_scan_eraseblock()
599 jffs2_dbg(1, "Free space at %08x ends at %08x\n", jeb->offset, in jffs2_scan_eraseblock()
600 jeb->offset + ofs); in jffs2_scan_eraseblock()
607 /* Now ofs is a complete physical flash offset as it always was... */ in jffs2_scan_eraseblock()
608 ofs += jeb->offset; in jffs2_scan_eraseblock()
612 dbg_summary("no summary found in jeb 0x%08x. Apply original scan.\n",jeb->offset); in jffs2_scan_eraseblock()
615 while(ofs < jeb->offset + c->sector_size) { in jffs2_scan_eraseblock()
627 pr_warn("Eep. ofs 0x%08x not word-aligned!\n", ofs); in jffs2_scan_eraseblock()
632 pr_warn("ofs 0x%08x has already been seen. Skipping\n", in jffs2_scan_eraseblock()
641 if (jeb->offset + c->sector_size < ofs + sizeof(*node)) { in jffs2_scan_eraseblock()
642 jffs2_dbg(1, "Fewer than %zd bytes left to end of block. (%x+%x<%x+%zx) Not reading\n", in jffs2_scan_eraseblock()
644 jeb->offset, c->sector_size, ofs, in jffs2_scan_eraseblock()
646 if ((err = jffs2_scan_dirty_space(c, jeb, (jeb->offset + c->sector_size)-ofs))) in jffs2_scan_eraseblock()
652 buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs); in jffs2_scan_eraseblock()
653 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()
662 node = (struct jffs2_unknown_node *)&buf[ofs-buf_ofs]; in jffs2_scan_eraseblock()
664 if (*(uint32_t *)(&buf[ofs-buf_ofs]) == 0xffffffff) { in jffs2_scan_eraseblock()
670 scan_end = min_t(uint32_t, EMPTY_SCAN_SIZE(c->sector_size)/8, buf_len); in jffs2_scan_eraseblock()
672 jffs2_dbg(1, "Found empty flash at 0x%08x\n", ofs); in jffs2_scan_eraseblock()
674 inbuf_ofs = ofs - buf_ofs; in jffs2_scan_eraseblock()
677 pr_warn("Empty flash at 0x%08x ends at 0x%08x\n", in jffs2_scan_eraseblock()
679 if ((err = jffs2_scan_dirty_space(c, jeb, ofs-empty_start))) in jffs2_scan_eraseblock()
688 jffs2_dbg(1, "Empty flash to end of buffer at 0x%08x\n", in jffs2_scan_eraseblock()
693 if (buf_ofs == jeb->offset && jeb->used_size == PAD(c->cleanmarker_size) && in jffs2_scan_eraseblock()
694 c->cleanmarker_size && !jeb->dirty_size && !ref_next(jeb->first_node)) { in jffs2_scan_eraseblock()
696 EMPTY_SCAN_SIZE(c->sector_size)); in jffs2_scan_eraseblock()
705 buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs); in jffs2_scan_eraseblock()
709 jffs2_dbg(1, "Empty flash at %08x runs to end of block. Treating as free_space\n", in jffs2_scan_eraseblock()
715 jffs2_dbg(1, "Reading another 0x%x at 0x%08x\n", in jffs2_scan_eraseblock()
724 if (ofs == jeb->offset && je16_to_cpu(node->magic) == KSAMTIB_CIGAM_2SFFJ) { in jffs2_scan_eraseblock()
725 pr_warn("Magic bitmask is backwards at offset 0x%08x. Wrong endian filesystem?\n", in jffs2_scan_eraseblock()
732 if (je16_to_cpu(node->magic) == JFFS2_DIRTY_BITMASK) { in jffs2_scan_eraseblock()
733 jffs2_dbg(1, "Dirty bitmask at 0x%08x\n", ofs); in jffs2_scan_eraseblock()
739 if (je16_to_cpu(node->magic) == JFFS2_OLD_MAGIC_BITMASK) { in jffs2_scan_eraseblock()
740 pr_warn("Old JFFS2 bitmask found at 0x%08x\n", ofs); in jffs2_scan_eraseblock()
747 if (je16_to_cpu(node->magic) != JFFS2_MAGIC_BITMASK) { in jffs2_scan_eraseblock()
749 noisy_printk(&noise, "%s(): Magic bitmask 0x%04x not found at 0x%08x: 0x%04x instead\n", in jffs2_scan_eraseblock()
752 je16_to_cpu(node->magic)); in jffs2_scan_eraseblock()
759 crcnode.magic = node->magic; in jffs2_scan_eraseblock()
760 crcnode.nodetype = cpu_to_je16( je16_to_cpu(node->nodetype) | JFFS2_NODE_ACCURATE); in jffs2_scan_eraseblock()
761 crcnode.totlen = node->totlen; in jffs2_scan_eraseblock()
762 hdr_crc = crc32(0, &crcnode, sizeof(crcnode)-4); in jffs2_scan_eraseblock()
764 if (hdr_crc != je32_to_cpu(node->hdr_crc)) { in jffs2_scan_eraseblock()
765 …noisy_printk(&noise, "%s(): Node at 0x%08x {0x%04x, 0x%04x, 0x%08x) has invalid CRC 0x%08x (calcul… in jffs2_scan_eraseblock()
767 ofs, je16_to_cpu(node->magic), in jffs2_scan_eraseblock()
768 je16_to_cpu(node->nodetype), in jffs2_scan_eraseblock()
769 je32_to_cpu(node->totlen), in jffs2_scan_eraseblock()
770 je32_to_cpu(node->hdr_crc), in jffs2_scan_eraseblock()
778 if (ofs + je32_to_cpu(node->totlen) > jeb->offset + c->sector_size) { in jffs2_scan_eraseblock()
780 pr_warn("Node at 0x%08x with length 0x%08x would run over the end of the erase block\n", in jffs2_scan_eraseblock()
781 ofs, je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
789 if (!(je16_to_cpu(node->nodetype) & JFFS2_NODE_ACCURATE)) { in jffs2_scan_eraseblock()
791 jffs2_dbg(2, "Node at 0x%08x is obsolete. Skipping\n", in jffs2_scan_eraseblock()
793 if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(node->totlen))))) in jffs2_scan_eraseblock()
795 ofs += PAD(je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
799 switch(je16_to_cpu(node->nodetype)) { in jffs2_scan_eraseblock()
802 buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs); in jffs2_scan_eraseblock()
803 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()
814 ofs += PAD(je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
818 if (buf_ofs + buf_len < ofs + je32_to_cpu(node->totlen)) { in jffs2_scan_eraseblock()
819 buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs); in jffs2_scan_eraseblock()
820 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()
821 je32_to_cpu(node->totlen), buf_len, in jffs2_scan_eraseblock()
831 ofs += PAD(je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
836 if (buf_ofs + buf_len < ofs + je32_to_cpu(node->totlen)) { in jffs2_scan_eraseblock()
837 buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs); in jffs2_scan_eraseblock()
838 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()
839 je32_to_cpu(node->totlen), buf_len, in jffs2_scan_eraseblock()
850 ofs += PAD(je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
853 if (buf_ofs + buf_len < ofs + je32_to_cpu(node->totlen)) { in jffs2_scan_eraseblock()
854 buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs); in jffs2_scan_eraseblock()
855 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()
856 je32_to_cpu(node->totlen), buf_len, in jffs2_scan_eraseblock()
867 ofs += PAD(je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
872 jffs2_dbg(1, "CLEANMARKER node found at 0x%08x\n", ofs); in jffs2_scan_eraseblock()
873 if (je32_to_cpu(node->totlen) != c->cleanmarker_size) { in jffs2_scan_eraseblock()
874 pr_notice("CLEANMARKER node found at 0x%08x has totlen 0x%x != normal 0x%x\n", in jffs2_scan_eraseblock()
875 ofs, je32_to_cpu(node->totlen), in jffs2_scan_eraseblock()
876 c->cleanmarker_size); in jffs2_scan_eraseblock()
880 } else if (jeb->first_node) { in jffs2_scan_eraseblock()
881 pr_notice("CLEANMARKER node found at 0x%08x, not first node in block (0x%08x)\n", in jffs2_scan_eraseblock()
882 ofs, jeb->offset); in jffs2_scan_eraseblock()
887 jffs2_link_node_ref(c, jeb, ofs | REF_NORMAL, c->cleanmarker_size, NULL); in jffs2_scan_eraseblock()
889 ofs += PAD(c->cleanmarker_size); in jffs2_scan_eraseblock()
895 jffs2_sum_add_padding_mem(s, je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
896 if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(node->totlen))))) in jffs2_scan_eraseblock()
898 ofs += PAD(je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
902 switch (je16_to_cpu(node->nodetype) & JFFS2_COMPAT_MASK) { in jffs2_scan_eraseblock()
904 pr_notice("Read-only compatible feature node (0x%04x) found at offset 0x%08x\n", in jffs2_scan_eraseblock()
905 je16_to_cpu(node->nodetype), ofs); in jffs2_scan_eraseblock()
906 c->flags |= JFFS2_SB_FLAG_RO; in jffs2_scan_eraseblock()
908 return -EROFS; in jffs2_scan_eraseblock()
909 if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(node->totlen))))) in jffs2_scan_eraseblock()
911 ofs += PAD(je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
915 pr_notice("Incompatible feature node (0x%04x) found at offset 0x%08x\n", in jffs2_scan_eraseblock()
916 je16_to_cpu(node->nodetype), ofs); in jffs2_scan_eraseblock()
917 return -EINVAL; in jffs2_scan_eraseblock()
920 jffs2_dbg(1, "Unknown but compatible feature node (0x%04x) found at offset 0x%08x\n", in jffs2_scan_eraseblock()
921 je16_to_cpu(node->nodetype), ofs); in jffs2_scan_eraseblock()
922 if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(node->totlen))))) in jffs2_scan_eraseblock()
924 ofs += PAD(je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
928 jffs2_dbg(1, "Unknown but compatible feature node (0x%04x) found at offset 0x%08x\n", in jffs2_scan_eraseblock()
929 je16_to_cpu(node->nodetype), ofs); in jffs2_scan_eraseblock()
931 jffs2_link_node_ref(c, jeb, ofs | REF_PRISTINE, PAD(je32_to_cpu(node->totlen)), NULL); in jffs2_scan_eraseblock()
935 ofs += PAD(je32_to_cpu(node->totlen)); in jffs2_scan_eraseblock()
943 if (PAD(s->sum_size + JFFS2_SUMMARY_FRAME_SIZE) > jeb->free_size) { in jffs2_scan_eraseblock()
950 …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()
951 jeb->offset, jeb->free_size, jeb->dirty_size, in jffs2_scan_eraseblock()
952 jeb->unchecked_size, jeb->used_size, jeb->wasted_size); in jffs2_scan_eraseblock()
955 if (jeb->wasted_size) { in jffs2_scan_eraseblock()
956 jeb->dirty_size += jeb->wasted_size; in jffs2_scan_eraseblock()
957 c->dirty_size += jeb->wasted_size; in jffs2_scan_eraseblock()
958 c->wasted_size -= jeb->wasted_size; in jffs2_scan_eraseblock()
959 jeb->wasted_size = 0; in jffs2_scan_eraseblock()
973 if (ino > c->highest_ino) in jffs2_scan_make_ino_cache()
974 c->highest_ino = ino; in jffs2_scan_make_ino_cache()
983 ic->ino = ino; in jffs2_scan_make_ino_cache()
984 ic->nodes = (void *)ic; in jffs2_scan_make_ino_cache()
987 ic->pino_nlink = 1; in jffs2_scan_make_ino_cache()
995 uint32_t crc, ino = je32_to_cpu(ri->ino); in jffs2_scan_inode_node()
997 jffs2_dbg(1, "%s(): Node at 0x%08x\n", __func__, ofs); in jffs2_scan_inode_node()
1000 this node; we can do all the CRC checking etc. later. There's a tradeoff here -- in jffs2_scan_inode_node()
1002 memory, then building all our in-core data structures and freeing the extra in jffs2_scan_inode_node()
1009 crc = crc32(0, ri, sizeof(*ri)-8); in jffs2_scan_inode_node()
1010 if (crc != je32_to_cpu(ri->node_crc)) { in jffs2_scan_inode_node()
1011 pr_notice("%s(): CRC failed on node at 0x%08x: Read 0x%08x, calculated 0x%08x\n", in jffs2_scan_inode_node()
1012 __func__, ofs, je32_to_cpu(ri->node_crc), crc); in jffs2_scan_inode_node()
1018 PAD(je32_to_cpu(ri->totlen))); in jffs2_scan_inode_node()
1025 return -ENOMEM; in jffs2_scan_inode_node()
1029 jffs2_link_node_ref(c, jeb, ofs | REF_UNCHECKED, PAD(je32_to_cpu(ri->totlen)), ic); in jffs2_scan_inode_node()
1031 jffs2_dbg(1, "Node is ino #%u, version %d. Range 0x%x-0x%x\n", in jffs2_scan_inode_node()
1032 je32_to_cpu(ri->ino), je32_to_cpu(ri->version), in jffs2_scan_inode_node()
1033 je32_to_cpu(ri->offset), in jffs2_scan_inode_node()
1034 je32_to_cpu(ri->offset)+je32_to_cpu(ri->dsize)); in jffs2_scan_inode_node()
1036 pseudo_random += je32_to_cpu(ri->version); in jffs2_scan_inode_node()
1039 jffs2_sum_add_inode_mem(s, ri, ofs - jeb->offset); in jffs2_scan_inode_node()
1054 jffs2_dbg(1, "%s(): Node at 0x%08x\n", __func__, ofs); in jffs2_scan_dirent_node()
1058 crc = crc32(0, rd, sizeof(*rd)-8); in jffs2_scan_dirent_node()
1060 if (crc != je32_to_cpu(rd->node_crc)) { in jffs2_scan_dirent_node()
1061 pr_notice("%s(): Node CRC failed on node at 0x%08x: Read 0x%08x, calculated 0x%08x\n", in jffs2_scan_dirent_node()
1062 __func__, ofs, je32_to_cpu(rd->node_crc), crc); in jffs2_scan_dirent_node()
1064 if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(rd->totlen))))) in jffs2_scan_dirent_node()
1069 pseudo_random += je32_to_cpu(rd->version); in jffs2_scan_dirent_node()
1072 checkedlen = strnlen(rd->name, rd->nsize); in jffs2_scan_dirent_node()
1073 if (checkedlen < rd->nsize) { in jffs2_scan_dirent_node()
1074 pr_err("Dirent at %08x has zeroes in name. Truncating to %d chars\n", in jffs2_scan_dirent_node()
1079 return -ENOMEM; in jffs2_scan_dirent_node()
1081 memcpy(&fd->name, rd->name, checkedlen); in jffs2_scan_dirent_node()
1082 fd->name[checkedlen] = 0; in jffs2_scan_dirent_node()
1084 crc = crc32(0, fd->name, checkedlen); in jffs2_scan_dirent_node()
1085 if (crc != je32_to_cpu(rd->name_crc)) { in jffs2_scan_dirent_node()
1086 pr_notice("%s(): Name CRC failed on node at 0x%08x: Read 0x%08x, calculated 0x%08x\n", in jffs2_scan_dirent_node()
1087 __func__, ofs, je32_to_cpu(rd->name_crc), crc); in jffs2_scan_dirent_node()
1089 fd->name, je32_to_cpu(rd->ino)); in jffs2_scan_dirent_node()
1093 if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(rd->totlen))))) in jffs2_scan_dirent_node()
1097 ic = jffs2_scan_make_ino_cache(c, je32_to_cpu(rd->pino)); in jffs2_scan_dirent_node()
1100 return -ENOMEM; in jffs2_scan_dirent_node()
1103 fd->raw = jffs2_link_node_ref(c, jeb, ofs | dirent_node_state(rd), in jffs2_scan_dirent_node()
1104 PAD(je32_to_cpu(rd->totlen)), ic); in jffs2_scan_dirent_node()
1106 fd->next = NULL; in jffs2_scan_dirent_node()
1107 fd->version = je32_to_cpu(rd->version); in jffs2_scan_dirent_node()
1108 fd->ino = je32_to_cpu(rd->ino); in jffs2_scan_dirent_node()
1109 fd->nhash = full_name_hash(NULL, fd->name, checkedlen); in jffs2_scan_dirent_node()
1110 fd->type = rd->type; in jffs2_scan_dirent_node()
1111 jffs2_add_fd_to_list(c, fd, &ic->scan_dents); in jffs2_scan_dirent_node()
1114 jffs2_sum_add_dirent_mem(s, rd, ofs - jeb->offset); in jffs2_scan_dirent_node()
1135 struct list_head *n = head->next; in rotate_list()
1138 while(count--) { in rotate_list()
1139 n = n->next; in rotate_list()
1146 uint32_t x; in jffs2_rotate_lists() local
1149 x = count_list(&c->clean_list); in jffs2_rotate_lists()
1150 if (x) { in jffs2_rotate_lists()
1151 rotateby = pseudo_random % x; in jffs2_rotate_lists()
1152 rotate_list((&c->clean_list), rotateby); in jffs2_rotate_lists()
1155 x = count_list(&c->very_dirty_list); in jffs2_rotate_lists()
1156 if (x) { in jffs2_rotate_lists()
1157 rotateby = pseudo_random % x; in jffs2_rotate_lists()
1158 rotate_list((&c->very_dirty_list), rotateby); in jffs2_rotate_lists()
1161 x = count_list(&c->dirty_list); in jffs2_rotate_lists()
1162 if (x) { in jffs2_rotate_lists()
1163 rotateby = pseudo_random % x; in jffs2_rotate_lists()
1164 rotate_list((&c->dirty_list), rotateby); in jffs2_rotate_lists()
1167 x = count_list(&c->erasable_list); in jffs2_rotate_lists()
1168 if (x) { in jffs2_rotate_lists()
1169 rotateby = pseudo_random % x; in jffs2_rotate_lists()
1170 rotate_list((&c->erasable_list), rotateby); in jffs2_rotate_lists()
1173 if (c->nr_erasing_blocks) { in jffs2_rotate_lists()
1174 rotateby = pseudo_random % c->nr_erasing_blocks; in jffs2_rotate_lists()
1175 rotate_list((&c->erase_pending_list), rotateby); in jffs2_rotate_lists()
1178 if (c->nr_free_blocks) { in jffs2_rotate_lists()
1179 rotateby = pseudo_random % c->nr_free_blocks; in jffs2_rotate_lists()
1180 rotate_list((&c->free_list), rotateby); in jffs2_rotate_lists()