static uint error_skip;
static u64 start_pos;
static u64 end_pos = ~(u64)0;
+static int show_status;
struct stat_rec {
u64 pos;
return have;
}
+static void stat_show(void)
+{
+ u64 last = 0;
+ for (uint i=0; i<GARY_SIZE(status); i++)
+ {
+ if (status[i].pos > 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,
OPT_UINT('e', "error-skip", error_skip, OPT_REQUIRED_VALUE, "<bytes>\tHow far to skip on error (default=block size)"),
OPT_U64(0, "start", start_pos, OPT_REQUIRED_VALUE, "<bytes>\tStart position (default=beginning of device)"),
OPT_U64(0, "end", end_pos, OPT_REQUIRED_VALUE, "<bytes>\tEnd position (default=end of device)"),
+ OPT_SWITCH(0, "status", show_status, 1, 0, "\tShow contents of status file"),
OPT_END
}
};
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);
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 };