Quellcode durchsuchen

tools/blkunpack: add "upto" argument

master
Virgil Dupras vor 3 Jahren
Ursprung
Commit
45fbce4eb9
1 geänderte Dateien mit 14 neuen und 2 gelöschten Zeilen
  1. +14
    -2
      tools/blkunpack.c

+ 14
- 2
tools/blkunpack.c Datei anzeigen

@@ -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;
} }

Laden…
Abbrechen
Speichern