Hi Denys,
On Wed, Aug 25, 2010 at 04:38:08PM +0200, Denys Vlasenko wrote:
> On Wed, Aug 25, 2010 at 6:38 AM, Baruch Siach <[email protected]> wrote:
> > + static unsigned next_good_eraseblock(int fd, struct mtd_info_user
> > *meminfo,
> > + unsigned block_offset)
> > +{
> > + loff_t offs = block_offset;
> > +
> > + while (1) {
> > + if (block_offset >= meminfo->size)
> > + bb_error_msg_and_die("not enough space in MTD
> > device");
> > + if (xioctl(fd, MEMGETBADBLOCK, &offs)) {
> > + offs += meminfo->erasesize;
> > + printf("Skipping bad block at 0x%08llx\n", offs);
>
> The message prints wrong offset (offs +=... should be after the message).
> %llx does not necessarily match loff_t type.
> You forgot to increment block_offset, thus you can run off the MTD.
>
> > + } else
> > + return offs;
> > + }
> > +}
>
> How about this?
>
> while (1) {
> loff_t offs;
> if (block_offset >= meminfo->size)
> bb_error_msg_and_die("not enough space in MTD
> device");
> offs = block_offset;
> if (xioctl(fd, MEMGETBADBLOCK, &offs) == 0)
> return block_offset;
> /* ioctl returned 1 = "bad block" */
> printf("Skipping bad block at 0x%08x\n", block_offset);
> block_offset += meminfo->erasesize;
> }
>
> Applied with a few changes:
>
> http://git.busybox.net/busybox/commit/?id=6f32ea4039535c48759a217fd6352193846a393c
Thanks.
> Please test current git.
I've found two problems:
1. The move from bb_strtou() to xatou() breaks hex offsets
2. The first erase block isn't checked when mtdoffset is not erase block
aligned
I'll post two patches fixing these problems as a reply to this message
shortly.
baruch
--
~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- [email protected] - tel: +972.2.679.5364, http://www.tkos.co.il -
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox