From: Martin Mares Date: Fri, 24 Jul 2020 08:25:31 +0000 (+0200) Subject: ddigger: --status X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=9f5e3d8bf6a40ffe03c98511395d5585519c703d;p=misc.git ddigger: --status --- diff --git a/ucw/Makefile b/ucw/Makefile index ded2342..89db4c9 100644 --- a/ucw/Makefile +++ b/ucw/Makefile @@ -7,7 +7,7 @@ LD=gcc CFLAGS=-O2 -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wredundant-decls -std=gnu99 $(UCWCF) -ggdb LDLIBS+=$(UCWLF) -all: qhash +all: ddigger clean: rm -f `find . -name "*~" -or -name "*.[oa]" -or -name "\#*\#" -or -name TAGS -or -name core -or -name .depend -or -name .#*` diff --git a/ucw/ddigger.c b/ucw/ddigger.c index 3df6981..4902979 100644 --- a/ucw/ddigger.c +++ b/ucw/ddigger.c @@ -15,6 +15,7 @@ static uint block_size = 1048576; static uint error_skip; static u64 start_pos; static u64 end_pos = ~(u64)0; +static int show_status; struct stat_rec { u64 pos; @@ -70,9 +71,22 @@ static u64 stat_have(void) return have; } +static void stat_show(void) +{ + u64 last = 0; + for (uint i=0; i last) + printf("Missing: %ju +%ju\n", (intmax_t) last, (intmax_t)(status[i].pos - last)); + last = status[i].pos + status[i].len; + } + printf("End at %ju\n", (intmax_t) last); +} + static struct opt_section options = { OPT_ITEMS { OPT_HELP("Usage: ddigger [options] block-device output-file status-file"), + OPT_HELP(" or: ddigger [options] --status - - status-file"), OPT_HELP(""), OPT_HELP("Options:"), OPT_HELP_OPTION, @@ -83,6 +97,7 @@ static struct opt_section options = { OPT_UINT('e', "error-skip", error_skip, OPT_REQUIRED_VALUE, "\tHow far to skip on error (default=block size)"), OPT_U64(0, "start", start_pos, OPT_REQUIRED_VALUE, "\tStart position (default=beginning of device)"), OPT_U64(0, "end", end_pos, OPT_REQUIRED_VALUE, "\tEnd position (default=end of device)"), + OPT_SWITCH(0, "status", show_status, 1, 0, "\tShow contents of status file"), OPT_END } }; @@ -93,6 +108,17 @@ int main(int argc UNUSED, char **argv) if (!error_skip) error_skip = block_size; + int stat_fd = ucw_open(stat_name, (show_status ? O_RDONLY : O_RDWR | O_CREAT), 0666); + if (stat_fd < 0) + die("Cannot open %s: %m", stat_name); + stat_read(stat_fd); + + if (show_status) + { + stat_show(); + return 0; + } + int dev_fd = ucw_open(dev_name, O_RDONLY | O_DIRECT); if (dev_fd < 0) die("Cannot open block device %s: %m", dev_name); @@ -110,12 +136,7 @@ int main(int argc UNUSED, char **argv) if (ucw_ftruncate(out_fd, dev_size) < 0) die("Cannot resize %s: %m", out_name); - int stat_fd = ucw_open(stat_name, O_RDWR | O_CREAT, 0666); - if (stat_fd < 0) - die("Cannot open %s: %m", stat_name); - stat_read(stat_fd); u64 remains = (end_pos - start_pos) + stat_have(); - ucw_seek(stat_fd, 0, SEEK_END); *GARY_PUSH(status) = (struct stat_rec) { .pos = end_pos, .len = 0 };