On 2025-12-24 08:08, Collin Funk wrote:
Pádraig Brady<[email protected]> writes:
I wonder do we want to do the dd_copy() though if the ftruncate failed,
as we'd be copying data at the wrong offset then?

Perhaps instead we might want:

   if (! exit_status)
     exit_status = dd_copy ();
Paul, what do you think?

Based on your commit message it seems like you wanted to do the copy as
long as we have the file open [1]?

Collin

[1]https://github.com/coreutils/coreutils/ commit/50e438972b8f6e4c7486c38beb542539de0298c7

As I recall, [1] merely is about doing a fsync of whatever we've already written, even if there was an error after we wrote it. The idea is that the fsync is not *further* copying; it's merely ensuring that the *previous* copying is fsynced.

ftruncate, on the other hand, is *further* copying, so if it fails then (as POSIX requires[1]) there should be no further attempt at copying, and a diagnostic should be written and the exit status should be nonzero.

[1]: https://pubs.opengroup.org/onlinepubs/9799919799/utilities/dd.html#tag_20_31_15

Reply via email to