svn commit: r264577 - stable/10/bin/dd

Xin LI delphij at FreeBSD.org
Thu Apr 17 00:31:21 UTC 2014


Author: delphij
Date: Thu Apr 17 00:31:20 2014
New Revision: 264577
URL: http://svnweb.freebsd.org/changeset/base/264577

Log:
  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

Modified:
  stable/10/bin/dd/args.c
  stable/10/bin/dd/dd.1
  stable/10/bin/dd/dd.h
  stable/10/bin/dd/misc.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/bin/dd/args.c
==============================================================================
--- stable/10/bin/dd/args.c	Thu Apr 17 00:31:02 2014	(r264576)
+++ stable/10/bin/dd/args.c	Thu Apr 17 00:31:20 2014	(r264577)
@@ -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;

Modified: stable/10/bin/dd/dd.1
==============================================================================
--- stable/10/bin/dd/dd.1	Thu Apr 17 00:31:02 2014	(r264576)
+++ stable/10/bin/dd/dd.1	Thu Apr 17 00:31:20 2014	(r264577)
@@ -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 discar
 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 
 standard.
 The
 .Cm files
-operand and the
+and
+.Cm status
+operands and the
 .Cm ascii ,
 .Cm ebcdic ,
 .Cm ibm ,

Modified: stable/10/bin/dd/dd.h
==============================================================================
--- stable/10/bin/dd/dd.h	Thu Apr 17 00:31:02 2014	(r264576)
+++ stable/10/bin/dd/dd.h	Thu Apr 17 00:31:20 2014	(r264577)
@@ -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)

Modified: stable/10/bin/dd/misc.c
==============================================================================
--- stable/10/bin/dd/misc.c	Thu Apr 17 00:31:02 2014	(r264576)
+++ stable/10/bin/dd/misc.c	Thu Apr 17 00:31:20 2014	(r264577)
@@ -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;
 }
 


More information about the svn-src-all mailing list