am bec02d57: skip over all-zero blocks when reading MTD partition

Merge commit 'bec02d57fb85cc7dd0196a54b0e9530e306623ac'

* commit 'bec02d57fb85cc7dd0196a54b0e9530e306623ac':
  skip over all-zero blocks when reading MTD partition
This commit is contained in:
Doug Zongker 2009-07-02 15:24:19 -07:00 committed by The Android Open Source Project
commit c457ff6436

View File

@ -297,7 +297,14 @@ static int read_block(const MtdPartition *partition, int fd, char *data)
after.corrected - before.corrected,
after.failed - before.failed, pos);
} else {
return 0; // Success!
int i;
for (i = 0; i < size; ++i) {
if (data[i] != 0) {
return 0; // Success!
}
}
fprintf(stderr, "mtd: read all-zero block at 0x%08lx; skipping\n",
pos);
}
pos += partition->erase_size;
@ -326,6 +333,10 @@ ssize_t mtd_read_data(MtdReadContext *ctx, char *data, size_t len)
read += ctx->partition->erase_size;
}
if (read >= len) {
return read;
}
// Read the next block into the buffer
if (ctx->consumed == ctx->partition->erase_size && read < (int) len) {
if (read_block(ctx->partition, ctx->fd, ctx->buffer)) return -1;