summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSami Tolvanen <samitolvanen@google.com>2015-06-10 22:54:03 +0200
committerAndroid Git Automerger <android-git-automerger@android.com>2015-06-10 22:54:03 +0200
commitabb78773a7f30a1bcb2742834749574436a7862e (patch)
treed8e2db6df2b5f0f3043f70442cd60751af423489
parentam 11cad65d: am 059e391f: am e6f6097a: Merge "Revert "Zero blocks before BLKDISCARD"" (diff)
parentam 915fc970: am 280cb6e9: Merge "Zero blocks before BLKDISCARD" (diff)
downloadandroid_bootable_recovery-abb78773a7f30a1bcb2742834749574436a7862e.tar
android_bootable_recovery-abb78773a7f30a1bcb2742834749574436a7862e.tar.gz
android_bootable_recovery-abb78773a7f30a1bcb2742834749574436a7862e.tar.bz2
android_bootable_recovery-abb78773a7f30a1bcb2742834749574436a7862e.tar.lz
android_bootable_recovery-abb78773a7f30a1bcb2742834749574436a7862e.tar.xz
android_bootable_recovery-abb78773a7f30a1bcb2742834749574436a7862e.tar.zst
android_bootable_recovery-abb78773a7f30a1bcb2742834749574436a7862e.zip
-rw-r--r--updater/blockimg.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/updater/blockimg.c b/updater/blockimg.c
index 5d0f1560c..fc35abe4d 100644
--- a/updater/blockimg.c
+++ b/updater/blockimg.c
@@ -1465,6 +1465,7 @@ pcdout:
static int PerformCommandErase(CommandParameters* params) {
char* range = NULL;
int i;
+ int j;
int rc = -1;
RangeSet* tgt = NULL;
struct stat st;
@@ -1491,7 +1492,7 @@ static int PerformCommandErase(CommandParameters* params) {
range = strtok_r(NULL, " ", &params->cpos);
if (range == NULL) {
- fprintf(stderr, "missing target blocks for zero\n");
+ fprintf(stderr, "missing target blocks for erase\n");
goto pceout;
}
@@ -1500,7 +1501,22 @@ static int PerformCommandErase(CommandParameters* params) {
if (params->canwrite) {
fprintf(stderr, " erasing %d blocks\n", tgt->size);
+ allocate(BLOCKSIZE, &params->buffer, &params->bufsize);
+ memset(params->buffer, 0, BLOCKSIZE);
+
for (i = 0; i < tgt->count; ++i) {
+ // Always zero the blocks first to work around possibly flaky BLKDISCARD
+ // Bug: 20881595
+ if (!check_lseek(params->fd, (off64_t) tgt->pos[i * 2] * BLOCKSIZE, SEEK_SET)) {
+ goto pceout;
+ }
+
+ for (j = tgt->pos[i * 2]; j < tgt->pos[i * 2 + 1]; ++j) {
+ if (write_all(params->fd, params->buffer, BLOCKSIZE) == -1) {
+ goto pceout;
+ }
+ }
+
// offset in bytes
blocks[0] = tgt->pos[i * 2] * (uint64_t) BLOCKSIZE;
// length in bytes