From efa2556c8235c7d8d6214282ada4c9d2d5b0c1a4 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Thu, 17 Dec 2020 20:19:12 -0500 Subject: [PATCH] tools/blkup: add shortcut for zero blocks --- tools/blkup.c | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/tools/blkup.c b/tools/blkup.c index fb09ad2..39cbcf5 100644 --- a/tools/blkup.c +++ b/tools/blkup.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "common.h" @@ -30,29 +31,43 @@ int main(int argc, char **argv) char s[0x40]; char buf[1024] = {0}; sendcmdp(fd, ": _ 1024 0 DO KEY DUP .x I BLK( + C! LOOP ;"); + sendcmdp(fd, ": Z BLK( 1024 0 FILL ;"); int returncode = 0; while (fread(buf, 1, 1024, fp)) { - sendcmd(fd, "_"); + bool allzero = true; for (int i=0; i<1024; i++) { - putchar('.'); + if (buf[i] != 0) { + allzero = false; + break; + } + } + if (allzero) { + sendcmdp(fd, "Z"); + putchar('Z'); fflush(stdout); - write(fd, &buf[i], 1); - usleep(1000); // let it breathe - mread(fd, s, 2); // read hex pair - s[2] = 0; // null terminate - unsigned char c = strtol(s, NULL, 16); - if (c != buf[i]) { - // mismatch! - fprintf(stderr, "Mismatch at bno %d (%d) %d != %d.\n", blkno, i, buf[i], c); - // we don't exit now because we need to "consume" our whole program. - returncode = 1; + } else { + sendcmd(fd, "_"); + for (int i=0; i<1024; i++) { + putchar('.'); + fflush(stdout); + write(fd, &buf[i], 1); + usleep(1000); // let it breathe + mread(fd, s, 2); // read hex pair + s[2] = 0; // null terminate + unsigned char c = strtol(s, NULL, 16); + if (c != buf[i]) { + // mismatch! + fprintf(stderr, "Mismatch at bno %d (%d) %d != %d.\n", blkno, i, buf[i], c); + // we don't exit now because we need to "consume" our whole program. + returncode = 1; + } + usleep(1000); // let it breathe } - usleep(1000); // let it breathe + readprompt(fd); + if (returncode) break; + memset(buf, 0, 1024); } - readprompt(fd); - if (returncode) break; - memset(buf, 0, 1024); sprintf(s, "%d BLK> ! BLK!", blkno); sendcmdp(fd, s); blkno++;