]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
dd: fix error detection with "nocache" flag
authorFrédéric Yhuel <frederic.yhuel@dalibo.com>
Sun, 9 Mar 2025 19:12:14 +0000 (19:12 +0000)
committerPádraig Brady <P@draigBrady.com>
Mon, 10 Mar 2025 12:32:08 +0000 (12:32 +0000)
* NEWS: Mention the bug fix.
* src/dd.c (invalidate_cache): Adjust to the unusual
error propagation sematics of posix_fadvise().

NEWS
src/dd.c

diff --git a/NEWS b/NEWS
index 8d82bc3525e37f024cc6cda93dc5e8780722fd93..902bdaf0e35ddb69e04a2d8d4f432a2af7263678 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   'cksum -a crc' misbehaved on aarch64 with 32-bit uint_fast32_t.
   [bug introduced in coreutils-9.6]
 
+  dd with the 'nocache' flag will now detect all failures to drop the
+  cache for the whole file.  Previously it may have erroneously succeeded.
+  [bug introduced with the "nocache" feature in coreutils-8.11]
+
   'ls -Z dir' would crash.
   [bug introduced in coreutils-9.6]
 
index 4e914336b901c5a777478ccba82666f6cd1cf3be..d549105169fcb1b2dba1cc8096e6ff48074d50df 100644 (file)
--- a/src/dd.c
+++ b/src/dd.c
@@ -1027,7 +1027,8 @@ cache_round (int fd, off_t len)
 
 /* Discard the cache from the current offset of either
    STDIN_FILENO or STDOUT_FILENO.
-   Return true on success.  */
+   Return true on success.
+   Return false on failure, with errno set.  */
 
 static bool
 invalidate_cache (int fd, off_t len)
@@ -1087,12 +1088,13 @@ invalidate_cache (int fd, off_t len)
      if (clen == 0)
        offset -= offset % page_size;
      adv_ret = posix_fadvise (fd, offset, clen, POSIX_FADV_DONTNEED);
+     errno = adv_ret;
 #else
      errno = ENOTSUP;
 #endif
    }
 
-  return adv_ret != -1 ? true : false;
+  return adv_ret == 0;
 }
 
 /* Read from FD into the buffer BUF of size SIZE, processing any