summaryrefslogtreecommitdiff
path: root/usr/src/cmd/dd
diff options
context:
space:
mode:
authorToomas Soome <tsoome@me.com>2019-05-03 21:58:10 +0300
committerToomas Soome <tsoome@me.com>2019-05-08 16:25:54 +0300
commitc232df923d558b3a28acd1911d7f0ee5952f7bbe (patch)
tree83a7a0272ffd2adf6393612331d321b0156e3472 /usr/src/cmd/dd
parent083aabdd02fbac3a467d358cbd26fbb44174e385 (diff)
downloadillumos-gate-c232df923d558b3a28acd1911d7f0ee5952f7bbe.tar.gz
10911 dd: add input flag fullblock
Reviewed by: Robert MusMustacchi <rm@joyent.com> Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src/cmd/dd')
-rw-r--r--usr/src/cmd/dd/dd.c50
1 files changed, 46 insertions, 4 deletions
diff --git a/usr/src/cmd/dd/dd.c b/usr/src/cmd/dd/dd.c
index 2cd372f604..3431548a91 100644
--- a/usr/src/cmd/dd/dd.c
+++ b/usr/src/cmd/dd/dd.c
@@ -98,6 +98,7 @@
#define SWAB 04 /* flag - swap bytes before conversion */
#define NERR 010 /* flag - proceed on input errors */
#define SYNC 020 /* flag - pad short input blocks with nulls */
+#define FULLBLOCK 040 /* flag - accumulate full blocks of input */
#define BADLIMIT 5 /* give up if no progress after BADLIMIT trys */
#define SVR4XLATE 0 /* use default EBCDIC translation */
#define BSDXLATE 1 /* use BSD-compatible EBCDIC translation */
@@ -106,10 +107,10 @@
"usage: dd [if=file] [of=file] [ibs=n|nk|nb|nxm] [obs=n|nk|nb|nxm]\n"\
" [bs=n|nk|nb|nxm] [cbs=n|nk|nb|nxm] [files=n] [skip=n]\n"\
" [iseek=n] [oseek=n] [seek=n] [stride=n] [istride=n]\n"\
- " [ostride=n] [count=n] [conv=[ascii] [,ebcdic][,ibm]\n"\
+ " [ostride=n] [count=n] [conv=[ascii][,ebcdic][,ibm]\n"\
" [,asciib][,ebcdicb][,ibmb][,block|unblock][,lcase|ucase]\n"\
" [,swab][,noerror][,notrunc][,sync]]\n"\
- " [oflag=[dsync][sync]]\n"
+ " [iflag=[fullblock]] [oflag=[dsync][sync]]\n"
/* Global references */
@@ -134,6 +135,7 @@ static unsigned cbc; /* number of bytes in the conversion buffer */
static int ibf; /* input file descriptor */
static int obf; /* output file descriptor */
static int cflag; /* conversion option flags */
+static int iflag; /* input flag options */
static int oflag; /* output flag options */
static int skipf; /* if skipf == 1, skip rest of input line */
static unsigned long long nifr; /* count of full input records */
@@ -486,6 +488,30 @@ siginfo_handler(int sig, siginfo_t *sip, void *ucp)
nstats = 1;
}
+static ssize_t
+iread(int fd, char *buf, size_t nbyte)
+{
+ ssize_t count;
+
+ count = 0;
+ while (nbyte != 0) {
+ ssize_t nr = read(fd, buf, nbyte);
+
+ if (nr < 0)
+ return (nr);
+
+ if (nr == 0)
+ break;
+ buf += nr;
+ count += nr;
+ nbyte -= nr;
+
+ if ((iflag & FULLBLOCK) == 0)
+ break;
+ }
+ return (count);
+}
+
int
main(int argc, char **argv)
{
@@ -664,6 +690,22 @@ main(int argc, char **argv)
}
continue;
}
+ if (match("iflag=")) {
+ for (;;) {
+ if (match(",")) {
+ continue;
+ }
+ if (*string == '\0') {
+ break;
+ }
+ if (match("fullblock")) {
+ iflag |= FULLBLOCK;
+ continue;
+ }
+ goto badarg;
+ }
+ continue;
+ }
if (match("oflag=")) {
for (;;) {
if (match(",")) {
@@ -919,7 +961,7 @@ main(int argc, char **argv)
/* Skip input blocks */
while (skip) {
- ibc = read(ibf, (char *)ibuf, ibs);
+ ibc = iread(ibf, (char *)ibuf, ibs);
if (ibc == (unsigned)-1) {
if (++nbad > BADLIMIT) {
(void) fprintf(stderr, "dd: %s\n",
@@ -994,7 +1036,7 @@ main(int argc, char **argv)
/* Read the next input block */
- ibc = read(ibf, (char *)ibuf, ibs);
+ ibc = iread(ibf, (char *)ibuf, ibs);
if (istriden > 0 && lseek(ibf, istriden * ((off_t)ibs),
SEEK_CUR) == -1) {