1 Depends-On-Patch: acls.diff
3 After applying this patch, run these commands for a successful build:
6 ./configure --enable-acl-support --enable-xattr-support
11 @@ -27,13 +27,13 @@ VERSION=@VERSION@
13 HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
14 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
15 - lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
16 + lib/permstring.o lib/pool_alloc.o lib/sysacls.o lib/sysxattr.o @LIBOBJS@
17 ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
18 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
19 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
20 main.o checksum.o match.o syscall.o log.o backup.o
21 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
22 - fileio.o batch.o clientname.o chmod.o acls.o
23 + fileio.o batch.o clientname.o chmod.o acls.o xattr.o
24 OBJS3=progress.o pipe.o
25 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
26 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
29 @@ -30,6 +30,7 @@ extern char *backup_dir;
32 extern int preserve_acls;
33 +extern int preserve_xattrs;
34 extern int preserve_devices;
35 extern int preserve_specials;
36 extern int preserve_links;
37 @@ -138,6 +139,10 @@ static int make_bak_dir(char *fullpath)
39 dup_acl(end, fullpath, st.st_mode);
41 +#ifdef SUPPORT_XATTRS
42 + if (preserve_xattrs)
43 + dup_xattr(end, fullpath );
48 @@ -195,6 +200,10 @@ static int keep_backup(char *fname)
50 push_keep_backup_acl(file, fname, buf);
52 +#ifdef SUPPORT_XATTRS
53 + if (preserve_xattrs)
54 + push_keep_backup_xattr(file, fname, buf);
57 /* Check to see if this is a device file, or link */
58 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
59 @@ -275,6 +284,10 @@ static int keep_backup(char *fname)
61 cleanup_keep_backup_acl();
63 +#ifdef SUPPORT_XATTRS
64 + if (preserve_xattrs)
65 + cleanup_keep_backup_xattr();
72 @@ -823,6 +823,30 @@ samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_
76 +AC_CHECK_HEADERS(attr/xattr.h)
77 +AC_MSG_CHECKING(whether to support extended attributes)
78 +AC_ARG_ENABLE(xattr-support,
79 +AC_HELP_STRING([--enable-xattr-support], [Include extended attribute support (default=no)]),
80 +[ case "$enableval" in
84 + AC_MSG_RESULT(Using Linux xattrs)
85 + AC_DEFINE(HAVE_LINUX_XATTRS, 1, [True if you have Linux xattrs])
88 + AC_MSG_RESULT(Xattrs requested but not linux. Good luck)
94 + AC_DEFINE(HAVE_NA_XATTRS, 1, [True if you don't have extended attributes])
97 + AC_DEFINE(HAVE_NO_XATTRL, 1, [True if you don't have extended attributes])
100 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
105 @@ -41,6 +41,7 @@ extern int one_file_system;
106 extern int copy_dirlinks;
107 extern int keep_dirlinks;
108 extern int preserve_acls;
109 +extern int preserve_xattrs;
110 extern int preserve_links;
111 extern int preserve_hard_links;
112 extern int preserve_devices;
113 @@ -966,6 +967,10 @@ static struct file_struct *send_file_nam
114 if (preserve_acls && make_acl(file, fname) < 0)
117 +#ifdef SUPPORT_XATTRS
118 + if (preserve_xattrs && make_xattr(file, fname) < 0)
122 maybe_emit_filelist_progress(flist->count + flist_count_offset);
124 @@ -978,12 +983,20 @@ static struct file_struct *send_file_nam
128 +#ifdef SUPPORT_XATTRS
129 + if (preserve_xattrs)
130 + send_xattr(file, f);
134 /* Cleanup unsent ACL(s). */
138 +#ifdef SUPPORT_XATTRS
139 + if (preserve_xattrs)
140 + send_xattr(file, -1);
145 @@ -1376,6 +1389,10 @@ struct file_list *recv_file_list(int f)
147 receive_acl(file, f);
149 +#ifdef SUPPORT_XATTRS
150 + if (preserve_xattrs)
151 + receive_xattr(file, f );
154 if (S_ISREG(file->mode) || S_ISLNK(file->mode))
155 stats.total_size += file->length;
156 @@ -1403,6 +1420,10 @@ struct file_list *recv_file_list(int f)
158 sort_file_acl_index_lists();
160 +#ifdef SUPPORT_XATTRS
161 + if (preserve_xattrs)
162 + sort_file_xattr_index_lists();
166 recv_uid_list(f, flist);
167 --- old/lib/sysxattr.c
168 +++ new/lib/sysxattr.c
171 + * Extended attribute support for rsync.
173 + * Copyright (C) 2004 Red Hat, Inc.
174 + * Written by Jay Fenlason.
176 + * This program is free software; you can redistribute it and/or modify
177 + * it under the terms of the GNU General Public License as published by
178 + * the Free Software Foundation; either version 2 of the License, or
179 + * (at your option) any later version.
181 + * This program is distributed in the hope that it will be useful,
182 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
183 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
184 + * GNU General Public License for more details.
186 + * You should have received a copy of the GNU General Public License along
187 + * with this program; if not, write to the Free Software Foundation, Inc.,
188 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
193 +#if defined HAVE_LINUX_XATTRS
195 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
197 + return lgetxattr(path, name, value, size);
200 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags)
202 + return lsetxattr(path, name, value, size, flags);
205 +ssize_t sys_llistxattr(const char *path, char *list, size_t size)
207 + return llistxattr(path, list, size);
212 +#endif /* No xattrs */
213 --- old/lib/sysxattr.h
214 +++ new/lib/sysxattr.h
216 +#if defined HAVE_LINUX_XATTRS
218 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size);
219 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags);
220 +ssize_t sys_llistxattr(const char *path, char *list, size_t size);
224 +#endif /* No xattrs */
227 @@ -48,6 +48,7 @@ int copy_links = 0;
228 int preserve_links = 0;
229 int preserve_hard_links = 0;
230 int preserve_acls = 0;
231 +int preserve_xattrs = 0;
232 int preserve_perms = 0;
233 int preserve_executability = 0;
234 int preserve_devices = 0;
235 @@ -196,6 +197,7 @@ static void print_rsync_version(enum log
236 char const *have_inplace = "no ";
237 char const *hardlinks = "no ";
238 char const *acls = "no ";
239 + char const *xattrs = "no ";
240 char const *links = "no ";
241 char const *ipv6 = "no ";
242 STRUCT_STAT *dumstat;
243 @@ -215,7 +217,9 @@ static void print_rsync_version(enum log
248 +#ifdef SUPPORT_XATTRS
254 @@ -229,9 +233,9 @@ static void print_rsync_version(enum log
255 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
256 rprintf(f, "<http://rsync.samba.org/>\n");
257 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
258 - "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
259 + "%shard links, %sACLs, %sxattrs, %ssymlinks, batchfiles,\n",
260 (int) (sizeof (OFF_T) * 8),
261 - got_socketpair, hardlinks, acls, links);
262 + got_socketpair, hardlinks, acls, xattrs, links);
264 /* Note that this field may not have type ino_t. It depends
265 * on the complicated interaction between largefile feature
266 @@ -304,6 +308,9 @@ void usage(enum logcode F)
268 rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
270 +#ifdef SUPPORT_XATTRS
271 + rprintf(F," -X, --xattrs preserve extended attributes (implies --perms)\n");
273 rprintf(F," --chmod=CHMOD change destination permissions\n");
274 rprintf(F," -o, --owner preserve owner (super-user only)\n");
275 rprintf(F," -g, --group preserve group\n");
276 @@ -422,6 +429,9 @@ static struct poptOption long_options[]
277 {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
278 {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
279 {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
280 + {"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 },
281 + {"no-xattrs", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
282 + {"no-X", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
283 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
284 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
285 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
286 @@ -1097,6 +1107,17 @@ int parse_arguments(int *argc, const cha
291 +#ifdef SUPPORT_XATTRS
292 + preserve_xattrs = 1;
293 + preserve_perms = 1;
296 + snprintf(err_buf,sizeof(err_buf),
297 + "extended attributes are not supported on this %s\n",
298 + am_server ? "server" : "client");
300 +#endif /* SUPPORT_XATTRS */
303 /* A large opt value means that set_refuse_options()
304 @@ -1544,6 +1565,10 @@ void server_options(char **args,int *arg
308 +#ifdef SUPPORT_XATTRS
309 + if (preserve_xattrs)
317 @@ -34,6 +34,7 @@ extern int verbose;
319 extern int daemon_log_format_has_i;
320 extern int preserve_acls;
321 +extern int preserve_xattrs;
322 extern int preserve_perms;
323 extern int preserve_executability;
324 extern int preserve_times;
325 @@ -215,6 +216,10 @@ int set_file_attrs(char *fname, struct f
326 if (preserve_acls && set_acl(fname, file, &st->st_mode) == 0)
329 +#ifdef SUPPORT_XATTRS
330 + if (preserve_xattrs && set_xattr(fname, file) == 0)
335 if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
338 @@ -674,6 +674,14 @@ struct chmod_mode_struct;
340 #include "smb_acls.h"
342 +#ifdef HAVE_LINUX_XATTRS
343 +#define SUPPORT_XATTRS 1
346 +#if defined SUPPORT_XATTRS && defined HAVE_ATTR_XATTR_H
347 +#include <attr/xattr.h>
352 /* We have replacement versions of these if they're missing. */
355 @@ -322,6 +322,7 @@ to the detailed description below for a
356 -p, --perms preserve permissions
357 -E, --executability preserve executability
358 -A, --acls preserve ACLs (implies -p) [non-standard]
359 + -X, --xattrs preserve extended attrs (implies -p) [n.s.]
360 --chmod=CHMOD change destination permissions
361 -o, --owner preserve owner (super-user only)
362 -g, --group preserve group
363 @@ -807,6 +808,11 @@ version makes it incompatible with sendi
364 rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
365 doubling is not needed when pulling files from an older rsync.
367 +dit(bf(-X, --xattrs)) This option causes rsync to update the remote
368 +extended attributes to be the same as the local ones. This will work
369 +only if the remote machine's rsync supports this option also. This is
370 +a non-standard option.
372 dit(bf(--chmod)) This option tells rsync to apply one or more
373 comma-separated "chmod" strings to the permission of the files in the
374 transfer. The resulting value is treated as though it was the permissions
379 + * Extended Attribute support for rsync.
381 + * Copyright (C) 2004 Red Hat, Inc.
382 + * Written by Jay Fenlason, vaguely based on the ACLs patch.
384 + * This program is free software; you can redistribute it and/or modify
385 + * it under the terms of the GNU General Public License as published by
386 + * the Free Software Foundation; either version 2 of the License, or
387 + * (at your option) any later version.
389 + * This program is distributed in the hope that it will be useful,
390 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
391 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
392 + * GNU General Public License for more details.
394 + * You should have received a copy of the GNU General Public License along
395 + * with this program; if not, write to the Free Software Foundation, Inc.,
396 + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
400 +#include "lib/sysxattr.h"
402 +#ifdef SUPPORT_XATTRS
406 +#define RSYNC_XAL_INITIAL 5
407 +#define RSYNC_XAL_LIST_INITIAL 100
428 +static size_t namebuf_len = 0;
429 +static char *namebuf = NULL;
431 +static size_t datumbuf_len = 0;
432 +static char *datumbuf = NULL;
434 +static rsync_xal curr_rsync_xal = { 0, 0, NULL };
435 +static rsync_xal_list rsync_xal_l = { 0, 0, NULL };
438 +/* ------------------------------------------------------------------------- */
440 +/* the below stuff is only used by the receiver */
442 +/* structure to hold index to rsync_xal_l member corresponding to
443 + * flist->files[i] */
446 + const struct file_struct *file;
453 + file_xal_index *filexalidxs;
454 +} file_xal_index_list;
456 +static file_xal_index_list fxil = {0, 0, NULL };
458 +/* stuff for redirecting calls to set_acl() from set_perms()
459 + * for keep_backup() */
460 +static const struct file_struct *backup_orig_file = NULL;
461 +static const char null_string[] = "";
462 +static const char *backup_orig_fname = null_string;
463 +static const char *backup_dest_fname = null_string;
464 +static rsync_xal backup_xal;
466 +/* ------------------------------------------------------------------------- */
468 +static void rsync_xal_free(rsync_xal *x)
472 + for (i = 0; i < x->count; i++) {
473 + free(x->rxas[i].name);
474 + /* free(x->rxas[i].value); */
479 +static int rsync_xal_compare_names(const void *x1, const void *x2)
481 + const rsync_xa *xa1;
482 + const rsync_xa *xa2;
486 + return strcmp(xa1->name, xa2->name);
489 +static int rsync_xal_get(const char *fname, rsync_xal *x)
492 + ssize_t datum_size;
500 + namebuf = new_array(char, namebuf_len);
501 + datumbuf_len = 100;
502 + datumbuf = new_array(char, datumbuf_len);
503 + if (!namebuf || !datumbuf)
504 + out_of_memory("rsync_xal_get");
507 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
508 + if (name_size > (ssize_t)namebuf_len) {
512 + if (name_size < 0) {
513 + if (errno == ENOTSUP)
515 + if (errno == ERANGE) {
516 + name_size = sys_llistxattr(fname, NULL, 0);
517 + if (name_size < 0) {
518 + rprintf(FERROR, "%s: rsync_xal_get: llistxattr: %s\n",
519 + fname, strerror(errno));
522 + namebuf = realloc_array(namebuf, char, name_size + 1);
524 + out_of_memory("rsync_xal_get");
525 + namebuf_len = name_size;
526 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
527 + if (name_size < 0) {
529 + "%s: rsync_xal_get: re-llistxattr failed: %s\n",
530 + fname, strerror(errno));
535 + "%s: rsync_xal_get: llistxattr failed: %s\n",
536 + fname, strerror(errno));
541 + if (name_size == 0)
543 + for (left = name_size, name = namebuf; left > 0 ; left -= len, name += len) {
544 + len = strlen(name) + 1;
546 + if (x->count >= x->alloc) {
548 + rsync_xa *new_rxas;
550 + new_alloc = x->alloc < RSYNC_XAL_INITIAL ? RSYNC_XAL_INITIAL : x->alloc * 2;
551 + new_rxas = realloc_array(x->rxas, rsync_xa, new_alloc);
553 + out_of_memory("rsync_xal_get");
554 + x->alloc = new_alloc;
555 + x->rxas = new_rxas;
557 + datum_size = sys_lgetxattr(fname, name, datumbuf, datumbuf_len);
558 + if (datum_size > (ssize_t)datumbuf_len) {
562 + if (datum_size < 0) {
563 + if (errno == ENOTSUP)
565 + if (errno == ERANGE) {
566 + datum_size = sys_lgetxattr(fname, name, NULL, 0);
567 + if (datum_size < 0) {
569 + "%s: rsync_xal_get: lgetxattr %s failed: %s\n",
570 + fname, name, strerror(errno));
573 + datumbuf = realloc_array(datumbuf, char, datum_size + 1);
575 + out_of_memory("rsync_xal_get");
576 + datumbuf_len = datum_size;
577 + datum_size = sys_lgetxattr(fname, name, datumbuf, datumbuf_len);
578 + if (datum_size < 0) {
580 + "%s: rsync_xal_get: re-lgetxattr of %s failed: %s\n",
581 + name, fname, strerror(errno));
586 + "%s: rsync_xal_get: lgetxattr %s failed: %s\n",
587 + fname, name, strerror(errno));
591 + ptr = new_array(char, len + datum_size);
593 + out_of_memory("rsync_xal_get");
596 + memcpy(ptr + len, datumbuf, datum_size);
597 + x->rxas[curr_rsync_xal.count].name_len = len;
598 + x->rxas[curr_rsync_xal.count].name = ptr;
599 + x->rxas[curr_rsync_xal.count].datum_len = datum_size;
600 + x->rxas[curr_rsync_xal.count].datum = ptr + len;
603 + if (x->count > 1) {
604 + qsort(x->rxas, x->count, sizeof (rsync_xa), rsync_xal_compare_names);
610 +/* generate the xattr(s) for this flist entry;
611 + * xattr(s) are either sent or cleaned-up by send_xattr() below */
613 +int make_xattr(UNUSED(const struct file_struct *file), const char *fname)
615 + rsync_xal_get(fname, &curr_rsync_xal);
616 + return 0; /* TODO: This needs to return 1 if no xattrs changed! */
619 +static ssize_t rsync_xal_find_matching(void)
624 + for (i = 0; i < rsync_xal_l.count; i++) {
625 + /* Wrong number of elements? */
626 + if (rsync_xal_l.rxals[i].count != curr_rsync_xal.count)
628 + /* any elements different? */
629 + for (j = 0; j < curr_rsync_xal.count; j++) {
630 + if (rsync_xal_l.rxals[i].rxas[j].name_len != curr_rsync_xal.rxas[j].name_len
631 + || rsync_xal_l.rxals[i].rxas[j].datum_len != curr_rsync_xal.rxas[j].datum_len
632 + || strcmp(rsync_xal_l.rxals[i].rxas[j].name, curr_rsync_xal.rxas[j].name)
633 + || memcmp(rsync_xal_l.rxals[i].rxas[j].datum, curr_rsync_xal.rxas[j].datum, curr_rsync_xal.rxas[j].datum_len))
636 + /* no differences found. This is The One! */
637 + if (j == curr_rsync_xal.count)
640 + if (i < rsync_xal_l.count)
642 + return (ssize_t)-1;
645 +/* Store curr_rsync_xal on the end of rsync_xal_l */
646 +static void rsync_xal_store(void)
648 + if (rsync_xal_l.count <= rsync_xal_l.alloc) {
652 + new_alloc = rsync_xal_l.count < RSYNC_XAL_LIST_INITIAL ? RSYNC_XAL_LIST_INITIAL : rsync_xal_l.count * 2;
653 + new_xal = realloc_array(rsync_xal_l.rxals, rsync_xal, new_alloc);
655 + out_of_memory("rsync_xal_store");
656 + rsync_xal_l.alloc = new_alloc;
657 + rsync_xal_l.rxals = new_xal;
659 + rsync_xal_l.rxals[rsync_xal_l.count] = curr_rsync_xal;
660 + rsync_xal_l.count++;
661 + curr_rsync_xal.count = 0;
662 + curr_rsync_xal.alloc = 0;
665 +/* send the make_xattr()-generated xattr list for this flist entry,
666 + * or clean up after an flist entry that's not being sent (f == -1) */
668 +void send_xattr(UNUSED(const struct file_struct *file), int f)
673 + rsync_xal_free(&curr_rsync_xal);
676 + index = rsync_xal_find_matching();
678 + write_byte(f, 'x');
679 + write_int(f, index);
680 + rsync_xal_free(&curr_rsync_xal);
685 + count = curr_rsync_xal.count;
686 + write_byte(f, 'X');
687 + write_int(f, count);
688 + for (rxa = curr_rsync_xal.rxas; count--; rxa++) {
689 + write_int(f, rxa->name_len);
690 + write_int(f, rxa->datum_len);
691 + write_buf(f, rxa->name, rxa->name_len);
692 + write_buf(f, rxa->datum, rxa->datum_len);
699 +/* ------------------------------------------------------------------------- */
700 +/* receive and build the rsync_xattr_lists */
702 +void receive_xattr(struct file_struct *file, int f)
707 + fname = f_name(file, NULL);
708 + tag = read_byte(f);
709 + if (tag != 'X' && tag != 'x') {
711 + "%s: receive_xattr: unknown extended attribute type tag: %c\n",
713 + exit_cleanup(RERR_STREAMIO);
716 + if (fxil.alloc <= fxil.count) {
720 + if (fxil.count < RSYNC_XAL_LIST_INITIAL)
721 + new_alloc = fxil.alloc + RSYNC_XAL_LIST_INITIAL;
723 + new_alloc = fxil.alloc * 2;
724 + new_ptr = realloc_array(fxil.filexalidxs, file_xal_index, new_alloc);
726 + out_of_memory("receive_xattr");
727 + if (verbose >= 3) {
728 + rprintf(FINFO, "receive_xattr to %lu bytes, %s move\n",
729 + (unsigned long)(new_alloc * sizeof (file_xal_index)),
730 + fxil.filexalidxs == new_ptr ? "did not" : "did");
733 + fxil.filexalidxs = new_ptr;
734 + fxil.alloc = new_alloc;
737 + fxil.filexalidxs[fxil.count].file = file;
742 + fxil.filexalidxs[fxil.count].xalidx = rsync_xal_l.count;
744 + count = read_int(f);
745 + curr_rsync_xal.count = count;
746 + curr_rsync_xal.alloc = count;
747 + curr_rsync_xal.rxas = new_array(rsync_xa, count);
748 + if (!curr_rsync_xal.rxas)
749 + out_of_memory("receive_xattr");
750 + for (i = 0; i < count; i++) {
755 + name_len = read_int(f);
756 + datum_len = read_int(f);
757 + if (name_len + datum_len < name_len)
758 + out_of_memory("receive_xattr"); /* overflow */
759 + ptr = new_array(char, name_len + datum_len);
761 + out_of_memory("receive_xattr");
762 + read_buf(f, ptr, name_len);
763 + read_buf(f, ptr + name_len, datum_len);
764 + curr_rsync_xal.rxas[i].name_len = name_len;
765 + curr_rsync_xal.rxas[i].datum_len = datum_len;
766 + curr_rsync_xal.rxas[i].name = ptr;
767 + curr_rsync_xal.rxas[i].datum = ptr + name_len;
773 + index = read_int(f);
774 + if (index >= rsync_xal_l.count) {
775 + rprintf(FERROR, "%s: receive_xattr: xa index %lu out of range\n",
776 + fname, (unsigned long)index);
777 + exit_cleanup(RERR_STREAMIO);
779 + fxil.filexalidxs[fxil.count].xalidx = index;
784 +static int rsync_xal_set(const char *fname, rsync_xal *x)
789 + for (i = 0; i < x->count; i++) {
790 + int status = sys_lsetxattr(fname, x->rxas[i].name, x->rxas[i].datum, x->rxas[i].datum_len, 0);
792 + rprintf(FERROR, "%s: rsync_xal_set: lsetxattr %s failed: %s\n",
793 + fname, x->rxas[i].name, strerror(errno));
800 +/* for duplicating xattrs on backups when using backup_dir */
802 +int dup_xattr(const char *orig, const char *bak)
806 + if (rsync_xal_get(orig, &backup_xal) < 0)
807 + ret = rsync_xal_set(bak, &backup_xal);
810 + rsync_xal_free(&backup_xal);
815 +void push_keep_backup_xattr(const struct file_struct *file, const char *orig, const char *dest)
817 + backup_orig_file = file;
818 + backup_orig_fname = orig;
819 + backup_dest_fname = dest;
820 + rsync_xal_get(orig, &backup_xal);
823 +static int set_keep_backup_xal(void)
825 + return rsync_xal_set(backup_dest_fname, &backup_xal);
828 +void cleanup_keep_backup_xattr(void)
830 + backup_orig_file = NULL;
831 + backup_orig_fname = null_string;
832 + backup_dest_fname = null_string;
833 + rsync_xal_free(&backup_xal);
836 +static int file_xal_index_compare(const void *x1, const void *x2)
838 + const file_xal_index *xa1;
839 + const file_xal_index *xa2;
843 + return xa1->file == xa2->file ? 0 : xa1->file < xa2->file ? -1 : 1;
846 +void sort_file_xattr_index_lists(void)
848 + qsort(fxil.filexalidxs, fxil.count, sizeof (file_xal_index), file_xal_index_compare);
851 +static int find_file_xal_index(const struct file_struct *file)
853 + int low = 0, high = fxil.count;
854 + const struct file_struct *file_mid;
857 + rprintf(FERROR, "find_file_xal_index: no entries\n");
858 + exit_cleanup(RERR_STREAMIO);
862 + int mid = (high + low) / 2;
863 + file_mid = fxil.filexalidxs[mid].file;
864 + if (file_mid == file)
865 + return fxil.filexalidxs[mid].xalidx;
866 + if (file_mid > file)
870 + } while (low < high);
872 + file_mid = fxil.filexalidxs[low].file;
873 + if (file_mid == file)
874 + return fxil.filexalidxs[low].xalidx;
877 + "find_file_xal_index: can't find entry for file in list\n");
878 + exit_cleanup(RERR_STREAMIO);
882 +/* set extended attributes on rsync-ed or keep_backup-ed file */
884 +int set_xattr(const char *fname, const struct file_struct *file)
890 + return 1; /* FIXME: --dry-run needs to compute this value */
892 + if (file == backup_orig_file) {
893 + if (!strcmp(fname, backup_dest_fname))
894 + return set_keep_backup_xal();
896 + xalidx = find_file_xal_index(file);
897 + x = &(rsync_xal_l.rxals[xalidx]);
899 + return rsync_xal_set(fname, x);
902 +#endif /* SUPPORT_XATTRS */