[PATCHv4] nandwrite: new mtd-utils applet
Denys Vlasenko
vda.linux at googlemail.com
Wed Aug 25 14:38:08 UTC 2010
On Wed, Aug 25, 2010 at 6:38 AM, Baruch Siach <baruch at tkos.co.il> 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
Please test current git.
--
vda
More information about the busybox
mailing list