summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2014-04-17 00:31:20 +0000
committerdelphij <delphij@FreeBSD.org>2014-04-17 00:31:20 +0000
commit4882a37127ce96ac685a0326038aa0bef5b0b37e (patch)
treee53e2a65f94d2262838062b0f26c27f53d50061f /bin
parent10d91505dda206d5ea507b188cf02017634e82ca (diff)
downloadFreeBSD-src-4882a37127ce96ac685a0326038aa0bef5b0b37e.zip
FreeBSD-src-4882a37127ce96ac685a0326038aa0bef5b0b37e.tar.gz
MFC r264059+264067:
Implement GNU's extension of 'status' operand. The GNU syntax is borrowed where syntax status=noxfer means no transfer statistics and status=none means no status information at all. This feature is useful because the statistics information can sometimes be annoying, and redirecting stderr to /dev/null would mean error messages also gets silenced. Obtained from: OpenBSD
Diffstat (limited to 'bin')
-rw-r--r--bin/dd/args.c14
-rw-r--r--bin/dd/dd.117
-rw-r--r--bin/dd/dd.h57
-rw-r--r--bin/dd/misc.c11
4 files changed, 67 insertions, 32 deletions
diff --git a/bin/dd/args.c b/bin/dd/args.c
index cc702f9..2f197f8 100644
--- a/bin/dd/args.c
+++ b/bin/dd/args.c
@@ -66,6 +66,7 @@ static void f_obs(char *);
static void f_of(char *);
static void f_seek(char *);
static void f_skip(char *);
+static void f_status(char *);
static uintmax_t get_num(const char *);
static off_t get_off_t(const char *);
@@ -88,6 +89,7 @@ static const struct arg {
{ "oseek", f_seek, C_SEEK, C_SEEK },
{ "seek", f_seek, C_SEEK, C_SEEK },
{ "skip", f_skip, C_SKIP, C_SKIP },
+ { "status", f_status, C_STATUS,C_STATUS },
};
static char *oper;
@@ -292,6 +294,18 @@ f_skip(char *arg)
in.offset = get_off_t(arg);
}
+static void
+f_status(char *arg)
+{
+
+ if (strcmp(arg, "none") == 0)
+ ddflags |= C_NOINFO;
+ else if (strcmp(arg, "noxfer") == 0)
+ ddflags |= C_NOXFER;
+ else
+ errx(1, "unknown status %s", arg);
+}
+
static const struct conv {
const char *name;
u_int set, noset;
diff --git a/bin/dd/dd.1 b/bin/dd/dd.1
index fa6d9a9..0541df8 100644
--- a/bin/dd/dd.1
+++ b/bin/dd/dd.1
@@ -32,7 +32,7 @@
.\" @(#)dd.1 8.2 (Berkeley) 1/13/94
.\" $FreeBSD$
.\"
-.Dd October 1, 2013
+.Dd April 2, 2014
.Dt DD 1
.Os
.Sh NAME
@@ -156,6 +156,17 @@ Otherwise, input data is read and discarded.
For pipes, the correct number of bytes is read.
For all other devices, the correct number of blocks is read without
distinguishing between a partial or complete block being read.
+.It Cm status Ns = Ns Ar value
+Where
+.Cm value
+is one of the symbols from the following list.
+.Bl -tag -width ".Cm noxfer"
+.It Cm noxfer
+Do not print the transfer statistics as the last line of status output.
+.It Cm none
+Do not print the status output.
+Error messages are shown; informational messages are not.
+.El
.It Cm conv Ns = Ns Ar value Ns Op , Ns Ar value ...
Where
.Cm value
@@ -410,7 +421,9 @@ utility is expected to be a superset of the
standard.
The
.Cm files
-operand and the
+and
+.Cm status
+operands and the
.Cm ascii ,
.Cm ebcdic ,
.Cm ibm ,
diff --git a/bin/dd/dd.h b/bin/dd/dd.h
index ad283fd..dace845 100644
--- a/bin/dd/dd.h
+++ b/bin/dd/dd.h
@@ -68,32 +68,35 @@ typedef struct {
} STAT;
/* Flags (in ddflags). */
-#define C_ASCII 0x00001
-#define C_BLOCK 0x00002
-#define C_BS 0x00004
-#define C_CBS 0x00008
-#define C_COUNT 0x00010
-#define C_EBCDIC 0x00020
-#define C_FILES 0x00040
-#define C_IBS 0x00080
-#define C_IF 0x00100
-#define C_LCASE 0x00200
-#define C_NOERROR 0x00400
-#define C_NOTRUNC 0x00800
-#define C_OBS 0x01000
-#define C_OF 0x02000
-#define C_OSYNC 0x04000
-#define C_PAREVEN 0x08000
-#define C_PARNONE 0x100000
-#define C_PARODD 0x200000
-#define C_PARSET 0x400000
-#define C_SEEK 0x800000
-#define C_SKIP 0x1000000
-#define C_SPARSE 0x2000000
-#define C_SWAB 0x4000000
-#define C_SYNC 0x8000000
-#define C_UCASE 0x10000000
-#define C_UNBLOCK 0x20000000
-#define C_FILL 0x40000000
+#define C_ASCII 0x00000001
+#define C_BLOCK 0x00000002
+#define C_BS 0x00000004
+#define C_CBS 0x00000008
+#define C_COUNT 0x00000010
+#define C_EBCDIC 0x00000020
+#define C_FILES 0x00000040
+#define C_IBS 0x00000080
+#define C_IF 0x00000100
+#define C_LCASE 0x00000200
+#define C_NOERROR 0x00000400
+#define C_NOTRUNC 0x00000800
+#define C_OBS 0x00001000
+#define C_OF 0x00002000
+#define C_OSYNC 0x00004000
+#define C_PAREVEN 0x00008000
+#define C_PARNONE 0x00010000
+#define C_PARODD 0x00020000
+#define C_PARSET 0x00040000
+#define C_SEEK 0x00080000
+#define C_SKIP 0x00100000
+#define C_SPARSE 0x00200000
+#define C_SWAB 0x00400000
+#define C_SYNC 0x00800000
+#define C_UCASE 0x01000000
+#define C_UNBLOCK 0x02000000
+#define C_FILL 0x04000000
+#define C_STATUS 0x08000000
+#define C_NOXFER 0x10000000
+#define C_NOINFO 0x20000000
#define C_PARITY (C_PAREVEN | C_PARODD | C_PARNONE | C_PARSET)
diff --git a/bin/dd/misc.c b/bin/dd/misc.c
index 84cc5ee..61f843b 100644
--- a/bin/dd/misc.c
+++ b/bin/dd/misc.c
@@ -59,6 +59,9 @@ summary(void)
struct timeval tv;
double secs;
+ if (ddflags & C_NOINFO)
+ return;
+
(void)gettimeofday(&tv, NULL);
secs = tv.tv_sec + tv.tv_usec * 1e-6 - st.start;
if (secs < 1e-6)
@@ -72,9 +75,11 @@ summary(void)
if (st.trunc)
(void)fprintf(stderr, "%ju truncated %s\n",
st.trunc, (st.trunc == 1) ? "block" : "blocks");
- (void)fprintf(stderr,
- "%ju bytes transferred in %.6f secs (%.0f bytes/sec)\n",
- st.bytes, secs, st.bytes / secs);
+ if (!(ddflags & C_NOXFER)) {
+ (void)fprintf(stderr,
+ "%ju bytes transferred in %.6f secs (%.0f bytes/sec)\n",
+ st.bytes, secs, st.bytes / secs);
+ }
need_summary = 0;
}
OpenPOWER on IntegriCloud