-+/* Read the xattr(s) for this filename. */
-+int get_xattr(const char *fname, statx *sxp)
-+{
-+ sxp->xattr = new(item_list);
-+ *sxp->xattr = empty_xattr;
-+ if (rsync_xal_get(fname, sxp->xattr) < 0) {
-+ free_xattr(sxp);
-+ return -1;
-+ }
-+ return 0;
-+}
-+
-+static int find_matching_xattr(item_list *xalp)
-+{
-+ size_t i, j;
-+ item_list *lst = rsync_xal_l.items;
-+
-+ for (i = 0; i < rsync_xal_l.count; i++) {
-+ rsync_xa *rxas1 = lst[i].items;
-+ rsync_xa *rxas2 = xalp->items;
-+
-+ /* Wrong number of elements? */
-+ if (lst[i].count != xalp->count)
-+ continue;
-+ /* any elements different? */
-+ for (j = 0; j < xalp->count; j++) {
-+ if (rxas1[j].name_len != rxas2[j].name_len
-+ || rxas1[j].datum_len != rxas2[j].datum_len
-+ || strcmp(rxas1[j].name, rxas2[j].name)
-+ || memcmp(rxas1[j].datum, rxas2[j].datum, rxas2[j].datum_len))
-+ break;
-+ }
-+ /* no differences found. This is The One! */
-+ if (j == xalp->count)
-+ return i;
-+ }
-+
-+ return -1;
-+}
-+
-+/* Store *xalp on the end of rsync_xal_l */
-+static void rsync_xal_store(item_list *xalp)
-+{
-+ item_list *new_lst = EXPAND_ITEM_LIST(&rsync_xal_l, item_list, RSYNC_XAL_LIST_INITIAL);
-+ /* Since the following call starts a new list, we know it will hold the
-+ * entire initial-count, not just enough space for one new item. */
-+ *new_lst = empty_xattr;
-+ (void)EXPAND_ITEM_LIST(new_lst, rsync_xa, xalp->count);
-+ memcpy(new_lst->items, xalp->items, xalp->count * sizeof (rsync_xa));
-+ new_lst->count = xalp->count;
-+ xalp->count = 0;
-+}
-+
-+/* Send the make_xattr()-generated xattr list for this flist entry. */
-+void send_xattr(statx *sxp, int f)
-+{
-+ int ndx = find_matching_xattr(sxp->xattr);
-+ if (ndx != -1) {
-+ write_byte(f, 'x');
-+ write_int(f, ndx);
-+ rsync_xal_free(sxp->xattr);
-+ } else {
-+ rsync_xa *rxa;
-+ int count = sxp->xattr->count;
-+ write_byte(f, 'X');
-+ write_int(f, count);
-+ for (rxa = sxp->xattr->items; count--; rxa++) {
-+#ifdef HAVE_LINUX_XATTRS
-+ write_int(f, rxa->name_len);
-+ write_int(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 (strncmp(rxa->name, RSYNC_PREFIX, RPRE_LEN) == 0) {
-+ write_int(f, rxa->name_len - RPRE_LEN);
-+ write_int(f, rxa->datum_len);
-+ write_buf(f, rxa->name + RPRE_LEN, rxa->name_len - RPRE_LEN);
-+ } else {
-+ write_int(f, rxa->name_len + UPRE_LEN);
-+ write_int(f, rxa->datum_len);
-+ write_buf(f, USER_PREFIX, UPRE_LEN);
-+ write_buf(f, rxa->name, rxa->name_len);
-+ }
-+#endif
-+ write_buf(f, rxa->datum, rxa->datum_len);
-+ }
-+ rsync_xal_store(sxp->xattr); /* adds item to rsync_xal_l */
-+ }
-+ free_xattr(sxp);
-+}
-+
-+/* ------------------------------------------------------------------------- */
-+
-+/* receive and build the rsync_xattr_lists */
-+void receive_xattr(struct file_struct *file, int f)
-+{
-+ static item_list temp_xattr = EMPTY_ITEM_LIST;
-+ char *ndx_ptr = (char*)file + file_struct_len;
-+ int ndx, tag = read_byte(f);
-+
-+ if (tag == 'X') {
-+ int i, count = read_int(f);
-+ for (i = 0; i < count; i++) {
-+ char *ptr, *name;
-+ rsync_xa *rxa;
-+ size_t name_len = read_int(f);
-+ size_t datum_len = read_int(f);
-+ if (name_len + datum_len < name_len)
-+ out_of_memory("receive_xattr"); /* overflow */
-+#ifndef HAVE_LINUX_XATTRS
-+ if (name_len + datum_len + RPRE_LEN < RPRE_LEN)
-+ out_of_memory("receive_xattr"); /* overflow */
-+#endif
-+ ptr = new_array(char, name_len + datum_len + RPRE_LEN);
-+ if (!ptr)
-+ out_of_memory("receive_xattr");
-+ name = ptr + datum_len + RPRE_LEN;
-+ read_buf(f, name, name_len);
-+ read_buf(f, ptr, datum_len);
-+#ifdef HAVE_LINUX_XATTRS
-+ /* Non-root can only save the user namespace. */
-+ if (!am_root && strncmp(name, USER_PREFIX, UPRE_LEN) != 0) {
-+ free(ptr);
-+ continue;
-+ }
-+#else
-+ /* This OS only has a user namespace, so we either
-+ * strip the user prefix, or we put a non-user
-+ * namespace inside our rsync hierarchy. */
-+ if (strncmp(name, USER_PREFIX, UPRE_LEN) == 0) {
-+ name += UPRE_LEN;
-+ name_len -= UPRE_LEN;
-+ } else {
-+ name -= RPRE_LEN;
-+ name_len += RPRE_LEN;
-+ memcpy(name, RSYNC_PREFIX, RPRE_LEN);
-+ }
-+#endif
-+ rxa = EXPAND_ITEM_LIST(&temp_xattr, rsync_xa, count);
-+ rxa->name = name;
-+ rxa->datum = ptr;
-+ rxa->name_len = name_len;
-+ rxa->datum_len = datum_len;
-+ }
-+ ndx = rsync_xal_l.count; /* pre-incremented count */
-+ rsync_xal_store(&temp_xattr); /* adds item to rsync_xal_l */
-+ } else if (tag == 'x') {
-+ ndx = read_int(f);
-+ if (ndx < 0 || (size_t)ndx >= rsync_xal_l.count) {
-+ rprintf(FERROR, "%s: receive_xattr: xa index %d out of range\n",
-+ f_name(file, NULL), ndx);
-+ exit_cleanup(RERR_STREAMIO);
-+ }
-+ } else {
-+ rprintf(FERROR,
-+ "%s: receive_xattr: unknown extended attribute type tag: %c\n",
-+ f_name(file, NULL), tag);
-+ exit_cleanup(RERR_STREAMIO);
-+ }
-+
-+ SIVAL(ndx_ptr, 0, ndx);
-+}
-+
-+/* Turn the xattr data in statx into cached xattr data, setting the index
-+ * values in the file struct. */
-+void cache_xattr(struct file_struct *file, statx *sxp)
-+{
-+ char *ndx_ptr = (char*)file + file_struct_len;