cli/dd: Fix size=, status=, oflag=append, pipe and character device inputs #94

Closed
koolkhel wants to merge 8 commits from koolkhel:cli-dd into master

8 Commits

Author SHA1 Message Date
Arsenii Ermilov
34b09af052 cli/dd: Free the skip buffer when reading the input fails
skip_read() returned on a read error or EOF without freeing the buffer
it allocated, leaking it once per failed dd.
2026-10-25 16:14:06 +03:00
891f7552d1 cli/dd: Read a character device input like a pipe
A character device reports st_size 0, so one that supports lseek (e.g.
/dev/mem or an MTD device) was taken as an empty seekable input and dd
always failed with "Input seek position is beyond end of input". Treat
every character device input as non-seekable with unknown size and read
it up to count=, size= or its end. /dev/zero and /dev/urandom don't
seek and were already read this way.
2026-10-20 10:49:38 +03:00
25ecb001aa cli/dd: Check write alignment before creating the output image
The "Unaligned write to Vitastor is not supported" check ran after the
output image was created or resized, so a seek= or bs= not aligned to
the pool's bitmap granularity failed with EINVAL but left a new or
resized image behind. Check it as soon as the granularity is known.
2026-10-20 10:44:24 +03:00
d4d227a838 cli/dd: Copy a pipe input to its end when no count= or size= is given
With a non-seekable input and no count= or size=, read_end stayed 0, or
was capped at zero bytes by out_size defaulting to seek=, so dd stopped
after the first block: "cat file | vitastor-cli dd of=copy" copied 1 MB
and exited 0. Leave read_end unlimited then and default out_size only
when the input length is known. A new or truncated image still needs
size=; conv=trunc on a file still truncates it at the seek offset.
2026-10-20 10:42:25 +03:00
0618b22013 cli/dd: Fix oflag=append
oflag=append replaced O_RDWR with O_APPEND, so the output file was
opened read-only and every write failed with EBADF. Open it with
O_WRONLY|O_APPEND. An appending output is not seekable, which also
skipped the final fsync: skip it only for outputs that can't be synced
(anything but regular files and block devices). Refuse conv=trunc with
oflag=append, the two contradict each other.
2026-10-20 10:41:27 +03:00
c040b3f98b cli/dd: Implement status=noxfer
status=noxfer is listed in the help, but dd ignored it. Make it drop
the final transfer statistics like in GNU dd. The progress line still
follows --progress and, if it was shown, is cleared at the end instead
of being replaced by the statistics. --json still returns them.
2026-10-20 10:40:37 +03:00
1c0cc44e32 cli/dd: Make status=none also suppress the progress output
status=none only dropped the final statistics when --progress 0 was
also given; with the default --progress 1 dd still printed the progress
line and the statistics. Turn progress off with status=none, so only
errors are printed, like in GNU dd. --json still returns the result.
2026-10-20 10:39:28 +03:00
6326a796ee cli/dd: Detect input size also when size= is given
size= turned input size detection off, so dd from an image, a file or a
block device with size= always failed with "Input seek position is
beyond end of input", after the output image was already created or
resized. Always detect the input size: size= only sets the output size.
Also check the input seek position before opening the output.
2026-10-20 10:37:47 +03:00