From 6ad981900cc170258d4914197e2796fc94a37863 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 21 Feb 2022 11:23:02 -0800 Subject: [PATCH 1/2] dd: support iseek= and oseek= Alias iseek=N to skip=N, oseek=N to seek=N (Bug#45648). * src/dd.c (scanargs): Parse iseek= and oseek=. * tests/dd/skip-seek.pl (sk-seek5): New test case. --- NEWS | 3 +++ doc/coreutils.texi | 16 ++++++++++------ src/dd.c | 8 ++++---- tests/dd/skip-seek.pl | 10 ++++++++++ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index ef65b4ab8..de03f0d47 100644 --- a/NEWS +++ b/NEWS @@ -57,6 +57,9 @@ GNU coreutils NEWS -*- outline -*- dd conv=fsync now synchronizes output even after a write error, and similarly for dd conv=fdatasync. + dd now supports the aliases iseek=N for skip=N, and oseek=N for seek=N, + like FreeBSD and other operating systems. + timeout --foreground --kill-after=... will now exit with status 137 if the kill signal was sent, which is consistent with the behavior when the --foreground option is not specified. This allows users to diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 8d2974bde..4ec998802 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -9189,8 +9189,7 @@ Read from @var{file} instead of standard input. @item of=@var{file} @opindex of Write to @var{file} instead of standard output. Unless -@samp{conv=notrunc} is given, @command{dd} truncates @var{file} to zero -bytes (or the size specified with @samp{seek=}). +@samp{conv=notrunc} is given, truncate @var{file} before writing it. @item ibs=@var{bytes} @opindex ibs @@ -9230,15 +9229,20 @@ When converting variable-length records to fixed-length ones use @var{bytes} as the fixed record length. @item skip=@var{n} +@itemx iseek=@var{n} @opindex skip +@opindex iseek Skip @var{n} @samp{ibs}-byte blocks in the input file before copying. If @samp{iflag=skip_bytes} is specified, @var{n} is interpreted as a byte count rather than a block count. @item seek=@var{n} +@itemx oseek=@var{n} @opindex seek -Skip @var{n} @samp{obs}-byte blocks in the output file before copying. -if @samp{oflag=seek_bytes} is specified, @var{n} is interpreted +@opindex oseek +Skip @var{n} @samp{obs}-byte blocks in the output file before +truncating or copying. +If @samp{oflag=seek_bytes} is specified, @var{n} is interpreted as a byte count rather than a block count. @item count=@var{n} @@ -9588,14 +9592,14 @@ This flag can be used only with @code{iflag}. @item skip_bytes @opindex skip_bytes -Interpret the @samp{skip=} operand as a byte count, +Interpret the @samp{skip=} or @samp{iseek=} operand as a byte count, rather than a block count, which allows specifying an offset that is not a multiple of the I/O block size. This flag can be used only with @code{iflag}. @item seek_bytes @opindex seek_bytes -Interpret the @samp{seek=} operand as a byte count, +Interpret the @samp{seek=} or @samp{oseek=} operand as a byte count, rather than a block count, which allows specifying an offset that is not a multiple of the I/O block size. This flag can be used only with @code{oflag}. diff --git a/src/dd.c b/src/dd.c index 7360a4973..1c30e414d 100644 --- a/src/dd.c +++ b/src/dd.c @@ -562,8 +562,8 @@ Copy a file, converting and formatting according to the operands.\n\ obs=BYTES write BYTES bytes at a time (default: 512)\n\ of=FILE write to FILE instead of stdout\n\ oflag=FLAGS write as per the comma separated symbol list\n\ - seek=N skip N obs-sized blocks at start of output\n\ - skip=N skip N ibs-sized blocks at start of input\n\ + seek=N (or oseek=N) skip N obs-sized output blocks\n\ + skip=N (or iseek=N) skip N ibs-sized input blocks\n\ status=LEVEL The LEVEL of information to print to stderr;\n\ 'none' suppresses everything but error messages,\n\ 'noxfer' suppresses the final transfer statistics,\n\ @@ -1564,9 +1564,9 @@ scanargs (int argc, char *const *argv) n_max = MIN (SIZE_MAX, IDX_MAX); converted_idx = &conversion_blocksize; } - else if (operand_is (name, "skip")) + else if (operand_is (name, "skip") || operand_is (name, "iseek")) skip = n; - else if (operand_is (name, "seek")) + else if (operand_is (name + (*name == 'o'), "seek")) seek = n; else if (operand_is (name, "count")) count = n; diff --git a/tests/dd/skip-seek.pl b/tests/dd/skip-seek.pl index 41639cc71..0fcb1cf25 100755 --- a/tests/dd/skip-seek.pl +++ b/tests/dd/skip-seek.pl @@ -68,6 +68,16 @@ my @Tests = {OUT=> "bc\n"}, {ERR=> "3+0 records in\n3+0 records out\n"}, ], + [ + # Check that iseek and oseek aliases work too. + 'sk-seek5', + qw (bs=1 iseek=1 oseek=2 conv=notrunc count=3 status=noxfer of=@AUX@ < ), + {IN=> '0123456789abcdef'}, + {AUX=> 'zyxwvutsrqponmlkji'}, + {OUT=> ''}, + {ERR=> "3+0 records in\n3+0 records out\n"}, + {CMP=> ['zy123utsrqponmlkji', {'@AUX@'=> undef}]}, + ], ); my $save_temps = $ENV{DEBUG}; -- 2.32.0