Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dd: pad partial record with spaces in some cases #3156

Merged
merged 1 commit into from
Mar 3, 2022

Conversation

jfinkels
Copy link
Collaborator

If conv=block,sync command-line arguments are given and there is at
least one partial record read from the input (for example, if the
length of the input is not divisible by the value of the ibs
argument), then output an extra block of cbs spaces.

For example, no extra spaces are printed in this example because the
input is of length 10, a multiple of ibs:

$ printf "012\nabcde\n" \
> | dd ibs=5 cbs=5 conv=block,sync status=noxfer \
> && echo $
012  abcde$
2+0 records in
0+1 records out

But in this example, 5 extra spaces are printed because the length of
the input is not a multiple of ibs:

$ printf "012\nabcdefg\n" \
> | dd ibs=5 cbs=5 conv=block,sync status=noxfer \
> && echo $
012  abcde     $
2+1 records in
0+1 records out
1 truncated record\n

The number of spaces printed is the size of the conversion block,
given by cbs.

(I came to this understanding of the program logic by reverse-engineering the output of GNU dd, so I may be wrong about it.)

tests/by-util/test_dd.rs Outdated Show resolved Hide resolved
@sylvestre
Copy link
Contributor

You have a conflict :) (probably caused by yourself :)

If `conv=block,sync` command-line arguments are given and there is at
least one partial record read from the input (for example, if the
length of the input is not divisible by the value of the `ibs`
argument), then output an extra block of `cbs` spaces.

For example, no extra spaces are printed in this example because the
input is of length 10, a multiple of `ibs`:

    $ printf "012\nabcde\n" \
    > | dd ibs=5 cbs=5 conv=block,sync status=noxfer \
    > && echo $
    012  abcde$
    2+0 records in
    0+1 records out

But in this example, 5 extra spaces are printed because the length of
the input is not a multiple of `ibs`:

    $ printf "012\nabcdefg\n" \
    > | dd ibs=5 cbs=5 conv=block,sync status=noxfer \
    > && echo $
    012  abcde     $
    2+1 records in
    0+1 records out
    1 truncated record

The number of spaces printed is the size of the conversion block,
given by `cbs`.
@sylvestre sylvestre merged commit 66e9956 into uutils:main Mar 3, 2022
@jfinkels jfinkels deleted the dd-cbs-blocks branch March 12, 2022 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants