[PATCH] copy_file_range: New function to copy file data

Florian Weimer fweimer@redhat.com
Thu Nov 23 15:23:00 GMT 2017


On 11/23/2017 04:13 PM, Andreas Schwab wrote:
> On Nov 17 2017, fweimer@redhat.com (Florian Weimer) wrote:
> 
>> +COPY_FILE_RANGE_DECL
>> +ssize_t
>> +COPY_FILE_RANGE (int infd, __off64_t *pinoff,
>> +                 int outfd, __off64_t *poutoff,
>> +                 size_t length, unsigned int flags)
>> +{
>> +  if (flags != 0)
>> +    {
>> +      __set_errno (EINVAL);
>> +      return -1;
>> +    }
>> +
>> +  struct stat64 instat;
>> +  struct stat64 outstat;
>> +  if (fstat64 (infd, &instat) != 0 || fstat64 (outfd, &outstat))
> 
> != 0

Thanks, fixed.

>> +      /* Write the buffer part which was read to the destination.  */
>> +      char *end = buf + read_count;
>> +      for (char *p = buf; p < end; )
>> +        {
>> +          ssize_t write_count;
>> +          if (poutoff == NULL)
>> +            write_count = write (outfd, p, end - p);
>> +          else
>> +            write_count = __libc_pwrite64 (outfd, p, end - p, *poutoff);
>> +          if (write_count == 0)
>> +            {
>> +              /* Assume that this means no space on the target file
>> +                 system, and use the error handling path below.  */
> 
> I don't think write can ever return 0 when writing more than zero bytes.

I can drop the check.  With the Linux VFS layer, it is difficult to tell 
whether this condition can ever happen, and if it does, we would likely 
enter an infinite loop without the check.

Thanks,
Florian



More information about the Libc-alpha mailing list