From: Jean-Christophe PLAGNIOL-VILLARD Date: Thu, 13 Nov 2008 19:06:05 +0100 Subject: [U-Boot] [PATCH 3/6] jffs2: rewrite jffs2 scanning code based on Linux one In-Reply-To: <1226594976-6087-4-git-send-email-yanok@emcraft.com> References: <1226594976-6087-1-git-send-email-yanok@emcraft.com> <1226594976-6087-4-git-send-email-yanok@emcraft.com> Message-ID: <20081113180605.GD25695@game.jcrosoft.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de > > /* start at the beginning of the partition */ > - while (offset < max) { > - if ((oldoffset >> SPIN_BLKSIZE) != (offset >> SPIN_BLKSIZE)) { > - printf("\b\b%c ", spinner[counter++ % sizeof(spinner)]); > - oldoffset = offset; > - } > + for (i = 0; i < nr_sectors; i++) { > + uint32_t sector_ofs = i * part->sector_size; > + uint32_t buf_ofs = sector_ofs; > + uint32_t buf_len = EMPTY_SCAN_SIZE(part->sector_size); > + uint32_t ofs, prevofs; > > WATCHDOG_RESET(); > + get_fl_mem((u32)part->offset + buf_ofs, buf_len, buf); > > - node = (struct jffs2_unknown_node *) get_node_mem((u32)part->offset + offset); > - if (node->magic == JFFS2_MAGIC_BITMASK && hdr_crc(node)) { > + /* We temporarily use 'ofs' as a pointer into the buffer/jeb */ > + ofs = 0; > + > + /* Scan only 4KiB of 0xFF before declaring it's empty */ > + while (ofs < EMPTY_SCAN_SIZE(part->sector_size) && > + *(uint32_t *)(&buf[ofs]) == 0xFFFFFFFF) please use readx/writex > + ofs += 4; > + > + if (ofs == EMPTY_SCAN_SIZE(part->sector_size)) > + continue; > + > + ofs += sector_ofs; > + prevofs = ofs - 1; > + > + scan_more: > + while (ofs < sector_ofs + part->sector_size) { > + if (ofs == prevofs) { > + printf("offset %08x already seen, skip\n", ofs); > + ofs += 4; > + counter4++; > + continue; > + } > + prevofs = ofs; > + if (sector_ofs + part->sector_size < > + ofs + sizeof(*node)) > + break; > + if (buf_ofs + buf_len < ofs + sizeof(*node)) { > + buf_len = min_t(uint32_t, buf_size, sector_ofs > + + part->sector_size - ofs); > + get_fl_mem((u32)part->offset + ofs, buf_len, > + buf); > + buf_ofs = ofs; > + } > + > + node = (struct jffs2_unknown_node *)&buf[ofs-buf_ofs]; > + > + if (*(uint32_t *)(&buf[ofs-buf_ofs]) == 0xffffffff) { please use readx/writex > + uint32_t inbuf_ofs; > + uint32_t empty_start, scan_end; > + > + empty_start = ofs; > + ofs += 4; > + scan_end = min_t(uint32_t, EMPTY_SCAN_SIZE( > + part->sector_size)/8, > + buf_len); > + more_empty: > + inbuf_ofs = ofs - buf_ofs; > + while (inbuf_ofs < scan_end) { > + if (*(uint32_t *)(&buf[inbuf_ofs]) != > + 0xffffffff) please use readx/writex and so on Best Regards, J.