This patch makes dd(1) output change from e.g.
$ dd if=/dev/sd0c of=/dev/null bs=512 count=16000
16000+0 records in
16000+0 records out
8192000 bytes transferred in 3.002 secs (2728488 bytes/sec)
to
$ obj/dd if=/dev/sd0c of=/dev/null bs=512 count=16000
16000+0 records in
16000+0 records out
8192000 bytes (7.8MB) transferred in 3.009 seconds (2.6MB/s)
Any interest?
Index: Makefile
===================================================================
RCS file: /cvs/src/bin/dd/Makefile,v
retrieving revision 1.5
diff -u -p -r1.5 Makefile
--- Makefile 29 May 1998 04:34:20 -0000 1.5
+++ Makefile 23 Aug 2011 18:43:43 -0000
@@ -2,5 +2,7 @@
PROG= dd
SRCS= args.c conv.c conv_tab.c dd.c misc.c position.c
+DPADD= ${LIBUTIL}
+LDADD= -lutil
.include <bsd.prog.mk>
Index: misc.c
===================================================================
RCS file: /cvs/src/bin/dd/misc.c,v
retrieving revision 1.16
diff -u -p -r1.16 misc.c
--- misc.c 27 Oct 2009 23:59:21 -0000 1.16
+++ misc.c 23 Aug 2011 18:43:43 -0000
@@ -45,6 +45,7 @@
#include <errno.h>
#include <time.h>
#include <unistd.h>
+#include <util.h>
#include "dd.h"
#include "extern.h"
@@ -57,6 +58,7 @@ summary(void)
struct iovec iov[4];
double microsecs;
int i = 0;
+ char sizebuf[FMT_SCALED_STRSIZE], ratebuf[FMT_SCALED_STRSIZE];
(void)gettimeofday(&nowtv, (struct timezone *)NULL);
timersub(&nowtv, &st.startv, &nowtv);
@@ -85,10 +87,19 @@ summary(void)
iov[i].iov_base = buf[2];
iov[i++].iov_len = strlen(buf[2]);
}
+
+ strlcpy(sizebuf, "?", sizeof sizebuf);
+ fmt_scaled(st.bytes, sizebuf);
+ sizebuf[strcspn(sizebuf, "B")] = '\0';
+
+ strlcpy(ratebuf, "?", sizeof ratebuf);
+ fmt_scaled(st.bytes * 1000000.0 / microsecs, ratebuf);
+ ratebuf[strcspn(ratebuf, "B")] = '\0';
+
(void)snprintf(buf[3], sizeof(buf[3]),
- "%qd bytes transferred in %ld.%03ld secs (%0.0f bytes/sec)\n",
- (long long)st.bytes, nowtv.tv_sec, nowtv.tv_usec / 1000,
- ((double)st.bytes * 1000000) / microsecs);
+ "%qd bytes (%sB) transferred in %ld.%03ld seconds (%sB/s)\n",
+ (long long)st.bytes, sizebuf, nowtv.tv_sec, nowtv.tv_usec / 1000,
+ ratebuf);
iov[i].iov_base = buf[3];
iov[i++].iov_len = strlen(buf[3]);