From 45fbce4eb9758215294fd5134cae56ccef8e3b73 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 21 Dec 2020 16:55:12 -0500 Subject: [PATCH] tools/blkunpack: add "upto" argument --- tools/blkunpack.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/blkunpack.c b/tools/blkunpack.c index a84b116..cffcab2 100644 --- a/tools/blkunpack.c +++ b/tools/blkunpack.c @@ -2,19 +2,28 @@ #include #include +/* Unpacks blkfs into its source form. + * + * If numerical "upto" is specified, we stop unpacking when reaching this + * blkno. + */ void usage() { - fprintf(stderr, "Usage: blkunpack < blkfs > blk.fs\n"); + fprintf(stderr, "Usage: blkunpack [upto] < blkfs > blk.fs\n"); } int main(int argc, char *argv[]) { char buf[1024]; int blkid = 0; - if (argc != 1) { + int upto = 0; + if (argc > 2) { usage(); return 1; } + if (argc == 2) { + upto = strtol(argv[1], NULL, 10); + } while (fread(buf, 1024, 1, stdin) == 1) { int linecnt = 0 ; for (int i=1023; i>=0; i--) { @@ -51,6 +60,9 @@ int main(int argc, char *argv[]) } } blkid++; + if (blkid == upto) { + break; + } } return 0; }