From 1768fdc5f78a46d653b57807d1eff73d3d665061 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Sat, 21 Nov 2026 10:09:04 +0300 Subject: [PATCH] cli/dd: Write an O_APPEND stdout in order With no of=, dd has treated a regular-file stdout as seekable since 0f98db3a and writes it with positional writes. On a shell's >> the kernel appends every positional write, so with iodepth > 1 (4 by default) the blocks landed in their completion order: the file got the right size and scrambled content, and dd exited with 0. Treat an O_APPEND stdout like oflag=append. --- src/cmd/cli_dd.cpp | 2 ++ tests/test_dd.sh | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/src/cmd/cli_dd.cpp b/src/cmd/cli_dd.cpp index 64b9eff8..7f40857c 100644 --- a/src/cmd/cli_dd.cpp +++ b/src/cmd/cli_dd.cpp @@ -308,6 +308,8 @@ resume_2: else { ofd = 1; + // positional writes to an O_APPEND stdout (shell >>) still go to its end + out_append = out_append || (fcntl(ofd, F_GETFL) & O_APPEND); } out_seekable = false; if (!out_append && lseek(ofd, 1, SEEK_SET) == (off_t)1) diff --git a/tests/test_dd.sh b/tests/test_dd.sh index 0cb4d08c..ca81ef55 100755 --- a/tests/test_dd.sh +++ b/tests/test_dd.sh @@ -94,6 +94,11 @@ if [[ -c /dev/net/tun && -r /dev/net/tun ]]; then else echo "SKIP: dd conv=noerror with a failing stream - /dev/net/tun is missing or not readable here" fi +# stdout opened with O_APPEND (>>) is written in order, also with iodepth > 1 +cp ./testdata/over ./testdata/testfile1 +$VITASTOR_CLI dd iimg=testimg bs=64k iodepth=16 count=160 >> ./testdata/testfile1 +(cat ./testdata/over; head -c 10M ./testdata/testfile) | cmp - ./testdata/testfile1 || format_error "dd to an O_APPEND stdout misplaced the blocks" +rm ./testdata/testfile1 # pipe in without count - copy to the end of input $VITASTOR_CLI dd iimg=testimg iodepth=4 | $VITASTOR_CLI dd of=./testdata/testfile1 iodepth=4 -- 2.47.3