Print this page
10911 dd: add input flag fullblock

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/dd/dd.c
          +++ new/usr/src/cmd/dd/dd.c
↓ open down ↓ 90 lines elided ↑ open up ↑
  91   91  #define LCEBCDIC        23      /* convert ASCII to lower case blocked EBCDIC */
  92   92  #define UCEBCDIC        24      /* convert ASCII to upper case blocked EBCDIC */
  93   93  #define IBM             25      /* convert ASCII to blocked IBM */
  94   94  #define LCIBM           26      /* convert ASCII to lower case blocked IBM */
  95   95  #define UCIBM           27      /* convert ASCII to upper case blocked IBM */
  96   96  #define LCASE           01      /* flag - convert to lower case */
  97   97  #define UCASE           02      /* flag - convert to upper case */
  98   98  #define SWAB            04      /* flag - swap bytes before conversion */
  99   99  #define NERR            010     /* flag - proceed on input errors */
 100  100  #define SYNC            020     /* flag - pad short input blocks with nulls */
      101 +#define FULLBLOCK       040     /* flag - accumulate full blocks of input */
 101  102  #define BADLIMIT        5       /* give up if no progress after BADLIMIT trys */
 102  103  #define SVR4XLATE       0       /* use default EBCDIC translation */
 103  104  #define BSDXLATE        1       /* use BSD-compatible EBCDIC translation */
 104  105  
 105  106  #define USAGE\
 106  107          "usage: dd [if=file] [of=file] [ibs=n|nk|nb|nxm] [obs=n|nk|nb|nxm]\n"\
 107  108          "          [bs=n|nk|nb|nxm] [cbs=n|nk|nb|nxm] [files=n] [skip=n]\n"\
 108  109          "          [iseek=n] [oseek=n] [seek=n] [stride=n] [istride=n]\n"\
 109      -        "          [ostride=n] [count=n] [conv=[ascii] [,ebcdic][,ibm]\n"\
      110 +        "          [ostride=n] [count=n] [conv=[ascii][,ebcdic][,ibm]\n"\
 110  111          "          [,asciib][,ebcdicb][,ibmb][,block|unblock][,lcase|ucase]\n"\
 111  112          "          [,swab][,noerror][,notrunc][,sync]]\n"\
 112      -        "          [oflag=[dsync][sync]]\n"
      113 +        "          [iflag=[fullblock]] [oflag=[dsync][sync]]\n"
 113  114  
 114  115  /* Global references */
 115  116  
 116  117  /* Local routine declarations */
 117  118  
 118  119  static int      match(char *);
 119  120  static void             term();
 120  121  static unsigned long long       number();
 121  122  static unsigned char    *flsh();
 122  123  static void             stats();
↓ open down ↓ 4 lines elided ↑ open up ↑
 127  128  static unsigned obs;    /* output buffer size */
 128  129  static unsigned bs;     /* buffer size, overrules ibs and obs */
 129  130  static unsigned cbs;    /* conversion buffer size, used for block conversions */
 130  131  static unsigned ibc;    /* number of bytes still in the input buffer */
 131  132  static unsigned obc;    /* number of bytes in the output buffer */
 132  133  static unsigned cbc;    /* number of bytes in the conversion buffer */
 133  134  
 134  135  static int      ibf;    /* input file descriptor */
 135  136  static int      obf;    /* output file descriptor */
 136  137  static int      cflag;  /* conversion option flags */
      138 +static int      iflag;  /* input flag options */
 137  139  static int      oflag;  /* output flag options */
 138  140  static int      skipf;  /* if skipf == 1, skip rest of input line */
 139  141  static unsigned long long       nifr;   /* count of full input records */
 140  142  static unsigned long long       nipr;   /* count of partial input records */
 141  143  static unsigned long long       nofr;   /* count of full output records */
 142  144  static unsigned long long       nopr;   /* count of partial output records */
 143  145  static unsigned long long       ntrunc; /* count of truncated input lines */
 144  146  static unsigned long long       nbad;   /* count of bad records since last */
 145  147                                          /* good one */
 146  148  static int      files;  /* number of input files to concatenate (tape only) */
↓ open down ↓ 332 lines elided ↑ open up ↑
 479  481  static unsigned char *etoa = svr4_etoa;
 480  482  static unsigned char *atoibm = svr4_atoibm;
 481  483  
 482  484  /*ARGSUSED*/
 483  485  static void
 484  486  siginfo_handler(int sig, siginfo_t *sip, void *ucp)
 485  487  {
 486  488          nstats = 1;
 487  489  }
 488  490  
      491 +static ssize_t
      492 +iread(int fd, char *buf, size_t nbyte)
      493 +{
      494 +        ssize_t count;
      495 +
      496 +        count = 0;
      497 +        while (nbyte != 0) {
      498 +                ssize_t nr = read(fd, buf, nbyte);
      499 +
      500 +                if (nr < 0)
      501 +                        return (nr);
      502 +
      503 +                if (nr == 0)
      504 +                        break;
      505 +                buf += nr;
      506 +                count += nr;
      507 +                nbyte -= nr;
      508 +
      509 +                if ((iflag & FULLBLOCK) == 0)
      510 +                        break;
      511 +        }
      512 +        return (count);
      513 +}
      514 +
 489  515  int
 490  516  main(int argc, char **argv)
 491  517  {
 492  518          unsigned char *ip, *op; /* input and output buffer pointers */
 493  519          int c;          /* character counter */
 494  520          int ic;         /* input character */
 495  521          int conv;               /* conversion option code */
 496  522          int trunc;              /* whether output file is truncated */
 497  523          struct stat file_stat;
 498  524          struct sigaction sact;
↓ open down ↓ 158 lines elided ↑ open up ↑
 657  683                                          continue;
 658  684                                  }
 659  685                                  if (match("sync")) {
 660  686                                          cflag |= SYNC;
 661  687                                          continue;
 662  688                                  }
 663  689                                  goto badarg;
 664  690                          }
 665  691                          continue;
 666  692                  }
      693 +                if (match("iflag=")) {
      694 +                        for (;;) {
      695 +                                if (match(",")) {
      696 +                                        continue;
      697 +                                }
      698 +                                if (*string == '\0') {
      699 +                                        break;
      700 +                                }
      701 +                                if (match("fullblock")) {
      702 +                                        iflag |= FULLBLOCK;
      703 +                                        continue;
      704 +                                }
      705 +                                goto badarg;
      706 +                        }
      707 +                        continue;
      708 +                }
 667  709                  if (match("oflag=")) {
 668  710                          for (;;) {
 669  711                                  if (match(",")) {
 670  712                                          continue;
 671  713                                  }
 672  714                                  if (*string == '\0') {
 673  715                                          break;
 674  716                                  }
 675  717                                  if (match("dsync")) {
 676  718                                          oflag |= O_DSYNC;
↓ open down ↓ 235 lines elided ↑ open up ↑
 912  954          if (sigaction(SIGUSR1, &sact, NULL) != 0) {
 913  955                  (void) fprintf(stderr, "dd: %s: %s\n",
 914  956                      gettext("failed to enable sigusr1 handler"),
 915  957                      gettext(strerror(errno)));
 916  958                  exit(2);
 917  959          }
 918  960  
 919  961          /* Skip input blocks */
 920  962  
 921  963          while (skip) {
 922      -                ibc = read(ibf, (char *)ibuf, ibs);
      964 +                ibc = iread(ibf, (char *)ibuf, ibs);
 923  965                  if (ibc == (unsigned)-1) {
 924  966                          if (++nbad > BADLIMIT) {
 925  967                                  (void) fprintf(stderr, "dd: %s\n",
 926  968                                      gettext("skip failed"));
 927  969                                  exit(2);
 928  970                          } else {
 929  971                                  perror("read");
 930  972                          }
 931  973                  } else {
 932  974                          if (ibc == 0) {
↓ open down ↓ 54 lines elided ↑ open up ↑
 987 1029                                  {
 988 1030                                          do {    /* clear two at a time */
 989 1031                                                  *--ip = 0;
 990 1032                                                  *--ip = 0;
 991 1033                                          } while (--c);
 992 1034                                  }
 993 1035                          }
 994 1036  
 995 1037                          /* Read the next input block */
 996 1038  
 997      -                        ibc = read(ibf, (char *)ibuf, ibs);
     1039 +                        ibc = iread(ibf, (char *)ibuf, ibs);
 998 1040  
 999 1041                          if (istriden > 0 && lseek(ibf, istriden * ((off_t)ibs),
1000 1042                              SEEK_CUR) == -1) {
1001 1043                                  perror("lseek");
1002 1044                                  exit(2);
1003 1045                          }
1004 1046  
1005 1047                          /* Process input errors */
1006 1048  
1007 1049                          if (ibc == (unsigned)-1) {
↓ open down ↓ 796 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX