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 @@ -29,6 +29,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 @@ -137,6 +138,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 @@ -194,6 +199,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 @@ -274,6 +283,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 @@ -45,6 +45,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 @@ -975,6 +976,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 @@ -987,12 +992,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 @@ -1385,6 +1398,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 @@ -1412,6 +1429,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
170 +/* Extended attribute support for rsync. */
171 +/* This file Copyright (C) 2004 Red Hat, Inc. */
172 +/* Written by Jay Fenlason */
174 +/* This program is free software; you can redistribute it and/or modify
175 + it under the terms of the GNU General Public License as published by
176 + the Free Software Foundation; either version 2 of the License, or
177 + (at your option) any later version.
179 + This program is distributed in the hope that it will be useful,
180 + but WITHOUT ANY WARRANTY; without even the implied warranty of
181 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
182 + GNU General Public License for more details.
184 + You should have received a copy of the GNU General Public License
185 + along with this program; if not, write to the Free Software
186 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
191 +#if defined HAVE_LINUX_XATTRS
193 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
195 + return lgetxattr(path, name, value, size);
198 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags)
200 + return lsetxattr(path, name, value, size, flags);
203 +ssize_t sys_llistxattr(const char *path, char *list, size_t size)
205 + return llistxattr(path, list, size);
210 +#endif /* No xattrs */
211 --- old/lib/sysxattr.h
212 +++ new/lib/sysxattr.h
214 +#if defined HAVE_LINUX_XATTRS
216 +ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size);
217 +int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags);
218 +ssize_t sys_llistxattr(const char *path, char *list, size_t size);
222 +#endif /* No xattrs */
225 @@ -46,6 +46,7 @@ int copy_links = 0;
226 int preserve_links = 0;
227 int preserve_hard_links = 0;
228 int preserve_acls = 0;
229 +int preserve_xattrs = 0;
230 int preserve_perms = 0;
231 int preserve_executability = 0;
232 int preserve_devices = 0;
233 @@ -194,6 +195,7 @@ static void print_rsync_version(enum log
234 char const *have_inplace = "no ";
235 char const *hardlinks = "no ";
236 char const *acls = "no ";
237 + char const *xattrs = "no ";
238 char const *links = "no ";
239 char const *ipv6 = "no ";
240 STRUCT_STAT *dumstat;
241 @@ -213,7 +215,9 @@ static void print_rsync_version(enum log
246 +#ifdef SUPPORT_XATTRS
252 @@ -227,9 +231,9 @@ static void print_rsync_version(enum log
253 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
254 rprintf(f, "<http://rsync.samba.org/>\n");
255 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
256 - "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
257 + "%shard links, %sACLs, %sxattrs, %ssymlinks, batchfiles,\n",
258 (int) (sizeof (OFF_T) * 8),
259 - got_socketpair, hardlinks, acls, links);
260 + got_socketpair, hardlinks, acls, xattrs, links);
262 /* Note that this field may not have type ino_t. It depends
263 * on the complicated interaction between largefile feature
264 @@ -302,6 +306,9 @@ void usage(enum logcode F)
266 rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
268 +#ifdef SUPPORT_XATTRS
269 + rprintf(F," -X, --xattrs preserve extended attributes (implies --perms)\n");
271 rprintf(F," --chmod=CHMOD change destination permissions\n");
272 rprintf(F," -o, --owner preserve owner (super-user only)\n");
273 rprintf(F," -g, --group preserve group\n");
274 @@ -420,6 +427,9 @@ static struct poptOption long_options[]
275 {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
276 {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
277 {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
278 + {"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 },
279 + {"no-xattrs", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
280 + {"no-X", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
281 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
282 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
283 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
284 @@ -1095,6 +1105,17 @@ int parse_arguments(int *argc, const cha
289 +#ifdef SUPPORT_XATTRS
290 + preserve_xattrs = 1;
291 + preserve_perms = 1;
294 + snprintf(err_buf,sizeof(err_buf),
295 + "extended attributes are not supported on this %s\n",
296 + am_server ? "server" : "client");
298 +#endif /* SUPPORT_XATTRS */
301 /* A large opt value means that set_refuse_options()
302 @@ -1542,6 +1563,10 @@ void server_options(char **args,int *arg
306 +#ifdef SUPPORT_XATTRS
307 + if (preserve_xattrs)
315 @@ -34,6 +34,7 @@ extern int verbose;
317 extern int daemon_log_format_has_i;
318 extern int preserve_acls;
319 +extern int preserve_xattrs;
320 extern int preserve_perms;
321 extern int preserve_executability;
322 extern int preserve_times;
323 @@ -215,6 +216,10 @@ int set_file_attrs(char *fname, struct f
324 if (preserve_acls && set_acl(fname, file, &st->st_mode) == 0)
327 +#ifdef SUPPORT_XATTRS
328 + if (preserve_xattrs && set_xattr(fname, file) == 0)
333 if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
336 @@ -674,6 +674,14 @@ struct chmod_mode_struct;
338 #include "smb_acls.h"
340 +#ifdef HAVE_LINUX_XATTRS
341 +#define SUPPORT_XATTRS 1
344 +#if defined SUPPORT_XATTRS && defined HAVE_ATTR_XATTR_H
345 +#include <attr/xattr.h>
350 /* We have replacement versions of these if they're missing. */
353 @@ -322,6 +322,7 @@ to the detailed description below for a
354 -p, --perms preserve permissions
355 -E, --executability preserve executability
356 -A, --acls preserve ACLs (implies -p) [non-standard]
357 + -X, --xattrs preserve extended attrs (implies -p) [n.s.]
358 --chmod=CHMOD change destination permissions
359 -o, --owner preserve owner (super-user only)
360 -g, --group preserve group
361 @@ -807,6 +808,11 @@ version makes it incompatible with sendi
362 rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
363 doubling is not needed when pulling files from an older rsync.
365 +dit(bf(-X, --xattrs)) This option causes rsync to update the remote
366 +extended attributes to be the same as the local ones. This will work
367 +only if the remote machine's rsync supports this option also. This is
368 +a non-standard option.
370 dit(bf(--chmod)) This option tells rsync to apply one or more
371 comma-separated "chmod" strings to the permission of the files in the
372 transfer. The resulting value is treated as though it was the permissions
376 +/* Extended Attribute support for rsync */
377 +/* Copyright (C) 2004 Red Hat, Inc */
378 +/* Written by Jay Fenlason, vaguely based on the ACLs patch */
380 +/* This program is free software; you can redistribute it and/or modify
381 + it under the terms of the GNU General Public License as published by
382 + the Free Software Foundation; either version 2 of the License, or
383 + (at your option) any later version.
385 + This program is distributed in the hope that it will be useful,
386 + but WITHOUT ANY WARRANTY; without even the implied warranty of
387 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
388 + GNU General Public License for more details.
390 + You should have received a copy of the GNU General Public License
391 + along with this program; if not, write to the Free Software
392 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
396 +#include "lib/sysxattr.h"
398 +#ifdef SUPPORT_XATTRS
402 +#define RSYNC_XAL_INITIAL 5
403 +#define RSYNC_XAL_LIST_INITIAL 100
424 +static size_t namebuf_len = 0;
425 +static char *namebuf = NULL;
427 +static size_t datumbuf_len = 0;
428 +static char *datumbuf = NULL;
430 +static rsync_xal curr_rsync_xal = { 0, 0, NULL };
431 +static rsync_xal_list rsync_xal_l = { 0, 0, NULL };
434 +/* ------------------------------------------------------------------------- */
436 +/* the below stuff is only used by the receiver */
438 +/* structure to hold index to rsync_xal_l member corresponding to
439 + * flist->files[i] */
442 + const struct file_struct *file;
449 + file_xal_index *filexalidxs;
450 +} file_xal_index_list;
452 +static file_xal_index_list fxil = {0, 0, NULL };
454 +/* stuff for redirecting calls to set_acl() from set_perms()
455 + * for keep_backup() */
456 +static const struct file_struct *backup_orig_file = NULL;
457 +static const char null_string[] = "";
458 +static const char *backup_orig_fname = null_string;
459 +static const char *backup_dest_fname = null_string;
460 +static rsync_xal backup_xal;
462 +/* ------------------------------------------------------------------------- */
464 +static void rsync_xal_free(rsync_xal *x)
468 + for (i = 0; i < x->count; i++) {
469 + free(x->rxas[i].name);
470 + /* free(x->rxas[i].value); */
475 +static int rsync_xal_compare_names(const void *x1, const void *x2)
477 + const rsync_xa *xa1;
478 + const rsync_xa *xa2;
482 + return strcmp(xa1->name, xa2->name);
485 +static int rsync_xal_get(const char *fname, rsync_xal *x)
488 + ssize_t datum_size;
496 + namebuf = new_array(char, namebuf_len);
497 + datumbuf_len = 100;
498 + datumbuf = new_array(char, datumbuf_len);
499 + if (!namebuf || !datumbuf)
500 + out_of_memory("rsync_xal_get");
503 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
504 + if (name_size > (ssize_t)namebuf_len) {
508 + if (name_size < 0) {
509 + if (errno == ENOTSUP)
511 + if (errno == ERANGE) {
512 + name_size = sys_llistxattr(fname, NULL, 0);
513 + if (name_size < 0) {
514 + rprintf(FERROR, "%s: rsync_xal_get: llistxattr: %s\n",
515 + fname, strerror(errno));
518 + namebuf = realloc_array(namebuf, char, name_size + 1);
520 + out_of_memory("rsync_xal_get");
521 + namebuf_len = name_size;
522 + name_size = sys_llistxattr(fname, namebuf, namebuf_len);
523 + if (name_size < 0) {
525 + "%s: rsync_xal_get: re-llistxattr failed: %s\n",
526 + fname, strerror(errno));
531 + "%s: rsync_xal_get: llistxattr failed: %s\n",
532 + fname, strerror(errno));
537 + if (name_size == 0)
539 + for (left = name_size, name = namebuf; left > 0 ; left -= len, name += len) {
540 + len = strlen(name) + 1;
542 + if (x->count >= x->alloc) {
544 + rsync_xa *new_rxas;
546 + new_alloc = x->alloc < RSYNC_XAL_INITIAL ? RSYNC_XAL_INITIAL : x->alloc * 2;
547 + new_rxas = realloc_array(x->rxas, rsync_xa, new_alloc);
549 + out_of_memory("rsync_xal_get");
550 + x->alloc = new_alloc;
551 + x->rxas = new_rxas;
553 + datum_size = sys_lgetxattr(fname, name, datumbuf, datumbuf_len);
554 + if (datum_size > (ssize_t)datumbuf_len) {
558 + if (datum_size < 0) {
559 + if (errno == ENOTSUP)
561 + if (errno == ERANGE) {
562 + datum_size = sys_lgetxattr(fname, name, NULL, 0);
563 + if (datum_size < 0) {
565 + "%s: rsync_xal_get: lgetxattr %s failed: %s\n",
566 + fname, name, strerror(errno));
569 + datumbuf = realloc_array(datumbuf, char, datum_size + 1);
571 + out_of_memory("rsync_xal_get");
572 + datumbuf_len = datum_size;
573 + datum_size = sys_lgetxattr(fname, name, datumbuf, datumbuf_len);
574 + if (datum_size < 0) {
576 + "%s: rsync_xal_get: re-lgetxattr of %s failed: %s\n",
577 + name, fname, strerror(errno));
582 + "%s: rsync_xal_get: lgetxattr %s failed: %s\n",
583 + fname, name, strerror(errno));
587 + ptr = new_array(char, len + datum_size);
589 + out_of_memory("rsync_xal_get");
592 + memcpy(ptr + len, datumbuf, datum_size);
593 + x->rxas[curr_rsync_xal.count].name_len = len;
594 + x->rxas[curr_rsync_xal.count].name = ptr;
595 + x->rxas[curr_rsync_xal.count].datum_len = datum_size;
596 + x->rxas[curr_rsync_xal.count].datum = ptr + len;
599 + if (x->count > 1) {
600 + qsort(x->rxas, x->count, sizeof (rsync_xa), rsync_xal_compare_names);
606 +/* generate the xattr(s) for this flist entry;
607 + * xattr(s) are either sent or cleaned-up by send_xattr() below */
609 +int make_xattr(UNUSED(const struct file_struct *file), const char *fname)
611 + rsync_xal_get(fname, &curr_rsync_xal);
612 + return 0; /* TODO: This needs to return 1 if no xattrs changed! */
615 +static ssize_t rsync_xal_find_matching(void)
620 + for (i = 0; i < rsync_xal_l.count; i++) {
621 + /* Wrong number of elements? */
622 + if (rsync_xal_l.rxals[i].count != curr_rsync_xal.count)
624 + /* any elements different? */
625 + for (j = 0; j < curr_rsync_xal.count; j++) {
626 + if (rsync_xal_l.rxals[i].rxas[j].name_len != curr_rsync_xal.rxas[j].name_len
627 + || rsync_xal_l.rxals[i].rxas[j].datum_len != curr_rsync_xal.rxas[j].datum_len
628 + || strcmp(rsync_xal_l.rxals[i].rxas[j].name, curr_rsync_xal.rxas[j].name)
629 + || memcmp(rsync_xal_l.rxals[i].rxas[j].datum, curr_rsync_xal.rxas[j].datum, curr_rsync_xal.rxas[j].datum_len))
632 + /* no differences found. This is The One! */
633 + if (j == curr_rsync_xal.count)
636 + if (i < rsync_xal_l.count)
638 + return (ssize_t)-1;
641 +/* Store curr_rsync_xal on the end of rsync_xal_l */
642 +static void rsync_xal_store(void)
644 + if (rsync_xal_l.count <= rsync_xal_l.alloc) {
648 + new_alloc = rsync_xal_l.count < RSYNC_XAL_LIST_INITIAL ? RSYNC_XAL_LIST_INITIAL : rsync_xal_l.count * 2;
649 + new_xal = realloc_array(rsync_xal_l.rxals, rsync_xal, new_alloc);
651 + out_of_memory("rsync_xal_store");
652 + rsync_xal_l.alloc = new_alloc;
653 + rsync_xal_l.rxals = new_xal;
655 + rsync_xal_l.rxals[rsync_xal_l.count] = curr_rsync_xal;
656 + rsync_xal_l.count++;
657 + curr_rsync_xal.count = 0;
658 + curr_rsync_xal.alloc = 0;
661 +/* send the make_xattr()-generated xattr list for this flist entry,
662 + * or clean up after an flist entry that's not being sent (f == -1) */
664 +void send_xattr(UNUSED(const struct file_struct *file), int f)
669 + rsync_xal_free(&curr_rsync_xal);
672 + index = rsync_xal_find_matching();
674 + write_byte(f, 'x');
675 + write_int(f, index);
676 + rsync_xal_free(&curr_rsync_xal);
681 + count = curr_rsync_xal.count;
682 + write_byte(f, 'X');
683 + write_int(f, count);
684 + for (rxa = curr_rsync_xal.rxas; count--; rxa++) {
685 + write_int(f, rxa->name_len);
686 + write_int(f, rxa->datum_len);
687 + write_buf(f, rxa->name, rxa->name_len);
688 + write_buf(f, rxa->datum, rxa->datum_len);
695 +/* ------------------------------------------------------------------------- */
696 +/* receive and build the rsync_xattr_lists */
698 +void receive_xattr(struct file_struct *file, int f)
703 + fname = f_name(file, NULL);
704 + tag = read_byte(f);
705 + if (tag != 'X' && tag != 'x') {
707 + "%s: receive_xattr: unknown extended attribute type tag: %c\n",
709 + exit_cleanup(RERR_STREAMIO);
712 + if (fxil.alloc <= fxil.count) {
716 + if (fxil.count < RSYNC_XAL_LIST_INITIAL)
717 + new_alloc = fxil.alloc + RSYNC_XAL_LIST_INITIAL;
719 + new_alloc = fxil.alloc * 2;
720 + new_ptr = realloc_array(fxil.filexalidxs, file_xal_index, new_alloc);
722 + out_of_memory("receive_xattr");
723 + if (verbose >= 3) {
724 + rprintf(FINFO, "receive_xattr to %lu bytes, %s move\n",
725 + (unsigned long)(new_alloc * sizeof (file_xal_index)),
726 + fxil.filexalidxs == new_ptr ? "did not" : "did");
729 + fxil.filexalidxs = new_ptr;
730 + fxil.alloc = new_alloc;
733 + fxil.filexalidxs[fxil.count].file = file;
738 + fxil.filexalidxs[fxil.count].xalidx = rsync_xal_l.count;
740 + count = read_int(f);
741 + curr_rsync_xal.count = count;
742 + curr_rsync_xal.alloc = count;
743 + curr_rsync_xal.rxas = new_array(rsync_xa, count);
744 + if (!curr_rsync_xal.rxas)
745 + out_of_memory("receive_xattr");
746 + for (i = 0; i < count; i++) {
751 + name_len = read_int(f);
752 + datum_len = read_int(f);
753 + if (name_len + datum_len < name_len)
754 + out_of_memory("receive_xattr"); /* overflow */
755 + ptr = new_array(char, name_len + datum_len);
757 + out_of_memory("receive_xattr");
758 + read_buf(f, ptr, name_len);
759 + read_buf(f, ptr + name_len, datum_len);
760 + curr_rsync_xal.rxas[i].name_len = name_len;
761 + curr_rsync_xal.rxas[i].datum_len = datum_len;
762 + curr_rsync_xal.rxas[i].name = ptr;
763 + curr_rsync_xal.rxas[i].datum = ptr + name_len;
769 + index = read_int(f);
770 + if (index >= rsync_xal_l.count) {
771 + rprintf(FERROR, "%s: receive_xattr: xa index %lu out of range\n",
772 + fname, (unsigned long)index);
773 + exit_cleanup(RERR_STREAMIO);
775 + fxil.filexalidxs[fxil.count].xalidx = index;
780 +static int rsync_xal_set(const char *fname, rsync_xal *x)
785 + for (i = 0; i < x->count; i++) {
786 + int status = sys_lsetxattr(fname, x->rxas[i].name, x->rxas[i].datum, x->rxas[i].datum_len, 0);
788 + rprintf(FERROR, "%s: rsync_xal_set: lsetxattr %s failed: %s\n",
789 + fname, x->rxas[i].name, strerror(errno));
796 +/* for duplicating xattrs on backups when using backup_dir */
798 +int dup_xattr(const char *orig, const char *bak)
802 + if (rsync_xal_get(orig, &backup_xal) < 0)
803 + ret = rsync_xal_set(bak, &backup_xal);
806 + rsync_xal_free(&backup_xal);
811 +void push_keep_backup_xattr(const struct file_struct *file, const char *orig, const char *dest)
813 + backup_orig_file = file;
814 + backup_orig_fname = orig;
815 + backup_dest_fname = dest;
816 + rsync_xal_get(orig, &backup_xal);
819 +static int set_keep_backup_xal(void)
821 + return rsync_xal_set(backup_dest_fname, &backup_xal);
824 +void cleanup_keep_backup_xattr(void)
826 + backup_orig_file = NULL;
827 + backup_orig_fname = null_string;
828 + backup_dest_fname = null_string;
829 + rsync_xal_free(&backup_xal);
832 +static int file_xal_index_compare(const void *x1, const void *x2)
834 + const file_xal_index *xa1;
835 + const file_xal_index *xa2;
839 + return xa1->file == xa2->file ? 0 : xa1->file < xa2->file ? -1 : 1;
842 +void sort_file_xattr_index_lists(void)
844 + qsort(fxil.filexalidxs, fxil.count, sizeof (file_xal_index), file_xal_index_compare);
847 +static int find_file_xal_index(const struct file_struct *file)
849 + int low = 0, high = fxil.count;
850 + const struct file_struct *file_mid;
853 + rprintf(FERROR, "find_file_xal_index: no entries\n");
854 + exit_cleanup(RERR_STREAMIO);
858 + int mid = (high + low) / 2;
859 + file_mid = fxil.filexalidxs[mid].file;
860 + if (file_mid == file)
861 + return fxil.filexalidxs[mid].xalidx;
862 + if (file_mid > file)
866 + } while (low < high);
868 + file_mid = fxil.filexalidxs[low].file;
869 + if (file_mid == file)
870 + return fxil.filexalidxs[low].xalidx;
873 + "find_file_xal_index: can't find entry for file in list\n");
874 + exit_cleanup(RERR_STREAMIO);
878 +/* set extended attributes on rsync-ed or keep_backup-ed file */
880 +int set_xattr(const char *fname, const struct file_struct *file)
886 + return 1; /* FIXME: --dry-run needs to compute this value */
888 + if (file == backup_orig_file) {
889 + if (!strcmp(fname, backup_dest_fname))
890 + return set_keep_backup_xal();
892 + xalidx = find_file_xal_index(file);
893 + x = &(rsync_xal_l.rxals[xalidx]);
895 + return rsync_xal_set(fname, x);
898 +#endif /* SUPPORT_XATTRS */