tools/blkunpack: add "upto" argument

This commit is contained in:
Virgil Dupras 2020-12-21 16:55:12 -05:00
parent efa2556c82
commit 45fbce4eb9

View File

@ -2,19 +2,28 @@
#include <stdlib.h> #include <stdlib.h>
#include <sys/stat.h> #include <sys/stat.h>
/* Unpacks blkfs into its source form.
*
* If numerical "upto" is specified, we stop unpacking when reaching this
* blkno.
*/
void usage() 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[]) int main(int argc, char *argv[])
{ {
char buf[1024]; char buf[1024];
int blkid = 0; int blkid = 0;
if (argc != 1) { int upto = 0;
if (argc > 2) {
usage(); usage();
return 1; return 1;
} }
if (argc == 2) {
upto = strtol(argv[1], NULL, 10);
}
while (fread(buf, 1024, 1, stdin) == 1) { while (fread(buf, 1024, 1, stdin) == 1) {
int linecnt = 0 ; int linecnt = 0 ;
for (int i=1023; i>=0; i--) { for (int i=1023; i>=0; i--) {
@ -51,6 +60,9 @@ int main(int argc, char *argv[])
} }
} }
blkid++; blkid++;
if (blkid == upto) {
break;
}
} }
return 0; return 0;
} }