Changed the rdev code to have both an "rdev" variable (which always
[rsync/rsync.git] / flist.c
diff --git a/flist.c b/flist.c
index 245a7ef..69594cc 100644 (file)
--- a/flist.c
+++ b/flist.c
@@ -361,7 +361,7 @@ void send_file_entry(struct file_struct *file, int f, unsigned short base_flags)
        unsigned short flags;
        static time_t modtime;
        static mode_t mode;
-       static DEV64_T rdev;    /* just high bytes in p28 onward */
+       static DEV64_T rdev, rdev_high;
        static DEV64_T dev;
        static uid_t uid;
        static gid_t gid;
@@ -375,7 +375,7 @@ void send_file_entry(struct file_struct *file, int f, unsigned short base_flags)
        if (!file) {
                write_byte(f, 0);
                modtime = 0, mode = 0;
-               rdev = 0, dev = 0;
+               rdev = 0, rdev_high = 0, dev = 0;
                uid = 0, gid = 0;
                *lastname = '\0';
                return;
@@ -404,10 +404,12 @@ void send_file_entry(struct file_struct *file, int f, unsigned short base_flags)
                        } else
                                rdev = 0;
                } else if (IS_DEVICE(mode)) {
-                       if ((file->u.rdev & ~0xFF) == rdev)
+                       if ((file->u.rdev & ~0xFF) == rdev_high)
                                flags |= XMIT_SAME_HIGH_RDEV;
-                       else
-                               rdev = file->u.rdev & ~0xFF;
+                       else {
+                               rdev = file->u.rdev;
+                               rdev_high = rdev & ~0xFF;
+                       }
                }
        }
        if (file->uid == uid)
@@ -441,18 +443,22 @@ void send_file_entry(struct file_struct *file, int f, unsigned short base_flags)
        if (l2 > 255)
                flags |= XMIT_LONG_NAME;
 
-       /* We must make sure we don't send a zero flag-byte or
-        * the other end will terminate the flist transfer. */
-       if (!(flags & 0xFF) && !S_ISDIR(mode))
-               flags |= XMIT_TOP_DIR; /* NOTE: no meaning for non-dir */
+       /* We must make sure we don't send a zero flag byte or the
+        * other end will terminate the flist transfer.  Note that
+        * the use of XMIT_TOP_DIR on a non-dir has no meaning, so
+        * it's harmless way to add a bit to the first flag byte. */
        if (protocol_version >= 28) {
-               if ((flags & 0xFF00) || !(flags & 0xFF)) {
+               if (!flags && !S_ISDIR(mode))
+                       flags |= XMIT_TOP_DIR;
+               if ((flags & 0xFF00) || !flags) {
                        flags |= XMIT_EXTENDED_FLAGS;
                        write_byte(f, flags);
                        write_byte(f, flags >> 8);
                } else
                        write_byte(f, flags);
        } else {
+               if (!(flags & 0xFF) && !S_ISDIR(mode))
+                       flags |= XMIT_TOP_DIR;
                if (!(flags & 0xFF))
                        flags |= XMIT_LONG_NAME;
                write_byte(f, flags);
@@ -480,12 +486,11 @@ void send_file_entry(struct file_struct *file, int f, unsigned short base_flags)
        }
        if (preserve_devices && IS_DEVICE(mode)) {
                /* If XMIT_SAME_HIGH_RDEV is off, XMIT_SAME_RDEV_pre28 is
-                * also off.  Also, avoid using "rdev" because it may be
-                * incomplete. */
+                * also off. */
                if (!(flags & XMIT_SAME_HIGH_RDEV))
-                       write_int(f, file->u.rdev);
+                       write_int(f, rdev);
                else if (protocol_version >= 28)
-                       write_byte(f, file->u.rdev);
+                       write_byte(f, rdev);
        }
 
 #if SUPPORT_LINKS
@@ -537,7 +542,7 @@ void receive_file_entry(struct file_struct **fptr, unsigned short flags, int f)
 {
        static time_t modtime;
        static mode_t mode;
-       static DEV64_T rdev;    /* just high bytes in p28 onward */
+       static DEV64_T rdev, rdev_high;
        static DEV64_T dev;
        static uid_t uid;
        static gid_t gid;
@@ -549,7 +554,7 @@ void receive_file_entry(struct file_struct **fptr, unsigned short flags, int f)
 
        if (!fptr) {
                modtime = 0, mode = 0;
-               rdev = 0, dev = 0;
+               rdev = 0, rdev_high = 0, dev = 0;
                uid = 0, gid = 0;
                *lastname = '\0';
                return;
@@ -636,10 +641,11 @@ void receive_file_entry(struct file_struct **fptr, unsigned short flags, int f)
                                rdev = 0;
                } else if (IS_DEVICE(mode)) {
                        if (!(flags & XMIT_SAME_HIGH_RDEV)) {
-                               file->u.rdev = (DEV64_T)read_int(f);
-                               rdev = file->u.rdev & ~0xFF;
+                               rdev = (DEV64_T)read_int(f);
+                               rdev_high = rdev & ~0xFF;
                        } else
-                               file->u.rdev = rdev | (DEV64_T)read_byte(f);
+                               rdev = rdev_high | (DEV64_T)read_byte(f);
+                       file->u.rdev = rdev;
                }
        }
 
@@ -824,7 +830,7 @@ struct file_struct *make_file(char *fname, struct string_area **ap,
                }
        }
 #ifdef HAVE_STRUCT_STAT_ST_RDEV
-       if (IS_DEVICE(st.st_mode))
+       if (preserve_devices && IS_DEVICE(st.st_mode))
                file->u.rdev = st.st_rdev;
 #endif