+ if (flags & XMIT_HAS_IDEV_DATA) {
+ if (protocol_version < 26) {
+ /* 32-bit dev_t and ino_t */
+ write_int(f, dev);
+ write_int(f, file->F_INODE);
+ } else {
+ /* 64-bit dev_t and ino_t */
+ if (!(flags & XMIT_SAME_DEV))
+ write_longint(f, dev);
+ write_longint(f, file->F_INODE);
+ }
+ }
+#endif
+
+ if (always_checksum) {
+ char *sum;
+ if (S_ISREG(mode))
+ sum = file->u.sum;
+ else if (protocol_version < 28) {
+ /* Prior to 28, we sent a useless set of nulls. */
+ sum = empty_sum;
+ } else
+ sum = NULL;
+ if (sum) {
+ write_buf(f, sum,
+ protocol_version < 21 ? 2 : MD4_SUM_LENGTH);
+ }
+ }
+
+ strlcpy(lastname, fname, MAXPATHLEN);
+
+ io_write_phase = "unknown";
+}
+
+
+
+void receive_file_entry(struct file_struct **fptr, unsigned short flags,
+ struct file_list *flist, int f)
+{
+ static time_t modtime;
+ static mode_t mode;
+ static int64 dev;
+ static dev_t rdev;
+ static uint32 rdev_major;
+ static uid_t uid;
+ static gid_t gid;
+ static char lastname[MAXPATHLEN], *lastdir;
+ static int lastdir_depth, lastdir_len = -1;
+ static unsigned int del_heir_name_len = -1;
+ static int in_del_hier = 0;
+ char thisname[MAXPATHLEN];
+ unsigned int l1 = 0, l2 = 0;
+ int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
+ OFF_T file_length;
+ char *basename, *dirname, *bp;
+ struct file_struct *file;
+
+ if (!fptr) {
+ modtime = 0, mode = 0;
+ dev = 0, rdev = makedev(0, 0);
+ rdev_major = 0;
+ uid = 0, gid = 0;
+ *lastname = '\0';
+ del_heir_name_len = lastdir_len = -1;
+ in_del_hier = 0;
+ return;
+ }
+
+ if (flags & XMIT_SAME_NAME)
+ l1 = read_byte(f);
+
+ if (flags & XMIT_LONG_NAME)
+ l2 = read_int(f);
+ else
+ l2 = read_byte(f);
+
+ if (l2 >= MAXPATHLEN - l1) {
+ rprintf(FERROR,
+ "overflow: flags=0x%x l1=%d l2=%d lastname=%s\n",
+ flags, l1, l2, lastname);
+ overflow("receive_file_entry");
+ }
+
+ strlcpy(thisname, lastname, l1 + 1);
+ read_sbuf(f, &thisname[l1], l2);
+ thisname[l1 + l2] = 0;
+
+ strlcpy(lastname, thisname, MAXPATHLEN);
+
+ clean_fname(thisname, 0);
+
+ if (sanitize_paths)
+ sanitize_path(thisname, thisname, "", 0);
+
+ if ((basename = strrchr(thisname, '/')) != NULL) {
+ dirname_len = ++basename - thisname; /* counts future '\0' */
+ if (lastdir_len == dirname_len - 1
+ && strncmp(thisname, lastdir, lastdir_len) == 0) {
+ dirname = lastdir;
+ dirname_len = 0; /* indicates no copy is needed */
+ } else
+ dirname = thisname;
+ } else {
+ basename = thisname;
+ dirname = NULL;
+ dirname_len = 0;
+ }
+ basename_len = strlen(basename) + 1; /* count the '\0' */
+
+ file_length = read_longint(f);
+ if (!(flags & XMIT_SAME_TIME))
+ modtime = (time_t)read_int(f);
+ if (!(flags & XMIT_SAME_MODE))
+ mode = from_wire_mode(read_int(f));
+
+ if (preserve_uid && !(flags & XMIT_SAME_UID))
+ uid = (uid_t)read_int(f);
+ if (preserve_gid && !(flags & XMIT_SAME_GID))
+ gid = (gid_t)read_int(f);
+
+ if (preserve_devices) {
+ if (protocol_version < 28) {
+ if (IS_DEVICE(mode)) {
+ if (!(flags & XMIT_SAME_RDEV_pre28))
+ rdev = (dev_t)read_int(f);
+ } else
+ rdev = makedev(0, 0);
+ } else if (IS_DEVICE(mode)) {
+ uint32 rdev_minor;
+ if (!(flags & XMIT_SAME_RDEV_MAJOR))
+ rdev_major = read_int(f);
+ if (flags & XMIT_RDEV_MINOR_IS_SMALL)
+ rdev_minor = read_byte(f);
+ else
+ rdev_minor = read_int(f);
+ rdev = makedev(rdev_major, rdev_minor);
+ }
+ }
+
+#if SUPPORT_LINKS
+ if (preserve_links && S_ISLNK(mode)) {
+ linkname_len = read_int(f) + 1; /* count the '\0' */
+ if (linkname_len <= 0 || linkname_len > MAXPATHLEN) {
+ rprintf(FERROR, "overflow: linkname_len=%d\n",
+ linkname_len - 1);
+ overflow("receive_file_entry");
+ }
+ }
+ else