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 @@ -135,6 +135,9 @@ static int make_bak_dir(char *fullpath)
31 dup_acl(end, fullpath, st.st_mode);
33 +#ifdef SUPPORT_XATTRS
34 + dup_xattr(end, fullpath );
39 @@ -191,6 +194,9 @@ static int keep_backup(char *fname)
41 push_keep_backup_acl(file, fname, buf);
43 +#ifdef SUPPORT_XATTRS
44 + push_keep_backup_xattr(file, fname, buf);
47 /* Check to see if this is a device file, or link */
48 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
49 @@ -270,6 +276,9 @@ static int keep_backup(char *fname)
51 cleanup_keep_backup_acl();
53 +#ifdef SUPPORT_XATTRS
54 + cleanup_keep_backup_xattr();
61 @@ -814,6 +814,30 @@ samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_
65 +AC_CHECK_HEADERS(attr/xattr.h)
66 +AC_MSG_CHECKING(whether to support extended attributes)
67 +AC_ARG_ENABLE(xattr-support,
68 +AC_HELP_STRING([--enable-xattr-support], [Include extended attribute support (default=no)]),
69 +[ case "$enableval" in
73 + AC_MSG_RESULT(Using Linux xattrs)
74 + AC_DEFINE(HAVE_LINUX_XATTRS, 1, [True if you have Linux xattrs])
77 + AC_MSG_RESULT(Xattrs requested but not linux. Good luck)
83 + AC_DEFINE(HAVE_NA_XATTRS, 1, [True if you don't have extended attributes])
86 + AC_DEFINE(HAVE_NO_XATTRL, 1, [True if you don't have extended attributes])
89 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
94 @@ -970,6 +970,10 @@ static struct file_struct *send_file_nam
95 if (make_acl(file, fname) < 0)
98 +#ifdef SUPPORT_XATTRS
99 + if (make_xattr(file, fname) < 0)
103 if (chmod_modes && !S_ISLNK(file->mode))
104 file->mode = tweak_mode(file->mode, chmod_modes);
105 @@ -983,10 +987,18 @@ static struct file_struct *send_file_nam
106 send_file_entry(file, f);
110 +#ifdef SUPPORT_XATTRS
111 + send_xattr(file, f);
115 /* Cleanup unsent ACL(s). */
118 +#ifdef SUPPORT_XATTRS
119 + send_xattr(file, -1);
124 @@ -1378,6 +1390,9 @@ struct file_list *recv_file_list(int f)
126 receive_acl(file, f);
128 +#ifdef SUPPORT_XATTRS
129 + receive_xattr(file, f );
132 if (S_ISREG(file->mode) || S_ISLNK(file->mode))
133 stats.total_size += file->length;
134 @@ -1404,6 +1419,9 @@ struct file_list *recv_file_list(int f)
136 sort_file_acl_index_lists();
138 +#ifdef SUPPORT_XATTRS
139 + sort_file_xattr_index_lists();
143 recv_uid_list(f, flist);
144 --- old/lib/sysxattr.c
145 +++ new/lib/sysxattr.c
147 +/* Extended attribute support for rsync. */
148 +/* This file Copyright (C) 2004 Red Hat, Inc. */
149 +/* Written by Jay Fenlason */
151 +/* This program is free software; you can redistribute it and/or modify
152 + it under the terms of the GNU General Public License as published by
153 + the Free Software Foundation; either version 2 of the License, or
154 + (at your option) any later version.
156 + This program is distributed in the hope that it will be useful,
157 + but WITHOUT ANY WARRANTY; without even the implied warranty of
158 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
159 + GNU General Public License for more details.
161 + You should have received a copy of the GNU General Public License
162 + along with this program; if not, write to the Free Software
163 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
168 +#if defined HAVE_LINUX_XATTRS
170 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
172 + return lgetxattr(path, name, value, size);
175 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags)
177 + return lsetxattr(path, name, value, size, flags);
180 +ssize_t sys_llistxattr(const char *path, char *list, size_t size)
182 + return llistxattr(path, list, size);
187 +#endif /* No xattrs */
188 --- old/lib/sysxattr.h
189 +++ new/lib/sysxattr.h
191 +#if defined HAVE_LINUX_XATTRS
193 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size);
194 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags);
195 +ssize_t sys_llistxattr(const char *path, char *list, size_t size);
199 +#endif /* No xattrs */
202 @@ -46,6 +46,7 @@ int copy_links = 0;
203 int preserve_links = 0;
204 int preserve_hard_links = 0;
205 int preserve_acls = 0;
206 +int preserve_xattrs = 0;
207 int preserve_perms = 0;
208 int preserve_executability = 0;
209 int preserve_devices = 0;
210 @@ -196,6 +197,7 @@ static void print_rsync_version(enum log
211 char const *have_inplace = "no ";
212 char const *hardlinks = "no ";
213 char const *acls = "no ";
214 + char const *xattrs = "no ";
215 char const *links = "no ";
216 char const *ipv6 = "no ";
217 STRUCT_STAT *dumstat;
218 @@ -215,7 +217,9 @@ static void print_rsync_version(enum log
223 +#ifdef SUPPORT_XATTRS
229 @@ -229,9 +233,9 @@ static void print_rsync_version(enum log
230 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
231 rprintf(f, "<http://rsync.samba.org/>\n");
232 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
233 - "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
234 + "%shard links, %sACLs, %sxattrs, %ssymlinks, batchfiles,\n",
235 (int) (sizeof (OFF_T) * 8),
236 - got_socketpair, hardlinks, acls, links);
237 + got_socketpair, hardlinks, acls, xattrs, links);
239 /* Note that this field may not have type ino_t. It depends
240 * on the complicated interaction between largefile feature
241 @@ -304,6 +308,9 @@ void usage(enum logcode F)
243 rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
245 +#ifdef SUPPORT_XATTRS
246 + rprintf(F," -X, --xattrs preserve extended attributes (implies --perms)\n");
248 rprintf(F," --chmod=CHMOD change destination permissions\n");
249 rprintf(F," -o, --owner preserve owner (super-user only)\n");
250 rprintf(F," -g, --group preserve group\n");
251 @@ -422,6 +429,9 @@ static struct poptOption long_options[]
252 {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
253 {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
254 {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
255 + {"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 },
256 + {"no-xattrs", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
257 + {"no-X", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
258 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
259 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
260 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
261 @@ -1096,6 +1106,17 @@ int parse_arguments(int *argc, const cha
266 +#ifdef SUPPORT_XATTRS
267 + preserve_xattrs = 1;
268 + preserve_perms = 1;
271 + snprintf(err_buf,sizeof(err_buf),
272 + "extended attributes are not supported on this %s\n",
273 + am_server ? "server" : "client");
275 +#endif /* SUPPORT_XATTRS */
278 /* A large opt value means that set_refuse_options()
279 @@ -1544,6 +1565,10 @@ void server_options(char **args,int *arg
283 +#ifdef SUPPORT_XATTRS
284 + if (preserve_xattrs)
292 @@ -224,6 +224,10 @@ int set_file_attrs(char *fname, struct f
293 if (set_acl(fname, file) == 0)
296 +#ifdef SUPPORT_XATTRS
297 + if (set_xattr(fname, file) == 0)
301 if (verbose > 1 && flags & ATTRS_REPORT) {
302 enum logcode code = daemon_log_format_has_i || dry_run
305 @@ -672,6 +672,14 @@ struct chmod_mode_struct;
307 #include "smb_acls.h"
309 +#ifdef HAVE_LINUX_XATTRS
310 +#define SUPPORT_XATTRS 1
313 +#if defined SUPPORT_XATTRS && defined HAVE_ATTR_XATTR_H
314 +#include <attr/xattr.h>
319 /* We have replacement versions of these if they're missing. */
322 @@ -322,6 +322,7 @@ to the detailed description below for a
323 -p, --perms preserve permissions
324 -E, --executability preserve executability
325 -A, --acls preserve ACLs (implies -p) [non-standard]
326 + -X, --xattrs preserve extended attrs (implies -p) [n.s.]
327 --chmod=CHMOD change destination permissions
328 -o, --owner preserve owner (super-user only)
329 -g, --group preserve group
330 @@ -802,6 +803,11 @@ dit(bf(-A, --acls)) This option causes r
331 ACLs to be the same as the source ACLs. This nonstandard option only
332 works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
334 +dit(bf(-X, --xattrs)) This option causes rsync to update the remote
335 +extended attributes to be the same as the local ones. This will work
336 +only if the remote machine's rsync supports this option also. This is
337 +a non-standard option.
339 dit(bf(--chmod)) This option tells rsync to apply one or more
340 comma-separated "chmod" strings to the permission of the files in the
341 transfer. The resulting value is treated as though it was the permissions
345 +/* Extended Attribute support for rsync */
346 +/* Copyright (C) 2004 Red Hat, Inc */
347 +/* Written by Jay Fenlason, vaguely based on the ACLs patch */
349 +/* This program is free software; you can redistribute it and/or modify
350 + it under the terms of the GNU General Public License as published by
351 + the Free Software Foundation; either version 2 of the License, or
352 + (at your option) any later version.
354 + This program is distributed in the hope that it will be useful,
355 + but WITHOUT ANY WARRANTY; without even the implied warranty of
356 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
357 + GNU General Public License for more details.
359 + You should have received a copy of the GNU General Public License
360 + along with this program; if not, write to the Free Software
361 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
365 +#include "lib/sysxattr.h"
367 +#ifdef SUPPORT_XATTRS
369 +extern int preserve_xattrs;
372 +#define RSYNC_XAL_INITIAL 5
373 +#define RSYNC_XAL_LIST_INITIAL 100
394 +static size_t namebuf_len = 0;
395 +static char *namebuf = NULL;
397 +static size_t datumbuf_len = 0;
398 +static char *datumbuf = NULL;
400 +static rsync_xal curr_rsync_xal = { 0, 0, NULL };
401 +static rsync_xal_list rsync_xal_l = { 0, 0, NULL };
404 +/* ------------------------------------------------------------------------- */
406 +/* the below stuff is only used by the receiver */
408 +/* structure to hold index to rsync_xal_l member corresponding to
409 + * flist->files[i] */
412 + const struct file_struct *file;
419 + file_xal_index *filexalidxs;
420 +} file_xal_index_list;
422 +static file_xal_index_list fxil = {0, 0, NULL };
424 +/* stuff for redirecting calls to set_acl() from set_perms()
425 + * for keep_backup() */
426 +static const struct file_struct *backup_orig_file = NULL;
427 +static const char null_string[] = "";
428 +static const char *backup_orig_fname = null_string;
429 +static const char *backup_dest_fname = null_string;
430 +static rsync_xal backup_xal;
432 +/* ------------------------------------------------------------------------- */
434 +static void rsync_xal_free(rsync_xal *x)
438 + for (i = 0; i < x->count; i++) {
439 + free(x->rxas[i].name);
440 + /* free(x->rxas[i].value); */
445 +static int rsync_xal_compare_names(const void *x1, const void *x2)
447 + const rsync_xa *xa1;
448 + const rsync_xa *xa2;
452 + return strcmp(xa1->name, xa2->name);
455 +static int rsync_xal_get(const char *fname, rsync_xal *x)
458 + ssize_t datum_size;
466 + namebuf = new_array(char, namebuf_len);
467 + datumbuf_len = 100;
468 + datumbuf = new_array(char, datumbuf_len);
469 + if (!namebuf || !datumbuf)
470 + out_of_memory("rsync_xal_get");
473 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
474 + if (name_size > (ssize_t)namebuf_len) {
478 + if (name_size < 0) {
479 + if (errno == ENOTSUP)
481 + if (errno == ERANGE) {
482 + name_size = sys_llistxattr(fname, NULL, 0);
483 + if (name_size < 0) {
484 + rprintf(FERROR, "%s: rsync_xal_get: llistxattr: %s\n",
485 + fname, strerror(errno));
488 + namebuf = realloc_array(namebuf, char, name_size + 1);
490 + out_of_memory("rsync_xal_get");
491 + namebuf_len = name_size;
492 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
493 + if (name_size < 0) {
495 + "%s: rsync_xal_get: re-llistxattr failed: %s\n",
496 + fname, strerror(errno));
501 + "%s: rsync_xal_get: llistxattr failed: %s\n",
502 + fname, strerror(errno));
507 + if (name_size == 0)
509 + for (left = name_size, name = namebuf; left > 0 ; left -= len, name += len) {
510 + len = strlen(name) + 1;
512 + if (x->count >= x->alloc) {
514 + rsync_xa *new_rxas;
516 + new_alloc = x->alloc < RSYNC_XAL_INITIAL ? RSYNC_XAL_INITIAL : x->alloc * 2;
517 + new_rxas = realloc_array(x->rxas, rsync_xa, new_alloc);
519 + out_of_memory("rsync_xal_get");
520 + x->alloc = new_alloc;
521 + x->rxas = new_rxas;
523 + datum_size = sys_lgetxattr(fname, name, datumbuf, datumbuf_len);
524 + if (datum_size > (ssize_t)datumbuf_len) {
528 + if (datum_size < 0) {
529 + if (errno == ENOTSUP)
531 + if (errno == ERANGE) {
532 + datum_size = sys_lgetxattr(fname, name, NULL, 0);
533 + if (datum_size < 0) {
535 + "%s: rsync_xal_get: lgetxattr %s failed: %s\n",
536 + fname, name, strerror(errno));
539 + datumbuf = realloc_array(datumbuf, char, datum_size + 1);
541 + out_of_memory("rsync_xal_get");
542 + datumbuf_len = datum_size;
543 + datum_size = sys_lgetxattr(fname, name, datumbuf, datumbuf_len);
544 + if (datum_size < 0) {
546 + "%s: rsync_xal_get: re-lgetxattr of %s failed: %s\n",
547 + name, fname, strerror(errno));
552 + "%s: rsync_xal_get: lgetxattr %s failed: %s\n",
553 + fname, name, strerror(errno));
557 + ptr = new_array(char, len + datum_size);
559 + out_of_memory("rsync_xal_get");
562 + memcpy(ptr + len, datumbuf, datum_size);
563 + x->rxas[curr_rsync_xal.count].name_len = len;
564 + x->rxas[curr_rsync_xal.count].name = ptr;
565 + x->rxas[curr_rsync_xal.count].datum_len = datum_size;
566 + x->rxas[curr_rsync_xal.count].datum = ptr + len;
569 + if (x->count > 1) {
570 + qsort(x->rxas, x->count, sizeof (rsync_xa), rsync_xal_compare_names);
576 +/* generate the xattr(s) for this flist entry;
577 + * xattr(s) are either sent or cleaned-up by send_xattr() below */
579 +int make_xattr(const struct file_struct *file, const char *fname)
581 + if (!preserve_xattrs || !file)
584 + rsync_xal_get(fname, &curr_rsync_xal);
585 + return 0; /* TODO: This needs to return 1 if no xattrs changed! */
588 +static ssize_t rsync_xal_find_matching(void)
593 + for (i = 0; i < rsync_xal_l.count; i++) {
594 + /* Wrong number of elements? */
595 + if (rsync_xal_l.rxals[i].count != curr_rsync_xal.count)
597 + /* any elements different? */
598 + for (j = 0; j < curr_rsync_xal.count; j++) {
599 + if (rsync_xal_l.rxals[i].rxas[j].name_len != curr_rsync_xal.rxas[j].name_len
600 + || rsync_xal_l.rxals[i].rxas[j].datum_len != curr_rsync_xal.rxas[j].datum_len
601 + || strcmp(rsync_xal_l.rxals[i].rxas[j].name, curr_rsync_xal.rxas[j].name)
602 + || memcmp(rsync_xal_l.rxals[i].rxas[j].datum, curr_rsync_xal.rxas[j].datum, curr_rsync_xal.rxas[j].datum_len))
605 + /* no differences found. This is The One! */
606 + if (j == curr_rsync_xal.count)
609 + if (i < rsync_xal_l.count)
611 + return (ssize_t)-1;
614 +/* Store curr_rsync_xal on the end of rsync_xal_l */
615 +static void rsync_xal_store(void)
617 + if (rsync_xal_l.count <= rsync_xal_l.alloc) {
621 + new_alloc = rsync_xal_l.count < RSYNC_XAL_LIST_INITIAL ? RSYNC_XAL_LIST_INITIAL : rsync_xal_l.count * 2;
622 + new_xal = realloc_array(rsync_xal_l.rxals, rsync_xal, new_alloc);
624 + out_of_memory("rsync_xal_store");
625 + rsync_xal_l.alloc = new_alloc;
626 + rsync_xal_l.rxals = new_xal;
628 + rsync_xal_l.rxals[rsync_xal_l.count] = curr_rsync_xal;
629 + rsync_xal_l.count++;
630 + curr_rsync_xal.count = 0;
631 + curr_rsync_xal.alloc = 0;
634 +/* send the make_xattr()-generated xattr list for this flist entry,
635 + * or clean up after an flist entry that's not being sent (f == -1) */
637 +void send_xattr(const struct file_struct *file, int f)
641 + if (!preserve_xattrs || !file)
645 + rsync_xal_free(&curr_rsync_xal);
648 + index = rsync_xal_find_matching();
650 + write_byte(f, 'x');
651 + write_int(f, index);
652 + rsync_xal_free(&curr_rsync_xal);
657 + count = curr_rsync_xal.count;
658 + write_byte(f, 'X');
659 + write_int(f, count);
660 + for (rxa = curr_rsync_xal.rxas; count--; rxa++) {
661 + write_int(f, rxa->name_len);
662 + write_int(f, rxa->datum_len);
663 + write_buf(f, rxa->name, rxa->name_len);
664 + write_buf(f, rxa->datum, rxa->datum_len);
671 +/* ------------------------------------------------------------------------- */
672 +/* receive and build the rsync_xattr_lists */
674 +void receive_xattr(struct file_struct *file, int f)
679 + if (!preserve_xattrs)
681 + fname = f_name(file, NULL);
682 + tag = read_byte(f);
683 + if (tag != 'X' && tag != 'x') {
685 + "%s: receive_xattr: unknown extended attribute type tag: %c\n",
687 + exit_cleanup(RERR_STREAMIO);
690 + if (fxil.alloc <= fxil.count) {
694 + if (fxil.count < RSYNC_XAL_LIST_INITIAL)
695 + new_alloc = fxil.alloc + RSYNC_XAL_LIST_INITIAL;
697 + new_alloc = fxil.alloc * 2;
698 + new_ptr = realloc_array(fxil.filexalidxs, file_xal_index, new_alloc);
700 + out_of_memory("receive_xattr");
701 + if (verbose >= 3) {
702 + rprintf(FINFO, "receive_xattr to %lu bytes, %s move\n",
703 + (unsigned long)(new_alloc * sizeof (file_xal_index)),
704 + fxil.filexalidxs == new_ptr ? "did not" : "did");
707 + fxil.filexalidxs = new_ptr;
708 + fxil.alloc = new_alloc;
711 + fxil.filexalidxs[fxil.count].file = file;
716 + fxil.filexalidxs[fxil.count].xalidx = rsync_xal_l.count;
718 + count = read_int(f);
719 + curr_rsync_xal.count = count;
720 + curr_rsync_xal.alloc = count;
721 + curr_rsync_xal.rxas = new_array(rsync_xa, count);
722 + if (!curr_rsync_xal.rxas)
723 + out_of_memory("receive_xattr");
724 + for (i = 0; i < count; i++) {
729 + name_len = read_int(f);
730 + datum_len = read_int(f);
731 + ptr = new_array(char, name_len + datum_len);
733 + out_of_memory("receive_xattr");
734 + read_buf(f, ptr, name_len);
735 + read_buf(f, ptr + name_len, datum_len);
736 + curr_rsync_xal.rxas[i].name_len = name_len;
737 + curr_rsync_xal.rxas[i].datum_len = datum_len;
738 + curr_rsync_xal.rxas[i].name = ptr;
739 + curr_rsync_xal.rxas[i].datum = ptr + name_len;
745 + index = read_int(f);
746 + if (index >= rsync_xal_l.count) {
747 + rprintf(FERROR, "%s: receive_xattr: xa index %lu out of range\n",
748 + fname, (unsigned long)index);
749 + exit_cleanup(RERR_STREAMIO);
751 + fxil.filexalidxs[fxil.count].xalidx = index;
756 +static int rsync_xal_set(const char *fname, rsync_xal *x)
761 + for (i = 0; i < x->count; i++) {
762 + int status = sys_lsetxattr(fname, x->rxas[i].name, x->rxas[i].datum, x->rxas[i].datum_len, 0);
764 + rprintf(FERROR, "%s: rsync_xal_set: lsetxattr %s failed: %s\n",
765 + fname, x->rxas[i].name, strerror(errno));
772 +/* for duplicating xattrs on backups when using backup_dir */
774 +int dup_xattr(const char *orig, const char *bak)
778 + if (!preserve_xattrs)
781 + if (rsync_xal_get(orig, &backup_xal) < 0)
782 + ret = rsync_xal_set(bak, &backup_xal);
785 + rsync_xal_free(&backup_xal);
789 +void push_keep_backup_xattr(const struct file_struct *file, const char *orig, const char *dest)
791 + if (!preserve_xattrs)
794 + backup_orig_file = file;
795 + backup_orig_fname = orig;
796 + backup_dest_fname = dest;
797 + rsync_xal_get(orig, &backup_xal);
800 +static int set_keep_backup_xal(void)
802 + if (!preserve_xattrs)
804 + return rsync_xal_set(backup_dest_fname, &backup_xal);
807 +void cleanup_keep_backup_xattr(void)
809 + if (!preserve_xattrs)
812 + backup_orig_file = NULL;
813 + backup_orig_fname = null_string;
814 + backup_dest_fname = null_string;
815 + rsync_xal_free(&backup_xal);
818 +static int file_xal_index_compare(const void *x1, const void *x2)
820 + const file_xal_index *xa1;
821 + const file_xal_index *xa2;
825 + return xa1->file == xa2->file ? 0 : xa1->file < xa2->file ? -1 : 1;
828 +void sort_file_xattr_index_lists(void)
830 + if (!preserve_xattrs)
832 + qsort(fxil.filexalidxs, fxil.count, sizeof (file_xal_index), file_xal_index_compare);
835 +static int find_file_xal_index(const struct file_struct *file)
837 + int low = 0, high = fxil.count;
838 + const struct file_struct *file_mid;
841 + rprintf(FERROR, "find_file_xal_index: no entries\n");
842 + exit_cleanup(RERR_STREAMIO);
846 + int mid = (high + low) / 2;
847 + file_mid = fxil.filexalidxs[mid].file;
848 + if (file_mid == file)
849 + return fxil.filexalidxs[mid].xalidx;
850 + if (file_mid > file)
854 + } while (low < high);
856 + file_mid = fxil.filexalidxs[low].file;
857 + if (file_mid == file)
858 + return fxil.filexalidxs[low].xalidx;
861 + "find_file_xal_index: can't find entry for file in list\n");
862 + exit_cleanup(RERR_STREAMIO);
866 +/* set extended attributes on rsync-ed or keep_backup-ed file */
868 +int set_xattr(const char *fname, const struct file_struct *file)
873 + if (dry_run || !preserve_xattrs)
875 + if (file == backup_orig_file) {
876 + if (!strcmp(fname, backup_dest_fname))
877 + return set_keep_backup_xal();
879 + xalidx = find_file_xal_index(file);
880 + x = &(rsync_xal_l.rxals[xalidx]);
881 + return rsync_xal_set(fname, x);
884 +#endif /* SUPPORT_XATTRS */