summaryrefslogtreecommitdiffstats
path: root/mtdutils
diff options
context:
space:
mode:
authorJean-Baptiste Queru <jbq@google.com>2009-07-26 02:48:00 +0200
committerJean-Baptiste Queru <jbq@google.com>2009-07-26 02:48:00 +0200
commit7bd5c660752ddd1b4ff6127b316fd6d8fb1005c7 (patch)
tree88c0fc6a69cade6f9d4437666c6420e0f757e278 /mtdutils
parentMerge commit 'korg/cupcake' (diff)
parentskip over all-zero blocks when reading MTD partition (diff)
downloadandroid_bootable_recovery-7bd5c660752ddd1b4ff6127b316fd6d8fb1005c7.tar
android_bootable_recovery-7bd5c660752ddd1b4ff6127b316fd6d8fb1005c7.tar.gz
android_bootable_recovery-7bd5c660752ddd1b4ff6127b316fd6d8fb1005c7.tar.bz2
android_bootable_recovery-7bd5c660752ddd1b4ff6127b316fd6d8fb1005c7.tar.lz
android_bootable_recovery-7bd5c660752ddd1b4ff6127b316fd6d8fb1005c7.tar.xz
android_bootable_recovery-7bd5c660752ddd1b4ff6127b316fd6d8fb1005c7.tar.zst
android_bootable_recovery-7bd5c660752ddd1b4ff6127b316fd6d8fb1005c7.zip
Diffstat (limited to 'mtdutils')
-rw-r--r--mtdutils/mtdutils.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/mtdutils/mtdutils.c b/mtdutils/mtdutils.c
index 2b0106f14..fc067669b 100644
--- a/mtdutils/mtdutils.c
+++ b/mtdutils/mtdutils.c
@@ -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;