summaryrefslogtreecommitdiff
path: root/usr/src/cmd/dd/dd.c
diff options
context:
space:
mode:
authorJerry Jelinek <jerry.jelinek@joyent.com>2019-05-09 11:36:25 +0000
committerJerry Jelinek <jerry.jelinek@joyent.com>2019-05-09 11:36:25 +0000
commit7206b5f287f083164b3183f08c59d976a894284f (patch)
tree19a0fd8fb67e78f68c90097192b4d9533a9f710c /usr/src/cmd/dd/dd.c
parent7847a0def2f92ff8670c7d008f9caae2b2585752 (diff)
parentd0e58ef5d66890a3cd67c9c6eb8c823f9865a70f (diff)
downloadillumos-joyent-7206b5f287f083164b3183f08c59d976a894284f.tar.gz
[illumos-gate merge]
commit d0e58ef5d66890a3cd67c9c6eb8c823f9865a70f 10896 Want support for AMD Zen CPC events commit c18e9bc303e04175d63c5c51206b2ce6f6efe6a4 10895 Update cpcgen tools and data for Cascade Lake commit 8095452365aae38329650734a6846e8886ac4d48 10912 loader: validate sectorsize argument in disk_open() commit c232df923d558b3a28acd1911d7f0ee5952f7bbe 10911 dd: add input flag fullblock commit 083aabdd02fbac3a467d358cbd26fbb44174e385 10905 loader.efi: uninitialized symbol 'ret' commit 4188fb37741cc73b35fdd065a2c20fc9054d7f49 10860 mdb: update mbr to print vbr and add vtoc command commit c28006dedbb1a63ed6cd12fc2ec1c2be15b425d1 10838 loader: bcache.c cstyle cleanup Conflicts: usr/src/uts/intel/sys/x86_archext.h usr/src/uts/i86pc/os/cpuid.c usr/src/data/Makefile
Diffstat (limited to 'usr/src/cmd/dd/dd.c')
-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) {