coreutils
[Top][All Lists]
Advanced

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

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


From: Pádraig Brady
Subject: Re: [PATCH] dd: don't discard data with if=fullblock
Date: Sat, 05 Mar 2011 01:57:31 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3

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

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