Skip to content

Commit 140eca1

Browse files
jeremy-compostellapixelb
authored andcommitted
dd: add count_bytes, skip_bytes and seek_bytes flags
dd now accepts the count_bytes and skip_bytes input flag and the seek_bytes output flag, to more easily allow processing portions of a file. * src/dd.c (scanargs): Compute skip_records and skip_bytes when 'skip_bytes' iflag is used. Compute max_records and max_bytes when 'count_bytes' iflag is used. Compute seek_records and seek_bytes when 'seek_bytes' oflag is used. (skip_via_lseek): Use new 'bytes' parameter and handle potential 'records' equals to zero. Update the bytes parameter when called with 'fdesc' equal to STDOUT_FILENO. Update the header comments. (dd_copy): Skip accordingly to skip_records AND skip_bytes. Count accordingly to max_records AND max_bytes. Seek on output accordingly to seek_records AND seek_bytes. * NEWS (New features): Mention it. * doc/coreutils.texi (dd invocation): Detail new flags and behaviors. * tests/dd/bytes: New file. Tests for these new flags. * tests/Makefile.am (TESTS): Add it.
1 parent da2b32e commit 140eca1

File tree

5 files changed

+253
-64
lines changed

5 files changed

+253
-64
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ GNU coreutils NEWS -*- outline -*-
22

33
* Noteworthy changes in release ?.? (????-??-??) [?]
44

5+
** New features
6+
7+
dd now accepts the count_bytes, skip_bytes iflags and the count_bytes
8+
oflag, to more easily allow processing portions of a file.
9+
510
** Bug fixes
611

712
mv now lets you move a symlink onto a same-inode destination file that

doc/coreutils.texi

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8057,18 +8057,24 @@ When converting variable-length records to fixed-length ones
80578057
(@option{conv=block}) or the reverse (@option{conv=unblock}),
80588058
use @var{bytes} as the fixed record length.
80598059

8060-
@item skip=@var{blocks}
8060+
@item skip=@var{n}
80618061
@opindex skip
8062-
Skip @var{blocks} @samp{ibs}-byte blocks in the input file before copying.
8062+
Skip @var{n} @samp{ibs}-byte blocks in the input file before copying.
8063+
If @samp{iflag=skip_bytes} is specified, @var{n} is interpreted
8064+
as a byte count rather than a block count.
80638065

8064-
@item seek=@var{blocks}
8066+
@item seek=@var{n}
80658067
@opindex seek
8066-
Skip @var{blocks} @samp{obs}-byte blocks in the output file before copying.
8068+
Skip @var{n} @samp{obs}-byte blocks in the output file before copying.
8069+
if @samp{oflag=seek_bytes} is specified, @var{n} is interpreted
8070+
as a byte count rather than a block count.
80678071

8068-
@item count=@var{blocks}
8072+
@item count=@var{n}
80698073
@opindex count
8070-
Copy @var{blocks} @samp{ibs}-byte blocks from the input file, instead
8074+
Copy @var{n} @samp{ibs}-byte blocks from the input file, instead
80718075
of everything until the end of the file.
8076+
if @samp{iflag=count_bytes} is specified, @var{n} is interpreted
8077+
as a byte count rather than a block count.
80728078

80738079
@item status=noxfer
80748080
@opindex status
@@ -8321,6 +8327,27 @@ When that happens, continue calling @code{read} to fill the remainder
83218327
of the block.
83228328
This flag can be used only with @code{iflag}.
83238329

8330+
@item count_bytes
8331+
@opindex count_bytes
8332+
Interpret the @samp{count=} operand as a byte count,
8333+
rather than a block count, which allows specifying
8334+
a length that is not a multiple of the I/O block size.
8335+
This flag can be used only with @code{iflag}.
8336+
8337+
@item skip_bytes
8338+
@opindex skip_bytes
8339+
Interpret the @samp{skip=} operand as a byte count,
8340+
rather than a block count, which allows specifying
8341+
an offset that is not a multiple of the I/O block size.
8342+
This flag can be used only with @code{iflag}.
8343+
8344+
@item seek_bytes
8345+
@opindex seek_bytes
8346+
Interpret the @samp{seek=} operand as a byte count,
8347+
rather than a block count, which allows specifying
8348+
an offset that is not a multiple of the I/O block size.
8349+
This flag can be used only with @code{oflag}.
8350+
83248351
@end table
83258352

83268353
These flags are not supported on all systems, and @samp{dd} rejects
@@ -8343,10 +8370,13 @@ should not be too large---values larger than a few megabytes
83438370
are generally wasteful or (as in the gigabyte..exabyte case) downright
83448371
counterproductive or error-inducing.
83458372

8346-
Use different @command{dd} invocations to use different block sizes for
8347-
skipping and I/O@. For example, the following shell commands copy data
8348-
in 512 KiB blocks between a disk and a tape, but do not save or restore a
8349-
4 KiB label at the start of the disk:
8373+
To process data that is at an offset or size that is not a
8374+
multiple of the I/O@ block size, you can use the @samp{skip_bytes},
8375+
@samp{seek_bytes} and @samp{count_bytes} flags. Alternatively
8376+
the traditional method of separate @command{dd} invocations can be used.
8377+
For example, the following shell commands copy data
8378+
in 512 KiB blocks between a disk and a tape, but do not save
8379+
or restore a 4 KiB label at the start of the disk:
83508380

83518381
@example
83528382
disk=/dev/rdsk/c0t1d0s2

0 commit comments

Comments
 (0)