summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Dagnelie <pcd@delphix.com>2014-08-08 16:01:22 -0700
committerPrakash Surya <prakash.surya@delphix.com>2017-06-12 19:51:05 -0700
commit61304e4faaed38301307f7f985160d1843473587 (patch)
treeea4e0a9034ca7112b13d93a7612ff7349703b3a4
parentdd627ace5d331edb6342d966323629e57008b71f (diff)
downloadillumos-joyent-61304e4faaed38301307f7f985160d1843473587.tar.gz
8086 Add Stride parameter to dd
Reviewed by: Alex Reece <alex@delphix.com> Reviewed by: Basil Crow <basil.crow@delphix.com> Reviewed by: Robert Mustacchi <rm@joyent.com>
-rw-r--r--usr/src/cmd/dd/dd.c54
-rw-r--r--usr/src/man/man1m/dd.1m48
2 files changed, 86 insertions, 16 deletions
diff --git a/usr/src/cmd/dd/dd.c b/usr/src/cmd/dd/dd.c
index 30f027f85a..6589ba740b 100644
--- a/usr/src/cmd/dd/dd.c
+++ b/usr/src/cmd/dd/dd.c
@@ -25,6 +25,7 @@
* Use is subject to license terms.
* Copyright 2012, Josef 'Jeff' Sipek <jeffpc@31bits.net>. All rights reserved.
* Copyright (c) 2014, Joyent, Inc. All rights reserved.
+ * Copyright (c) 2014 by Delphix. All rights reserved.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
@@ -103,10 +104,10 @@
#define USAGE\
"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] [count=n] [conv=[ascii]\n"\
- " [,ebcdic][,ibm][,asciib][,ebcdicb][,ibmb]\n"\
- " [,block|unblock][,lcase|ucase][,swab]\n"\
- " [,noerror][,notrunc][,sync]]\n"\
+ " [iseek=n] [oseek=n] [seek=n] [stride=n] [istride=n]\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"
/* Global references */
@@ -148,6 +149,11 @@ static off_t oseekn; /* number of output records to seek past */
static unsigned long long count; /* number of input records to copy */
/* (0 = all) */
static boolean_t ecount; /* explicit count given */
+static off_t ostriden; /* number of output blocks to skip between */
+ /* records */
+static off_t istriden; /* number of input blocks to skip between */
+ /* records */
+
static int trantype; /* BSD or SVr4 compatible EBCDIC */
static char *string; /* command arg pointer */
@@ -569,6 +575,21 @@ main(int argc, char **argv)
oseekn = number(BIG);
continue;
}
+ if (match("ostride="))
+ {
+ ostriden = ((off_t)number(BIG)) - 1;
+ continue;
+ }
+ if (match("istride="))
+ {
+ istriden = ((off_t)number(BIG)) - 1;
+ continue;
+ }
+ if (match("stride="))
+ {
+ istriden = ostriden = ((off_t)number(BIG)) - 1;
+ continue;
+ }
if (match("count="))
{
count = number(BIG);
@@ -720,6 +741,16 @@ main(int argc, char **argv)
gettext("buffer sizes cannot be zero"));
exit(2);
}
+ if (ostriden == (off_t)-1) {
+ (void) fprintf(stderr, "dd: %s\n",
+ gettext("stride must be greater than zero"));
+ exit(2);
+ }
+ if (istriden == (off_t)-1) {
+ (void) fprintf(stderr, "dd: %s\n",
+ gettext("stride must be greater than zero"));
+ exit(2);
+ }
if (conv == COPY)
{
if ((bs == 0) || (cflag&(LCASE|UCASE)))
@@ -1035,6 +1066,12 @@ main(int argc, char **argv)
ibc = read(ibf, (char *)ibuf, ibs);
+ if (istriden > 0 && lseek(ibf, istriden * ((off_t)ibs),
+ SEEK_CUR) == -1) {
+ perror("lseek");
+ exit(2);
+ }
+
/* Process input errors */
if (ibc == (unsigned)-1)
@@ -1804,7 +1841,7 @@ long long big;
/* Flush the output buffer, move any excess bytes down to the beginning */
/* */
/* Arg: none */
-/* Global args: obuf, obc, obs, nofr, nopr */
+/* Global args: obuf, obc, obs, nofr, nopr, ostriden */
/* */
/* Return: Pointer to the first free byte in the output buffer. */
/* Also reset `obc' to account for moved bytes. */
@@ -1839,6 +1876,13 @@ static unsigned char
"wrote %d bytes, expected %d\n"), bc, oc);
term(2);
}
+
+ if (ostriden > 0 && lseek(obf, ostriden * ((off_t)obs),
+ SEEK_CUR) == -1) {
+ perror("lseek");
+ exit(2);
+ }
+
obc -= oc;
op = obuf;
obytes += bc;
diff --git a/usr/src/man/man1m/dd.1m b/usr/src/man/man1m/dd.1m
index a9b8e18a60..8ae530e285 100644
--- a/usr/src/man/man1m/dd.1m
+++ b/usr/src/man/man1m/dd.1m
@@ -1,5 +1,6 @@
'\" te
.\" Copyright (c) 2014, Joyent, Inc. All rights Reserved.
+.\" Copyright (c) 2014 by Delphix. All rights reserved.
.\" Copyright (c) 1992, X/Open Company Limited All Rights Reserved
.\" Copyright 1989 AT&T
.\" Portions Copyright (c) 1995, Sun Microsystems, Inc. All Rights Reserved
@@ -10,7 +11,7 @@
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
-.TH DD 1M "Jan 04, 2014"
+.TH DD 1M "Dec 12, 2014"
.SH NAME
dd \- convert and copy a file
.SH SYNOPSIS
@@ -20,7 +21,6 @@ dd \- convert and copy a file
.fi
.SH DESCRIPTION
-.sp
.LP
The \fBdd\fR utility copies the specified input file to the specified output
with possible conversions. The standard input and output are used by default.
@@ -54,7 +54,6 @@ character set without changing the input file's block structure. The
After completion, \fBdd\fR reports the number of whole and partial input and
output blocks.
.SH OPERANDS
-.sp
.LP
The following operands are supported:
.sp
@@ -200,6 +199,41 @@ offset or reads the blocks as described for non-seekable files.
.sp
.ne 2
.na
+\fB\fBostride=\fR\fIn\fR\fR
+.ad
+.sp .6
+.RS 4n
+Writes every \fIn\fRth block (using the specified output block size) when
+writing output. Skips \fIn\fR - 1 blocks after writing each record.
+.RE
+
+.sp
+.ne 2
+.na
+\fB\fBistride=\fR\fIn\fR\fR
+.ad
+.sp .6
+.RS 4n
+Reads every \fIn\fRth block (using the specified input block size) when
+reading input. Skips \fIn\fR - 1 blocks after reading each record.
+.RE
+
+.sp
+.ne 2
+.na
+\fB\fBstride=\fR\fIn\fR\fR
+.ad
+.sp .6
+.RS 4n
+Reads every \fIn\fRth block (using the specified input block size) when
+reading input. Skips \fIn\fR - 1 blocks after reading each record. Also
+writes every \fIn\fRth block (using the specified output block size) when
+writing output. Skips \fIn\fR - 1 blocks after writing each record.
+.RE
+
+.sp
+.ne 2
+.na
\fB\fBcount=\fR\fIn\fR\fR
.ad
.sp .6
@@ -482,7 +516,6 @@ separated by \fBx\fR, specifying the product of the indicated values.
.LP
All of the operands will be processed before any input is read.
.SH SIGNALS
-.sp
.LP
When \fBdd\fR receives either SIGINFO or SIGUSR1, \fBdd\fR will emit the current
input and output block counts, total bytes written, total time elapsed, and the
@@ -496,7 +529,6 @@ For \fBSIGINT\fR, \fBdd\fR writes status information to standard error before
exiting. \fBdd\fR takes the standard action for all other signals.
.SH USAGE
-.sp
.LP
See \fBlargefile\fR(5) for the description of the behavior of \fBdd\fR when
encountering files greater than or equal to 2 Gbyte ( 2^31 bytes).
@@ -560,13 +592,11 @@ example% \fBtar cvf - . | compress | dd obs=1024k of=/dev/rmt/0 conv=sync\fR
.sp
.SH ENVIRONMENT VARIABLES
-.sp
.LP
See \fBenviron\fR(5) for descriptions of the following environment variables
that affect the execution of \fBdd\fR: \fBLANG\fR, \fBLC_ALL\fR,
\fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
.SH EXIT STATUS
-.sp
.LP
The following exit values are returned:
.sp
@@ -595,7 +625,6 @@ diagnostic message will be written, and the copy operation will be
discontinued. If some other error is detected, a diagnostic message will be
written and the copy operation will be discontinued.
.SH ATTRIBUTES
-.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp
@@ -611,12 +640,10 @@ Interface Stability Standard
.TE
.SH SEE ALSO
-.sp
.LP
\fBcp\fR(1), \fBsed\fR(1), \fBtr\fR(1), \fBfcntl.h\fR(3HEAD),
\fBattributes\fR(5), \fBenviron\fR(5), \fBlargefile\fR(5), \fBstandards\fR(5)
.SH DIAGNOSTICS
-.sp
.ne 2
.na
\fB\fBf+p records in(out)\fR\fR
@@ -626,7 +653,6 @@ numbers of full and partial blocks read(written)
.RE
.SH NOTES
-.sp
.LP
Do not use \fBdd\fR to copy files between file systems having different block
sizes.