[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Patch to implement progress in dd
From: |
Sean Reifschneider |
Subject: |
Patch to implement progress in dd |
Date: |
Tue, 29 Apr 2003 22:30:53 -0600 |
User-agent: |
Mutt/1.4.1i |
This patch implements a "progress=1" option to dd that will display the
number of blocks written via stderr. It's just sometimes nice to know
where in the copy/dump you are.
Sean
===============
--- fileutils-4.1-newdd/src/dd.c.old 2003-04-29 21:12:13.000000000 -0600
+++ fileutils-4.1-newdd/src/dd.c 2003-04-29 22:13:41.000000000 -0600
@@ -134,6 +134,10 @@
/* Records truncated by conv=block. */
static uintmax_t r_truncate = 0;
+/* Do we display progress to stderr. */
+static int progress_arg = 0;
+static time_t progress_lasttime = 0;
+
/* Output representation of newline and space characters.
They change if we're converting to EBCDIC. */
static unsigned char newline_character = '\n';
@@ -301,6 +305,7 @@
if=FILE read from FILE instead of stdin\n\
obs=BYTES write BYTES bytes at a time\n\
of=FILE write to FILE instead of stdout\n\
+ progress=(0|1) display progress to stderr\n\
seek=BLOCKS skip BLOCKS obs-sized blocks at start of output\n\
skip=BLOCKS skip BLOCKS ibs-sized blocks at start of input\n\
--help display this help and exit\n\
@@ -355,6 +360,8 @@
print_stats (void)
{
char buf[2][LONGEST_HUMAN_READABLE + 1];
+ if (progress_arg)
+ fprintf(stderr, " \r"),
fprintf (stderr, _("%s+%s records in\n"),
human_readable (r_full, buf[0], 1, 1),
human_readable (r_partial, buf[1], 1, 1));
@@ -470,6 +477,15 @@
else
w_full++;
oc = 0;
+
+ if (progress_arg) {
+ time_t now = time(NULL);
+ if ((now - progress_lasttime) > 1) {
+ progress_lasttime = now;
+ fprintf(stderr, " %ld/%ld \r", (long) w_full, (long) w_partial);
+ fflush(stderr);
+ }
+ }
}
/* Interpret one "conv=..." option.
@@ -572,6 +588,8 @@
invalid |= input_blocksize != n || input_blocksize == 0;
conversions_mask |= C_TWOBUFS;
}
+ else if (STREQ (name, "progress"))
+ progress_arg = n;
else if (STREQ (name, "obs"))
{
output_blocksize = n;
--- fileutils-4.1-newdd/man/dd.1.old 2003-04-29 22:05:39.000000000 -0600
+++ fileutils-4.1-newdd/man/dd.1 2003-04-29 22:10:50.000000000 -0600
@@ -34,6 +34,11 @@
of=FILE
write to FILE instead of stdout
.TP
+progress=(0|1)
+display a count of blocks written every second as the program is running.
+If set to 1, two values are displayed: "X/Y", where the first value is the
+number of fully written blocks and the second is partially written blocks.
+.TP
seek=BLOCKS
skip BLOCKS obs-sized blocks at start of output
.TP
--
The question of whether a computer can think is no more interesting than the
question of whether a submarine can swim." -- Edsgar W. Dijkstra (1930-2002)
Sean Reifschneider, Inimitably Superfluous <address@hidden>
tummy.com, ltd. - Linux Consulting since 1995. Qmail, Python, SysAdmin
- Patch to implement progress in dd,
Sean Reifschneider <=