coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] dd: don't discard data with if=fullblock


From: Pádraig Brady
Subject: [PATCH] dd: don't discard data with if=fullblock
Date: Mon, 28 Feb 2011 09:28:59 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3

I just noticed that dd may discard read data
in the presence of I/O errors.
Would something like this suffice?

cheers,
Pádraig.

diff --git a/src/dd.c b/src/dd.c
index 1a0e177..a1d47ff 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -811,12 +811,28 @@ static ssize_t
 iread_fullblock (int fd, char *buf, size_t size)
 {
   ssize_t nread = 0;
+  static iread_errno;
+
+  /* Return a pending error.  */
+  if (iread_errno)
+    {
+      errno = iread_errno;
+      iread_errno = 0;
+      return -1;
+    }

   while (0 < size)
     {
       ssize_t ncurr = iread (fd, buf, size);
       if (ncurr < 0)
-        return ncurr;
+        {
+          if (nread > 0)
+            {
+              iread_errno = errno;
+              ncurr = nread;
+            }
+          return ncurr;
+        }
       if (ncurr == 0)
         break;
       nread += ncurr;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]