Author: delphij
Date: Thu Apr 17 00:34:49 2014
New Revision: 264579
URL: http://svnweb.freebsd.org/changeset/base/264579

Log:
  MFC all recent changes on -HEAD to dd(1).

Modified:
  stable/9/bin/dd/args.c
  stable/9/bin/dd/conv_tab.c
  stable/9/bin/dd/dd.1
  stable/9/bin/dd/dd.c
  stable/9/bin/dd/dd.h
  stable/9/bin/dd/extern.h
  stable/9/bin/dd/misc.c
  stable/9/bin/dd/position.c
Directory Properties:
  stable/9/bin/dd/   (props changed)

Modified: stable/9/bin/dd/args.c
==============================================================================
--- stable/9/bin/dd/args.c      Thu Apr 17 00:31:54 2014        (r264578)
+++ stable/9/bin/dd/args.c      Thu Apr 17 00:34:49 2014        (r264579)
@@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$");
 #include <errno.h>
 #include <inttypes.h>
 #include <limits.h>
+#include <signal.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -65,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 *);
 
@@ -87,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;
@@ -291,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/9/bin/dd/conv_tab.c
==============================================================================
--- stable/9/bin/dd/conv_tab.c  Thu Apr 17 00:31:54 2014        (r264578)
+++ stable/9/bin/dd/conv_tab.c  Thu Apr 17 00:34:49 2014        (r264579)
@@ -41,6 +41,12 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/types.h>
 
+#include <signal.h>
+#include <stdint.h>
+
+#include "dd.h"
+#include "extern.h"
+
 /*
  * There are currently six tables:
  *

Modified: stable/9/bin/dd/dd.1
==============================================================================
--- stable/9/bin/dd/dd.1        Thu Apr 17 00:31:54 2014        (r264578)
+++ stable/9/bin/dd/dd.1        Thu Apr 17 00:34:49 2014        (r264579)
@@ -32,7 +32,7 @@
 .\"     @(#)dd.1       8.2 (Berkeley) 1/13/94
 .\" $FreeBSD$
 .\"
-.Dd January 23, 2009
+.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
@@ -378,12 +389,12 @@ will exit.
 .Sh EXAMPLES
 Check that a disk drive contains no bad blocks:
 .Pp
-.Dl "dd if=/dev/ad0 of=/dev/null bs=1m"
+.Dl "dd if=/dev/ada0 of=/dev/null bs=1m"
 .Pp
 Do a refresh of a disk drive, in order to prevent presently
 recoverable read errors from progressing into unrecoverable read errors:
 .Pp
-.Dl "dd if=/dev/ad0 of=/dev/ad0 bs=1m"
+.Dl "dd if=/dev/ada0 of=/dev/ada0 bs=1m"
 .Pp
 Remove parity bit from a file:
 .Pp
@@ -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/9/bin/dd/dd.c
==============================================================================
--- stable/9/bin/dd/dd.c        Thu Apr 17 00:31:54 2014        (r264578)
+++ stable/9/bin/dd/dd.c        Thu Apr 17 00:34:49 2014        (r264579)
@@ -81,6 +81,7 @@ size_t        cbsz;                   /* conversion block 
size 
 uintmax_t files_cnt = 1;       /* # of files to copy */
 const  u_char *ctab;           /* conversion table */
 char   fill_char;              /* Character to fill with if defined */
+volatile sig_atomic_t need_summary;
 
 int
 main(int argc __unused, char *argv[])
@@ -89,7 +90,7 @@ main(int argc __unused, char *argv[])
        jcl(argv);
        setup();
 
-       (void)signal(SIGINFO, summaryx);
+       (void)signal(SIGINFO, siginfo_handler);
        (void)signal(SIGINT, terminate);
 
        atexit(summary);
@@ -98,6 +99,13 @@ main(int argc __unused, char *argv[])
                dd_in();
 
        dd_close();
+       /*
+        * Some devices such as cfi(4) may perform significant amounts
+        * of work when a write descriptor is closed.  Close the out
+        * descriptor explicitly so that the summary handler (called
+        * from an atexit() hook) includes this work.
+        */
+       close(out.fd);
        exit(0);
 }
 
@@ -232,8 +240,8 @@ setup(void)
                ctab = casetab;
        }
 
-       (void)gettimeofday(&tv, (struct timezone *)NULL);
-       st.start = tv.tv_sec + tv.tv_usec * 1e-6; 
+       (void)gettimeofday(&tv, NULL);
+       st.start = tv.tv_sec + tv.tv_usec * 1e-6;
 }
 
 static void
@@ -368,6 +376,9 @@ dd_in(void)
 
                in.dbp += in.dbrcnt;
                (*cfunc)();
+               if (need_summary) {
+                       summary();
+               }
        }
 }
 

Modified: stable/9/bin/dd/dd.h
==============================================================================
--- stable/9/bin/dd/dd.h        Thu Apr 17 00:31:54 2014        (r264578)
+++ stable/9/bin/dd/dd.h        Thu Apr 17 00:34:49 2014        (r264579)
@@ -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/9/bin/dd/extern.h
==============================================================================
--- stable/9/bin/dd/extern.h    Thu Apr 17 00:31:54 2014        (r264578)
+++ stable/9/bin/dd/extern.h    Thu Apr 17 00:34:49 2014        (r264579)
@@ -43,7 +43,7 @@ void jcl(char **);
 void pos_in(void);
 void pos_out(void);
 void summary(void);
-void summaryx(int);
+void siginfo_handler(int);
 void terminate(int);
 void unblock(void);
 void unblock_close(void);
@@ -61,3 +61,4 @@ extern const u_char e2a_32V[], e2a_POSIX
 extern const u_char a2ibm_32V[], a2ibm_POSIX[];
 extern u_char casetab[];
 extern char fill_char;
+extern volatile sig_atomic_t need_summary;

Modified: stable/9/bin/dd/misc.c
==============================================================================
--- stable/9/bin/dd/misc.c      Thu Apr 17 00:31:54 2014        (r264578)
+++ stable/9/bin/dd/misc.c      Thu Apr 17 00:34:49 2014        (r264579)
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
 
 #include <errno.h>
 #include <inttypes.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -57,41 +58,37 @@ summary(void)
 {
        struct timeval tv;
        double secs;
-       char buf[100];
 
-       (void)gettimeofday(&tv, (struct timezone *)NULL);
+       if (ddflags & C_NOINFO)
+               return;
+
+       (void)gettimeofday(&tv, NULL);
        secs = tv.tv_sec + tv.tv_usec * 1e-6 - st.start;
        if (secs < 1e-6)
                secs = 1e-6;
-       /* Use snprintf(3) so that we don't reenter stdio(3). */
-       (void)snprintf(buf, sizeof(buf),
+       (void)fprintf(stderr,
            "%ju+%ju records in\n%ju+%ju records out\n",
            st.in_full, st.in_part, st.out_full, st.out_part);
-       (void)write(STDERR_FILENO, buf, strlen(buf));
-       if (st.swab) {
-               (void)snprintf(buf, sizeof(buf), "%ju odd length swab %s\n",
+       if (st.swab)
+               (void)fprintf(stderr, "%ju odd length swab %s\n",
                     st.swab, (st.swab == 1) ? "block" : "blocks");
-               (void)write(STDERR_FILENO, buf, strlen(buf));
-       }
-       if (st.trunc) {
-               (void)snprintf(buf, sizeof(buf), "%ju truncated %s\n",
+       if (st.trunc)
+               (void)fprintf(stderr, "%ju truncated %s\n",
                     st.trunc, (st.trunc == 1) ? "block" : "blocks");
-               (void)write(STDERR_FILENO, buf, strlen(buf));
+       if (!(ddflags & C_NOXFER)) {
+               (void)fprintf(stderr,
+                   "%ju bytes transferred in %.6f secs (%.0f bytes/sec)\n",
+                   st.bytes, secs, st.bytes / secs);
        }
-       (void)snprintf(buf, sizeof(buf),
-           "%ju bytes transferred in %.6f secs (%.0f bytes/sec)\n",
-           st.bytes, secs, st.bytes / secs);
-       (void)write(STDERR_FILENO, buf, strlen(buf));
+       need_summary = 0;
 }
 
 /* ARGSUSED */
 void
-summaryx(int notused __unused)
+siginfo_handler(int signo __unused)
 {
-       int save_errno = errno;
 
-       summary();
-       errno = save_errno;
+       need_summary = 1;
 }
 
 /* ARGSUSED */

Modified: stable/9/bin/dd/position.c
==============================================================================
--- stable/9/bin/dd/position.c  Thu Apr 17 00:31:54 2014        (r264578)
+++ stable/9/bin/dd/position.c  Thu Apr 17 00:34:49 2014        (r264579)
@@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$");
 #include <err.h>
 #include <errno.h>
 #include <inttypes.h>
+#include <signal.h>
 #include <unistd.h>
 
 #include "dd.h"
@@ -91,6 +92,8 @@ pos_in(void)
                                }
                        } else
                                --cnt;
+                       if (need_summary)
+                               summary();
                        continue;
                }
 
_______________________________________________
svn-src-stable-9@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-stable-9
To unsubscribe, send any mail to "svn-src-stable-9-unsubscr...@freebsd.org"

Reply via email to