- if (f >= 0) {
- recv_uid_list(f, flist);
---- old/lib/sysxattr.c
-+++ new/lib/sysxattr.c
-@@ -0,0 +1,41 @@
-+/* Extended attribute support for rsync. */
-+/* This file Copyright (C) 2004 Red Hat, Inc. */
-+/* Written by Jay Fenlason */
-+
-+/* This program is free software; you can redistribute it and/or modify
-+ it under the terms of the GNU General Public License as published by
-+ the Free Software Foundation; either version 2 of the License, or
-+ (at your option) any later version.
-+
-+ This program is distributed in the hope that it will be useful,
-+ but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ GNU General Public License for more details.
-+
-+ You should have received a copy of the GNU General Public License
-+ along with this program; if not, write to the Free Software
-+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-+*/
-+
-+#include "rsync.h"
-+
-+#if defined HAVE_LINUX_XATTRS
-+
-+ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
-+{
-+ return lgetxattr(path, name, value, size);
-+}
-+
-+int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags)
-+{
-+ return lsetxattr(path, name, value, size, flags);
-+}
-+
-+ssize_t sys_llistxattr(const char *path, char *list, size_t size)
-+{
-+ return llistxattr(path, list, size);
-+}
-+
-+#else
-+
-+#endif /* No xattrs */
---- old/lib/sysxattr.h
-+++ new/lib/sysxattr.h
-@@ -0,0 +1,9 @@
-+#if defined HAVE_LINUX_XATTRS
-+
-+ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size);
-+int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags);
-+ssize_t sys_llistxattr(const char *path, char *list, size_t size);
-+
-+#else
-+
-+#endif /* No xattrs */
---- old/options.c
-+++ new/options.c
-@@ -46,6 +46,7 @@ int copy_links = 0;
- int preserve_links = 0;
- int preserve_hard_links = 0;
- int preserve_acls = 0;
-+int preserve_xattrs = 0;
- int preserve_perms = 0;
- int preserve_executability = 0;
- int preserve_devices = 0;
-@@ -196,6 +197,7 @@ static void print_rsync_version(enum log
- char const *have_inplace = "no ";
- char const *hardlinks = "no ";
- char const *acls = "no ";
-+ char const *xattrs = "no ";
- char const *links = "no ";
- char const *ipv6 = "no ";
- STRUCT_STAT *dumstat;
-@@ -215,7 +217,9 @@ static void print_rsync_version(enum log
- #ifdef SUPPORT_ACLS
- acls = "";
- #endif
--
-+#ifdef SUPPORT_XATTRS
-+ xattrs = "";
-+#endif
- #ifdef SUPPORT_LINKS
- links = "";
- #endif
-@@ -229,9 +233,9 @@ static void print_rsync_version(enum log
- rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
- rprintf(f, "<http://rsync.samba.org/>\n");
- rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
-- "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
-+ "%shard links, %sACLs, %sxattrs, %ssymlinks, batchfiles,\n",
- (int) (sizeof (OFF_T) * 8),
-- got_socketpair, hardlinks, acls, links);
-+ got_socketpair, hardlinks, acls, xattrs, links);
-
- /* Note that this field may not have type ino_t. It depends
- * on the complicated interaction between largefile feature
-@@ -304,6 +308,9 @@ void usage(enum logcode F)
- #ifdef SUPPORT_ACLS
- rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
- #endif
-+#ifdef SUPPORT_XATTRS
-+ rprintf(F," -X, --xattrs preserve extended attributes (implies --perms)\n");
-+#endif
- rprintf(F," --chmod=CHMOD change destination permissions\n");
- rprintf(F," -o, --owner preserve owner (super-user only)\n");
- rprintf(F," -g, --group preserve group\n");
-@@ -422,6 +429,9 @@ static struct poptOption long_options[]
- {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
- {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
- {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
-+ {"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 },
-+ {"no-xattrs", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
-+ {"no-X", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
- {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
- {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
- {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
-@@ -1096,6 +1106,17 @@ int parse_arguments(int *argc, const cha
- return 0;
- #endif
-
-+ case 'X':
-+#ifdef SUPPORT_XATTRS
-+ preserve_xattrs = 1;
-+ preserve_perms = 1;
-+ break;
-+#else
-+ snprintf(err_buf,sizeof(err_buf),
-+ "extended attributes are not supported on this %s\n",
-+ am_server ? "server" : "client");
-+ return 0;
-+#endif /* SUPPORT_XATTRS */
-
- default:
- /* A large opt value means that set_refuse_options()
-@@ -1544,6 +1565,10 @@ void server_options(char **args,int *arg
- if (preserve_acls)
- argstr[x++] = 'A';
- #endif
-+#ifdef SUPPORT_XATTRS
-+ if (preserve_xattrs)
-+ argstr[x++] = 'X';
-+#endif
- if (preserve_uid)
- argstr[x++] = 'o';
- if (preserve_gid)
---- old/rsync.c
-+++ new/rsync.c
-@@ -34,6 +34,7 @@ extern int verbose;
- extern int dry_run;
- extern int daemon_log_format_has_i;
- extern int preserve_acls;
-+extern int preserve_xattrs;
- extern int preserve_perms;
- extern int preserve_executability;
- extern int preserve_times;
-@@ -211,6 +212,10 @@ int set_file_attrs(char *fname, struct f
- if (preserve_acls && set_acl(fname, file) == 0)
- updated = 1;
- #endif
-+#ifdef SUPPORT_XATTRS
-+ if (preserve_xattrs && set_xattr(fname, file) == 0)
-+ updated = 1;
-+#endif
-
- #ifdef HAVE_CHMOD
- if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
---- old/rsync.h
-+++ new/rsync.h
-@@ -672,6 +672,14 @@ struct chmod_mode_struct;
+ if (delete_mode && !(delete_before+delete_during+delete_after)) {
+diff --git a/xattrs.c b/xattrs.c
+--- a/xattrs.c
++++ b/xattrs.c
+@@ -21,6 +21,7 @@
+
+ #include "rsync.h"
+ #include "ifuncs.h"
++#include "io.h"
+ #include "lib/sysxattrs.h"
+
+ #ifdef SUPPORT_XATTRS
+@@ -33,6 +34,7 @@ extern int read_only;
+ extern int list_only;
+ extern int preserve_xattrs;
+ extern int checksum_seed;
++extern int protocol_version;
+
+ #define RSYNC_XAL_INITIAL 5
+ #define RSYNC_XAL_LIST_INITIAL 100
+@@ -239,7 +241,7 @@ static int rsync_xal_get(const char *fname, item_list *xalp)
+ if (!(ptr = get_xattr_data(fname, name, &datum_len, 0)))
+ return -1;
+
+- if (datum_len > MAX_FULL_DATUM) {
++ if (datum_len > MAX_FULL_DATUM && protocol_version >= 30) {
+ /* For large datums, we store a flag and a checksum. */
+ name_offset = 1 + MAX_DIGEST_LEN;
+ sum_init(checksum_seed);
+@@ -307,7 +309,7 @@ static int find_matching_xattr(item_list *xalp)
+ || rxas1[j].datum_len != rxas2[j].datum_len
+ || strcmp(rxas1[j].name, rxas2[j].name))
+ break;
+- if (rxas1[j].datum_len > MAX_FULL_DATUM) {
++ if (rxas1[j].datum_len > MAX_FULL_DATUM && protocol_version >= 30) {
+ if (memcmp(rxas1[j].datum + 1,
+ rxas2[j].datum + 1,
+ MAX_DIGEST_LEN) != 0)
+@@ -344,34 +346,43 @@ int send_xattr(stat_x *sxp, int f)
+ {
+ int ndx = find_matching_xattr(sxp->xattr);
+
+- /* Send 0 (-1 + 1) to indicate that literal xattr data follows. */
+- write_varint(f, ndx + 1);
++ if (protocol_version < 30) {
++ if (ndx < 0)
++ write_byte(f, 'X');
++ else {
++ write_byte(f, 'x');
++ write_int(f, ndx);
++ }
++ } else {
++ /* Send 0 (-1 + 1) to indicate that literal xattr data follows. */
++ write_varint(f, ndx + 1);
++ }
+
+ if (ndx < 0) {
+ rsync_xa *rxa;
+ int count = sxp->xattr->count;
+- write_varint(f, count);
++ write_varint30(f, count);
+ for (rxa = sxp->xattr->items; count--; rxa++) {
+ #ifdef HAVE_LINUX_XATTRS
+- write_varint(f, rxa->name_len);
+- write_varint(f, rxa->datum_len);
++ write_varint30(f, rxa->name_len);
++ write_varint30(f, rxa->datum_len);
+ write_buf(f, rxa->name, rxa->name_len);
+ #else
+ /* We strip the rsync prefix from disguised namespaces
+ * and put everything else in the user namespace. */
+ if (HAS_PREFIX(rxa->name, RSYNC_PREFIX)
+ && rxa->name[RPRE_LEN] != '%') {
+- write_varint(f, rxa->name_len - RPRE_LEN);
+- write_varint(f, rxa->datum_len);
++ write_varint30(f, rxa->name_len - RPRE_LEN);
++ write_varint30(f, rxa->datum_len);
+ write_buf(f, rxa->name + RPRE_LEN, rxa->name_len - RPRE_LEN);
+ } else {
+- write_varint(f, rxa->name_len + UPRE_LEN);
+- write_varint(f, rxa->datum_len);
++ write_varint30(f, rxa->name_len + UPRE_LEN);
++ write_varint30(f, rxa->datum_len);
+ write_buf(f, USER_PREFIX, UPRE_LEN);
+ write_buf(f, rxa->name, rxa->name_len);
+ }