Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d7c9bf41 authored by Sami Tolvanen's avatar Sami Tolvanen Committed by Android (Google) Code Review
Browse files

Merge "Zero blocks before BLKDISCARD" into mnc-dev

parents 0005f89c b65f0272
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -1404,6 +1404,7 @@ pcdout:
static int PerformCommandErase(CommandParameters* params) {
    char* range = NULL;
    int i;
    int j;
    int rc = -1;
    RangeSet* tgt = NULL;
    struct stat st;
@@ -1430,7 +1431,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;
    }

@@ -1439,7 +1440,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