1 This patch adds support for HFS+ compression.
3 Written by Mike Bombich. Taken from http://www.bombich.com/rsync.html
5 Modified by Wayne to fix some issues and tweak the implementation a bit.
6 This compiles on OS X and passes the testsuite, but otherwise UNTESTED!
8 To use this patch, run these commands for a successful build:
10 patch -p1 <patches/fileflags.diff
11 patch -p1 <patches/crtimes.diff
12 patch -p1 <patches/hfs-compression.diff
18 - Should rsync try to treat the compressed data as file data and use the
19 rsync algorithm on the data transfer?
21 based-on: patch/master/crtimes
22 diff --git a/flist.c b/flist.c
25 @@ -1565,6 +1565,9 @@ static struct file_struct *send_file_name(int f, struct file_list *flist,
27 if (preserve_xattrs) {
28 sx.st.st_mode = file->mode;
29 + if (preserve_fileflags)
30 + sx.st.st_flags = F_FFLAGS(file);
31 + sx.st.st_mtime = file->modtime; /* get_xattr needs mtime for decmpfs xattrs */
32 if (get_xattr(fname, &sx) < 0) {
33 io_error |= IOERR_GENERAL;
35 diff --git a/generator.c b/generator.c
38 @@ -37,6 +37,7 @@ extern int implied_dirs;
39 extern int keep_dirlinks;
40 extern int preserve_acls;
41 extern int preserve_xattrs;
42 +extern int preserve_hfs_compression;
43 extern int preserve_links;
44 extern int preserve_devices;
45 extern int preserve_specials;
46 @@ -1782,6 +1783,14 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
49 sx.st.st_size = F_LENGTH(fuzzy_file);
50 +#ifdef SUPPORT_HFS_COMPRESSION
51 + if (sx.st.st_flags & UF_COMPRESSED) {
52 + if (preserve_hfs_compression)
55 + sx.st.st_flags &= ~UF_COMPRESSED;
59 fnamecmp = fnamecmpbuf;
61 @@ -1949,6 +1958,18 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
65 +#ifdef SUPPORT_HFS_COMPRESSION
66 + if (F_FFLAGS(file) & UF_COMPRESSED) {
67 + /* At this point the attrs have already been copied, we don't need to transfer a data fork
68 + * If my filesystem doesn't support HFS compression, the existing file's content
69 + * will not be automatically truncated, so we'll do that manually here */
70 + if (preserve_hfs_compression && sx.st.st_size > 0) {
71 + if (ftruncate(fd, 0) == 0)
77 if (statret != 0 || whole_file)
78 write_sum_head(f_out, NULL);
79 else if (sx.st.st_size <= 0) {
80 diff --git a/lib/sysxattrs.c b/lib/sysxattrs.c
85 #include "sysxattrs.h"
87 +extern int preserve_hfs_compression;
91 #ifdef HAVE_OSX_XATTRS
92 +#ifndef XATTR_SHOWCOMPRESSION
93 +#define XATTR_SHOWCOMPRESSION 0x0020
95 #define GETXATTR_FETCH_LIMIT (64*1024*1024)
97 +int xattr_options = XATTR_NOFOLLOW;
100 #if defined HAVE_LINUX_XATTRS
101 @@ -59,7 +66,12 @@ ssize_t sys_llistxattr(const char *path, char *list, size_t size)
103 ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
105 - ssize_t len = getxattr(path, name, value, size, 0, XATTR_NOFOLLOW);
108 + if (preserve_hfs_compression)
109 + xattr_options |= XATTR_SHOWCOMPRESSION;
111 + len = getxattr(path, name, value, size, 0, xattr_options);
113 /* If we're retrieving data, handle resource forks > 64MB specially */
114 if (value != NULL && len == GETXATTR_FETCH_LIMIT && (size_t)len < size) {
115 @@ -67,7 +79,7 @@ ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t si
116 u_int32_t offset = len;
117 size_t data_retrieved = len;
118 while (data_retrieved < size) {
119 - len = getxattr(path, name, value + offset, size - data_retrieved, offset, XATTR_NOFOLLOW);
120 + len = getxattr(path, name, value + offset, size - data_retrieved, offset, xattr_options);
123 data_retrieved += len;
124 @@ -91,12 +103,16 @@ int sys_lsetxattr(const char *path, const char *name, const void *value, size_t
126 int sys_lremovexattr(const char *path, const char *name)
128 - return removexattr(path, name, XATTR_NOFOLLOW);
129 + if (preserve_hfs_compression)
130 + xattr_options |= XATTR_SHOWCOMPRESSION;
131 + return removexattr(path, name, xattr_options);
134 ssize_t sys_llistxattr(const char *path, char *list, size_t size)
136 - return listxattr(path, list, size, XATTR_NOFOLLOW);
137 + if (preserve_hfs_compression)
138 + xattr_options |= XATTR_SHOWCOMPRESSION;
139 + return listxattr(path, list, size, xattr_options);
142 #elif HAVE_FREEBSD_XATTRS
143 diff --git a/main.c b/main.c
147 #ifdef SUPPORT_FORCE_CHANGE
148 #include <sys/sysctl.h>
150 +#ifdef SUPPORT_HFS_COMPRESSION
151 +#include <sys/attr.h> /* For getattrlist() */
152 +#include <sys/mount.h> /* For statfs() */
156 extern int list_only;
157 @@ -53,6 +57,7 @@ extern int copy_dirlinks;
158 extern int copy_unsafe_links;
159 extern int keep_dirlinks;
160 extern int preserve_hard_links;
161 +extern int preserve_hfs_compression;
162 extern int protocol_version;
163 extern int force_change;
164 extern int file_total;
165 @@ -108,6 +113,7 @@ int daemon_over_rsh = 0;
166 mode_t orig_umask = 0;
167 int batch_gen_fd = -1;
168 int sender_keeps_checksum = 0;
169 +int fs_supports_hfs_compression = 0;
171 /* There's probably never more than at most 2 outstanding child processes,
172 * but set it higher, just in case. */
173 @@ -567,6 +573,43 @@ static pid_t do_cmd(char *cmd, char *machine, char *user, char **remote_argv, in
174 return 0; /* not reached */
177 +#ifdef SUPPORT_HFS_COMPRESSION
178 +static void hfs_receiver_check(void)
181 + struct attrlist attrs;
184 + vol_capabilities_set_t caps;
187 + if (preserve_hfs_compression != 1)
188 + return; /* Nothing to check if --hfs-compression option isn't enabled. */
190 + if (statfs(".", &fsb) < 0) {
191 + rsyserr(FERROR, errno, "statfs %s failed", curr_dir);
192 + exit_cleanup(RERR_FILESELECT);
195 + bzero(&attrs, sizeof attrs);
196 + attrs.bitmapcount = ATTR_BIT_MAP_COUNT;
197 + attrs.volattr = ATTR_VOL_CAPABILITIES;
199 + bzero(&attrData, sizeof attrData);
200 + attrData.len = sizeof attrData;
202 + if (getattrlist(fsb.f_mntonname, &attrs, &attrData, sizeof attrData, 0) < 0) {
203 + rsyserr(FERROR, errno, "getattrlist %s failed", curr_dir);
204 + exit_cleanup(RERR_FILESELECT);
207 + if (!(attrData.caps[VOL_CAPABILITIES_FORMAT] & VOL_CAP_FMT_DECMPFS_COMPRESSION)) {
208 + rprintf(FERROR, "The destination filesystem does not support HFS+ compression.\n");
209 + exit_cleanup(RERR_UNSUPPORTED);
214 /* The receiving side operates in one of two modes:
216 * 1. it receives any number of files into a destination directory,
217 @@ -625,6 +668,9 @@ static char *get_local_name(struct file_list *flist, char *dest_path)
218 exit_cleanup(RERR_FILESELECT);
220 filesystem_dev = st.st_dev; /* ensures --force works right w/-x */
221 +#ifdef SUPPORT_HFS_COMPRESSION
222 + hfs_receiver_check();
226 if (file_total > 1) {
227 @@ -685,7 +731,9 @@ static char *get_local_name(struct file_list *flist, char *dest_path)
228 full_fname(dest_path));
229 exit_cleanup(RERR_FILESELECT);
232 +#ifdef SUPPORT_HFS_COMPRESSION
233 + hfs_receiver_check();
238 @@ -705,6 +753,9 @@ static char *get_local_name(struct file_list *flist, char *dest_path)
239 full_fname(dest_path));
240 exit_cleanup(RERR_FILESELECT);
242 +#ifdef SUPPORT_HFS_COMPRESSION
243 + hfs_receiver_check();
248 diff --git a/options.c b/options.c
251 @@ -54,6 +54,7 @@ int preserve_links = 0;
252 int preserve_hard_links = 0;
253 int preserve_acls = 0;
254 int preserve_xattrs = 0;
255 +int preserve_hfs_compression = 0;
256 int preserve_perms = 0;
257 int preserve_fileflags = 0;
258 int preserve_executability = 0;
259 @@ -712,6 +713,10 @@ void usage(enum logcode F)
260 #ifdef SUPPORT_XATTRS
261 rprintf(F," -X, --xattrs preserve extended attributes\n");
263 +#ifdef SUPPORT_HFS_COMPRESSION
264 + rprintf(F," --hfs-compression preserve HFS compression if supported\n");
265 + rprintf(F," --protect-decmpfs preserve HFS compression as xattrs\n");
267 rprintf(F," -o, --owner preserve owner (super-user only)\n");
268 rprintf(F," -g, --group preserve group\n");
269 rprintf(F," --devices preserve device files (super-user only)\n");
270 @@ -974,6 +979,12 @@ static struct poptOption long_options[] = {
271 {"force-uchange", 0, POPT_ARG_VAL, &force_change, USR_IMMUTABLE, 0, 0 },
272 {"force-schange", 0, POPT_ARG_VAL, &force_change, SYS_IMMUTABLE, 0, 0 },
274 +#ifdef SUPPORT_HFS_COMPRESSION
275 + {"hfs-compression", 0, POPT_ARG_VAL, &preserve_hfs_compression, 1, 0, 0 },
276 + {"no-hfs-compression",0, POPT_ARG_VAL, &preserve_hfs_compression, 0, 0, 0 },
277 + {"protect-decmpfs", 0, POPT_ARG_VAL, &preserve_hfs_compression, 2, 0, 0 },
278 + {"no-protect-decmpfs",0, POPT_ARG_VAL, &preserve_hfs_compression, 0, 0, 0 },
280 {"ignore-errors", 0, POPT_ARG_VAL, &ignore_errors, 1, 0, 0 },
281 {"no-ignore-errors", 0, POPT_ARG_VAL, &ignore_errors, 0, 0, 0 },
282 {"max-delete", 0, POPT_ARG_INT, &max_delete, 0, 0, 0 },
283 @@ -2008,6 +2019,15 @@ int parse_arguments(int *argc_p, const char ***argv_p)
287 +#ifdef SUPPORT_HFS_COMPRESSION
288 + if (preserve_hfs_compression) {
289 + if (!preserve_xattrs)
290 + preserve_xattrs = 1;
291 + if (!preserve_fileflags)
292 + preserve_fileflags = 1;
296 if (block_size > MAX_BLOCK_SIZE) {
297 snprintf(err_buf, sizeof err_buf,
298 "--block-size=%lu is too large (max: %u)\n", block_size, MAX_BLOCK_SIZE);
299 @@ -2603,6 +2623,11 @@ void server_options(char **args, int *argc_p)
300 if (preserve_fileflags)
301 args[ac++] = "--fileflags";
303 +#ifdef SUPPORT_HFS_COMPRESSION
304 + if (preserve_hfs_compression)
305 + args[ac++] = preserve_hfs_compression == 1 ? "--hfs-compression" : "--protect-decmpfs";
308 if (do_compression && def_compress_level != Z_DEFAULT_COMPRESSION) {
309 if (asprintf(&arg, "--compress-level=%d", def_compress_level) < 0)
311 diff --git a/rsync.c b/rsync.c
314 @@ -579,8 +579,14 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
315 #ifdef SUPPORT_XATTRS
317 set_stat_xattr(fname, file, new_mode);
318 - if (preserve_xattrs && fnamecmp)
319 + if (preserve_xattrs && fnamecmp) {
320 + uint32 tmpflags = sxp->st.st_flags;
321 + sxp->st.st_flags = F_FFLAGS(file); /* set_xattr() needs to check UF_COMPRESSED */
322 set_xattr(fname, file, fnamecmp, sxp);
323 + sxp->st.st_flags = tmpflags;
324 + if (S_ISDIR(sxp->st.st_mode))
325 + link_stat(fname, &sx2.st, 0);
330 @@ -591,6 +597,9 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
331 if (sxp->st.st_ino == 2 && S_ISDIR(sxp->st.st_mode))
332 flags |= ATTRS_SKIP_CRTIME;
333 if (!(flags & ATTRS_SKIP_MTIME)
334 +#ifdef SUPPORT_HFS_COMPRESSION
335 + && !(sxp->st.st_flags & UF_COMPRESSED) /* setting this alters mtime, so defer to after set_fileflags */
337 && (sxp->st.st_mtime != file->modtime
339 || (NSEC_BUMP(file) && (uint32)sxp->st.ST_MTIME_NSEC != F_MOD_NSEC(file))
340 @@ -653,6 +662,16 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
341 && !set_fileflags(fname, fileflags))
344 +#ifdef SUPPORT_HFS_COMPRESSION
345 + int ret = set_modtime(fname, file->modtime, F_MOD_NSEC(file), new_mode, fileflags);
347 + rsyserr(FERROR_XFER, errno, "failed to set times on %s",
348 + full_fname(fname));
352 + file->flags |= FLAG_TIME_FAILED;
357 diff --git a/rsync.h b/rsync.h
360 @@ -555,6 +555,17 @@ typedef unsigned int size_t;
361 #define ST_FLAGS(st) NO_FFLAGS
364 +#ifndef UF_COMPRESSED
365 +#define UF_COMPRESSED 0x00000020
367 +#ifndef VOL_CAP_FMT_DECMPFS_COMPRESSION
368 +#define VOL_CAP_FMT_DECMPFS_COMPRESSION 0x00010000
371 +#if defined SUPPORT_XATTRS && defined SUPPORT_FILEFLAGS
372 +#define SUPPORT_HFS_COMPRESSION 1
375 /* Find a variable that is either exactly 32-bits or longer.
376 * If some code depends on 32-bit truncation, it will need to
377 * take special action in a "#if SIZEOF_INT32 > 4" section. */
378 diff --git a/rsync.yo b/rsync.yo
381 @@ -367,6 +367,8 @@ to the detailed description below for a complete description. verb(
382 --chmod=CHMOD affect file and/or directory permissions
383 -A, --acls preserve ACLs (implies -p)
384 -X, --xattrs preserve extended attributes
385 + --hfs-compression preserve HFS compression if supported
386 + --protect-decmpfs preserve HFS compression as xattrs
387 -o, --owner preserve owner (super-user only)
388 -g, --group preserve group
389 --devices preserve device files (super-user only)
390 @@ -1176,6 +1178,42 @@ flags on files and directories that are being updated or deleted on the
391 receiving side. It does not try to affect user flags. This option overrides
392 bf(--force-change) and bf(--force-uchange).
394 +dit(bf(--hfs-compression)) This option causes rsync to preserve HFS+
395 +compression if the destination filesystem supports it. If the destination
396 +does not support it, rsync will exit with an error.
398 +Filesystem compression was introduced to HFS+ in Mac OS 10.6. A file that is
399 +compressed has no data in its data fork. Rather, the compressed data is stored
400 +in an extended attribute named com.apple.decmpfs and a file flag is set to
401 +indicate that the file is compressed (UF_COMPRESSED). HFS+ decompresses this
402 +data "on-the-fly" and presents it to the operating system as a normal file.
403 +Normal attempts to copy compressed files (e.g. in the Finder, via cp, ditto,
404 +etc.) will copy the file's decompressed contents, remove the UF_COMPRESSED file
405 +flag, and discard the com.apple.decmpfs extended attribute. This option will
406 +preserve the data in the com.apple.decmpfs extended attribute and ignore the
407 +synthesized data in the file contents.
409 +This option implies both bf(--fileflags) and (--xattrs).
411 +dit(bf(--protect-decmpfs)) The com.apple.decmpfs extended attribute is hidden
412 +by default from list/get xattr calls, therefore normal attempts to copy
413 +compressed files will functionally decompress those files. While this is
414 +desirable behavior when copying files to filesystems that do not support HFS+
415 +compression, it has serious performance and capacity impacts when backing up
416 +or restoring the Mac OS X filesystem.
418 +This option will transfer the com.apple.decmpfs extended attribute regardless
419 +of support on the destination. If a source file is compressed and an existing
420 +file on the destination is not compressed, the data fork of the destination
421 +file will be truncated and the com.apple.decmpfs xattr will be transferred
422 +instead. Note that compressed files will not be readable to the operating
423 +system of the destination if that operating system does not support HFS+
424 +compression. Once restored (with or without this option) to an operating system
425 +that supports HFS+ compression, however, these files will be accessible as
428 +This option implies bf(--fileflags) and bf(--xattrs).
430 dit(bf(--chmod)) This option tells rsync to apply one or more
431 comma-separated "chmod" modes to the permission of the files in the
432 transfer. The resulting value is treated as though it were the permissions
433 diff --git a/t_stub.c b/t_stub.c
436 @@ -32,6 +32,7 @@ int force_change = 0;
437 int preserve_acls = 0;
438 int preserve_times = 0;
439 int preserve_xattrs = 0;
440 +int preserve_hfs_compression = 0;
443 filter_rule_list daemon_filter_list;
444 diff --git a/xattrs.c b/xattrs.c
447 @@ -33,6 +33,7 @@ extern int am_generator;
448 extern int read_only;
449 extern int list_only;
450 extern int preserve_xattrs;
451 +extern int preserve_hfs_compression;
452 extern int preserve_links;
453 extern int preserve_devices;
454 extern int preserve_specials;
455 @@ -42,6 +43,10 @@ extern int saw_xattr_filter;
456 #define RSYNC_XAL_INITIAL 5
457 #define RSYNC_XAL_LIST_INITIAL 100
459 +#define GXD_NO_MISSING_ERROR (1<<0)
460 +#define GXD_OMIT_COMPRESSED (1<<1)
461 +#define GXD_FILE_IS_COMPRESSED (1<<2)
463 #define MAX_FULL_DATUM 32
465 #define HAS_PREFIX(str, prfx) (*(str) == *(prfx) \
466 @@ -74,6 +79,17 @@ extern int saw_xattr_filter;
467 #define XDEF_ACL_SUFFIX "dacl"
468 #define XDEF_ACL_ATTR RSYNC_PREFIX "%" XDEF_ACL_SUFFIX
470 +#define APPLE_PREFIX "com.apple."
471 +#define APLPRE_LEN ((int)sizeof APPLE_PREFIX - 1)
472 +#define DECMPFS_SUFFIX "decmpfs"
473 +#define RESOURCEFORK_SUFFIX "ResourceFork"
475 +#define UNREAD_DATA ((char *)1)
477 +#if MAX_DIGEST_LEN < SIZEOF_TIME_T
478 +#error MAX_DIGEST_LEN is too small to hold an mtime
483 size_t datum_len, name_len;
484 @@ -185,8 +201,7 @@ static ssize_t get_xattr_names(const char *fname)
485 /* On entry, the *len_ptr parameter contains the size of the extra space we
486 * should allocate when we create a buffer for the data. On exit, it contains
487 * the length of the datum. */
488 -static char *get_xattr_data(const char *fname, const char *name, size_t *len_ptr,
489 - int no_missing_error)
490 +static char *get_xattr_data(const char *fname, const char *name, size_t *len_ptr, int flags)
492 size_t datum_len = sys_lgetxattr(fname, name, NULL, 0);
493 size_t extra_len = *len_ptr;
494 @@ -195,7 +210,7 @@ static char *get_xattr_data(const char *fname, const char *name, size_t *len_ptr
495 *len_ptr = datum_len;
497 if (datum_len == (size_t)-1) {
498 - if (errno == ENOTSUP || no_missing_error)
499 + if (errno == ENOTSUP || flags & GXD_NO_MISSING_ERROR)
501 rsyserr(FERROR_XFER, errno,
502 "get_xattr_data: lgetxattr(%s,\"%s\",0) failed",
503 @@ -203,6 +218,15 @@ static char *get_xattr_data(const char *fname, const char *name, size_t *len_ptr
507 + if (flags & GXD_OMIT_COMPRESSED && datum_len > MAX_FULL_DATUM
508 + && HAS_PREFIX(name, APPLE_PREFIX)
509 + && (strcmp(name+APLPRE_LEN, DECMPFS_SUFFIX) == 0
510 + || (flags & GXD_FILE_IS_COMPRESSED && strcmp(name+APLPRE_LEN, RESOURCEFORK_SUFFIX) == 0))) {
511 + /* If we are omitting compress-file-related data, we don't want to
512 + * actually read this data. */
513 + return UNREAD_DATA;
516 if (!datum_len && !extra_len)
517 extra_len = 1; /* request non-zero amount of memory */
518 if (datum_len + extra_len < datum_len)
519 @@ -231,7 +255,31 @@ static char *get_xattr_data(const char *fname, const char *name, size_t *len_ptr
523 -static int rsync_xal_get(const char *fname, item_list *xalp)
524 +static void checksum_xattr_data(char *sum, const char *datum, size_t datum_len, stat_x *sxp)
526 + if (datum == UNREAD_DATA) {
527 + /* For abbreviated compressed data, we store the file's mtime as the checksum. */
528 + SIVAL(sum, 0, sxp->st.st_mtime);
529 +#if SIZEOF_TIME_T > 4
530 + SIVAL(sum, 4, sxp->st.st_mtime >> 32);
531 +#if MAX_DIGEST_LEN > 8
532 + memset(sum + 8, 0, MAX_DIGEST_LEN - 8);
535 +#if MAX_DIGEST_LEN > 4
536 + memset(sum + 4, 0, MAX_DIGEST_LEN - 4);
540 + sum_init(-1, checksum_seed);
541 + sum_update(datum, datum_len);
546 +$$$ERROR$$$ the old patch needs reworking since rsync_xal_get() has totally changed!
548 +static int rsync_xal_get(const char *fname, stat_x *sxp)
550 ssize_t list_len, name_len;
551 size_t datum_len, name_offset;
552 @@ -240,7 +288,8 @@ static int rsync_xal_get(const char *fname, item_list *xalp)
553 int user_only = am_sender ? 0 : !am_root;
558 + item_list *xalp = sxp->xattr;
560 /* This puts the name list into the "namebuf" buffer. */
561 if ((list_len = get_xattr_names(fname)) < 0)
562 @@ -271,11 +320,15 @@ static int rsync_xal_get(const char *fname, item_list *xalp)
565 datum_len = name_len; /* Pass extra size to get_xattr_data() */
566 - if (!(ptr = get_xattr_data(fname, name, &datum_len, 0)))
567 + flags = GXD_OMIT_COMPRESSED;
568 + if (preserve_hfs_compression && sxp->st.st_flags & UF_COMPRESSED)
569 + flags |= GXD_FILE_IS_COMPRESSED;
570 + if (!(ptr = get_xattr_data(fname, name, &datum_len, flags)))
573 if (datum_len > MAX_FULL_DATUM) {
574 /* For large datums, we store a flag and a checksum. */
576 name_offset = 1 + MAX_DIGEST_LEN;
577 sum_init(-1, checksum_seed);
578 sum_update(ptr, datum_len);
579 @@ -284,7 +337,9 @@ static int rsync_xal_get(const char *fname, item_list *xalp)
580 if (!(ptr = new_array(char, name_offset + name_len)))
581 out_of_memory("rsync_xal_get");
582 *ptr = XSTATE_ABBREV;
584 + checksum_xattr_data(ptr+1, datum, datum_len, sxp);
585 + if (datum != UNREAD_DATA)
588 name_offset = datum_len;
590 @@ -330,7 +385,7 @@ int get_xattr(const char *fname, stat_x *sxp)
591 } else if (IS_MISSING_FILE(sxp->st))
594 - if (rsync_xal_get(fname, sxp->xattr) < 0) {
595 + if (rsync_xal_get(fname, sxp) < 0) {
599 @@ -367,6 +422,8 @@ int copy_xattrs(const char *source, const char *dest)
601 if (!(ptr = get_xattr_data(source, name, &datum_len, 0)))
603 + if (ptr == UNREAD_DATA)
604 + continue; /* XXX Is this right? */
605 if (sys_lsetxattr(dest, name, ptr, datum_len) < 0) {
606 int save_errno = errno ? errno : EINVAL;
607 rsyserr(FERROR_XFER, errno,
608 @@ -457,6 +514,7 @@ static int find_matching_xattr(const item_list *xalp)
615 /* Store *xalp on the end of rsync_xal_l */
616 @@ -678,11 +736,13 @@ void send_xattr_request(const char *fname, struct file_struct *file, int f_out)
618 /* Re-read the long datum. */
619 if (!(ptr = get_xattr_data(fname, rxa->name, &len, 0))) {
620 - rprintf(FERROR_XFER, "failed to re-read xattr %s for %s\n", rxa->name, fname);
621 + if (errno != ENOTSUP && errno != ENOATTR)
622 + rprintf(FERROR_XFER, "failed to re-read xattr %s for %s\n", rxa->name, fname);
623 write_varint(f_out, 0);
627 + assert(ptr != UNREAD_DATA);
628 write_varint(f_out, len); /* length might have changed! */
629 write_bigbuf(f_out, ptr, len);
631 @@ -969,7 +1029,7 @@ static int rsync_xal_set(const char *fname, item_list *xalp,
632 int user_only = am_root <= 0;
636 + int flags, ret = 0;
638 /* This puts the current name list into the "namebuf" buffer. */
639 if ((list_len = get_xattr_names(fname)) < 0)
640 @@ -982,7 +1042,10 @@ static int rsync_xal_set(const char *fname, item_list *xalp,
642 /* See if the fnamecmp version is identical. */
643 len = name_len = rxas[i].name_len;
644 - if ((ptr = get_xattr_data(fnamecmp, name, &len, 1)) == NULL) {
645 + flags = GXD_OMIT_COMPRESSED | GXD_NO_MISSING_ERROR;
646 + if (preserve_hfs_compression && sxp->st.st_flags & UF_COMPRESSED)
647 + flags |= GXD_FILE_IS_COMPRESSED;
648 + if ((ptr = get_xattr_data(fnamecmp, name, &len, flags)) == NULL) {
652 @@ -991,6 +1054,8 @@ static int rsync_xal_set(const char *fname, item_list *xalp,
656 + if (ptr == UNREAD_DATA)
657 + continue; /* XXX Is this right? */
658 if (len != rxas[i].datum_len) {
661 @@ -1068,6 +1133,10 @@ static int rsync_xal_set(const char *fname, item_list *xalp,
665 +#ifdef HAVE_OSX_XATTRS
666 + rsync_xal_free(xalp); /* Free this because we aren't using find_matching_xattr(). */
672 @@ -1117,7 +1186,7 @@ char *get_xattr_acl(const char *fname, int is_access_acl, size_t *len_p)
674 const char *name = is_access_acl ? XACC_ACL_ATTR : XDEF_ACL_ATTR;
675 *len_p = 0; /* no extra data alloc needed from get_xattr_data() */
676 - return get_xattr_data(fname, name, len_p, 1);
677 + return get_xattr_data(fname, name, len_p, GXD_NO_MISSING_ERROR);
680 int set_xattr_acl(const char *fname, int is_access_acl, const char *buf, size_t buf_len)
681 @@ -1260,11 +1329,33 @@ int set_stat_xattr(const char *fname, struct file_struct *file, mode_t new_mode)
685 +#ifdef SUPPORT_HFS_COMPRESSION
686 +static inline void hfs_compress_tweaks(STRUCT_STAT *fst)
688 + if (fst->st_flags & UF_COMPRESSED) {
689 + if (preserve_hfs_compression) {
690 + /* We're sending the compression xattr, not the decompressed data fork.
691 + * Setting rsync's idea of the file size to 0 effectively prevents the
692 + * transfer of the data fork. */
695 + /* If the sender's filesystem supports compression, then we'll be able
696 + * to send the decompressed data fork and the decmpfs xattr will be
697 + * hidden (not sent). As such, we need to strip the compression flag. */
698 + fst->st_flags &= ~UF_COMPRESSED;
704 int x_stat(const char *fname, STRUCT_STAT *fst, STRUCT_STAT *xst)
706 int ret = do_stat(fname, fst);
707 if ((ret < 0 || get_stat_xattr(fname, -1, fst, xst) < 0) && xst)
709 +#ifdef SUPPORT_HFS_COMPRESSION
710 + hfs_compress_tweaks(fst);
715 @@ -1273,6 +1364,9 @@ int x_lstat(const char *fname, STRUCT_STAT *fst, STRUCT_STAT *xst)
716 int ret = do_lstat(fname, fst);
717 if ((ret < 0 || get_stat_xattr(fname, -1, fst, xst) < 0) && xst)
719 +#ifdef SUPPORT_HFS_COMPRESSION
720 + hfs_compress_tweaks(fst);
725 @@ -1281,6 +1375,9 @@ int x_fstat(int fd, STRUCT_STAT *fst, STRUCT_STAT *xst)
726 int ret = do_fstat(fd, fst);
727 if ((ret < 0 || get_stat_xattr(NULL, fd, fst, xst) < 0) && xst)
729 +#ifdef SUPPORT_HFS_COMPRESSION
730 + hfs_compress_tweaks(fst);