-@@ -1009,11 +1027,19 @@ static struct file_struct *send_file_nam
- if (preserve_acls)
- send_acl(&sx, f);
- #endif
-+#ifdef SUPPORT_XATTRS
-+ if (preserve_xattrs)
-+ send_xattr(&sx, f);
-+#endif
- } else {
- #ifdef SUPPORT_ACLS
- if (preserve_acls)
- free_acl(&sx);
- #endif
-+#ifdef SUPPORT_XATTRS
-+ if (preserve_xattrs)
-+ free_xattr(&sx);
-+#endif
- }
- return file;
- }
---- old/lib/sysxattr.c
-+++ new/lib/sysxattr.c
-@@ -0,0 +1,44 @@
-+/*
-+ * Extended attribute support for rsync.
-+ *
-+ * 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.,
-+ * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
-+ */
-+
-+#include "rsync.h"
-+#include "sysxattr.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,13 @@
-+#if defined SUPPORT_XATTRS && defined HAVE_ATTR_XATTR_H
-+#include <attr/xattr.h>
-+#endif
-+
-+#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
-@@ -48,6 +48,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 },
-@@ -1099,6 +1109,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()
-@@ -1538,6 +1559,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;
-@@ -223,6 +224,10 @@ int set_file_attrs(char *fname, struct f
- if (preserve_acls && set_acl(fname, file, sxp) == 0)
- updated = 1;
- #endif
-+#ifdef SUPPORT_XATTRS
-+ if (preserve_xattrs && set_xattr(fname, file, sxp) == 0)
-+ updated = 1;
-+#endif
-
- #ifdef HAVE_CHMOD
- if ((sxp->st.st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
---- old/rsync.h
-+++ new/rsync.h
-@@ -494,6 +494,10 @@ struct idev {
- #define ACLS_NEED_MASK 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);
+ }