On 28/02/11 09:28, Pádraig Brady wrote:
> 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;

Hmm, this issue is largely theoretical as we won't
be getting short reads from files in the first place
where we could get EIO.

I'll leave this for the moment

Reply via email to