bug in rsync write-devices patch

Gardner, Ryan W. Ryan.Gardner at jhuapl.edu
Wed Apr 4 15:30:53 MDT 2012


All,

I tried using the write-devices patch from rsync-patches.  Thanks for creating it.  I hope that and copy-devices become part of mainline.


When I tried to copy from a regular file to a device, with a command like
   rsync -write-devices -inplace rsync://10.10.10.1/share/drive.img /dev/sdb3
I used to get a 'rsync: ftruncate failed on "/dev/sdb3": Invalid argument (22)' error.

The problem seems to be rooted in line 135 of write-devices.diff (from the rsync-patches repo).
Namely, I believe
   !IS_DEVICE(file->mode)
is checking the mode of the source file, not the destination, which is what it should check.  I wrote a hack to check if fd corresponds to a device instead (simple code changes below), which seemed to make things work although it should be coded more cleanly.  Thanks.

Ryan



Informal description of changes from receiver.c line 369:



Original code (after applying write-devices patch):

#ifdef HAVE_TRUNCATE
                If((inplace
#ifdef PREALLOCATE_NEEDS_TRUNCATE
|| preallocated_len > offset
#endif
                ) && fd != -1 && !IS_DEVICE(file->mode) && do_ftruncate(fd, offset) < 0) {




Code after change:

#ifdef HAVE_TRUNCATE
{
                STRUCT_STAT st;
                Do_fstat(fd, &st);
                If((inplace
#ifdef PREALLOCATE_NEEDS_TRUNCATE
|| preallocated_len > offset
#endif
                ) && fd != -1 && !IS_DEVICE(st.st_mode) && do_ftruncate(fd, offset) < 0) {


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.samba.org/pipermail/rsync/attachments/20120404/de9b59fe/attachment.html>


More information about the rsync mailing list