1 Depends-On-Patch: acls.diff
3 This patch adds preliminary support for extended attributes.
5 After applying this patch, run these commands for a successful build:
8 ./configure --enable-acl-support --enable-xattr-support
13 - This patch needs to more efficiently handle large xattrs, especially when
16 - Extraneous xattr values need to be removed from files that are not being
19 - We need to affect the itemized output to know when xattrs are being updated.
21 - We need to affect the --link-dest option to avoid hard-linking two files
22 that differ in their xattrs (when --xattrs was specified).
26 @@ -28,13 +28,13 @@ VERSION=@VERSION@
28 HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
29 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
30 - lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
31 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o lib/sysxattr.o @LIBOBJS@
32 ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
33 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
34 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
35 main.o checksum.o match.o syscall.o log.o backup.o
36 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
37 - fileio.o batch.o clientname.o chmod.o acls.o
38 + fileio.o batch.o clientname.o chmod.o acls.o xattr.o
39 OBJS3=progress.o pipe.o
40 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
41 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
44 @@ -31,6 +31,7 @@ extern int read_only;
46 extern int orig_umask;
47 extern int preserve_acls;
48 +extern int preserve_xattrs;
49 extern unsigned int file_struct_len;
51 /* === ACL structures === */
52 @@ -742,6 +743,10 @@ void receive_acl(struct file_struct *fil
53 type = SMB_ACL_TYPE_ACCESS;
54 racl_list = &access_acl_list;
55 ndx_ptr = (char*)file + file_struct_len;
56 +#ifdef SUPPORT_XATTRS
57 + if (preserve_xattrs)
61 char tag = read_byte(f);
63 @@ -801,6 +806,10 @@ void cache_acl(struct file_struct *file,
65 racl_list = &access_acl_list;
66 ndx_ptr = (char*)file + file_struct_len;
67 +#ifdef SUPPORT_XATTRS
68 + if (preserve_xattrs)
74 @@ -921,6 +930,10 @@ int set_acl(const char *fname, const str
76 type = SMB_ACL_TYPE_ACCESS;
77 ndx_ptr = (char*)file + file_struct_len;
78 +#ifdef SUPPORT_XATTRS
79 + if (preserve_xattrs)
87 @@ -30,6 +30,7 @@ extern char *backup_dir;
90 extern int preserve_acls;
91 +extern int preserve_xattrs;
92 extern int preserve_devices;
93 extern int preserve_specials;
94 extern int preserve_links;
95 @@ -136,6 +137,9 @@ static int make_bak_dir(char *fullpath)
97 sx.acc_acl = sx.def_acl = NULL;
99 +#ifdef SUPPORT_XATTRS
102 if (!(file = make_file(rel, NULL, NULL, 0, NO_FILTERS)))
105 @@ -144,6 +148,12 @@ static int make_bak_dir(char *fullpath)
106 cache_acl(file, &sx);
109 +#ifdef SUPPORT_XATTRS
110 + if (preserve_xattrs) {
111 + get_xattr(rel, &sx);
112 + cache_xattr(file, &sx);
115 set_file_attrs(fullpath, file, NULL, 0);
118 @@ -195,6 +205,9 @@ static int keep_backup(char *fname)
120 sx.acc_acl = sx.def_acl = NULL;
122 +#ifdef SUPPORT_XATTRS
126 if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
127 return 1; /* the file could have disappeared */
128 @@ -208,6 +221,12 @@ static int keep_backup(char *fname)
129 cache_acl(file, &sx);
132 +#ifdef SUPPORT_XATTRS
133 + if (preserve_xattrs) {
134 + get_xattr(fname, &sx);
135 + cache_xattr(file, &sx);
139 /* Check to see if this is a device file, or link */
140 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
143 @@ -856,6 +856,35 @@ samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_
147 +AC_CHECK_HEADERS(attr/xattr.h)
148 +AC_CHECK_HEADERS(sys/xattr.h)
149 +AC_MSG_CHECKING(whether to support extended attributes)
150 +AC_ARG_ENABLE(xattr-support,
151 +AC_HELP_STRING([--enable-xattr-support], [Include extended attribute support (default=no)]),
152 +[ case "$enableval" in
156 + AC_MSG_RESULT(Using Linux xattrs)
157 + AC_DEFINE(HAVE_LINUX_XATTRS, 1, [True if you have Linux xattrs])
160 + AC_MSG_RESULT(Using OS X xattrs)
161 + AC_DEFINE(HAVE_OSX_XATTRS, 1, [True if you have Mac OS X xattrs])
164 + AC_MSG_RESULT(Xattrs requested but not Linux or OS X. Good luck...)
170 + AC_DEFINE(HAVE_NO_XATTRS, 1, [True if you don't have extended attributes])
173 + AC_DEFINE(HAVE_NO_XATTRS, 1, [True if you don't have extended attributes])
176 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
181 @@ -41,6 +41,7 @@ extern int one_file_system;
182 extern int copy_dirlinks;
183 extern int keep_dirlinks;
184 extern int preserve_acls;
185 +extern int preserve_xattrs;
186 extern int preserve_links;
187 extern int preserve_hard_links;
188 extern int preserve_devices;
189 @@ -498,7 +499,7 @@ static struct file_struct *receive_file_
190 char thisname[MAXPATHLEN];
191 unsigned int l1 = 0, l2 = 0;
192 int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
194 +#if defined SUPPORT_ACLS || defined SUPPORT_XATTRS
198 @@ -610,10 +611,16 @@ static struct file_struct *receive_file_
199 xtra_len = (S_ISDIR(mode) ? 2 : 1) * 4;
202 +#elif defined SUPPORT_XATTRS
205 +#ifdef SUPPORT_XATTRS
206 + if (preserve_xattrs)
210 alloc_len = file_struct_len + dirname_len + basename_len
212 +#if defined SUPPORT_ACLS || defined SUPPORT_XATTRS
215 + linkname_len + sum_len;
216 @@ -622,7 +629,7 @@ static struct file_struct *receive_file_
217 file = (struct file_struct *)bp;
218 memset(bp, 0, file_struct_len);
219 bp += file_struct_len;
221 +#if defined SUPPORT_ACLS || defined SUPPORT_XATTRS
225 @@ -723,6 +730,10 @@ static struct file_struct *receive_file_
227 receive_acl(file, f);
229 +#ifdef SUPPORT_XATTRS
230 + if (preserve_xattrs)
231 + receive_xattr(file, f );
236 @@ -974,7 +985,7 @@ static struct file_struct *send_file_nam
237 unsigned short flags)
239 struct file_struct *file;
241 +#if defined SUPPORT_ACLS || defined SUPPORT_XATTRS
245 @@ -994,6 +1005,13 @@ static struct file_struct *send_file_nam
249 +#ifdef SUPPORT_XATTRS
250 + if (preserve_xattrs) {
252 + if (get_xattr(fname, &sx) < 0)
257 maybe_emit_filelist_progress(flist->count + flist_count_offset);
259 @@ -1006,11 +1024,19 @@ static struct file_struct *send_file_nam
263 +#ifdef SUPPORT_XATTRS
264 + if (preserve_xattrs)
265 + send_xattr(&sx, f);
272 +#ifdef SUPPORT_XATTRS
273 + if (preserve_xattrs)
279 --- old/lib/sysxattr.c
280 +++ new/lib/sysxattr.c
283 + * Extended attribute support for rsync.
285 + * Copyright (C) 2004 Red Hat, Inc.
286 + * Written by Jay Fenlason.
288 + * This program is free software; you can redistribute it and/or modify
289 + * it under the terms of the GNU General Public License as published by
290 + * the Free Software Foundation; either version 2 of the License, or
291 + * (at your option) any later version.
293 + * This program is distributed in the hope that it will be useful,
294 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
295 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
296 + * GNU General Public License for more details.
298 + * You should have received a copy of the GNU General Public License along
299 + * with this program; if not, write to the Free Software Foundation, Inc.,
300 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
304 +#include "sysxattr.h"
306 +#ifdef SUPPORT_XATTRS
308 +#if defined HAVE_LINUX_XATTRS
310 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
312 + return lgetxattr(path, name, value, size);
315 +ssize_t sys_fgetxattr(int filedes, const char *name, void *value, size_t size)
317 + return fgetxattr(filedes, name, value, size);
320 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags)
322 + return lsetxattr(path, name, value, size, flags);
325 +int sys_lremovexattr(const char *path, const char *name)
327 + return lremovexattr(path, name);
330 +ssize_t sys_llistxattr(const char *path, char *list, size_t size)
332 + return llistxattr(path, list, size);
335 +#elif HAVE_OSX_XATTRS
337 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
339 + return getxattr(path, name, value, size, 0, XATTR_NOFOLLOW);
342 +ssize_t sys_fgetxattr(int filedes, const char *name, void *value, size_t size)
344 + return fgetxattr(filedes, name, value, size, 0, 0);
347 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags)
349 + return setxattr(path, name, value, size, 0, XATTR_NOFOLLOW | flags);
352 +int sys_lremovexattr(const char *path, const char *name)
354 + return removexattr(path, name, XATTR_NOFOLLOW);
357 +ssize_t sys_llistxattr(const char *path, char *list, size_t size)
359 + return listxattr(path, list, size, XATTR_NOFOLLOW);
364 +#error You need to create xattr compatibility functions.
368 +#endif /* SUPPORT_XATTRS */
369 --- old/lib/sysxattr.h
370 +++ new/lib/sysxattr.h
372 +#ifdef SUPPORT_XATTRS
374 +#if defined HAVE_ATTR_XATTR_H
375 +#include <attr/xattr.h>
376 +#elif defined HAVE_SYS_XATTR_H
377 +#include <sys/xattr.h>
380 +/* Linux 2.4 does not define this as a distinct errno value: */
382 +#define ENOATTR ENODATA
385 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size);
386 +ssize_t sys_fgetxattr(int filedes, const char *name, void *value, size_t size);
387 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags);
388 +int sys_lremovexattr(const char *path, const char *name);
389 +ssize_t sys_llistxattr(const char *path, char *list, size_t size);
393 +/* No xattrs available */
398 @@ -48,6 +48,7 @@ int copy_links = 0;
399 int preserve_links = 0;
400 int preserve_hard_links = 0;
401 int preserve_acls = 0;
402 +int preserve_xattrs = 0;
403 int preserve_perms = 0;
404 int preserve_executability = 0;
405 int preserve_devices = 0;
406 @@ -201,6 +202,7 @@ static void print_rsync_version(enum log
407 char const *have_inplace = "no ";
408 char const *hardlinks = "no ";
409 char const *acls = "no ";
410 + char const *xattrs = "no ";
411 char const *links = "no ";
412 char const *ipv6 = "no ";
413 STRUCT_STAT *dumstat;
414 @@ -220,7 +222,9 @@ static void print_rsync_version(enum log
419 +#ifdef SUPPORT_XATTRS
425 @@ -236,8 +240,8 @@ static void print_rsync_version(enum log
426 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, %shard links, %ssymlinks,\n",
427 (int) (sizeof (OFF_T) * 8), got_socketpair, hardlinks, links);
429 - rprintf(f, " batchfiles, %sinplace, %sIPv6, %sACLs,\n",
430 - have_inplace, ipv6, acls);
431 + rprintf(f, " batchfiles, %sinplace, %sIPv6, %sACLs, %sxattrs,\n",
432 + have_inplace, ipv6, acls, xattrs);
434 /* Note that this field may not have type ino_t. It depends
435 * on the complicated interaction between largefile feature
436 @@ -289,7 +293,7 @@ void usage(enum logcode F)
437 rprintf(F," -q, --quiet suppress non-error messages\n");
438 rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n");
439 rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
440 - rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H, -A)\n");
441 + rprintf(F," -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)\n");
442 rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
443 rprintf(F," -r, --recursive recurse into directories\n");
444 rprintf(F," -R, --relative use relative path names\n");
445 @@ -314,6 +318,9 @@ void usage(enum logcode F)
447 rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
449 +#ifdef SUPPORT_XATTRS
450 + rprintf(F," -X, --xattrs preserve extended attributes (implies --perms)\n");
452 rprintf(F," -o, --owner preserve owner (super-user only)\n");
453 rprintf(F," -g, --group preserve group\n");
454 rprintf(F," --devices preserve device files (super-user only)\n");
455 @@ -436,6 +443,9 @@ static struct poptOption long_options[]
456 {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
457 {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
458 {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
459 + {"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 },
460 + {"no-xattrs", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
461 + {"no-X", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
462 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
463 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
464 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
465 @@ -1117,6 +1127,17 @@ int parse_arguments(int *argc, const cha
470 +#ifdef SUPPORT_XATTRS
471 + preserve_xattrs = 1;
472 + preserve_perms = 1;
475 + snprintf(err_buf,sizeof(err_buf),
476 + "extended attributes are not supported on this %s\n",
477 + am_server ? "server" : "client");
482 /* A large opt value means that set_refuse_options()
483 @@ -1563,6 +1584,10 @@ void server_options(char **args,int *arg
487 +#ifdef SUPPORT_XATTRS
488 + if (preserve_xattrs)
499 extern int preserve_acls;
500 +extern int preserve_xattrs;
501 extern int preserve_perms;
502 extern int preserve_executability;
503 extern int preserve_times;
504 @@ -219,6 +220,10 @@ int set_file_attrs(char *fname, struct f
505 if (daemon_chmod_modes && !S_ISLNK(new_mode))
506 new_mode = tweak_mode(new_mode, daemon_chmod_modes);
508 +#ifdef SUPPORT_XATTRS
509 + if (preserve_xattrs && set_xattr(fname, file, sxp) == 0)
513 /* It's OK to call set_acl() now, even for a dir, as the generator
514 * will enable owner-writability using chmod, if necessary.
517 @@ -500,6 +500,10 @@ struct idev {
518 #define ACLS_NEED_MASK 1
521 +#ifndef HAVE_NO_XATTRS
522 +#define SUPPORT_XATTRS 1
525 #define GID_NONE ((gid_t)-1)
527 #define HL_CHECK_MASTER 0
528 @@ -694,6 +698,9 @@ typedef struct {
529 struct rsync_acl *acc_acl; /* access ACL */
530 struct rsync_acl *def_acl; /* default ACL */
532 +#ifdef SUPPORT_XATTRS
537 #define ACL_READY(sx) ((sx).acc_acl != NULL)
540 @@ -301,7 +301,7 @@ to the detailed description below for a
541 -q, --quiet suppress non-error messages
542 --no-motd suppress daemon-mode MOTD (see caveat)
543 -c, --checksum skip based on checksum, not mod-time & size
544 - -a, --archive archive mode; same as -rlptgoD (no -H, -A)
545 + -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
546 --no-OPTION turn off an implied OPTION (e.g. --no-D)
547 -r, --recursive recurse into directories
548 -R, --relative use relative path names
549 @@ -324,6 +324,7 @@ to the detailed description below for a
550 -E, --executability preserve executability
551 --chmod=CHMOD affect file and/or directory permissions
552 -A, --acls preserve ACLs (implies -p) [non-standard]
553 + -X, --xattrs preserve extended attrs (implies -p) [n.s.]
554 -o, --owner preserve owner (super-user only)
555 -g, --group preserve group
556 --devices preserve device files (super-user only)
557 @@ -818,6 +819,11 @@ version makes it incompatible with sendi
558 rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
559 doubling is not needed when pulling files from an older rsync.
561 +dit(bf(-X, --xattrs)) This option causes rsync to update the remote
562 +extended attributes to be the same as the local ones. This will work
563 +only if the remote machine's rsync supports this option also. This is
564 +a non-standard option.
566 dit(bf(--chmod)) This option tells rsync to apply one or more
567 comma-separated "chmod" strings to the permission of the files in the
568 transfer. The resulting value is treated as though it was the permissions
573 + * Extended Attribute support for rsync.
574 + * Written by Jay Fenlason, vaguely based on the ACLs patch.
576 + * Copyright (C) 2004 Red Hat, Inc.
577 + * Copyright (C) 2006 Wayne Davison
579 + * This program is free software; you can redistribute it and/or modify
580 + * it under the terms of the GNU General Public License as published by
581 + * the Free Software Foundation; either version 2 of the License, or
582 + * (at your option) any later version.
584 + * This program is distributed in the hope that it will be useful,
585 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
586 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
587 + * GNU General Public License for more details.
589 + * You should have received a copy of the GNU General Public License along
590 + * with this program; if not, write to the Free Software Foundation, Inc.,
591 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
595 +#include "lib/sysxattr.h"
597 +#ifdef SUPPORT_XATTRS
600 +extern int read_only;
601 +extern int list_only;
602 +extern unsigned int file_struct_len;
604 +#define RSYNC_XAL_INITIAL 5
605 +#define RSYNC_XAL_LIST_INITIAL 100
614 +static size_t namebuf_len = 0;
615 +static char *namebuf = NULL;
617 +static item_list empty_xattr = EMPTY_ITEM_LIST;
618 +static item_list rsync_xal_l = EMPTY_ITEM_LIST;
620 +#ifdef HAVE_OSX_XATTRS
621 +#define UNIQUE_PREFIX "user.0S%." /* OSX */
622 +#define UPRE_LEN (sizeof UNIQUE_PREFIX - 1)
625 +/* ------------------------------------------------------------------------- */
627 +static void rsync_xal_free(item_list *xalp)
630 + rsync_xa *rxas = xalp->items;
632 + for (i = 0; i < xalp->count; i++) {
633 + free(rxas[i].name);
634 + /* free(rxas[i].value); */
639 +void free_xattr(statx *sxp)
641 + rsync_xal_free(sxp->xattr);
646 +static int rsync_xal_compare_names(const void *x1, const void *x2)
648 + const rsync_xa *xa1 = x1;
649 + const rsync_xa *xa2 = x2;
650 + return strcmp(xa1->name, xa2->name);
653 +static int rsync_xal_get(const char *fname, item_list *xalp)
656 + ssize_t datum_size;
663 + namebuf_len = 1024;
664 + namebuf = new_array(char, namebuf_len);
666 + out_of_memory("rsync_xal_get");
669 + /* The length returned includes all the '\0' terminators. */
670 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
671 + if (name_size > (ssize_t)namebuf_len) {
675 + if (name_size < 0) {
676 + if (errno == ENOTSUP)
678 + if (errno == ERANGE) {
679 + name_size = sys_llistxattr(fname, NULL, 0);
680 + if (name_size < 0) {
681 + rsyserr(FERROR, errno, "%s: rsync_xal_get: llistxattr",
685 + namebuf = realloc_array(namebuf, char, name_size + 1024);
687 + out_of_memory("rsync_xal_get");
688 + namebuf_len = name_size + 1024;
689 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
690 + if (name_size < 0) {
691 + rsyserr(FERROR, errno,
692 + "%s: rsync_xal_get: re-llistxattr failed",
697 + rsyserr(FERROR, errno,
698 + "%s: rsync_xal_get: llistxattr failed:",
703 + if (name_size == 0)
705 + for (left = name_size, name = namebuf; left > 0 ; left -= len, name += len) {
706 + rsync_xa *rxas = EXPAND_ITEM_LIST(xalp, rsync_xa, RSYNC_XAL_INITIAL);
708 + len = strlen(name) + 1;
709 + datum_size = sys_lgetxattr(fname, name, NULL, 0);
710 + if (datum_size < 0) {
711 + if (errno == ENOTSUP)
713 + rsyserr(FERROR, errno,
714 + "%s: rsync_xal_get: lgetxattr %s failed",
718 + ptr = new_array(char, len + datum_size);
720 + out_of_memory("rsync_xal_get");
721 + memcpy(ptr, name, len);
722 + rxas->name_len = len;
724 + rxas->datum_len = datum_size;
725 + rxas->datum = ptr + len;
727 + ssize_t size = sys_lgetxattr(fname, name, rxas->datum, datum_size);
728 + if (size != datum_size) {
730 + rsyserr(FERROR, errno,
731 + "rsync_xal_get: lgetxattr(%s,%s)"
732 + " failed", fname, name);
735 + "rsync_xal_get: lgetxattr(%s,%s)"
736 + " returned %ld instead of %ld\n",
738 + (long)size, (long)datum_size);
744 + if (xalp->count > 1)
745 + qsort(xalp->items, xalp->count, sizeof (rsync_xa), rsync_xal_compare_names);
749 +/* Read the xattr(s) for this filename. */
750 +int get_xattr(const char *fname, statx *sxp)
752 + sxp->xattr = new(item_list);
753 + *sxp->xattr = empty_xattr;
754 + if (rsync_xal_get(fname, sxp->xattr) < 0) {
761 +static int find_matching_xattr(item_list *xalp)
764 + item_list *lst = rsync_xal_l.items;
766 + for (i = 0; i < rsync_xal_l.count; i++) {
767 + rsync_xa *rxas1 = lst[i].items;
768 + rsync_xa *rxas2 = xalp->items;
770 + /* Wrong number of elements? */
771 + if (lst[i].count != xalp->count)
773 + /* any elements different? */
774 + for (j = 0; j < xalp->count; j++) {
775 + if (rxas1[j].name_len != rxas2[j].name_len
776 + || rxas1[j].datum_len != rxas2[j].datum_len
777 + || strcmp(rxas1[j].name, rxas2[j].name)
778 + || memcmp(rxas1[j].datum, rxas2[j].datum, rxas2[j].datum_len))
781 + /* no differences found. This is The One! */
782 + if (j == xalp->count)
789 +/* Store *xalp on the end of rsync_xal_l */
790 +static void rsync_xal_store(item_list *xalp)
792 + item_list *new_lst = EXPAND_ITEM_LIST(&rsync_xal_l, item_list, RSYNC_XAL_LIST_INITIAL);
793 + /* Since the following call starts a new list, we know it will hold the
794 + * entire initial-count, not just enough space for one new item. */
795 + *new_lst = empty_xattr;
796 + (void)EXPAND_ITEM_LIST(new_lst, rsync_xa, xalp->count);
797 + memcpy(new_lst->items, xalp->items, xalp->count * sizeof (rsync_xa));
798 + new_lst->count = xalp->count;
802 +/* Send the make_xattr()-generated xattr list for this flist entry. */
803 +void send_xattr(statx *sxp, int f)
805 + int ndx = find_matching_xattr(sxp->xattr);
807 + write_byte(f, 'x');
809 + rsync_xal_free(sxp->xattr);
812 + int count = sxp->xattr->count;
813 + write_byte(f, 'X');
814 + write_int(f, count);
815 + for (rxa = sxp->xattr->items; count--; rxa++) {
816 +#ifdef HAVE_OSX_XATTRS
817 + if (strncmp(rxa->name, "user.", 5) != 0
818 + && strncmp(rxa->name, "system.", 7) != 0) {
819 + write_int(f, rxa->name_len + UPRE_LEN);
820 + write_int(f, rxa->datum_len);
821 + write_buf(f, UNIQUE_PREFIX, UPRE_LEN);
825 + write_int(f, rxa->name_len);
826 + write_int(f, rxa->datum_len);
828 + write_buf(f, rxa->name, rxa->name_len);
829 + write_buf(f, rxa->datum, rxa->datum_len);
831 + rsync_xal_store(sxp->xattr); /* adds item to rsync_xal_l */
836 +/* ------------------------------------------------------------------------- */
838 +/* receive and build the rsync_xattr_lists */
839 +void receive_xattr(struct file_struct *file, int f)
841 + static item_list temp_xattr = EMPTY_ITEM_LIST;
842 + int tag = read_byte(f);
843 + char *ndx_ptr = (char*)file + file_struct_len;
847 + int i, count = read_int(f);
848 + for (i = 0; i < count; i++) {
851 + size_t name_len = read_int(f);
852 + size_t datum_len = read_int(f);
853 + if (name_len + datum_len < name_len)
854 + out_of_memory("receive_xattr"); /* overflow */
855 + rxa = EXPAND_ITEM_LIST(&temp_xattr, rsync_xa, count);
856 + ptr = new_array(char, name_len + datum_len);
858 + out_of_memory("receive_xattr");
859 + read_buf(f, ptr, name_len);
860 + read_buf(f, ptr + name_len, datum_len);
861 + rxa->name_len = name_len;
862 + rxa->datum_len = datum_len;
864 + rxa->datum = ptr + name_len;
865 +#ifdef HAVE_OSX_XATTRS
866 + if (strncmp(rxa->name, UNIQUE_PREFIX, UPRE_LEN) == 0) {
867 + rxa->name_len -= UPRE_LEN;
868 + memmove(rxa->name, rxa->name + UPRE_LEN, rxa->name_len);
872 + ndx = rsync_xal_l.count; /* pre-incremented count */
873 + rsync_xal_store(&temp_xattr); /* adds item to rsync_xal_l */
874 + } else if (tag == 'x') {
876 + if (ndx < 0 || (size_t)ndx >= rsync_xal_l.count) {
877 + rprintf(FERROR, "%s: receive_xattr: xa index %d out of range\n",
878 + f_name(file, NULL), ndx);
879 + exit_cleanup(RERR_STREAMIO);
883 + "%s: receive_xattr: unknown extended attribute type tag: %c\n",
884 + f_name(file, NULL), tag);
885 + exit_cleanup(RERR_STREAMIO);
886 + ndx = 0; /* silence a compiler warning... */
889 + SIVAL(ndx_ptr, 0, ndx);
892 +/* Turn the xattr data in statx into cached xattr data, setting the index
893 + * values in the file struct. */
894 +void cache_xattr(struct file_struct *file, statx *sxp)
896 + char *ndx_ptr = (char*)file + file_struct_len;
902 + ndx = find_matching_xattr(sxp->xattr);
904 + rsync_xal_store(sxp->xattr); /* adds item to rsync_xal_l */
907 + SIVAL(ndx_ptr, 0, ndx);
910 +static int rsync_xal_set(const char *fname, item_list *xalp)
912 + rsync_xa *rxas = xalp->items;
916 + for (i = 0; i < xalp->count; i++) {
917 + int status = sys_lsetxattr(fname, rxas[i].name, rxas[i].datum, rxas[i].datum_len, 0);
919 + rsyserr(FERROR, errno, "%s: rsync_xal_set: lsetxattr %s failed",
920 + fname, rxas[i].name);
927 +/* Set extended attributes on indicated filename. */
928 +int set_xattr(const char *fname, const struct file_struct *file, UNUSED(statx *sxp))
931 + char *ndx_ptr = (char*)file + file_struct_len;
932 + item_list *lst = rsync_xal_l.items;
935 + return 1; /* FIXME: --dry-run needs to compute this value */
937 + if (read_only || list_only) {
942 + ndx = IVAL(ndx_ptr, 0);
943 + return rsync_xal_set(fname, lst + ndx); /* TODO: This needs to return 1 if no xattrs changed! */
946 +#endif /* SUPPORT_XATTRS */