From 4bd44556863ad07f3890496245497d9fc0348da6 Mon Sep 17 00:00:00 2001 From: Mike Karels Date: Tue, 12 Dec 1989 19:13:07 -0800 Subject: [PATCH] fix noerror, sync SCCS-vsn: bin/dd/dd.c 4.7 --- usr/src/bin/dd/dd.c | 96 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 84 insertions(+), 12 deletions(-) diff --git a/usr/src/bin/dd/dd.c b/usr/src/bin/dd/dd.c index 9c34764b04..89709de17e 100644 --- a/usr/src/bin/dd/dd.c +++ b/usr/src/bin/dd/dd.c @@ -2,7 +2,11 @@ static char *sccsid = "@(#)dd.c 4.7 (Berkeley) %G%"; #endif +#include #include +#include +#include +#include #include #include @@ -144,6 +148,8 @@ char atoibm[] = 0356,0357,0372,0373,0374,0375,0376,0377, }; +enum ftype { unknown, reg, chr, tape, pipe } iftype; +enum ftype checktype(); main(argc, argv) int argc; @@ -258,6 +264,7 @@ char **argv; perror(ifile); exit(1); } + iftype = checktype(ibf); obf = ofile ? open(ofile, O_WRONLY|O_CREAT, 0666) : dup(1); if(obf < 0) { fprintf(stderr,"cannot create: %s\n", ofile); @@ -289,22 +296,45 @@ char **argv; if (signal(SIGINT, SIG_IGN) != SIG_IGN) signal(SIGINT, term); - while(skip) { - read(ibf, ibuf, ibs); - skip--; + if (skip) + switch (iftype) { + case tape: { + struct mtop op; + + op.mt_op = MTFSR; + op.mt_count = skip; + if (ioctl(ibf, MTIOCTOP, (char *)&op) < 0) + perror("dd: skip: tape forward-space-record"); + } + break; + case reg: + lseek(ibf, skip*ibs, L_INCR); + break; + default: + while (skip--) + read(ibf, ibuf, ibs); + break; } - while(seekn) { - lseek(obf, (long)obs, 1); - seekn--; + if (seekn) + switch (checktype(obf)) { + case reg: + lseek(obf, (long)obs*seekn, L_INCR); + break; + case pipe: + fprintf(stderr, "dd: can't seek on pipe\n"); + break; + default: + while (seekn--) + lseek(obf, (long)obs, L_INCR); + break; } loop: if(ibc-- == 0) { ibc = 0; if(count==0 || nifr+nipr!=count) { - if(cflag&(NERR|SYNC)) - for(ip=ibuf+ibs; ip>ibuf;) - *--ip = 0; + if (cflag&NERR) + bzero((char *)ibuf, ibs); ibc = read(ibf, ibuf, ibs); } if(ibc == -1) { @@ -313,20 +343,25 @@ loop: flsh(); term(); } - ibc = 0; + /* guess actual read size; default still -1 */ for(c=0; c